/
audio.js
112 lines (101 loc) · 3.29 KB
/
audio.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/* webrtc interop testing using using selenium
* Copyright (c) 2016, Philipp Hancke
*/
var os = require('os');
var test = require('tape');
var buildDriver = require('./webdriver').buildDriver;
var getTestpage = require('./webdriver').getTestpage;
var WebRTCClient = require('./webrtcclient');
function interop(t, browserA, browserB, preferredAudioCodec) {
var driverA = buildDriver(browserA);
var driverB = buildDriver(browserB);
var clientA = new WebRTCClient(driverA);
var clientB = new WebRTCClient(driverB);
getTestpage(driverA)
.then(() => getTestpage(driverB))
.then(() => clientA.create())
.then(() => clientB.create())
.then(() => clientA.getUserMedia({audio: true}))
.then((stream) => {
t.pass('got user media');
return clientA.addStream(stream);
})
.then(() => clientA.createOffer())
.then(offer => {
t.pass('created offer');
if (preferredAudioCodec) {
var sections = SDPUtils.splitSections(offer.sdp);
var codecs = SDPUtils.parseRtpParameters(sections[1]).codecs;
var pt;
for (var i = 0; i < codecs.length; i++) {
if (codecs[i].name === preferredAudioCodec) {
pt = codecs[i].payloadType;
var lines = sections[1].split('\r\n');
mLine = lines.shift().split(' ');
// remove PT from current pos.
mLine.splice(mLine.indexOf(pt.toString()), 1);
mLine.splice(3, 0, pt); // insert at first pos.
mLine = mLine.join(' ');
lines.unshift(mLine);
sections[1] = lines.join('\r\n');
offer.sdp = sections.join('');
break;
}
}
t.ok(pt !== undefined, 'preferred audio codec ' + preferredAudioCodec +
' with PT ' + pt);
}
return clientA.setLocalDescription(offer); // modify offer here?
})
.then(offerWithCandidates => {
t.pass('offer ready to signal');
return clientB.setRemoteDescription(offerWithCandidates);
})
.then(() => clientB.createAnswer())
.then(answer => {
t.pass('created answer');
return clientB.setLocalDescription(answer); // modify answer here?
})
.then(answerWithCandidates => {
t.pass('answer ready to signal');
return clientA.setRemoteDescription(answerWithCandidates);
})
.then(() => // wait for the iceConnectionState to become either connected/completed
// or failed.
clientA.waitForIceConnectionStateChange())
.then(iceConnectionState => {
t.ok(iceConnectionState !== 'failed', 'ICE connection is established');
})
/*
* here is where the fun starts. getStats etc
*/
.then(() => clientA.getStats())
.then(stats => {
console.log(stats);
})
.then(() => Promise.all([driverA.quit(), driverB.quit()])
.then(() => {
t.end();
}))
.catch(err => {
t.fail(err);
});
}
test('Chrome-Edge', {skip: os.platform() !== 'win32'}, t => {
interop(t, 'chrome', 'MicrosoftEdge');
});
test('Edge-Chrome', {skip: os.platform() !== 'win32'}, t => {
interop(t, 'MicrosoftEdge', 'chrome');
});
test('Firefox-Edge', {skip: os.platform() !== 'win32'}, t => {
interop(t, 'firefox', 'MicrosoftEdge');
});
test('Edge-Firefox', {skip: os.platform() !== 'win32'}, t => {
interop(t, 'MicrosoftEdge', 'firefox');
});
test('Chrome-Firefox', t => {
interop(t, 'chrome', 'firefox');
});
test('Firefox-Chrome', t => {
interop(t, 'firefox', 'chrome');
});