dynamic initWebsocket([bool reconnect = true ])

Source

initWebsocket([bool reconnect = true]) {
  var socket = new WebSocket("$wsUpdateUri?session=$session&format=$format");
  _wsConnection = new WebSocketConnection(
      socket, this, enableAck: enableAck, useCodec: DsCodec.getCodec(format));

  if (responder != null) {
    responder.connection = _wsConnection.responderChannel;
  }

  if (requester != null) {
    _wsConnection.onRequesterReady.then((channel) {
      requester.connection = channel;
      if (!_onRequesterReadyCompleter.isCompleted) {
        _onRequesterReadyCompleter.complete(requester);
      }
    });
  }
  _wsConnection.onDisconnected.then((connection) {
    logger.info("Disconnected");
    if (_wsConnection._opened) {
      _wsDelay = 1;
      initWebsocket(false);
    } else if (reconnect) {
      DsTimer.timerOnceAfter(initWebsocket, _wsDelay * 1000);
      if (_wsDelay < 60) _wsDelay++;
    } else {
      _wsDelay = 5;
      DsTimer.timerOnceAfter(initWebsocket, 5000);
    }
  });
}