close() { this._ws.close(); }
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() {}; } }
App.ws.use(async (ctx, next) => { await next(ctx); if (ctx.websocket.listenerCount('message') === 0) { ctx.websocket.close(); } });
/** * 断开连接 */ public disconnect() { // 清空数据 this.dataCache = new Buffer(0); this.isReceiveProcess = false; this.mSocket.close(); this.mSocket = null; }
close() { this.reconnect = false clearTimeout(this.reconnectTimeout) this.reconnectTimeout = null this.ws.close() }
close() { this.logger.info('Closing connection', {category: 'bybit-ws'}); this.readyState = READY_STATE_CLOSING; this._teardown(); this.ws.close(); }
destroy() { if (this.token_expiration_ref) { clearInterval(this.token_expiration_ref) } if (this.heartbeat_ref) { clearInterval(this.heartbeat_ref) } if (this.self_heal_ref) { clearTimeout(this.self_heal_ref) } if (this.websocket) { this.websocket.close(WS_CLOSE_REASON_USER, "User terminated") } }
wss.on("connection", function(ws) { ws.on("message", function(message) { if (message === 'exit') { ws.close(); } else { wss.clients.forEach(function(client) { client.send(message); }); } }); ws.send("Welcome to cyber chat"); });
unsub () { if (!this.socket) return try { this.socket.close() } catch (e) {} this.socket = null this.disconnected() }
close() { return new Promise(resolve => { this.ws.close(); this.ws.once("close", resolve); }); }
destroy() { clearTimeout(this.reconnectTimeoutId); this.shouldAttemptReconnect = false; this.socket.close(); }
close() { this.ws.close(); }
stop() { this.stoped = true if (this.ws.readyState === 1) { this.ws.close() } }
close() { this.ws.close(); }