lib/client: error out on unsupported WebSocket data type

This commit is contained in:
Simon Ser 2021-09-06 17:15:52 +02:00
parent beef13d273
commit 76f097e8a8

View File

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