diff --git a/lib/client.js b/lib/client.js index f3ddca8..0b2aed7 100644 --- a/lib/client.js +++ b/lib/client.js @@ -26,6 +26,7 @@ const RECONNECT_DELAY_SEC = 10; // https://www.rfc-editor.org/rfc/rfc6455.html#section-7.4.1 const NORMAL_CLOSURE = 1000; const GOING_AWAY = 1001; +const UNSUPPORTED_DATA = 1003; let lastLabel = 0; @@ -138,7 +139,7 @@ export default class Client extends EventTarget { this.setPingInterval(0); if (this.ws) { - this.ws.close(1000); + this.ws.close(NORMAL_CLOSURE); } } @@ -168,6 +169,12 @@ export default class Client extends EventTarget { } handleMessage(event) { + if (typeof event.data !== "string") { + console.error("Received unsupported data type:", event.data); + this.ws.close(UNSUPPORTED_DATA); + return; + } + let msg = irc.parseMessage(event.data); console.debug("Received:", msg);