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.
11 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
12 <title>RTCPeerConnection Connection Test</title>
17 <video id="local-view" autoplay="autoplay"></video>
18 <video id="remote-view" autoplay="autoplay"/>
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 {"ancestors":["window"], "name":"RTCPeerConnection"},
29 {"ancestors":["window"], "name":"RTCSessionDescription"},
30 {"ancestors":["window"], "name":"RTCIceCandidate"}]'
31 data-prefixed-prototypes=
32 '[{"ancestors":["HTMLMediaElement"],"name":"srcObject"}]'>
34 <script type="text/javascript">
35 var test = async_test('Can set up a basic WebRTC call.', {timeout: 5000});
37 var gFirstConnection = null;
38 var gSecondConnection = null;
40 function getUserMediaOkCallback(localStream) {
41 gFirstConnection = new RTCPeerConnection(null, null);
42 gFirstConnection.onicecandidate = onIceCandidateToFirst;
43 gFirstConnection.addStream(localStream);
44 gFirstConnection.createOffer(onOfferCreated, failed('createOffer'));
46 var videoTag = document.getElementById('local-view');
47 videoTag.srcObject = localStream;
50 var onOfferCreated = test.step_func(function(offer) {
51 gFirstConnection.setLocalDescription(offer);
53 // This would normally go across the application's signaling solution.
54 // In our case, the "signaling" is to call this function.
55 receiveCall(offer.sdp);
58 function receiveCall(offerSdp) {
59 gSecondConnection = new RTCPeerConnection(null, null);
60 gSecondConnection.onicecandidate = onIceCandidateToSecond;
61 gSecondConnection.onaddstream = onRemoteStream;
63 var parsedOffer = new RTCSessionDescription({ type: 'offer',
65 gSecondConnection.setRemoteDescription(parsedOffer);
67 gSecondConnection.createAnswer(onAnswerCreated,
68 failed('createAnswer'));
71 var onAnswerCreated = test.step_func(function(answer) {
72 gSecondConnection.setLocalDescription(answer);
74 // Similarly, this would go over the application's signaling solution.
75 handleAnswer(answer.sdp);
78 function handleAnswer(answerSdp) {
79 var parsedAnswer = new RTCSessionDescription({ type: 'answer',
81 gFirstConnection.setRemoteDescription(parsedAnswer);
83 // Call negotiated: done.
87 // Note: the ice candidate handlers are special. We can not wrap them in test
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.
92 if (event.candidate) {
93 var candidate = new RTCIceCandidate(event.candidate);
94 gSecondConnection.addIceCandidate(candidate);
98 var onIceCandidateToSecond = function(event) {
99 if (event.candidate) {
100 var candidate = new RTCIceCandidate(event.candidate);
101 gFirstConnection.addIceCandidate(candidate);
105 var onRemoteStream = test.step_func(function(event) {
106 var videoTag = document.getElementById('remote-view');
107 videoTag.srcObject = event.stream;
110 // Returns a suitable error callback.
111 function failed(function_name) {
112 return test.step_func(function() {
113 assert_unreached('WebRTC called error callback for ' + function_name);
117 // This function starts the test.
118 test.step(function() {
119 navigator.getUserMedia({ video: true, audio: true },
120 getUserMediaOkCallback,
121 failed('getUserMedia'));