Skip to content

Commit

Permalink
Added support for handling websocket messages sent as binary.
Browse files Browse the repository at this point in the history
  • Loading branch information
lukehb committed Jul 13, 2022
1 parent 11e19a0 commit e46c4dc
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions SignallingWebServer/scripts/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -2279,7 +2279,25 @@ function connect() {
ws = new WebSocket(connectionUrl);
ws.attemptStreamReconnection = true;

ws.onmessagebinary = function(event) {
if(!event || !event.data) { return; }

event.data.text().then(function(messageString){
// send the new stringified event back into `onmessage`
ws.onmessage({ data: messageString });
}).catch(function(error){
console.error(`Failed to parse binary blob from websocket, reason: ${error}`);
});
}

ws.onmessage = function(event) {

// Check if websocket message is binary, if so, stringify it.
if(event.data && event.data instanceof Blob) {
ws.onmessagebinary(event);
return;
}

let msg = JSON.parse(event.data);
if (msg.type === 'config') {
console.log("%c[Inbound SS (config)]", "background: lightblue; color: black", msg);
Expand Down

0 comments on commit e46c4dc

Please sign in to comment.