From 64ca53b4946266c2238cae29570430003d5ba15e Mon Sep 17 00:00:00 2001 From: Evert Prants Date: Sun, 25 Sep 2022 11:02:15 +0300 Subject: [PATCH] ws test --- src/connector/websocket.connector.ts | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/src/connector/websocket.connector.ts b/src/connector/websocket.connector.ts index bf3b671..6ef957a 100644 --- a/src/connector/websocket.connector.ts +++ b/src/connector/websocket.connector.ts @@ -50,25 +50,19 @@ export class IRCWebSocketConnector } write(format: string, ...args: any[]): void { - this.socket?.send(formatstr(format, ...args) + '\r\n'); + this.socket?.send(formatstr(format, ...args)); } private handle() { - let buffer: string = ''; this.socket?.addEventListener('message', (event) => { - const chunk = event.data.toString(); - buffer += chunk; - const data = buffer.split('\r\n'); - buffer = data.pop() || ''; + const line = event.data.toString(); - data.forEach((line: string) => { - if (line.indexOf('PING') === 0 && !this.connOpts?.skipPings) { - this.socket?.send('PONG' + line.substring(4) + '\r\n'); - return; - } + if (line.indexOf('PING') === 0 && !this.connOpts?.skipPings) { + this.socket?.send('PONG' + line.substring(4)); + return; + } - this.emit('data', line); - }); + this.emit('data', line); }); this.socket?.addEventListener('error', (err) => this.emit('error', err));