Skip to content

Commit

Permalink
ff to ff working
Browse files Browse the repository at this point in the history
  • Loading branch information
Contra committed Feb 19, 2013
1 parent b4a9595 commit da4e6af
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 12 deletions.
2 changes: 2 additions & 0 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
Full firefox support (just needs some shims and encryption fixes)

Mute/unmute/hold sugar

Data channel support (easy)

Easier way to access remote stream details (has audio, has video)
Expand Down
36 changes: 32 additions & 4 deletions examples/holla.js
Original file line number Diff line number Diff line change
Expand Up @@ -3560,7 +3560,7 @@ require.register("holla/dist/Call.js", function(exports, require, module){
Call.prototype.createConnection = function() {
var pc,
_this = this;
pc = new RTC.PeerConnection(RTC.PeerConnConfig);
pc = new RTC.PeerConnection(RTC.PeerConnConfig, RTC.constraints);
pc.onconnecting = function() {
_this.emit('connecting');
};
Expand Down Expand Up @@ -3659,7 +3659,6 @@ require.register("holla/dist/Call.js", function(exports, require, module){
var done, err,
_this = this;
done = function(desc) {
desc.sdp = RTC.processSDP(desc.sdp);
_this.pc.setLocalDescription(desc);
return _this.socket.write({
type: "sdp",
Expand Down Expand Up @@ -3693,7 +3692,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, processSDP, shim, supported,
var IceCandidate, MediaStream, PeerConnection, SessionDescription, URL, attachStream, browser, getUserMedia, mediaConstraints, mergeConstraints, processSDP, shim, supported,
__indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };

PeerConnection = window.mozRTCPeerConnection || window.PeerConnection || window.webkitPeerConnection00 || window.webkitRTCPeerConnection;
Expand All @@ -3712,6 +3711,13 @@ require.register("holla/dist/RTC.js", function(exports, require, module){

supported = (PeerConnection != null) && (getUserMedia != null);

mediaConstraints = {
mandatory: {
OfferToReceiveAudio: true,
OfferToReceiveVideo: true
}
};

getUserMedia = getUserMedia.bind(navigator);

processSDP = function(sdp) {
Expand Down Expand Up @@ -3750,6 +3756,27 @@ require.register("holla/dist/RTC.js", function(exports, require, module){
return el;
};

mergeConstraints = function(a, b) {
var k, nu, v, _ref, _ref1;
nu = {
mandatory: {},
optional: []
};
_ref = a.mandatory;
for (k in _ref) {
v = _ref[k];
nu.mandatory[k] = v;
}
_ref1 = b.mandatory;
for (k in _ref1) {
v = _ref1[k];
nu.mandatory[k] = v;
}
nu = nu.optional.concat(a.optional);
nu = nu.optional.concat(b.optional);
return nu;
};

shim = function() {
var PeerConnConfig, out;
if (!supported) {
Expand Down Expand Up @@ -3811,7 +3838,8 @@ require.register("holla/dist/RTC.js", function(exports, require, module){
processSDP: processSDP,
PeerConnConfig: PeerConnConfig,
browser: browser,
supported: supported
supported: supported,
constraints: mediaConstraints
};
return out;
};
Expand Down
36 changes: 32 additions & 4 deletions holla.js
Original file line number Diff line number Diff line change
Expand Up @@ -3560,7 +3560,7 @@ require.register("holla/dist/Call.js", function(exports, require, module){
Call.prototype.createConnection = function() {
var pc,
_this = this;
pc = new RTC.PeerConnection(RTC.PeerConnConfig);
pc = new RTC.PeerConnection(RTC.PeerConnConfig, RTC.constraints);
pc.onconnecting = function() {
_this.emit('connecting');
};
Expand Down Expand Up @@ -3659,7 +3659,6 @@ require.register("holla/dist/Call.js", function(exports, require, module){
var done, err,
_this = this;
done = function(desc) {
desc.sdp = RTC.processSDP(desc.sdp);
_this.pc.setLocalDescription(desc);
return _this.socket.write({
type: "sdp",
Expand Down Expand Up @@ -3693,7 +3692,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, processSDP, shim, supported,
var IceCandidate, MediaStream, PeerConnection, SessionDescription, URL, attachStream, browser, getUserMedia, mediaConstraints, mergeConstraints, processSDP, shim, supported,
__indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };

PeerConnection = window.mozRTCPeerConnection || window.PeerConnection || window.webkitPeerConnection00 || window.webkitRTCPeerConnection;
Expand All @@ -3712,6 +3711,13 @@ require.register("holla/dist/RTC.js", function(exports, require, module){

supported = (PeerConnection != null) && (getUserMedia != null);

mediaConstraints = {
mandatory: {
OfferToReceiveAudio: true,
OfferToReceiveVideo: true
}
};

getUserMedia = getUserMedia.bind(navigator);

processSDP = function(sdp) {
Expand Down Expand Up @@ -3750,6 +3756,27 @@ require.register("holla/dist/RTC.js", function(exports, require, module){
return el;
};

mergeConstraints = function(a, b) {
var k, nu, v, _ref, _ref1;
nu = {
mandatory: {},
optional: []
};
_ref = a.mandatory;
for (k in _ref) {
v = _ref[k];
nu.mandatory[k] = v;
}
_ref1 = b.mandatory;
for (k in _ref1) {
v = _ref1[k];
nu.mandatory[k] = v;
}
nu = nu.optional.concat(a.optional);
nu = nu.optional.concat(b.optional);
return nu;
};

shim = function() {
var PeerConnConfig, out;
if (!supported) {
Expand Down Expand Up @@ -3811,7 +3838,8 @@ require.register("holla/dist/RTC.js", function(exports, require, module){
processSDP: processSDP,
PeerConnConfig: PeerConnConfig,
browser: browser,
supported: supported
supported: supported,
constraints: mediaConstraints
};
return out;
};
Expand Down
2 changes: 1 addition & 1 deletion holla.min.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions lib/Call.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class Call extends EventEmitter
@emit "chat", msg

createConnection: ->
pc = new RTC.PeerConnection RTC.PeerConnConfig
pc = new RTC.PeerConnection RTC.PeerConnConfig, RTC.constraints
pc.onconnecting = =>
@emit 'connecting'
return
Expand Down Expand Up @@ -110,14 +110,14 @@ class Call extends EventEmitter

initSDP: ->
done = (desc) =>
desc.sdp = RTC.processSDP desc.sdp
#desc.sdp = RTC.processSDP desc.sdp
@pc.setLocalDescription desc
@socket.write
type: "sdp"
to: @user
args: desc

err = (e) -> console.log e
err = (e) -> throw e

return @pc.createOffer done, err if @isCaller
return @pc.createAnswer done, err if @pc.remoteDescription
Expand Down
15 changes: 15 additions & 0 deletions lib/RTC.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ URL = window.URL or window.webkitURL or window.msURL or window.oURL

browser = (if navigator.mozGetUserMedia then 'firefox' else 'chrome')
supported = (PeerConnection? and getUserMedia?)
mediaConstraints =
mandatory:
OfferToReceiveAudio: true
OfferToReceiveVideo: true

# scope bind hax
getUserMedia = getUserMedia.bind navigator
Expand All @@ -32,6 +36,16 @@ attachStream = (uri, el) ->
el.play()
return el

mergeConstraints = (a,b) ->
nu =
mandatory: {}
optional: []
nu.mandatory[k]=v for k,v of a.mandatory
nu.mandatory[k]=v for k,v of b.mandatory
nu = nu.optional.concat a.optional
nu = nu.optional.concat b.optional
return nu

shim = ->
return unless supported # no need to shim
if browser is 'firefox'
Expand Down Expand Up @@ -71,6 +85,7 @@ shim = ->
PeerConnConfig: PeerConnConfig
browser: browser
supported: supported
constraints: mediaConstraints
return out

module.exports = shim()

0 comments on commit da4e6af

Please sign in to comment.