1 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
4 To quickly iterate when developing this test, use --use-fake-ui-for-media-stream
5 for Chrome and set the media.navigator.permission.disabled property to true in
6 Firefox. You must either have a webcam/mic available on the system or use for
7 instance --use-fake-device-for-media-stream for Chrome.
12 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
13 <title>PeerConnection Connection Test</title>
18 <video id="local-view" autoplay="autoplay"></video>
19 <video id="remote-view" autoplay="autoplay"/>
23 <!-- These files are in place when executing on W3C. -->
24 <script src="/resources/testharness.js"></script>
25 <script src="/resources/testharnessreport.js"></script>
26 <script src="/common/vendor-prefix.js"
27 data-prefixed-objects=
28 '[{"ancestors":["navigator"], "name":"getUserMedia"},
29 {"ancestors":["window"], "name":"RTCPeerConnection"},
30 {"ancestors":["window"], "name":"RTCSessionDescription"},
31 {"ancestors":["window"], "name":"RTCIceCandidate"}]'
32 data-prefixed-prototypes=
33 '[{"ancestors":["HTMLMediaElement"],"name":"srcObject"}]'>
35 <script type="text/javascript">
36 var test = async_test('Can set up a basic WebRTC call.', {timeout: 5000});
38 var gFirstConnection = null;
39 var gSecondConnection = null;
41 function getUserMediaOkCallback(localStream) {
42 gFirstConnection = new RTCPeerConnection(null, null);
43 gFirstConnection.onicecandidate = onIceCandidateToFirst;
44 gFirstConnection.addStream(localStream);
45 gFirstConnection.createOffer(onOfferCreated, failed('createOffer'));
47 var videoTag = document.getElementById('local-view');
48 videoTag.src = URL.createObjectURL(localStream);
51 var onOfferCreated = test.step_func(function(offer) {
52 gFirstConnection.setLocalDescription(offer);
54 // This would normally go across the application's signaling solution.
55 // In our case, the "signaling" is to call this function.
56 receiveCall(offer.sdp);
59 function receiveCall(offerSdp) {
60 gSecondConnection = new RTCPeerConnection(null, null);
61 gSecondConnection.onicecandidate = onIceCandidateToSecond;
62 gSecondConnection.onaddstream = onRemoteStream;
64 var parsedOffer = new RTCSessionDescription({ type: 'offer',
66 gSecondConnection.setRemoteDescription(parsedOffer);
68 gSecondConnection.createAnswer(onAnswerCreated,
69 failed('createAnswer'));
72 var onAnswerCreated = test.step_func(function(answer) {
73 gSecondConnection.setLocalDescription(answer);
75 // Similarly, this would go over the application's signaling solution.
76 handleAnswer(answer.sdp);
79 function handleAnswer(answerSdp) {
80 var parsedAnswer = new RTCSessionDescription({ type: 'answer',
82 gFirstConnection.setRemoteDescription(parsedAnswer);
84 // Call negotiated: done.
88 // Note: the ice candidate handlers are special. We can not wrap them in test
89 // steps since that seems to cause some kind of starvation that prevents the
90 // call of being set up. Unfortunately we cannot report errors in here.
91 var onIceCandidateToFirst = function(event) {
92 // If event.candidate is null = no more candidates.
93 if (event.candidate) {
94 var candidate = new RTCIceCandidate(event.candidate);
95 gSecondConnection.addIceCandidate(candidate);
99 var onIceCandidateToSecond = function(event) {
100 if (event.candidate) {
101 var candidate = new RTCIceCandidate(event.candidate);
102 gFirstConnection.addIceCandidate(candidate);
106 var onRemoteStream = test.step_func(function(event) {
107 var videoTag = document.getElementById('remote-view');
108 videoTag.src = URL.createObjectURL(event.stream);
111 // Returns a suitable error callback.
112 function failed(function_name) {
113 return test.step_func(function() {
114 assert_unreached('WebRTC called error callback for ' + function_name);
118 // This function starts the test.
119 test.step(function() {
120 navigator.getUserMedia({ video: true, audio: true },
121 getUserMediaOkCallback,
122 failed('getUserMedia'));