onWSClose() { debug(`socket close`) debug(`socket reconnect: ${this.reconnect}`) this.stopPingPong() this.ws.removeAllListeners() this.ws = null Object.values(this.promises).forEach((cb) => cb.reject()) this.promises = {} if (this.reconnect) { this.reconnecting = true this.emit('reconnecting') this.connect() } else { this.reconnecting = false this.emit('close') } }
webSocketServer.on("connection", (socket: WebSocket) => { if (connection) { connection.removeAllListeners("message"); connection.removeAllListeners("ping"); connection.close(); } connection = socket; connection.on("message", (rawMessage: RawMessage) => { const message: Message<IncomingMessage> = parse(rawMessage); if ( message.type === "header" || message.type === "data" || message.type === "end" ) { emitter.emit(`${message.type}:${message.identifier}`, message); } }); });