OLD | NEW |
---|---|
1 <html> | 1 <html> |
2 <head> | 2 <head> |
3 <script type="text/javascript" src="webrtc_test_utilities.js"></script> | 3 <script type="text/javascript" src="webrtc_test_utilities.js"></script> |
4 <script type="text/javascript"> | 4 <script type="text/javascript"> |
5 $ = function(id) { | 5 $ = function(id) { |
6 return document.getElementById(id); | 6 return document.getElementById(id); |
7 }; | 7 }; |
8 | 8 |
9 var gFirstConnection = null; | 9 var gFirstConnection = null; |
10 var gSecondConnection = null; | 10 var gSecondConnection = null; |
11 var gTestWithoutMsidAndBundle = false; | 11 var gTestWithoutMsidAndBundle = false; |
12 | 12 |
13 var gLocalStream = null; | 13 var gLocalStream = null; |
14 var gSentTones = ''; | 14 var gSentTones = ''; |
15 | 15 |
16 setAllEventsOccuredHandler(function() { | 16 setAllEventsOccuredHandler(function() { |
17 document.title = 'OK'; | 17 document.title = 'OK'; |
18 }); | 18 }); |
19 | 19 |
20 // Test that we can setup call with an audio and video track. | 20 // Test that we can setup call with an audio and video track. |
21 function call(constraints) { | 21 function call(constraints) { |
22 createConnections(null); | 22 createConnections(null); |
23 navigator.webkitGetUserMedia(constraints, | 23 navigator.webkitGetUserMedia(constraints, |
24 addStreamToBothConnectionsAndNegotiate, printGetUserMediaError); | 24 addStreamToBothConnectionsAndNegotiate, printGetUserMediaError); |
25 waitForVideo('remote-view-1'); | 25 waitForVideo('remote-view-1'); |
26 waitForVideo('remote-view-2'); | 26 waitForVideo('remote-view-2'); |
27 } | 27 } |
28 | 28 |
29 // First calls without streams on any connections, and then adds a stream | 29 // First calls without streams on any connections, and then adds a stream |
30 // to peer connection 1 which gets sent to peer connection 2. | 30 // to peer connection 1 which gets sent to peer connection 2. We must wait |
31 function makeEmptyCallThenAddOneStreamAndRenegotiate(constraints) { | 31 // for the first negotiation to complete before starting the second one, which |
32 // is why we wait until the connection is stable before re-negotiating. | |
33 function callEmptyThenAddOneStreamAndRenegotiate(constraints) { | |
32 createConnections(null); | 34 createConnections(null); |
33 negotiate(); | 35 negotiate(); |
36 waitForConnectionToStabilize(gFirstConnection); | |
34 navigator.webkitGetUserMedia(constraints, | 37 navigator.webkitGetUserMedia(constraints, |
35 addStreamToTheFirstConnectionAndNegotiate, printGetUserMediaError); | 38 addStreamToTheFirstConnectionAndNegotiate, printGetUserMediaError); |
36 // Only the first connection is sending here. | 39 // Only the first connection is sending here. |
37 waitForVideo('remote-view-2'); | 40 waitForVideo('remote-view-2'); |
38 } | 41 } |
39 | 42 |
40 // Test that we can setup call with an audio and video track and | 43 // Test that we can setup call with an audio and video track and |
41 // simulate that the remote peer don't support MSID. | 44 // simulate that the remote peer don't support MSID. |
42 function callWithoutMsidAndBundle() { | 45 function callWithoutMsidAndBundle() { |
43 createConnections(null); | 46 createConnections(null); |
44 gTestWithoutMsidAndBundle = true; | 47 gTestWithoutMsidAndBundle = true; |
45 navigator.webkitGetUserMedia({audio:true, video:true}, | 48 navigator.webkitGetUserMedia({audio:true, video:true}, |
46 addStreamToBothConnectionsAndNegotiate, printGetUserMediaError); | 49 addStreamToBothConnectionsAndNegotiate, printGetUserMediaError); |
47 waitForVideo('remote-view-1'); | 50 waitForVideo('remote-view-1'); |
48 waitForVideo('remote-view-2'); | 51 waitForVideo('remote-view-2'); |
49 } | 52 } |
50 | 53 |
51 // Test only a data channel. | 54 // Test only a data channel. |
52 function callWithDataOnly() { | 55 function callWithDataOnly() { |
53 createConnections({optional:[{RtpDataChannels: true}]}); | 56 createConnections({optional:[{RtpDataChannels: true}]}); |
54 setupDataChannel(); | 57 setupDataChannel(); |
55 gFirstConnection.createOffer(onOfferCreated); | 58 negotiate(); |
56 } | 59 } |
57 | 60 |
58 // Test call with audio, video and a data channel. | 61 // Test call with audio, video and a data channel. |
59 function callWithDataAndMedia() { | 62 function callWithDataAndMedia() { |
60 createConnections({optional:[{RtpDataChannels: true}]}); | 63 createConnections({optional:[{RtpDataChannels: true}]}); |
61 setupDataChannel(); | 64 setupDataChannel(); |
62 navigator.webkitGetUserMedia({audio:true, video:true}, | 65 navigator.webkitGetUserMedia({audio:true, video:true}, |
63 addStreamToBothConnectionsAndNegotiate, | 66 addStreamToBothConnectionsAndNegotiate, |
64 printGetUserMediaError); | 67 printGetUserMediaError); |
65 waitForVideo('remote-view-1'); | 68 waitForVideo('remote-view-1'); |
66 waitForVideo('remote-view-2'); | 69 waitForVideo('remote-view-2'); |
67 } | 70 } |
68 | 71 |
69 // Test call with a data channel and later add audio and video. | 72 // Test call with a data channel and later add audio and video. |
70 function callWithDataAndLaterAddMedia() { | 73 function callWithDataAndLaterAddMedia() { |
71 createConnections({optional:[{RtpDataChannels: true}]}); | 74 createConnections({optional:[{RtpDataChannels: true}]}); |
72 setupDataChannel(); | 75 setupDataChannel(); |
73 gFirstConnection.createOffer(onOfferCreated); | 76 negotiate(); |
74 | 77 |
75 // Set an event handler for when the data channel has been closed. | 78 // Set an event handler for when the data channel has been closed. |
76 setAllEventsOccuredHandler(function() { | 79 setAllEventsOccuredHandler(function() { |
77 // When the video is flowing the test is done. | 80 // When the video is flowing the test is done. |
78 setAllEventsOccuredHandler(function() { | 81 setAllEventsOccuredHandler(function() { |
79 document.title = 'OK'; | 82 document.title = 'OK'; |
80 }); | 83 }); |
81 navigator.webkitGetUserMedia({audio:true, video:true}, | 84 navigator.webkitGetUserMedia({audio:true, video:true}, |
82 addStreamToBothConnectionsAndNegotiate, printGetUserMediaError); | 85 addStreamToBothConnectionsAndNegotiate, printGetUserMediaError); |
83 waitForVideo('remote-view-1'); | 86 waitForVideo('remote-view-1'); |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
201 firstDataChannel.onopen = function() { | 204 firstDataChannel.onopen = function() { |
202 expectEquals('open', firstDataChannel.readyState); | 205 expectEquals('open', firstDataChannel.readyState); |
203 firstDataChannel.send(sendDataString); | 206 firstDataChannel.send(sendDataString); |
204 } | 207 } |
205 | 208 |
206 // When |firstDataChannel| receive a message, close the channel and | 209 // When |firstDataChannel| receive a message, close the channel and |
207 // initiate a new offer/answer exchange to complete the closure. | 210 // initiate a new offer/answer exchange to complete the closure. |
208 firstDataChannel.onmessage = function(event) { | 211 firstDataChannel.onmessage = function(event) { |
209 expectEquals(event.data, sendDataString); | 212 expectEquals(event.data, sendDataString); |
210 firstDataChannel.close(); | 213 firstDataChannel.close(); |
211 gFirstConnection.createOffer(onOfferCreated); | 214 negotiate(); |
212 } | 215 } |
213 | 216 |
214 // When |firstDataChannel| transition to closed state, the test pass. | 217 // When |firstDataChannel| transition to closed state, the test pass. |
215 addExpectedEvent(); | 218 addExpectedEvent(); |
216 firstDataChannel.onclose = function() { | 219 firstDataChannel.onclose = function() { |
217 expectEquals('closed', firstDataChannel.readyState); | 220 expectEquals('closed', firstDataChannel.readyState); |
218 eventOccured(); | 221 eventOccured(); |
219 } | 222 } |
220 | 223 |
221 // Event handler for when |gSecondConnection| receive a new dataChannel. | 224 // Event handler for when |gSecondConnection| receive a new dataChannel. |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
283 // |localStream| is added. | 286 // |localStream| is added. |
284 function createNewVideoStreamAndAddToBothConnections(localStream) { | 287 function createNewVideoStreamAndAddToBothConnections(localStream) { |
285 displayAndRemember(localStream); | 288 displayAndRemember(localStream); |
286 var new_stream = new webkitMediaStream(); | 289 var new_stream = new webkitMediaStream(); |
287 new_stream.addTrack(localStream.getVideoTracks()[0]); | 290 new_stream.addTrack(localStream.getVideoTracks()[0]); |
288 gFirstConnection.addStream(new_stream); | 291 gFirstConnection.addStream(new_stream); |
289 gSecondConnection.addStream(new_stream); | 292 gSecondConnection.addStream(new_stream); |
290 negotiate(); | 293 negotiate(); |
291 } | 294 } |
292 | 295 |
293 function negotiate() { | 296 function negotiate() { |
phoglund_chromium
2013/05/28 08:04:34
This should catch future negotiation races, such a
| |
297 // Not stable = negotiation is ongoing. The behavior of re-negotiating while | |
298 // a negotiation is ongoing is more or less undefined, so avoid this. | |
299 if (gFirstConnection.signalingState != 'stable') | |
300 throw 'You can only negotiate when the connection is stable!'; | |
301 | |
294 gFirstConnection.createOffer(onOfferCreated); | 302 gFirstConnection.createOffer(onOfferCreated); |
295 } | 303 } |
296 | 304 |
297 function onOfferCreated(offer) { | 305 function onOfferCreated(offer) { |
298 gFirstConnection.setLocalDescription(offer); | 306 gFirstConnection.setLocalDescription(offer); |
299 expectEquals('have-local-offer', gFirstConnection.signalingState); | 307 expectEquals('have-local-offer', gFirstConnection.signalingState); |
300 receiveOffer(offer.sdp); | 308 receiveOffer(offer.sdp); |
301 } | 309 } |
302 | 310 |
303 function receiveOffer(offerSdp) { | 311 function receiveOffer(offerSdp) { |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
380 autoplay="autoplay"></video></td> | 388 autoplay="autoplay"></video></td> |
381 <!-- Canvases are named after their corresponding video elements. --> | 389 <!-- Canvases are named after their corresponding video elements. --> |
382 <td><canvas width="320" height="240" id="remote-view-1-canvas" | 390 <td><canvas width="320" height="240" id="remote-view-1-canvas" |
383 style="display:none"></canvas></td> | 391 style="display:none"></canvas></td> |
384 <td><canvas width="320" height="240" id="remote-view-2-canvas"> | 392 <td><canvas width="320" height="240" id="remote-view-2-canvas"> |
385 style="display:none"></canvas></td> | 393 style="display:none"></canvas></td> |
386 </tr> | 394 </tr> |
387 </table> | 395 </table> |
388 </body> | 396 </body> |
389 </html> | 397 </html> |
OLD | NEW |