onStatusChange method

Function onStatusChange(
  1. void callback(
    1. dynamic value
    ), [
  2. void errorsHandler(
    1. dynamic value
    )?
])

Allows to subscribe to connection status changes and handle connection errors.

Implementation

Function onStatusChange(void Function(dynamic value) callback,
    [void Function(dynamic value)? errorsHandler]) {
  _statusChangeSubscriptions.add(callback);
  if (errorsHandler != null) {
    _statusChangeErrorSubscriptions.add(errorsHandler);
  }

  unsubscribe() {
    if (_statusChangeSubscriptions.contains(callback)) {
      _statusChangeSubscriptions.remove(callback);
    }
    if (errorsHandler != null &&
        _statusChangeErrorSubscriptions.contains(errorsHandler)) {
      _statusChangeErrorSubscriptions.remove(errorsHandler);
    }
  }

  return unsubscribe;
}