Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove RTCPeerConnection shims in FF44+ #168

Merged
merged 1 commit into from
Jan 22, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 38 additions & 43 deletions adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ reattachMediaStream = function(to, from) {
if (typeof window === 'undefined' || !window.navigator) {
webrtcUtils.log('This does not appear to be a browser');
webrtcDetectedBrowser = 'not a browser';
} else if (navigator.mozGetUserMedia && window.mozRTCPeerConnection) {
} else if (navigator.mozGetUserMedia) {
webrtcUtils.log('This appears to be Firefox');

webrtcDetectedBrowser = 'firefox';
Expand All @@ -102,57 +102,52 @@ if (typeof window === 'undefined' || !window.navigator) {
// the minimum firefox version still supported by adapter.
webrtcMinimumVersion = 31;

// The RTCPeerConnection object.
window.RTCPeerConnection = function(pcConfig, pcConstraints) {
if (webrtcDetectedVersion < 38) {
// .urls is not supported in FF < 38.
// create RTCIceServers with a single url.
if (pcConfig && pcConfig.iceServers) {
var newIceServers = [];
for (var i = 0; i < pcConfig.iceServers.length; i++) {
var server = pcConfig.iceServers[i];
if (server.hasOwnProperty('urls')) {
for (var j = 0; j < server.urls.length; j++) {
var newServer = {
url: server.urls[j]
};
if (server.urls[j].indexOf('turn') === 0) {
newServer.username = server.username;
newServer.credential = server.credential;
// Shim for RTCPeerConnection on older versions.
if (!window.RTCPeerConnection) {
window.RTCPeerConnection = function(pcConfig, pcConstraints) {
if (webrtcDetectedVersion < 38) {
// .urls is not supported in FF < 38.
// create RTCIceServers with a single url.
if (pcConfig && pcConfig.iceServers) {
var newIceServers = [];
for (var i = 0; i < pcConfig.iceServers.length; i++) {
var server = pcConfig.iceServers[i];
if (server.hasOwnProperty('urls')) {
for (var j = 0; j < server.urls.length; j++) {
var newServer = {
url: server.urls[j]
};
if (server.urls[j].indexOf('turn') === 0) {
newServer.username = server.username;
newServer.credential = server.credential;
}
newIceServers.push(newServer);
}
newIceServers.push(newServer);
} else {
newIceServers.push(pcConfig.iceServers[i]);
}
} else {
newIceServers.push(pcConfig.iceServers[i]);
}
pcConfig.iceServers = newIceServers;
}
pcConfig.iceServers = newIceServers;
}
}
return new mozRTCPeerConnection(pcConfig, pcConstraints); // jscs:ignore requireCapitalizedConstructors
};
return new mozRTCPeerConnection(pcConfig, pcConstraints); // jscs:ignore requireCapitalizedConstructors
};

// wrap static methods. Currently just generateCertificate.
if (mozRTCPeerConnection.generateCertificate) {
Object.defineProperty(window.RTCPeerConnection, 'generateCertificate', {
get: function() {
if (arguments.length) {
return mozRTCPeerConnection.generateCertificate.apply(null,
arguments);
} else {
return mozRTCPeerConnection.generateCertificate;
// wrap static methods. Currently just generateCertificate.
if (mozRTCPeerConnection.generateCertificate) {
Object.defineProperty(window.RTCPeerConnection, 'generateCertificate', {
get: function() {
if (arguments.length) {
return mozRTCPeerConnection.generateCertificate.apply(null,
arguments);
} else {
return mozRTCPeerConnection.generateCertificate;
}
}
}
});
}
});
}

// The RTCSessionDescription object.
if (!window.RTCSessionDescription) {
window.RTCSessionDescription = mozRTCSessionDescription;
}

// The RTCIceCandidate object.
if (!window.RTCIceCandidate) {
window.RTCIceCandidate = mozRTCIceCandidate;
}

Expand Down