reconnect method Null safety

dynamic reconnect()
inherited

Reconnects to last broadcast.

Implementation

reconnect() async {
  try {
    if (stopReconnection) {
      return;
    }

    if (!isActive()) {
      stop();
      if (options != null) {
        await connect(options: options!);
      } else {
        await connect();
      }
      alreadyDisconnected = false;
      reconnectionInterval = baseInterval;
      firstReconnection = true;
    }
  } catch (error) {
    reconnectionInterval = nextReconnectInterval(reconnectionInterval!);
    logger.e(
        '''Reconnection failed, retrying in ${reconnectionInterval}ms. Error was: $error''');

    ///  Emits with every reconnection attempt made when an active stream
    ///  stopped unexpectedly.
    ///
    ///  [timeout] - Next retry interval in milliseconds.
    ///  [error] - Error object with cause of failure.
    emit(
        'reconnect', this, {'timeout': reconnectionInterval, 'error': error});
    Timer(Duration(milliseconds: reconnectionInterval!), () => reconnect());
  }
}