| OLD | NEW |
| (Empty) |
| 1 <!doctype html> | |
| 2 <!-- | |
| 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 | |
| 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. | |
| 7 --> | |
| 8 | |
| 9 <html> | |
| 10 <head> | |
| 11 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> | |
| 12 <title>RTCPeerConnection Connection Test</title> | |
| 13 </head> | |
| 14 <body> | |
| 15 <div id="log"></div> | |
| 16 <div> | |
| 17 <video id="local-view" autoplay="autoplay"></video> | |
| 18 <video id="remote-view" autoplay="autoplay"/> | |
| 19 </video> | |
| 20 </div> | |
| 21 | |
| 22 <!-- These files are in place when executing on W3C. --> | |
| 23 <script src="../../../resources/testharness.js"></script> | |
| 24 <script src="../../../resources/testharnessreport.js"></script> | |
| 25 <script src="../../../resources/vendor-prefix.js" | |
| 26 data-prefixed-objects= | |
| 27 '[{"ancestors":["navigator"], "name":"getUserMedia"}]' | |
| 28 data-prefixed-prototypes= | |
| 29 '[{"ancestors":["HTMLMediaElement"],"name":"srcObject"}]'> | |
| 30 </script> | |
| 31 <script type="text/javascript"> | |
| 32 var test = async_test('Can set up a basic WebRTC call.', {timeout: 5000}); | |
| 33 | |
| 34 var gFirstConnection = null; | |
| 35 var gSecondConnection = null; | |
| 36 | |
| 37 function getUserMediaOkCallback(localStream) { | |
| 38 gFirstConnection = new RTCPeerConnection(null); | |
| 39 gFirstConnection.onicecandidate = onIceCandidateToFirst; | |
| 40 gFirstConnection.addStream(localStream); | |
| 41 gFirstConnection.createOffer(onOfferCreated, failed('createOffer')); | |
| 42 | |
| 43 var videoTag = document.getElementById('local-view'); | |
| 44 videoTag.srcObject = localStream; | |
| 45 }; | |
| 46 | |
| 47 var onOfferCreated = test.step_func(function(offer) { | |
| 48 gFirstConnection.setLocalDescription(offer); | |
| 49 | |
| 50 // This would normally go across the application's signaling solution. | |
| 51 // In our case, the "signaling" is to call this function. | |
| 52 receiveCall(offer.sdp); | |
| 53 }); | |
| 54 | |
| 55 function receiveCall(offerSdp) { | |
| 56 gSecondConnection = new RTCPeerConnection(null); | |
| 57 gSecondConnection.onicecandidate = onIceCandidateToSecond; | |
| 58 gSecondConnection.onaddstream = onRemoteStream; | |
| 59 | |
| 60 var parsedOffer = new RTCSessionDescription({ type: 'offer', | |
| 61 sdp: offerSdp }); | |
| 62 gSecondConnection.setRemoteDescription(parsedOffer); | |
| 63 | |
| 64 gSecondConnection.createAnswer(onAnswerCreated, | |
| 65 failed('createAnswer')); | |
| 66 }; | |
| 67 | |
| 68 var onAnswerCreated = test.step_func(function(answer) { | |
| 69 gSecondConnection.setLocalDescription(answer); | |
| 70 | |
| 71 // Similarly, this would go over the application's signaling solution. | |
| 72 handleAnswer(answer.sdp); | |
| 73 }); | |
| 74 | |
| 75 function handleAnswer(answerSdp) { | |
| 76 var parsedAnswer = new RTCSessionDescription({ type: 'answer', | |
| 77 sdp: answerSdp }); | |
| 78 gFirstConnection.setRemoteDescription(parsedAnswer); | |
| 79 | |
| 80 // Call negotiated: done. | |
| 81 test.done(); | |
| 82 }; | |
| 83 | |
| 84 var onIceCandidateToFirst = test.step_func(function(event) { | |
| 85 // If event.candidate is null = no more candidates. | |
| 86 if (event.candidate) { | |
| 87 gSecondConnection.addIceCandidate(event.candidate); | |
| 88 } | |
| 89 }); | |
| 90 | |
| 91 var onIceCandidateToSecond = test.step_func(function(event) { | |
| 92 if (event.candidate) { | |
| 93 gFirstConnection.addIceCandidate(event.candidate); | |
| 94 } | |
| 95 }); | |
| 96 | |
| 97 var onRemoteStream = test.step_func(function(event) { | |
| 98 var videoTag = document.getElementById('remote-view'); | |
| 99 videoTag.srcObject = event.stream; | |
| 100 }); | |
| 101 | |
| 102 // Returns a suitable error callback. | |
| 103 function failed(function_name) { | |
| 104 return test.step_func(function() { | |
| 105 assert_unreached('WebRTC called error callback for ' + function_name); | |
| 106 }); | |
| 107 } | |
| 108 | |
| 109 // This function starts the test. | |
| 110 test.step(function() { | |
| 111 navigator.getUserMedia({ video: true, audio: true }, | |
| 112 getUserMediaOkCallback, | |
| 113 failed('getUserMedia')); | |
| 114 }); | |
| 115 </script> | |
| 116 | |
| 117 </body> | |
| 118 </html> | |
| OLD | NEW |