phoglund@webrtc.org | 7d74bdb | 2012-11-28 13:03:17 +0000 | [diff] [blame^] | 1 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> |
| 2 | |
| 3 | <!-- |
| 4 | To 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 |
| 6 | Chrome when it's requesting access to your webcam. |
| 7 | Notice that this requires the site you're browsing to use HTTPS. |
| 8 | |
| 9 | Without that, the test might timeout before you have had the chance to accept |
| 10 | access 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 | |
| 25 | var getUserMediaFailedCallback = test.step_func(function(error) { |
| 26 | assert_unreached('Should not get an error callback'); |
| 27 | }); |
| 28 | |
| 29 | function getUserMediaOkCallback(localStream) { |
| 30 | gFirstConnection = new webkitRTCPeerConnection(null, null); |
| 31 | gFirstConnection.onicecandidate = onIceCandidateToFirst; |
| 32 | gFirstConnection.addStream(localStream); |
| 33 | gFirstConnection.createOffer(onOfferCreated); |
| 34 | }; |
| 35 | |
| 36 | var onOfferCreated = test.step_func(function(offer) { |
| 37 | gFirstConnection.setLocalDescription(offer); |
| 38 | |
| 39 | // This would normally go across the application's signaling solution. |
| 40 | // In our case, the "signaling" is to call this function. |
| 41 | receiveCall(offer.sdp); |
| 42 | }); |
| 43 | |
| 44 | var receiveCall = test.step_func(function(offerSdp) { |
| 45 | gSecondConnection = new webkitRTCPeerConnection(null, null); |
| 46 | gSecondConnection.onicecandidate = onIceCandidateToSecond; |
| 47 | gSecondConnection.onaddstream = onRemoteStream; |
| 48 | |
| 49 | var parsedOffer = new RTCSessionDescription({ type: 'offer', |
| 50 | sdp: offerSdp }); |
| 51 | gSecondConnection.setRemoteDescription(parsedOffer); |
| 52 | |
| 53 | gSecondConnection.createAnswer(onAnswerCreated); |
| 54 | }); |
| 55 | |
| 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 | |
| 63 | var handleAnswer = test.step_func(function(answerSdp) { |
| 64 | var parsedAnswer = new RTCSessionDescription({ type: 'answer', |
| 65 | sdp: answerSdp }); |
| 66 | gFirstConnection.setRemoteDescription(parsedAnswer); |
| 67 | }); |
| 68 | |
| 69 | var onIceCandidateToFirst = test.step_func(function(event) { |
| 70 | // If event.candidate is null = no more candidates. |
| 71 | if (event.candidate) { |
| 72 | var candidate = new RTCIceCandidate(event.candidate); |
| 73 | gSecondConnection.addIceCandidate(candidate); |
| 74 | } |
| 75 | }); |
| 76 | |
| 77 | var onIceCandidateToSecond = test.step_func(function(event) { |
| 78 | if (event.candidate) { |
| 79 | var candidate = new RTCIceCandidate(event.candidate); |
| 80 | gFirstConnection.addIceCandidate(candidate); |
| 81 | } |
| 82 | }); |
| 83 | |
| 84 | var onRemoteStream = test.step_func(function(e) { |
| 85 | test.done(); |
| 86 | }); |
| 87 | |
| 88 | test.step(function() { |
| 89 | navigator.webkitGetUserMedia({ video: true, audio: true }, |
| 90 | getUserMediaOkCallback, |
| 91 | getUserMediaFailedCallback) |
| 92 | }); |
| 93 | </script> |
| 94 | </head> |
| 95 | |
| 96 | <body> |
| 97 | </body> |
| 98 | |
| 99 | <div id="log"></div> |
| 100 | </body> |
| 101 | </html> |