make calls work in Firefox

This commit is contained in:
David Baker 2014-09-09 14:53:47 +01:00
parent fd2d3fcfd7
commit 472b4fe48c

View File

@ -35,6 +35,20 @@ var forAllTracksOnStream = function(s, f) {
forAllAudioTracksOnStream(s, f); forAllAudioTracksOnStream(s, f);
} }
navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia;
window.RTCPeerConnection = window.RTCPeerConnection || window.webkitRTCPeerConnection; // but not mozRTCPeerConnection because its interface is not compatible
window.RTCSessionDescription = window.RTCSessionDescription || window.webkitRTCSessionDescription || window.mozRTCSessionDescription;
window.RTCIceCandidate = window.RTCIceCandidate || window.webkitRTCIceCandidate || window.mozRTCIceCandidate;
var createPeerConnection = function() {
var stunServer = 'stun:stun.l.google.com:19302';
if (window.mozRTCPeerConnection) {
return new window.mozRTCPeerConnection({'url': stunServer});
} else {
return new window.RTCPeerConnection({"iceServers":[{"urls":"stun:stun.l.google.com:19302"}]});
}
}
angular.module('MatrixCall', []) angular.module('MatrixCall', [])
.factory('MatrixCall', ['matrixService', 'matrixPhoneService', '$rootScope', function MatrixCallFactory(matrixService, matrixPhoneService, $rootScope) { .factory('MatrixCall', ['matrixService', 'matrixPhoneService', '$rootScope', function MatrixCallFactory(matrixService, matrixPhoneService, $rootScope) {
var MatrixCall = function(room_id) { var MatrixCall = function(room_id) {
@ -44,10 +58,6 @@ angular.module('MatrixCall', [])
this.didConnect = false; this.didConnect = false;
} }
navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia;
window.RTCPeerConnection = window.RTCPeerConnection || window.webkitRTCPeerConnection || window.mozRTCPeerConnection;
MatrixCall.prototype.placeCall = function() { MatrixCall.prototype.placeCall = function() {
self = this; self = this;
matrixPhoneService.callPlaced(this); matrixPhoneService.callPlaced(this);
@ -58,7 +68,7 @@ angular.module('MatrixCall', [])
MatrixCall.prototype.initWithInvite = function(msg) { MatrixCall.prototype.initWithInvite = function(msg) {
this.msg = msg; this.msg = msg;
this.peerConn = new window.RTCPeerConnection({"iceServers":[{"urls":"stun:stun.l.google.com:19302"}]}) this.peerConn = createPeerConnection();
self= this; self= this;
this.peerConn.oniceconnectionstatechange = function() { self.onIceConnectionStateChanged(); }; this.peerConn.oniceconnectionstatechange = function() { self.onIceConnectionStateChanged(); };
this.peerConn.onicecandidate = function(c) { self.gotLocalIceCandidate(c); }; this.peerConn.onicecandidate = function(c) { self.gotLocalIceCandidate(c); };
@ -79,12 +89,12 @@ angular.module('MatrixCall', [])
MatrixCall.prototype.stopAllMedia = function() { MatrixCall.prototype.stopAllMedia = function() {
if (this.localAVStream) { if (this.localAVStream) {
forAllTracksOnStream(this.localAVStream, function(t) { forAllTracksOnStream(this.localAVStream, function(t) {
t.stop(); if (t.stop) t.stop();
}); });
} }
if (this.remoteAVStream) { if (this.remoteAVStream) {
forAllTracksOnStream(this.remoteAVStream, function(t) { forAllTracksOnStream(this.remoteAVStream, function(t) {
t.stop(); if (t.stop) t.stop();
}); });
} }
}; };
@ -93,6 +103,7 @@ angular.module('MatrixCall', [])
console.trace("Ending call "+this.call_id); console.trace("Ending call "+this.call_id);
this.stopAllMedia(); this.stopAllMedia();
this.peerConn.close();
var content = { var content = {
version: 0, version: 0,
@ -108,7 +119,7 @@ angular.module('MatrixCall', [])
for (var i = 0; i < audioTracks.length; i++) { for (var i = 0; i < audioTracks.length; i++) {
audioTracks[i].enabled = true; audioTracks[i].enabled = true;
} }
this.peerConn = new window.RTCPeerConnection({"iceServers":[{"urls":"stun:stun.l.google.com:19302"}]}) this.peerConn = createPeerConnection();
self = this; self = this;
this.peerConn.oniceconnectionstatechange = function() { self.onIceConnectionStateChanged(); }; this.peerConn.oniceconnectionstatechange = function() { self.onIceConnectionStateChanged(); };
this.peerConn.onsignalingstatechange = function() { self.onSignallingStateChanged(); }; this.peerConn.onsignalingstatechange = function() { self.onSignallingStateChanged(); };
@ -275,6 +286,7 @@ angular.module('MatrixCall', [])
$rootScope.$apply(function() { $rootScope.$apply(function() {
self.state = 'ended'; self.state = 'ended';
self.stopAllMedia(); self.stopAllMedia();
this.peerConn.close();
self.onHangup(); self.onHangup();
}); });
}; };
@ -289,6 +301,7 @@ angular.module('MatrixCall', [])
MatrixCall.prototype.onHangupReceived = function() { MatrixCall.prototype.onHangupReceived = function() {
this.state = 'ended'; this.state = 'ended';
this.stopAllMedia(); this.stopAllMedia();
this.peerConn.close();
this.onHangup(); this.onHangup();
}; };