blob: 30d06d742ab09d60409410843b15cb6f07097d06 [file] [log] [blame]
phoglund@webrtc.org7d74bdb2012-11-28 13:03:17 +00001<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
2
3<!--
4To quickly iterate when developing this test, make sure you select
5'Always allow this site to use this webcam' option in the dropdown menu of
6Chrome when it's requesting access to your webcam.
7Notice that this requires the site you're browsing to use HTTPS.
8
9Without that, the test might timeout before you have had the chance to accept
10access to the webcam.
11-->
12
13<html>
14<head>
15 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
16 <title>PeerConnection Connection Test</title>
17
18 <script src="https://w3c-test.org/resources/testharness.js"></script>
19
20 <script type="text/javascript">
21 var test = async_test('Can set up a basic WebRTC call.', {timeout: 5000});
22 var gFirstConnection = null;
23 var gSecondConnection = null;
24
phoglund@webrtc.org7d74bdb2012-11-28 13:03:17 +000025 function getUserMediaOkCallback(localStream) {
26 gFirstConnection = new webkitRTCPeerConnection(null, null);
27 gFirstConnection.onicecandidate = onIceCandidateToFirst;
28 gFirstConnection.addStream(localStream);
29 gFirstConnection.createOffer(onOfferCreated);
phoglund@webrtc.org53034fb2012-11-30 11:59:20 +000030
31 var videoTag = document.getElementById('local-view');
32 videoTag.src = webkitURL.createObjectURL(localStream);
phoglund@webrtc.org7d74bdb2012-11-28 13:03:17 +000033 };
34
35 var onOfferCreated = test.step_func(function(offer) {
36 gFirstConnection.setLocalDescription(offer);
37
38 // This would normally go across the application's signaling solution.
39 // In our case, the "signaling" is to call this function.
40 receiveCall(offer.sdp);
41 });
42
phoglund@webrtc.org53034fb2012-11-30 11:59:20 +000043 function receiveCall(offerSdp) {
phoglund@webrtc.org7d74bdb2012-11-28 13:03:17 +000044 gSecondConnection = new webkitRTCPeerConnection(null, null);
45 gSecondConnection.onicecandidate = onIceCandidateToSecond;
46 gSecondConnection.onaddstream = onRemoteStream;
47
48 var parsedOffer = new RTCSessionDescription({ type: 'offer',
49 sdp: offerSdp });
50 gSecondConnection.setRemoteDescription(parsedOffer);
51
phoglund@webrtc.org53034fb2012-11-30 11:59:20 +000052 gSecondConnection.createAnswer(onAnswerCreated,
53 failed('createAnswer'));
54 };
phoglund@webrtc.org7d74bdb2012-11-28 13:03:17 +000055
56 var onAnswerCreated = test.step_func(function(answer) {
57 gSecondConnection.setLocalDescription(answer);
58
59 // Similarly, this would go over the application's signaling solution.
60 handleAnswer(answer.sdp);
61 });
62
phoglund@webrtc.org53034fb2012-11-30 11:59:20 +000063 function handleAnswer(answerSdp) {
phoglund@webrtc.org7d74bdb2012-11-28 13:03:17 +000064 var parsedAnswer = new RTCSessionDescription({ type: 'answer',
65 sdp: answerSdp });
66 gFirstConnection.setRemoteDescription(parsedAnswer);
phoglund@webrtc.org7d74bdb2012-11-28 13:03:17 +000067
phoglund@webrtc.org53034fb2012-11-30 11:59:20 +000068 // Call negotiated: done.
69 test.done();
70 };
71
72 // Note: the ice candidate handlers are special. We can not wrap them in test
73 // steps since that seems to cause some kind of starvation that prevents the
74 // call of being set up. Unfortunately we cannot report errors in here.
75 var onIceCandidateToFirst = function(event) {
phoglund@webrtc.org7d74bdb2012-11-28 13:03:17 +000076 // If event.candidate is null = no more candidates.
77 if (event.candidate) {
78 var candidate = new RTCIceCandidate(event.candidate);
79 gSecondConnection.addIceCandidate(candidate);
80 }
phoglund@webrtc.org53034fb2012-11-30 11:59:20 +000081 };
phoglund@webrtc.org7d74bdb2012-11-28 13:03:17 +000082
phoglund@webrtc.org53034fb2012-11-30 11:59:20 +000083 var onIceCandidateToSecond = function(event) {
phoglund@webrtc.org7d74bdb2012-11-28 13:03:17 +000084 if (event.candidate) {
85 var candidate = new RTCIceCandidate(event.candidate);
86 gFirstConnection.addIceCandidate(candidate);
87 }
phoglund@webrtc.org53034fb2012-11-30 11:59:20 +000088 };
89
90 var onRemoteStream = test.step_func(function(event) {
91 var videoTag = document.getElementById('remote-view');
92 videoTag.src = webkitURL.createObjectURL(event.stream);
phoglund@webrtc.org7d74bdb2012-11-28 13:03:17 +000093 });
94
phoglund@webrtc.org53034fb2012-11-30 11:59:20 +000095 // Returns a suitable error callback.
96 function failed(function_name) {
97 return test.step_func(function() {
98 assert_unreached('WebRTC called error callback for ' + function_name);
99 });
100 }
phoglund@webrtc.org7d74bdb2012-11-28 13:03:17 +0000101
phoglund@webrtc.org53034fb2012-11-30 11:59:20 +0000102 // This function starts the test.
phoglund@webrtc.org7d74bdb2012-11-28 13:03:17 +0000103 test.step(function() {
104 navigator.webkitGetUserMedia({ video: true, audio: true },
105 getUserMediaOkCallback,
phoglund@webrtc.org53034fb2012-11-30 11:59:20 +0000106 failed('getUserMedia'));
phoglund@webrtc.org7d74bdb2012-11-28 13:03:17 +0000107 });
108</script>
109</head>
110
111<body>
phoglund@webrtc.org7d74bdb2012-11-28 13:03:17 +0000112
phoglund@webrtc.org53034fb2012-11-30 11:59:20 +0000113<div>
114 <video width="320" height="240" id="remote-view" autoplay="autoplay"></video>
115 <video width="320" height="240" id="local-view" autoplay="autoplay"></video>
116</div>
phoglund@webrtc.org7d74bdb2012-11-28 13:03:17 +0000117<div id="log"></div>
118</body>
phoglund@webrtc.org53034fb2012-11-30 11:59:20 +0000119</html>