unsubscribeFromScript method

void unsubscribeFromScript(
  1. ScriptType type,
  2. String payload
)

Unsubscribe from the given script type and payload

Implementation

void unsubscribeFromScript(ScriptType type, String payload) {
  // Build sub according to chronik expected type
  final subscription = WsSubScriptClient(
    scriptType: type.value,
    payload: payload,
  );

  // Find the requested unsub script and remove it
  final key = '${type.value}:$payload';
  if (!subs.scripts.contains(key)) {
    // If we cannot find this subscription in this.subs, throw an error
    // We do not want an app developer thinking they have unsubscribed from something
    throw ValidationException('No existing sub at ${type.value}, $payload');
  }

  // Remove the requested subscription from this.subs
  subs.scripts.remove(key);

  if (ws != null) {
    _subUnsubScript(true, subscription);
  }
}