Skip to content

Commit

Permalink
Allow receiving WebSocket binary messages (fixes #17). Code provided by
Browse files Browse the repository at this point in the history
  • Loading branch information
ibc committed Nov 13, 2012
1 parent e0c60d6 commit 11c6bb6
Showing 1 changed file with 25 additions and 8 deletions.
33 changes: 25 additions & 8 deletions src/Transport.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,16 +156,33 @@ JsSIP.Transport.prototype = {
var message, transaction,
data = e.data;

if (this.ua.configuration.trace_sip === true) {
console.info(JsSIP.c.LOG_TRANSPORT +'Received WebSocket message: \n\n' + data + '\n');
}

// Keep alive response from server. Scape it.
// CRLF Keep Alive response from server. Ignore it.
if(data === '\r\n') {
if (this.ua.configuration.trace_sip === true) {
console.info(JsSIP.c.LOG_TRANSPORT +'Received WebSocket message with CRLF Keep Alive response');
}
return;
} else if (typeof data !== 'string') {
console.info(JsSIP.c.LOG_TRANSPORT +'Binary data received. Ignoring message\n');
return;
}

// WebSocket binary message.
else if (typeof data !== 'string') {
try {
data = String.fromCharCode.apply(null, new Uint8Array(e.data));
} catch(e) {
console.warn(JsSIP.c.LOG_TRANSPORT +'Received WebSocket binary message failed to be converted into String, message ignored');
return;
}

if (this.ua.configuration.trace_sip === true) {
console.info(JsSIP.c.LOG_TRANSPORT +'Received WebSocket binary message: \n\n' + data + '\n');
}
}

// WebSocket text message.
else {
if (this.ua.configuration.trace_sip === true) {
console.info(JsSIP.c.LOG_TRANSPORT +'Received WebSocket text message: \n\n' + data + '\n');
}
}

message = JsSIP.Parser.parseMessage(data);
Expand Down

0 comments on commit 11c6bb6

Please sign in to comment.