/** * @param {!WebSocket} ws */ constructor(ws) { this._ws = ws; this._handler = null; this._messageListener = this._messageReceived.bind(this); this._ws.on('message', this._messageListener); }
getUserIdFromReq(rawSocket.upgradeReq) .then(id => id && setUserOnline(id, false)) .catch(err => { console.error(err); })
close() { this._ws.close(); }
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')); }); });
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 }), }; })
/** * @param {string} message */ send(message) { if (this._ws.readyState === WebSocket.OPEN) { protocolDebug('>', message); this._ws.send(message); } }
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() {}; } }
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 } }); });
dispose() { this._ws.removeListener('message', this._messageListener); }
ws.on('message', function(data) { if (done) { return; } done = true; callback && callback(JSON.parse(data)); exit(); });
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 } }); });