This commit is contained in:
Evert Prants 2022-09-25 11:02:15 +03:00
parent bd82c52fcd
commit 64ca53b494
Signed by: evert
GPG Key ID: 1688DA83D222D0B5
1 changed files with 7 additions and 13 deletions

View File

@ -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));