LiveQueryReconnectingController constructor

LiveQueryReconnectingController(
  1. Function _reconnect,
  2. Stream<LiveQueryClientEvent> _eventStream,
  3. bool debug
)

Implementation

LiveQueryReconnectingController(
  this._reconnect,
  this._eventStream,
  this.debug,
) {
  final ParseConnectivityProvider? connectivityProvider =
      ParseCoreData().connectivityProvider;
  if (connectivityProvider != null) {
    connectivityProvider.checkConnectivity().then(_connectivityChanged);
    connectivityProvider.connectivityStream.listen(_connectivityChanged);
  } else {
    print(
        'LiveQuery does not work, if there is no ParseConnectivityProvider provided.');
  }
  _eventStream.listen((LiveQueryClientEvent event) {
    switch (event) {
      case LiveQueryClientEvent.connected:
        _isConnected = true;
        _retryState = 0;
        _userDisconnected = false;
        break;
      case LiveQueryClientEvent.disconnected:
        _isConnected = false;
        _setReconnect();
        break;
      case LiveQueryClientEvent.userDisconnected:
        _userDisconnected = true;
        Timer? currentTimer = _currentTimer;
        if (currentTimer != null) {
          currentTimer.cancel();
          _currentTimer = null;
        }
        break;
    }

    if (debug) {
      print('$debugTag: $event');
    }
  });
  ParseCoreData().appResumedStream?.listen((void _) => _setReconnect());
}