Skip to content

Commit

Permalink
chrome->ff support
Browse files Browse the repository at this point in the history
  • Loading branch information
Contra committed Feb 19, 2013
1 parent fda9827 commit f051f25
Show file tree
Hide file tree
Showing 5 changed files with 300 additions and 75 deletions.
144 changes: 116 additions & 28 deletions examples/holla.js
Original file line number Diff line number Diff line change
Expand Up @@ -3545,9 +3545,9 @@ require.register("holla/dist/Call.js", function(exports, require, module){
this.parent.on("candidate." + this.user, function(candidate) {
return _this.pc.addIceCandidate(new RTC.IceCandidate(candidate));
});
this.parent.on("sdp." + this.user, function(stuff) {
console.log(stuff);
_this.pc.setRemoteDescription(new RTC.SessionDescription(stuff));
this.parent.on("sdp." + this.user, function(desc) {
desc.sdp = RTC.processSDPIn(desc.sdp);
_this.pc.setRemoteDescription(new RTC.SessionDescription(desc));
return _this.emit("sdp");
});
this.parent.on("hangup." + this.user, function() {
Expand Down Expand Up @@ -3647,7 +3647,9 @@ require.register("holla/dist/Call.js", function(exports, require, module){

Call.prototype.end = function() {
this.endTime = new Date;
this.pc.close();
try {
this.pc.close();
} catch (_error) {}
this.socket.write({
type: "hangup",
to: this.user
Expand All @@ -3660,7 +3662,7 @@ require.register("holla/dist/Call.js", function(exports, require, module){
var done, err,
_this = this;
done = function(desc) {
desc.sdp = RTC.processSDP(desc.sdp);
desc.sdp = RTC.processSDPOut(desc.sdp);
_this.pc.setLocalDescription(desc);
return _this.socket.write({
type: "sdp",
Expand Down Expand Up @@ -3694,7 +3696,7 @@ require.register("holla/dist/Call.js", function(exports, require, module){
require.register("holla/dist/RTC.js", function(exports, require, module){
// Generated by CoffeeScript 1.4.0
(function() {
var IceCandidate, MediaStream, PeerConnection, SessionDescription, URL, attachStream, browser, getUserMedia, mediaConstraints, mergeConstraints, processSDP, shim, supported;
var IceCandidate, MediaStream, PeerConnection, SessionDescription, URL, attachStream, browser, extract, getUserMedia, mediaConstraints, mergeConstraints, processSDPIn, processSDPOut, removeCN, replaceCodec, shim, supported, useOPUS;

PeerConnection = window.mozRTCPeerConnection || window.PeerConnection || window.webkitPeerConnection00 || window.webkitRTCPeerConnection;

Expand All @@ -3715,29 +3717,120 @@ require.register("holla/dist/RTC.js", function(exports, require, module){
mediaConstraints = {
mandatory: {
OfferToReceiveAudio: true,
OfferToReceiveVideo: true
}
OfferToReceiveVideo: true,
MozDontOfferDataChannel: true
},
optional: [
{
DtlsSrtpKeyAgreement: true
}
]
};

getUserMedia = getUserMedia.bind(navigator);

processSDP = function(sdp) {
var addCrypto, line, out, _i, _len, _ref;
if (browser !== 'firefox') {
extract = function(str, reg) {
var match;
match = str.match(reg);
return (match != null ? match[1] : null);
};

replaceCodec = function(line, codec) {
var el, els, idx, out, _i, _len;
els = line.split(' ');
out = [];
for (idx = _i = 0, _len = els.length; _i < _len; idx = ++_i) {
el = els[idx];
if (idx === 3) {
out[idx++] = codec;
}
if (el !== codec) {
out[idx++] = el;
}
}
return out.join(' ');
};

removeCN = function(lines, mLineIdx) {
var cnPos, idx, line, mLineEls, payload, _i, _len;
mLineEls = lines[mLineIdx].split(' ');
for (idx = _i = 0, _len = lines.length; _i < _len; idx = ++_i) {
line = lines[idx];
if (!(line != null)) {
continue;
}
payload = extract(line, /a=rtpmap:(\d+) CN\/\d+/i);
if (payload != null) {
cnPos = mLineEls.indexOf(payload);
if (cnPos !== -1) {
mLineEls.splice(cnPos, 1);
}
lines.splice(idx, 1);
}
}
lines[mLineIdx] = mLineEls.join(' ');
return lines;
};

useOPUS = function(sdp) {
var idx, line, lines, mLineIdx, payload, _i, _len;
lines = sdp.split('\r\n');
mLineIdx = ((function() {
var _i, _len, _results;
_results = [];
for (idx = _i = 0, _len = lines.length; _i < _len; idx = ++_i) {
line = lines[idx];
if (line.indexOf('m=audio') !== -1) {
_results.push(idx);
}
}
return _results;
})())[0];
if (mLineIdx == null) {
return sdp;
}
addCrypto = "a=crypto:1 AES_CM_128_HMAC_SHA1_80 inline:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
for (idx = _i = 0, _len = lines.length; _i < _len; idx = ++_i) {
line = lines[idx];
if (!(line.indexOf('opus/48000') !== -1)) {
continue;
}
payload = extract(line, /:(\d+) opus\/48000/i);
if (payload != null) {
lines[mLineIdx] = replaceCodec(lines[mLineIdx], payload);
}
break;
}
lines = removeCN(lines, mLineIdx);
return lines.join('\r\n');
};

processSDPOut = function(sdp) {
var addCrypto, line, out, _i, _j, _len, _len1, _ref, _ref1;
out = [];
console.log(sdp.split('\r\n'));
_ref = sdp.split('\r\n');
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
line = _ref[_i];
out.push(line);
if (line.indexOf('m=') === 0) {
out.push(addCrypto);
if (browser === 'firefox') {
addCrypto = "a=crypto:1 AES_CM_128_HMAC_SHA1_80 inline:BAADBAADBAADBAADBAADBAADBAADBAADBAADBAAD";
_ref = sdp.split('\r\n');
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
line = _ref[_i];
out.push(line);
if (line.indexOf('m=') === 0) {
out.push(addCrypto);
}
}
} else {
_ref1 = sdp.split('\r\n');
for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
line = _ref1[_j];
if (line.indexOf("a=ice-options:google-ice") === -1) {
out.push(line);
}
}
}
return out.join('\r\n');
return useOPUS(out.join('\r\n'));
};

processSDPIn = function(sdp) {
return sdp;
};

attachStream = function(uri, el) {
Expand Down Expand Up @@ -3790,8 +3883,7 @@ require.register("holla/dist/RTC.js", function(exports, require, module){
{
url: "stun:23.21.150.121"
}
],
optional: []
]
};
MediaStream.prototype.getVideoTracks = function() {
return [];
Expand All @@ -3805,11 +3897,6 @@ require.register("holla/dist/RTC.js", function(exports, require, module){
{
url: "stun:stun.l.google.com:19302"
}
],
optional: [
{
DtlsSrtpKeyAgreement: true
}
]
};
if (!MediaStream.prototype.getVideoTracks) {
Expand Down Expand Up @@ -3837,7 +3924,8 @@ require.register("holla/dist/RTC.js", function(exports, require, module){
getUserMedia: getUserMedia,
URL: URL,
attachStream: attachStream,
processSDP: processSDP,
processSDPIn: processSDPIn,
processSDPOut: processSDPOut,
PeerConnConfig: PeerConnConfig,
browser: browser,
supported: supported,
Expand Down
Loading

0 comments on commit f051f25

Please sign in to comment.