src/events/ReconnectingWebSocket.js
/**
   * Connect to the websocket server, using an exponential backoff
   * algorithm if an error occurs while connecting.
   *
   * @param {function} callback function with signature (err). Called upon
   *  successful connection to the server, or when the maxRetries has
   *  been exceeded.
   */
Connect to the websocket server, using an exponential backoff
algorithm if an error occurs while connecting.

@param {function} callback function with signature (err). Called upon
successful connection to the server, or when the maxRetries has
been exceeded.
Connect to the websocket server using an exponential backoff algorithm if an error occurs while connecting . @param { function } callback function with signature ( err ) . Called upon successful connection to the server or when the maxRetries has been exceeded .
connect(callback) {
    const operation = retry.operation(this._retryOptions);
    operation.attempt((attemptNumber) => {
      const numRetries = attemptNumber - 1;
      if (this._ws) {
        this._ws.removeAllListeners();
        this._ws.close();
      }
      this._ws = new WebSocket(this._url, this._wsOptions);
      const handleConnectError = (err) => {
        debug("connection attempt failed", err);
        if (!this._reconnect) {
          callback(err);
          return;
        }
        if (operation.retry(err)) {
          return;
        }
        debug('connection attempts exhaused',
          { err, reconnect: this._reconnect, numRetries });
        callback(operation.mainError());
      };
      this._ws.once("error", handleConnectError);
      this._ws.once("open", () => {
        debug("connected", { numRetries });
        this._ws.removeListener("error", handleConnectError);
        this._ws.on("message", this.emit.bind(this, "message"));
        this._ws.once("error", this.handleError.bind(this));
        this._ws.once("close", this.handleClose.bind(this));
        callback();
      });
    });
  }
connect ( callback ) { const operation = retry . operation ( this . _retryOptions ) ; operation . attempt ( ( attemptNumber ) => { const numRetries = attemptNumber - 1 ; if ( this . _ws ) { this . _ws . removeAllListeners ( ) ; this . _ws . close ( ) ; } this . _ws = new WebSocket ( this . _url , this . _wsOptions ) ; const handleConnectError = ( err ) => { debug ( "connection attempt failed" , err ) ; if ( ! this . _reconnect ) { callback ( err ) ; return ; } if ( operation . retry ( err ) ) { return ; } debug ( 'connection attempts exhaused' , { err , reconnect : this . _reconnect , numRetries } ) ; callback ( operation . mainError ( ) ) ; } ; this . _ws . once ( "error" , handleConnectError ) ; this . _ws . once ( "open" , ( ) => { debug ( "connected" , { numRetries } ) ; this . _ws . removeListener ( "error" , handleConnectError ) ; this . _ws . on ( "message" , this . emit . bind ( this , "message" ) ) ; this . _ws . once ( "error" , this . handleError . bind ( this ) ) ; this . _ws . once ( "close" , this . handleClose . bind ( this ) ) ; callback ( ) ; } ) ; } ) ; }
Connect to the websocket server, using an exponential backoff
 algorithm if an error occurs while connecting.
Connect to the websocket server using an exponential backoff algorithm if an error occurs while connecting .
// cleanup any existing instance /** @private */ // prettier-ignore