Skip to content

Commit

Permalink
Inaugural Hacks.js - Replace Firefox turn candidates in Ack SDP
Browse files Browse the repository at this point in the history
  • Loading branch information
Will Mitchell committed Apr 8, 2014
1 parent 5ab81d2 commit dfbbe17
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 13 deletions.
1 change: 1 addition & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ module.exports = function(grunt) {
'src/WebRTC.js',
'src/UA.js',
'src/Utils.js',
'src/Hacks.js',
'src/SanityCheck.js',
'src/DigestAuthentication.js',
'src/tail.js'
Expand Down
35 changes: 35 additions & 0 deletions src/Hacks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* @fileoverview Hacks - This file contains all of the things we
* wish we didn't have to do, just for interop. It is similar to
* Utils, which provides actually useful and relevant functions for
* a SIP library. Methods in this file are grouped by vendor, so
* as to most easily track when particular hacks may not be necessary anymore.
*/

(function (SIP) {

var Hacks;

Hacks = {

Firefox: {
/* Condition to detect if hacks are applicable */
isFirefox: function () {
return window.mozRTCPeerConnection !== undefined;
},
cannotHandleRelayCandidates: function (message) {
if (this.isFirefox() && message.body) {
message.body = message.body.replace(/relay/g, 'host generation 0');
}
},
cannotHandleExtraWhitespace: function (message) {
if (this.isFirefox() && message.body) {
message.body = message.body.replace(/ \r\n/g, "\r\n");
}
}
}
};


SIP.Hacks = Hacks;
}(SIP));
22 changes: 9 additions & 13 deletions src/Session.js
Original file line number Diff line number Diff line change
Expand Up @@ -973,11 +973,8 @@ InviteServerContext = function(ua, request) {
}

//TODO: move this into media handler
if (request.body && window.mozRTCPeerConnection !== undefined) {
request.body = request.body.
replace(/relay/g,"host generation 0").
replace(/ \r\n/g, "\r\n");
}
SIP.Hacks.Firefox.cannotHandleRelayCandidates(request);
SIP.Hacks.Firefox.cannotHandleExtraWhitespace(request);

SIP.Utils.augment(this, SIP.ServerContext, [ua, request]);
SIP.Utils.augment(this, SIP.Session, [ua.configuration.mediaHandlerFactory]);
Expand Down Expand Up @@ -1441,6 +1438,9 @@ InviteServerContext.prototype = {
if (!this.hasAnswer) {
if(request.body && request.getHeader('content-type') === 'application/sdp') {
// ACK contains answer to an INVITE w/o SDP negotiation
SIP.Hacks.Firefox.cannotHandleRelayCandidates(request);
SIP.Hacks.Firefox.cannotHandleExtraWhitespace(request);

this.hasAnswer = true;
this.mediaHandler.setDescription(
request.body,
Expand Down Expand Up @@ -1806,10 +1806,8 @@ InviteClientContext.prototype = {
return;
}

if (response.body && window.mozRTCPeerConnection !== undefined) {
response.body = response.body.replace(/relay/g, 'host generation 0');
response.body = response.body.replace(/ \r\n/g, '\r\n');
}
SIP.Hacks.Firefox.cannotHandleRelayCandidates(response);
SIP.Hacks.Firefox.cannotHandleExtraWhitespace(response);

if (!response.body) {
extraHeaders.push('RAck: ' + response.getHeader('rseq') + ' ' + response.getHeader('cseq'));
Expand Down Expand Up @@ -1934,10 +1932,8 @@ InviteClientContext.prototype = {
break;
}

if (response.body && window.mozRTCPeerConnection !== undefined) {
response.body = response.body.replace(/relay/g, 'host generation 0');
response.body = response.body.replace(/ \r\n/g, '\r\n');
}
SIP.Hacks.Firefox.cannotHandleRelayCandidates(response);
SIP.Hacks.Firefox.cannotHandleExtraWhitespace(response);

// This is an invite without sdp
if (!this.hasOffer) {
Expand Down

0 comments on commit dfbbe17

Please sign in to comment.