OLD | NEW |
---|---|
(Empty) | |
1 <!DOCTYPE html> | |
2 <html> | |
3 <head><title>Loopback test</title></head> | |
4 <body> | |
5 <video id="localVideo" width="1280" height="720" autoplay muted></video> | |
6 <video id="remoteVideo" width="1280" height="720" autoplay muted></video> | |
7 <script> | |
8 | |
nednguyen
2015/09/04 15:46:40
Add: 'use strict';
cpaulin (no longer in chrome)
2015/09/16 22:57:04
Acknowledged.
| |
9 durationMS = 30000; | |
phoglund_chromium
2015/09/02 11:27:45
Style guide: Use NAMES_LIKE_THIS for constant valu
cpaulin (no longer in chrome)
2015/09/16 22:57:04
Acknowledged.
| |
10 testProgress = 0; | |
phoglund_chromium
2015/09/02 11:27:45
This variable is badly named - a better name would
cpaulin (no longer in chrome)
2015/09/16 22:57:04
Acknowledged.
| |
11 | |
12 // Starts the test. | |
13 function testCamera(resolution) { | |
14 var test = new CameraTest(resolution); | |
15 test.run(); | |
16 } | |
17 | |
18 | |
19 // Actual test object. | |
20 function CameraTest(resolutionArray) { | |
21 this.resolution = resolutionArray; | |
22 this.localStream = null; | |
23 this.remoteStream = null; | |
24 this.remoteVideo = document.getElementById("remoteVideo"); | |
25 this.localVideo = document.getElementById("localVideo"); | |
26 this.localVideo.width = this.resolution[0].toString(); | |
27 this.localVideo.height = this.resolution[1].toString(); | |
28 this.remoteVideo.width = this.resolution[0].toString(); | |
29 this.remoteVideo.height = this.resolution[1].toString(); | |
30 } | |
31 | |
32 | |
33 CameraTest.prototype = { | |
34 run: function() { | |
35 setTimeout(function() {testProgress = 1}, durationMS); | |
36 this.triggerGetUserMedia(this.resolution); | |
37 }, | |
38 | |
39 triggerGetUserMedia: function(resolution) { | |
40 var constraints = { | |
41 audio: false, | |
42 video: { | |
43 mandatory: { | |
44 minWidth: resolution[0], | |
45 minHeight: resolution[1], | |
46 maxWidth: resolution[0], | |
47 maxHeight: resolution[1] | |
48 } | |
49 } | |
50 }; | |
51 try { | |
52 this.doGetUserMedia(constraints, this.gotLocalStream.bind(this), | |
53 this.onGetUserMediaError.bind(this)); | |
54 } catch (exception) { | |
55 console.log('Unexpected exception: ', exception); | |
56 this.reportError('gUM', 'doGetUserMedia failed: ' + exception); | |
57 } | |
58 }, | |
59 | |
60 reportError: function(errorType, message) { | |
61 console.log(errorType, message); | |
62 }, | |
63 | |
64 doGetUserMedia: function(constraints, onSuccess, onFail) { | |
65 navigator.getUserMedia = navigator.getUserMedia || | |
66 navigator.webkitGetUserMedia; | |
67 navigator.getUserMedia(constraints, onSuccess, onFail); | |
68 }, | |
69 | |
70 gotLocalStream: function(stream) { | |
71 this.localStream = stream; | |
72 var servers = null; | |
73 | |
74 this.localPeerConnection = new webkitRTCPeerConnection(servers); | |
75 this.localPeerConnection.onicecandidate = this.gotLocalIceCandidate.bind( | |
76 this); | |
77 | |
78 this.remotePeerConnection = new webkitRTCPeerConnection(servers); | |
79 this.remotePeerConnection.onicecandidate = this.gotRemoteIceCandidate.bind( | |
80 this); | |
81 this.remotePeerConnection.onaddstream = this.gotRemoteStream.bind(this); | |
82 | |
83 this.localPeerConnection.addStream(this.localStream); | |
84 this.localPeerConnection.createOffer(this.gotLocalDescription.bind(this)); | |
85 this.localVideo.src = URL.createObjectURL(stream); | |
86 }, | |
87 | |
88 onGetUserMediaError: function(stream) { | |
89 this.reportError('gUM', 'gUM call failed'); | |
90 }, | |
91 | |
92 gotRemoteStream: function(event) { | |
93 this.remoteVideo.src = URL.createObjectURL(event.stream); | |
94 }, | |
95 | |
96 gotLocalDescription: function(description) { | |
97 this.localPeerConnection.setLocalDescription(description); | |
98 this.remotePeerConnection.setRemoteDescription(description); | |
99 this.remotePeerConnection.createAnswer(this.gotRemoteDescription.bind( | |
100 this)); | |
101 }, | |
102 | |
103 gotRemoteDescription: function(description) { | |
104 this.remotePeerConnection.setLocalDescription(description); | |
105 this.localPeerConnection.setRemoteDescription(description); | |
106 }, | |
107 | |
108 gotLocalIceCandidate: function(event) { | |
109 if (event.candidate) | |
110 this.remotePeerConnection.addIceCandidate( | |
111 new RTCIceCandidate(event.candidate)); | |
112 }, | |
113 | |
114 gotRemoteIceCandidate: function(event) { | |
115 if (event.candidate) | |
116 this.localPeerConnection.addIceCandidate( | |
117 new RTCIceCandidate(event.candidate)); | |
118 }, | |
119 } | |
120 | |
121 window.onload = testCamera([1280, 720]); | |
122 window.onerror = function (message, filename, lineno, colno, error) { | |
123 console.log("Something went wrong, here is the stack trace --> %s", | |
124 error.stack); | |
125 }; | |
126 </script> | |
127 </body> | |
128 </html> | |
OLD | NEW |