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. |
31 function makeEmptyCallThenAddOneStreamAndRenegotiate(constraints) { | 31 function makeEmptyCallThenAddOneStreamAndRenegotiate(constraints) { |
32 createConnections(null); | 32 createConnections(null); |
33 negotiate(); | 33 negotiate(); |
34 navigator.webkitGetUserMedia(constraints, | 34 navigator.webkitGetUserMedia(constraints, |
35 addStreamToTheFirstConnectionAndNegotiate, printGetUserMediaError); | 35 addStreamToTheFirstConnectionAndNegotiate, printGetUserMediaError); |
36 // Only the first connection is sending here. | 36 // Only the first connection is sending here. |
37 waitForVideo('remote-view-2'); | 37 waitForVideo('remote-view-2'); |
38 } | 38 } |
39 | 39 |
40 // Test that we can setup call with an audio and video track and | 40 // Test that we can setup call with an audio and video track and |
41 // simulate that the remote peer don't support MSID. | 41 // simulate that the remote peer don't support MSID. |
42 function callWithoutMsidAndBundle() { | 42 function callWithoutMsidAndBundle() { |
43 createConnections(null); | 43 createConnections(null); |
44 gTestWithoutMsidAndBundle = true; | 44 gTestWithoutMsidAndBundle = true; |
45 navigator.webkitGetUserMedia({audio:true, video:true}, | 45 navigator.webkitGetUserMedia({audio:true, video:true}, |
46 addStreamToBothConnectionsAndNegotiate, printGetUserMediaError); | 46 addStreamToBothConnectionsAndNegotiate, printGetUserMediaError); |
47 waitForVideo('remote-view-1'); | 47 waitForVideo('remote-view-1'); |
48 waitForVideo('remote-view-2'); | 48 waitForVideo('remote-view-2'); |
49 } | 49 } |
50 | 50 |
51 // Test only a data channel. | 51 // Test only a data channel. |
52 function callWithDataOnly() { | 52 function callWithDataOnly() { |
53 createConnections({optional:[{RtpDataChannels: true}]}); | 53 createConnections({optional:[{RtpDataChannels: true}]}); |
54 setupDataChannel(); | 54 setupDataChannel(); |
55 gFirstConnection.createOffer(onOfferCreated); | 55 gFirstConnection.createOffer(onOfferCreated); |
56 } | 56 } |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 if (gSentTones == tones) { | 96 if (gSentTones == tones) { |
97 clearInterval(waitDtmf); | 97 clearInterval(waitDtmf); |
98 eventOccured(); | 98 eventOccured(); |
99 } | 99 } |
100 }, 100); | 100 }, 100); |
101 } | 101 } |
102 | 102 |
103 // Do the DTMF test after we have received video. | 103 // Do the DTMF test after we have received video. |
104 detectVideoIn('remote-view-2', onCallEstablished); | 104 detectVideoIn('remote-view-2', onCallEstablished); |
105 } | 105 } |
106 | 106 |
107 // Test call with a new Video MediaStream that has been created based on a | 107 // Test call with a new Video MediaStream that has been created based on a |
108 // stream generated by getUserMedia. | 108 // stream generated by getUserMedia. |
109 function callWithNewVideoMediaStream() { | 109 function callWithNewVideoMediaStream() { |
110 createConnections(null); | 110 createConnections(null); |
111 navigator.webkitGetUserMedia({audio:true, video:true}, | 111 navigator.webkitGetUserMedia({audio:true, video:true}, |
112 createNewVideoStreamAndAddToBothConnections, printGetUserMediaError); | 112 createNewVideoStreamAndAddToBothConnections, printGetUserMediaError); |
113 waitForVideo('remote-view-1'); | 113 waitForVideo('remote-view-1'); |
114 waitForVideo('remote-view-2'); | 114 waitForVideo('remote-view-2'); |
115 } | 115 } |
116 | 116 |
| 117 // Test call with a new Video MediaStream that has been created based on a |
| 118 // stream generated by getUserMedia. When Video is flowing, an audio track |
| 119 // is added to the sent stream and the video track is removed. This |
| 120 // is to test that adding and removing of remote tracks on an existing |
| 121 // mediastream works. |
| 122 function callWithNewVideoMediaStreamLaterSwitchToAudio() { |
| 123 createConnections(null); |
| 124 navigator.webkitGetUserMedia({audio:true, video:true}, |
| 125 createNewVideoStreamAndAddToBothConnections, printGetUserMediaError); |
| 126 |
| 127 waitForVideo('remote-view-1'); |
| 128 waitForVideo('remote-view-2'); |
| 129 |
| 130 // Set an event handler for when video is playing. |
| 131 setAllEventsOccuredHandler(function() { |
| 132 // Add an audio track to the local stream and remove the video track and |
| 133 // then renegotiate. But first - setup the expectations. |
| 134 local_stream = gFirstConnection.getLocalStreams()[0]; |
| 135 |
| 136 remote_stream_1 = gFirstConnection.getRemoteStreams()[0]; |
| 137 // Add an expected event that onaddtrack will be called on the remote |
| 138 // mediastream received on gFirstConnection when the audio track is |
| 139 // received. |
| 140 addExpectedEvent(); |
| 141 remote_stream_1.onaddtrack = function(){ |
| 142 expectEquals(remote_stream_1.getAudioTracks()[0].id, |
| 143 local_stream.getAudioTracks()[0].id); |
| 144 eventOccured(); |
| 145 } |
| 146 |
| 147 // Add an expectation that the received video track is removed from |
| 148 // gFirstConnection. |
| 149 addExpectedEvent(); |
| 150 remote_stream_1.onremovetrack = function() { |
| 151 eventOccured(); |
| 152 } |
| 153 |
| 154 // Add an expected event that onaddtrack will be called on the remote |
| 155 // mediastream received on gSecondConnection when the audio track is |
| 156 // received. |
| 157 remote_stream_2 = gSecondConnection.getRemoteStreams()[0]; |
| 158 addExpectedEvent(); |
| 159 remote_stream_2.onaddtrack = function() { |
| 160 expectEquals(remote_stream_2.getAudioTracks()[0].id, |
| 161 local_stream.getAudioTracks()[0].id); |
| 162 eventOccured(); |
| 163 } |
| 164 |
| 165 // Add an expectation that the received video track is removed from |
| 166 // gSecondConnection. |
| 167 addExpectedEvent(); |
| 168 remote_stream_2.onremovetrack = function() { |
| 169 eventOccured(); |
| 170 } |
| 171 // When all the above events have occurred- the test pass. |
| 172 setAllEventsOccuredHandler(function() { document.title = 'OK'; }); |
| 173 |
| 174 local_stream.addTrack(gLocalStream.getAudioTracks()[0]); |
| 175 local_stream.removeTrack(local_stream.getVideoTracks()[0]); |
| 176 negotiate(); |
| 177 }); // End of setAllEventsOccuredHandler. |
| 178 } |
| 179 |
117 // This function is used for setting up a test that: | 180 // This function is used for setting up a test that: |
118 // 1. Creates a data channel on |gFirstConnection| and sends data to | 181 // 1. Creates a data channel on |gFirstConnection| and sends data to |
119 // |gSecondConnection|. | 182 // |gSecondConnection|. |
120 // 2. When data is received on |gSecondConnection| a message | 183 // 2. When data is received on |gSecondConnection| a message |
121 // is sent to |gFirstConnection|. | 184 // is sent to |gFirstConnection|. |
122 // 3. When data is received on |gFirstConnection|, the data | 185 // 3. When data is received on |gFirstConnection|, the data |
123 // channel is closed. The test passes when the state transition completes. | 186 // channel is closed. The test passes when the state transition completes. |
124 function setupDataChannel() { | 187 function setupDataChannel() { |
125 var sendDataString = "send some text on a data channel." | 188 var sendDataString = "send some text on a data channel." |
126 firstDataChannel = gFirstConnection.createDataChannel( | 189 firstDataChannel = gFirstConnection.createDataChannel( |
(...skipping 25 matching lines...) Expand all Loading... |
152 gSecondConnection.ondatachannel = function (event) { | 215 gSecondConnection.ondatachannel = function (event) { |
153 var secondDataChannel = event.channel; | 216 var secondDataChannel = event.channel; |
154 | 217 |
155 // When |secondDataChannel| receive a message, send a message back. | 218 // When |secondDataChannel| receive a message, send a message back. |
156 secondDataChannel.onmessage = function(event) { | 219 secondDataChannel.onmessage = function(event) { |
157 expectEquals(event.data, sendDataString); | 220 expectEquals(event.data, sendDataString); |
158 expectEquals('open', secondDataChannel.readyState); | 221 expectEquals('open', secondDataChannel.readyState); |
159 secondDataChannel.send(sendDataString); | 222 secondDataChannel.send(sendDataString); |
160 } | 223 } |
161 } | 224 } |
162 } | 225 } |
163 | 226 |
164 function onToneChange(tone) { | 227 function onToneChange(tone) { |
165 gSentTones += tone.tone; | 228 gSentTones += tone.tone; |
166 document.title = gSentTones; | 229 document.title = gSentTones; |
167 } | 230 } |
168 | 231 |
169 function createConnections(constraints) { | 232 function createConnections(constraints) { |
170 gFirstConnection = new webkitRTCPeerConnection(null, constraints); | 233 gFirstConnection = new webkitRTCPeerConnection(null, constraints); |
171 gFirstConnection.onicecandidate = onIceCandidateToFirst; | 234 gFirstConnection.onicecandidate = onIceCandidateToFirst; |
172 gFirstConnection.onaddstream = function(event) { | 235 gFirstConnection.onaddstream = function(event) { |
(...skipping 27 matching lines...) Expand all Loading... |
200 gSecondConnection.addStream(localStream); | 263 gSecondConnection.addStream(localStream); |
201 negotiate(); | 264 negotiate(); |
202 } | 265 } |
203 | 266 |
204 // Called if getUserMedia succeeds when we want to send from one connection. | 267 // Called if getUserMedia succeeds when we want to send from one connection. |
205 function addStreamToTheFirstConnectionAndNegotiate(localStream) { | 268 function addStreamToTheFirstConnectionAndNegotiate(localStream) { |
206 displayAndRemember(localStream); | 269 displayAndRemember(localStream); |
207 gFirstConnection.addStream(localStream); | 270 gFirstConnection.addStream(localStream); |
208 negotiate(); | 271 negotiate(); |
209 } | 272 } |
210 | 273 |
211 // Called if getUserMedia succeeds when we want to send a modified | 274 // Called if getUserMedia succeeds when we want to send a modified |
212 // MediaStream. A new MediaStream is created and the video track from | 275 // MediaStream. A new MediaStream is created and the video track from |
213 // |localStream| is added. | 276 // |localStream| is added. |
214 function createNewVideoStreamAndAddToBothConnections(localStream) { | 277 function createNewVideoStreamAndAddToBothConnections(localStream) { |
| 278 displayAndRemember(localStream); |
215 var new_stream = new webkitMediaStream(); | 279 var new_stream = new webkitMediaStream(); |
216 new_stream.addTrack(localStream.getVideoTracks()[0]); | 280 new_stream.addTrack(localStream.getVideoTracks()[0]); |
217 addStreamToBothConnectionsAndNegotiate(new_stream); | 281 gFirstConnection.addStream(new_stream); |
| 282 gSecondConnection.addStream(new_stream); |
| 283 negotiate(); |
218 } | 284 } |
219 | 285 |
220 function negotiate() { | 286 function negotiate() { |
221 gFirstConnection.createOffer(onOfferCreated); | 287 gFirstConnection.createOffer(onOfferCreated); |
222 } | 288 } |
223 | 289 |
224 function onOfferCreated(offer) { | 290 function onOfferCreated(offer) { |
225 gFirstConnection.setLocalDescription(offer); | 291 gFirstConnection.setLocalDescription(offer); |
226 expectEquals('have-local-offer', gFirstConnection.signalingState); | 292 expectEquals('have-local-offer', gFirstConnection.signalingState); |
227 receiveOffer(offer.sdp); | 293 receiveOffer(offer.sdp); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
281 function onRemoteStream(e, target) { | 347 function onRemoteStream(e, target) { |
282 if (gTestWithoutMsidAndBundle && e.stream.label != "default") { | 348 if (gTestWithoutMsidAndBundle && e.stream.label != "default") { |
283 document.title = 'a default remote stream was expected but instead ' + | 349 document.title = 'a default remote stream was expected but instead ' + |
284 e.stream.label + ' was received.'; | 350 e.stream.label + ' was received.'; |
285 return; | 351 return; |
286 } | 352 } |
287 var remoteStreamUrl = webkitURL.createObjectURL(e.stream); | 353 var remoteStreamUrl = webkitURL.createObjectURL(e.stream); |
288 var remoteVideo = $(target); | 354 var remoteVideo = $(target); |
289 remoteVideo.src = remoteStreamUrl; | 355 remoteVideo.src = remoteStreamUrl; |
290 } | 356 } |
291 | 357 |
292 </script> | 358 </script> |
293 </head> | 359 </head> |
294 <body> | 360 <body> |
295 <table border="0"> | 361 <table border="0"> |
296 <tr> | 362 <tr> |
297 <td>Local Preview</td> | 363 <td>Local Preview</td> |
298 <td>Remote Stream for Connection 1</td> | 364 <td>Remote Stream for Connection 1</td> |
299 <td>Remote Stream for Connection 2</td> | 365 <td>Remote Stream for Connection 2</td> |
300 </tr> | 366 </tr> |
301 <tr> | 367 <tr> |
302 <td><video width="320" height="240" id="local-view" | 368 <td><video width="320" height="240" id="local-view" |
303 autoplay="autoplay"></video></td> | 369 autoplay="autoplay"></video></td> |
304 <td><video width="320" height="240" id="remote-view-1" | 370 <td><video width="320" height="240" id="remote-view-1" |
305 autoplay="autoplay"></video></td> | 371 autoplay="autoplay"></video></td> |
306 <td><video width="320" height="240" id="remote-view-2" | 372 <td><video width="320" height="240" id="remote-view-2" |
307 autoplay="autoplay"></video></td> | 373 autoplay="autoplay"></video></td> |
308 <!-- Canvases are named after their corresponding video elements. --> | 374 <!-- Canvases are named after their corresponding video elements. --> |
309 <td><canvas width="320" height="240" id="remote-view-1-canvas" | 375 <td><canvas width="320" height="240" id="remote-view-1-canvas" |
310 style="display:none"></canvas></td> | 376 style="display:none"></canvas></td> |
311 <td><canvas width="320" height="240" id="remote-view-2-canvas"> | 377 <td><canvas width="320" height="240" id="remote-view-2-canvas"> |
312 style="display:none"></canvas></td> | 378 style="display:none"></canvas></td> |
313 </tr> | 379 </tr> |
314 </table> | 380 </table> |
315 </body> | 381 </body> |
316 </html> | 382 </html> |
OLD | NEW |