code: function(newState) {
            switch (newState) {
              case 'disconnected':
              case 'error':
                webSocket = null;
                if (onClose) {
                  var error;
                  if(hasLostConnectivity()) {
                    error = new Error(wsCloseErrorCodes[4001]);
                    error.code = 4001;
                  }
                  onClose(error);
                }
                break;
            }
          }
docs: Timer for the connectivity checks // Private API