7
7
var camVideo = $ ( '#camera' ) [ 0 ] , //where we will put & test our video output
8
8
deviceList = $ ( '#devices' ) [ 0 ] , //device list dropdown
9
9
devices , //getSources object to hold various camera options
10
+ localStream ,
10
11
selectedCamera = [ ] , //used to hold a camera's ID and other parameters
11
12
tests , //holder for our test results
12
13
r = 0 , //used for iterating through the array
@@ -155,41 +156,59 @@ function gum(candidate, camId) {
155
156
console . log ( "trying " + candidate . label ) ;
156
157
157
158
//Kill any running streams;
158
- if ( ! ! window . stream ) {
159
- camVideo . src = null ;
160
- window . stream . stop ( ) ;
159
+ if ( localStream ) {
160
+ localStream . getTracks ( ) . forEach ( function ( track ) {
161
+ track . stop ( ) ;
162
+ } ) ;
163
+ var videoTracks = localStream . getVideoTracks ( ) ;
164
+ for ( var i = 0 ; i !== videoTracks . length ; ++ i ) {
165
+ videoTracks [ i ] . stop ( ) ;
166
+ }
161
167
}
162
168
163
169
//create constraints object
164
170
var constraints = {
165
- audio : false ,
166
- video : {
167
- mandatory : {
168
- sourceId : camId ,
169
- minWidth : candidate . width ,
170
- minHeight : candidate . height ,
171
- maxWidth : candidate . width ,
172
- maxHeight : candidate . height
171
+ audio : false ,
172
+ video : {
173
+ mandatory : {
174
+ sourceId : camId ,
175
+ minWidth : candidate . width ,
176
+ minHeight : candidate . height ,
177
+ maxWidth : candidate . width ,
178
+ maxHeight : candidate . height
173
179
174
- }
175
180
}
176
- } ;
181
+ }
182
+ } ;
183
+
184
+ navigator . mediaDevices . getUserMedia ( constraints )
185
+ . then ( gotStream )
186
+ . catch ( function ( error ) {
187
+ console . log ( 'getUserMedia error!' , error ) ;
188
+
189
+ if ( scanning ) {
190
+ //console.log("Stream dimensions for " + candidates[r].label + ": " + camVideo.videoWidth + "x" + camVideo.videoHeight);
191
+ captureResults ( "fail: " + error . name ) ;
192
+ }
193
+ } ) ;
177
194
178
- getUserMedia ( constraints , onStream , onFail ) ; //getUserMedia call
179
195
180
- function onStream ( stream ) {
196
+ //getUserMedia(constraints, onStream, onFail); //getUserMedia call
197
+
198
+ function gotStream ( stream ) {
181
199
182
200
//change the video dimensions
183
201
console . log ( "Display size for " + candidate . label + ": " + candidate . width + "x" + candidate . height ) ;
184
202
camVideo . width = candidate . width ;
185
203
camVideo . height = candidate . height ;
186
204
187
- window . stream = stream ; // stream available to console
205
+ localstream = stream ; // stream available to console
188
206
camVideo . src = window . URL . createObjectURL ( stream ) ;
189
207
camVideo . play ( ) ;
190
208
191
209
}
192
-
210
+ }
211
+ /*
193
212
function onFail(error) {
194
213
console.log('Video error!', error);
195
214
@@ -198,7 +217,7 @@ function gum(candidate, camId) {
198
217
captureResults("fail: " + error.name);
199
218
}
200
219
}
201
- }
220
+ }*/
202
221
203
222
204
223
//Attach to play event
0 commit comments