mirror of
https://gitlab.com/comunic/comunicapiv2
synced 2024-11-22 13:29:22 +00:00
Accept only text messages on WebSocket
This commit is contained in:
parent
729ee6a2a9
commit
587f482736
@ -118,8 +118,26 @@ export class UserWebSocketController {
|
|||||||
this.active_clients.splice(this.active_clients.indexOf(client), 1);
|
this.active_clients.splice(this.active_clients.indexOf(client), 1);
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// Handles error
|
||||||
|
ws.addEventListener("error", (e) => {
|
||||||
|
if(ws.readyState == ws.OPEN)
|
||||||
|
ws.close();
|
||||||
|
|
||||||
console.log(this.active_clients)
|
console.log("WebSocket error", e)
|
||||||
|
})
|
||||||
|
|
||||||
|
// Handles incoming messages
|
||||||
|
ws.addEventListener("message", (msg) => {
|
||||||
|
|
||||||
|
// Only accept text messages
|
||||||
|
if(msg.type != "message") {
|
||||||
|
console.error("Received a non-text messsage through a WebSocket !")
|
||||||
|
ws.close();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user