Skip to content

Commit 3f27a18

Browse files
committed
Merge pull request #266 from jan-ivar/initdict
Shim away RTCSessionDescription/RTCIceCandidate.
2 parents c2b7734 + 1606722 commit 3f27a18

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

src/js/chrome/chrome_shim.js

+2
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,8 @@ var chromeShim = {
187187
webkitRTCPeerConnection.prototype[method] = function() {
188188
var args = arguments;
189189
var self = this;
190+
args[0] = new ((method === 'addIceCandidate')?
191+
RTCIceCandidate : RTCSessionDescription)(args[0]);
190192
return new Promise(function(resolve, reject) {
191193
nativeMethod.apply(self, [args[0],
192194
function() {

src/js/firefox/firefox_shim.js

+11
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,17 @@ var firefoxShim = {
102102
window.RTCSessionDescription = mozRTCSessionDescription;
103103
window.RTCIceCandidate = mozRTCIceCandidate;
104104
}
105+
106+
// shim away need for obsolete RTCIceCandidate/RTCSessionDescription.
107+
['setLocalDescription', 'setRemoteDescription', 'addIceCandidate']
108+
.forEach(function(method) {
109+
var nativeMethod = RTCPeerConnection.prototype[method];
110+
RTCPeerConnection.prototype[method] = function() {
111+
arguments[0] = new ((method === 'addIceCandidate')?
112+
RTCIceCandidate : RTCSessionDescription)(arguments[0]);
113+
return nativeMethod.apply(this, arguments);
114+
};
115+
});
105116
},
106117

107118
shimGetUserMedia: function() {

test/test.js

+7-6
Original file line numberDiff line numberDiff line change
@@ -1460,10 +1460,11 @@ test('Basic connection establishment with promise', function(t) {
14601460
}
14611461
};
14621462

1463+
var dictionary = obj => JSON.parse(JSON.stringify(obj));
1464+
14631465
var addCandidate = function(pc, event) {
14641466
if (event.candidate) {
1465-
var cand = new RTCIceCandidate(event.candidate);
1466-
pc.addIceCandidate(cand).then(function() {
1467+
pc.addIceCandidate(dictionary(event.candidate)).then(function() {
14671468
// TODO: Decide if we are interested in adding all candidates
14681469
// as passed tests.
14691470
tc.pass('addIceCandidate ' + counter++);
@@ -1486,19 +1487,19 @@ test('Basic connection establishment with promise', function(t) {
14861487
pc1.addStream(stream);
14871488
pc1.createOffer().then(function(offer) {
14881489
tc.pass('pc1.createOffer');
1489-
return pc1.setLocalDescription(offer);
1490+
return pc1.setLocalDescription(dictionary(offer));
14901491
}).then(function() {
14911492
tc.pass('pc1.setLocalDescription');
1492-
return pc2.setRemoteDescription(pc1.localDescription);
1493+
return pc2.setRemoteDescription(dictionary(pc1.localDescription));
14931494
}).then(function() {
14941495
tc.pass('pc2.setRemoteDescription');
14951496
return pc2.createAnswer();
14961497
}).then(function(answer) {
14971498
tc.pass('pc2.createAnswer');
1498-
return pc2.setLocalDescription(answer);
1499+
return pc2.setLocalDescription(dictionary(answer));
14991500
}).then(function() {
15001501
tc.pass('pc2.setLocalDescription');
1501-
return pc1.setRemoteDescription(pc2.localDescription);
1502+
return pc1.setRemoteDescription(dictionary(pc2.localDescription));
15021503
}).then(function() {
15031504
tc.pass('pc1.setRemoteDescription');
15041505
}).catch(function(err) {

0 commit comments

Comments
 (0)