@@ -162,48 +162,76 @@ const photoBooth = (function () {
162162 return ;
163163 }
164164
165- jQuery
166- . post ( 'api/takeVideo.php' , data )
167- . done ( function ( result ) {
168- console . log ( 'Start webcam' , result ) ;
169- pid = result . pid ;
170- const getMedia =
171- navigator . mediaDevices . getUserMedia ||
172- navigator . mediaDevices . webkitGetUserMedia ||
173- navigator . mediaDevices . mozGetUserMedia ||
174- false ;
175-
176- if ( ! getMedia ) {
177- return ;
178- }
165+ if ( config . preview_mode === 'gphoto' ) {
166+ jQuery
167+ . post ( 'api/takeVideo.php' , data )
168+ . done ( function ( result ) {
169+ console . log ( 'Start webcam' , result ) ;
170+ pid = result . pid ;
171+ const getMedia =
172+ navigator . mediaDevices . getUserMedia ||
173+ navigator . mediaDevices . webkitGetUserMedia ||
174+ navigator . mediaDevices . mozGetUserMedia ||
175+ false ;
176+
177+ if ( ! getMedia ) {
178+ return ;
179+ }
179180
180- if ( config . previewCamFlipHorizontal ) {
181- $ ( '#video--view' ) . addClass ( 'flip-horizontal' ) ;
182- $ ( '#video--preview' ) . addClass ( 'flip-horizontal' ) ;
183- }
181+ if ( config . previewCamFlipHorizontal ) {
182+ $ ( '#video--view' ) . addClass ( 'flip-horizontal' ) ;
183+ $ ( '#video--preview' ) . addClass ( 'flip-horizontal' ) ;
184+ }
184185
185- getMedia
186- . call ( navigator . mediaDevices , webcamConstraints )
187- . then ( function ( stream ) {
188- if ( mode === 'preview' ) {
189- $ ( '#video--preview' ) . show ( ) ;
190- videoPreview . srcObject = stream ;
191- api . stream = stream ;
192- wrapper . css ( 'background-image' , 'none' ) ;
193- wrapper . css ( 'background-color' , 'transparent' ) ;
194- } else {
186+ getMedia
187+ . call ( navigator . mediaDevices , webcamConstraints )
188+ . then ( function ( stream ) {
195189 $ ( '#video--view' ) . show ( ) ;
196190 videoView . srcObject = stream ;
197- }
191+ api . stream = stream ;
192+ } )
193+ . catch ( function ( error ) {
194+ console . log ( 'Could not get user media: ' , error ) ;
195+ } ) ;
196+ } )
197+ . fail ( function ( xhr , status , result ) {
198+ console . log ( 'Could not start webcam' , result ) ;
199+ } ) ;
200+ } else {
201+ const getMedia =
202+ navigator . mediaDevices . getUserMedia ||
203+ navigator . mediaDevices . webkitGetUserMedia ||
204+ navigator . mediaDevices . mozGetUserMedia ||
205+ false ;
206+
207+ if ( ! getMedia ) {
208+ return ;
209+ }
210+
211+ if ( config . previewCamFlipHorizontal ) {
212+ $ ( '#video--view' ) . addClass ( 'flip-horizontal' ) ;
213+ $ ( '#video--preview' ) . addClass ( 'flip-horizontal' ) ;
214+ }
215+
216+ getMedia
217+ . call ( navigator . mediaDevices , webcamConstraints )
218+ . then ( function ( stream ) {
219+ if ( mode === 'preview' ) {
220+ $ ( '#video--preview' ) . show ( ) ;
221+ videoPreview . srcObject = stream ;
198222 api . stream = stream ;
199- } )
200- . catch ( function ( error ) {
201- console . log ( 'Could not get user media: ' , error ) ;
202- } ) ;
203- } )
204- . fail ( function ( xhr , status , result ) {
205- console . log ( 'Could not start webcam' , result ) ;
206- } ) ;
223+ wrapper . css ( 'background-image' , 'none' ) ;
224+ wrapper . css ( 'background-color' , 'transparent' ) ;
225+ } else {
226+ $ ( '#video--view' ) . show ( ) ;
227+ videoView . srcObject = stream ;
228+ }
229+ api . stream = stream ;
230+ } )
231+ . catch ( function ( error ) {
232+ console . log ( 'Could not get user media: ' , error ) ;
233+ } ) ;
234+ }
207235 } ;
208236
209237 api . stopVideo = function ( mode ) {
@@ -261,7 +289,7 @@ const photoBooth = (function () {
261289 photoStyle = 'collage' ;
262290 }
263291
264- if ( config . preview_mode === 'device_cam' ) {
292+ if ( config . preview_mode === 'device_cam' || config . preview_mode === 'gphoto' ) {
265293 api . startVideo ( 'view' ) ;
266294 } else if ( config . preview_mode === 'url' ) {
267295 $ ( '#ipcam--view' ) . show ( ) ;
@@ -296,7 +324,13 @@ const photoBooth = (function () {
296324 . appendTo ( '.cheese' ) ;
297325 }
298326
299- if ( config . no_cheese ) {
327+ if ( config . preview_mode === 'device_cam' && config . previewCamTakesPic && ! api . stream && ! config . dev ) {
328+ console . log ( 'No preview by device cam available!' ) ;
329+
330+ api . errorPic ( {
331+ error : 'No preview by device cam available!'
332+ } ) ;
333+ } else if ( config . no_cheese ) {
300334 api . takePic ( photoStyle ) ;
301335 } else {
302336 setTimeout ( ( ) => {
@@ -315,7 +349,16 @@ const photoBooth = (function () {
315349 ioClient . emit ( 'photobooth-socket' , 'in progress' ) ;
316350 }
317351
318- if ( config . preview_mode === 'url' ) {
352+ if ( config . preview_mode === 'device_cam' || config . preview_mode === 'gphoto' ) {
353+ if ( config . previewCamTakesPic && ! config . dev ) {
354+ videoSensor . width = videoView . videoWidth ;
355+ videoSensor . height = videoView . videoHeight ;
356+ videoSensor . getContext ( '2d' ) . drawImage ( videoView , 0 , 0 ) ;
357+ }
358+ if ( config . preview_mode === 'device_cam' ) {
359+ api . stopVideo ( 'view' ) ;
360+ }
361+ } else if ( config . preview_mode === 'url' ) {
319362 $ ( '#ipcam--view' ) . removeClass ( 'streaming' ) ;
320363 $ ( '#ipcam--view' ) . hide ( ) ;
321364 }
@@ -334,12 +377,7 @@ const photoBooth = (function () {
334377 loader . css ( 'background' , config . colors . panel ) ;
335378 loader . css ( 'background-color' , config . colors . panel ) ;
336379
337- if ( config . preview_mode === 'device_cam' ) {
338- if ( config . previewCamTakesPic && ! config . dev ) {
339- videoSensor . width = videoView . videoWidth ;
340- videoSensor . height = videoView . videoHeight ;
341- videoSensor . getContext ( '2d' ) . drawImage ( videoView , 0 , 0 ) ;
342- }
380+ if ( config . preview_mode === 'gphoto' ) {
343381 api . stopVideoAndTakePic ( data ) ;
344382 } else {
345383 api . callTakePicApi ( data ) ;
0 commit comments