Tabnine Logo For Javascript
ws
Code IndexAdd Tabnine to your IDE (free)

How to use ws

Best JavaScript code snippets using ws(Showing top 15 results out of 1,332)

origin: avwo/whistle

ws.on('open', function open() {
  if (/checkStatusCode/.test(url)) {
   if (done) {
    return;
   }
   done = true;
   callback && callback('checkStatusCode');
   exit();
  } else {
   ws.send('something');
  }
 });
origin: cube-js/cube.js

async close() {
  if (this.wsServer) {
   const close = util.promisify(this.wsServer.close.bind(this.wsServer));
   await close();
  }
  if (this.subscriptionsTimer) {
   clearInterval(this.subscriptionsTimer);
  }
 }
origin: GoogleChromeLabs/ndb

/**
  * @param {!WebSocket} ws
  */
 constructor(ws) {
  this._ws = ws;
  this._handler = null;
  this._messageListener = this._messageReceived.bind(this);
  this._ws.on('message', this._messageListener);
 }
origin: parse-community/parse-server

start() {
  const wss = new WebSocketServer({
   server: this.options.server
  });
  wss.on('listening', this.onListen);
  wss.on('connection', this.onConnection);
  wss.on('error', this.onError);
 }
origin: withspectrum/spectrum

getUserIdFromReq(rawSocket.upgradeReq)
    .then(id => id && setUserOnline(id, false))
    .catch(err => {
     console.error(err);
    })
origin: GoogleChromeLabs/ndb

close() {
  this._ws.close();
 }
origin: avwo/whistle

wss.on('connection', function connection(ws) {
 var req = ws.upgradeReq;
 ws.on('message', function(msg) {
  ws.send(JSON.stringify({
   type: 'server',
   method: req.method,
   headers: req.headers,
   body: msg
  }, null, '\t'));
 });
});
origin: withspectrum/spectrum

getUserIdFromReq(rawSocket.upgradeReq)
    .then(id => (id ? setUserOnline(id, true) : null))
    .then(user => {
     return {
      user: user || null,
      loaders: createLoaders({ cache: false }),
     };
    })
    .catch(err => {
     console.error(err);
     return {
      loaders: createLoaders({ cache: false }),
     };
    })
origin: GoogleChromeLabs/ndb

/**
  * @param {string} message
  */
 send(message) {
  if (this._ws.readyState === WebSocket.OPEN) {
   protocolDebug('>', message);
   this._ws.send(message);
  }
 }
origin: GoogleChromeLabs/ndb

async _startSession(info, frontend) {
  const ws = new WebSocket(info.inspectorUrl);
  const openPromise = new Promise(resolve => ws.once('open', () => resolve(DebugState.WS_OPEN)));
  const errorPromise = new Promise(resolve => ws.once('error', () => resolve(DebugState.WS_ERROR)));
  const closePromise = new Promise(resolve => ws.once('close', () => resolve(DebugState.WS_CLOSE)));
  let state = await Promise.race([openPromise, errorPromise, closePromise, this._disconnectPromise]);
  if (state === DebugState.WS_OPEN) {
   this._connected.add(info.id);
   const channel = new Channel(ws);
   state = await Promise.race([frontend.detected(info, rpc.handle(channel)), this._disconnectPromise]);
   return async() => {
    if (state !== DebugState.PROCESS_DISCONNECT)
     state = await Promise.race([closePromise, errorPromise, this._disconnectPromise]);
    channel.dispose();
    this._connected.delete(info.id);
    if (state !== DebugState.PROCESS_DISCONNECT)
     frontend.disconnected(info.id);
    else
     ws.send(CALL_EXIT_MESSAGE, () => ws.close());
   };
  } else {
   return async function() {};
  }
 }
origin: GitSquared/edex-ui

this.wss.on("connection", ws => {
        this.onopened(this.tty._pid);
        ws.on("close", (code, reason) => {
          this.ondisconnected(code, reason);
        });
        ws.on("message", msg => {
          this.tty.write(msg);
        });
        this.tty.onData(data => {
          this._nextTickUpdateTtyCWD = true;
          this._nextTickUpdateProcess = true;
          try {
            ws.send(data);
          } catch (e) {
            // Websocket closed
          }
        });
      });
origin: GoogleChromeLabs/ndb

dispose() {
  this._ws.removeListener('message', this._messageListener);
 }
origin: avwo/whistle

ws.on('message', function(data) {
  if (done) {
   return;
  }
  done = true;
  callback && callback(JSON.parse(data));
  exit();
 });
origin: parse-community/parse-server

start() {
  const wss = new WebSocketServer({ server: this.options.server });
  wss.on('listening', this.onListen);
  wss.on('connection', this.onConnection);
  wss.on('error', this.onError);
 }
origin: GitSquared/edex-ui

this.wss.on("connection", ws => {
        this.onopened(this.tty._pid);
        ws.on("close", (code, reason) => {
          this.ondisconnected(code, reason);
        });
        ws.on("message", msg => {
          this.tty.write(msg);
        });
        this.tty.onData(data => {
          this._nextTickUpdateTtyCWD = true;
          this._nextTickUpdateProcess = true;
          try {
            ws.send(data);
          } catch (e) {
            // Websocket closed
          }
        });
      });
ws(npm)

JSDoc

Simple to use, blazing fast and thoroughly tested websocket client and server for Node.js

Most used ws functions

  • WebSocket.on
  • Server.on
  • WebSocket.send
  • WebSocket.close
  • WebSocket.Server
  • Server.clients,
  • WebSocket.readyState,
  • Server.close,
  • WebSocket.terminate,
  • Server.handleUpgrade,
  • Server.emit,
  • Server.broadcast,
  • WebSocket.once,
  • WebSocket.ping,
  • WebSocket.removeListener,
  • WebSocket.id,
  • WebSocket.upgradeReq,
  • WebSocket._socket,
  • ServerOptions.path

Popular in JavaScript

  • ms
    Tiny millisecond conversion utility
  • cheerio
    Tiny, fast, and elegant implementation of core jQuery designed specifically for the server
  • glob
    a little globber
  • mime-types
    The ultimate javascript content-type utility.
  • rimraf
    A deep deletion module for node (like `rm -rf`)
  • js-yaml
    YAML 1.2 parser and serializer
  • through2
    A tiny wrapper around Node.js streams.Transform (Streams2/3) to avoid explicit subclassing noise
  • node-fetch
    A light-weight module that brings window.fetch to node.js
  • qs
    A querystring parser that supports nesting and arrays, with a depth limit
  • Top PhpStorm plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJavascript Code Index
Get Tabnine for your IDE now