Skip to content
Permalink
Browse files

Allow receiving WebSocket binary messages (fixes #17). Code provided by

  • Loading branch information
ibc committed Nov 13, 2012
1 parent e0c60d6 commit 11c6bb6aeef9de3bf2a339263f620b1caf60d634
Showing with 25 additions and 8 deletions.
  1. +25 −8 src/Transport.js
@@ -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);

0 comments on commit 11c6bb6

Please sign in to comment.
You can’t perform that action at this time.