| OLD | NEW |
| 1 <!doctype html> | 1 <!doctype html> |
| 2 <!-- | 2 <!-- |
| 3 To quickly iterate when developing this test, use --use-fake-ui-for-media-stream | 3 To quickly iterate when developing this test, use --use-fake-ui-for-media-stream |
| 4 for Chrome and set the media.navigator.permission.disabled property to true in | 4 for Chrome and set the media.navigator.permission.disabled property to true in |
| 5 Firefox. You must either have a webcam/mic available on the system or use for | 5 Firefox. You must either have a webcam/mic available on the system or use for |
| 6 instance --use-fake-device-for-media-stream for Chrome. | 6 instance --use-fake-device-for-media-stream for Chrome. |
| 7 --> | 7 --> |
| 8 | 8 |
| 9 <html> | 9 <html> |
| 10 <head> | 10 <head> |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 data-prefixed-prototypes= | 31 data-prefixed-prototypes= |
| 32 '[{"ancestors":["HTMLMediaElement"],"name":"srcObject"}]'> | 32 '[{"ancestors":["HTMLMediaElement"],"name":"srcObject"}]'> |
| 33 </script> | 33 </script> |
| 34 <script type="text/javascript"> | 34 <script type="text/javascript"> |
| 35 var test = async_test('Can set up a basic WebRTC call.', {timeout: 5000}); | 35 var test = async_test('Can set up a basic WebRTC call.', {timeout: 5000}); |
| 36 | 36 |
| 37 var gFirstConnection = null; | 37 var gFirstConnection = null; |
| 38 var gSecondConnection = null; | 38 var gSecondConnection = null; |
| 39 | 39 |
| 40 function getUserMediaOkCallback(localStream) { | 40 function getUserMediaOkCallback(localStream) { |
| 41 gFirstConnection = new RTCPeerConnection(null, null); | 41 gFirstConnection = new RTCPeerConnection(null); |
| 42 gFirstConnection.onicecandidate = onIceCandidateToFirst; | 42 gFirstConnection.onicecandidate = onIceCandidateToFirst; |
| 43 gFirstConnection.addStream(localStream); | 43 gFirstConnection.addStream(localStream); |
| 44 gFirstConnection.createOffer(onOfferCreated, failed('createOffer')); | 44 gFirstConnection.createOffer(onOfferCreated, failed('createOffer')); |
| 45 | 45 |
| 46 var videoTag = document.getElementById('local-view'); | 46 var videoTag = document.getElementById('local-view'); |
| 47 videoTag.srcObject = localStream; | 47 videoTag.srcObject = localStream; |
| 48 }; | 48 }; |
| 49 | 49 |
| 50 var onOfferCreated = test.step_func(function(offer) { | 50 var onOfferCreated = test.step_func(function(offer) { |
| 51 gFirstConnection.setLocalDescription(offer); | 51 gFirstConnection.setLocalDescription(offer); |
| 52 | 52 |
| 53 // This would normally go across the application's signaling solution. | 53 // This would normally go across the application's signaling solution. |
| 54 // In our case, the "signaling" is to call this function. | 54 // In our case, the "signaling" is to call this function. |
| 55 receiveCall(offer.sdp); | 55 receiveCall(offer.sdp); |
| 56 }); | 56 }); |
| 57 | 57 |
| 58 function receiveCall(offerSdp) { | 58 function receiveCall(offerSdp) { |
| 59 gSecondConnection = new RTCPeerConnection(null, null); | 59 gSecondConnection = new RTCPeerConnection(null); |
| 60 gSecondConnection.onicecandidate = onIceCandidateToSecond; | 60 gSecondConnection.onicecandidate = onIceCandidateToSecond; |
| 61 gSecondConnection.onaddstream = onRemoteStream; | 61 gSecondConnection.onaddstream = onRemoteStream; |
| 62 | 62 |
| 63 var parsedOffer = new RTCSessionDescription({ type: 'offer', | 63 var parsedOffer = new RTCSessionDescription({ type: 'offer', |
| 64 sdp: offerSdp }); | 64 sdp: offerSdp }); |
| 65 gSecondConnection.setRemoteDescription(parsedOffer); | 65 gSecondConnection.setRemoteDescription(parsedOffer); |
| 66 | 66 |
| 67 gSecondConnection.createAnswer(onAnswerCreated, | 67 gSecondConnection.createAnswer(onAnswerCreated, |
| 68 failed('createAnswer')); | 68 failed('createAnswer')); |
| 69 }; | 69 }; |
| 70 | 70 |
| 71 var onAnswerCreated = test.step_func(function(answer) { | 71 var onAnswerCreated = test.step_func(function(answer) { |
| 72 gSecondConnection.setLocalDescription(answer); | 72 gSecondConnection.setLocalDescription(answer); |
| 73 | 73 |
| 74 // Similarly, this would go over the application's signaling solution. | 74 // Similarly, this would go over the application's signaling solution. |
| 75 handleAnswer(answer.sdp); | 75 handleAnswer(answer.sdp); |
| 76 }); | 76 }); |
| 77 | 77 |
| 78 function handleAnswer(answerSdp) { | 78 function handleAnswer(answerSdp) { |
| 79 var parsedAnswer = new RTCSessionDescription({ type: 'answer', | 79 var parsedAnswer = new RTCSessionDescription({ type: 'answer', |
| 80 sdp: answerSdp }); | 80 sdp: answerSdp }); |
| 81 gFirstConnection.setRemoteDescription(parsedAnswer); | 81 gFirstConnection.setRemoteDescription(parsedAnswer); |
| 82 | 82 |
| 83 // Call negotiated: done. | 83 // Call negotiated: done. |
| 84 test.done(); | 84 test.done(); |
| 85 }; | 85 }; |
| 86 | 86 |
| 87 // Note: the ice candidate handlers are special. We can not wrap them in test | 87 var onIceCandidateToFirst = test.step_func(function(event) { |
| 88 // steps since that seems to cause some kind of starvation that prevents the | |
| 89 // call of being set up. Unfortunately we cannot report errors in here. | |
| 90 var onIceCandidateToFirst = function(event) { | |
| 91 // If event.candidate is null = no more candidates. | 88 // If event.candidate is null = no more candidates. |
| 92 if (event.candidate) { | 89 if (event.candidate) { |
| 93 var candidate = new RTCIceCandidate(event.candidate); | 90 gSecondConnection.addIceCandidate(event.candidate); |
| 94 gSecondConnection.addIceCandidate(candidate); | |
| 95 } | 91 } |
| 96 }; | 92 }); |
| 97 | 93 |
| 98 var onIceCandidateToSecond = function(event) { | 94 var onIceCandidateToSecond = test.step_func(function(event) { |
| 99 if (event.candidate) { | 95 if (event.candidate) { |
| 100 var candidate = new RTCIceCandidate(event.candidate); | 96 gFirstConnection.addIceCandidate(event.candidate); |
| 101 gFirstConnection.addIceCandidate(candidate); | |
| 102 } | 97 } |
| 103 }; | 98 }); |
| 104 | 99 |
| 105 var onRemoteStream = test.step_func(function(event) { | 100 var onRemoteStream = test.step_func(function(event) { |
| 106 var videoTag = document.getElementById('remote-view'); | 101 var videoTag = document.getElementById('remote-view'); |
| 107 videoTag.srcObject = event.stream; | 102 videoTag.srcObject = event.stream; |
| 108 }); | 103 }); |
| 109 | 104 |
| 110 // Returns a suitable error callback. | 105 // Returns a suitable error callback. |
| 111 function failed(function_name) { | 106 function failed(function_name) { |
| 112 return test.step_func(function() { | 107 return test.step_func(function() { |
| 113 assert_unreached('WebRTC called error callback for ' + function_name); | 108 assert_unreached('WebRTC called error callback for ' + function_name); |
| 114 }); | 109 }); |
| 115 } | 110 } |
| 116 | 111 |
| 117 // This function starts the test. | 112 // This function starts the test. |
| 118 test.step(function() { | 113 test.step(function() { |
| 119 navigator.getUserMedia({ video: true, audio: true }, | 114 navigator.getUserMedia({ video: true, audio: true }, |
| 120 getUserMediaOkCallback, | 115 getUserMediaOkCallback, |
| 121 failed('getUserMedia')); | 116 failed('getUserMedia')); |
| 122 }); | 117 }); |
| 123 </script> | 118 </script> |
| 124 | 119 |
| 125 </body> | 120 </body> |
| 126 </html> | 121 </html> |
| OLD | NEW |