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