11/* eslint n/no-unsupported-features/node-builtins: "off" */
2+
23/* globals photoBooth photoboothTools */
34
45function getPreviewUrlWithCacheBusting ( ) {
@@ -24,18 +25,18 @@ function getBasePreviewUrl() {
2425 return match ? match [ 2 ] : raw ;
2526}
2627
27- const photoboothPreview = ( function ( ) {
28+ const photoboothPreview = ( function ( ) {
2829 // vars
2930 const CameraDisplayMode = {
3031 INIT : 1 ,
3132 BACKGROUND : 2 ,
3233 COUNTDOWN : 3 ,
33- TEST : 4
34+ TEST : 4 ,
3435 } ,
3536 PreviewMode = {
3637 NONE : 'none' ,
3738 DEVICE : 'device_cam' ,
38- URL : 'url'
39+ URL : 'url' ,
3940 } ,
4041 api = { } ;
4142
@@ -47,19 +48,19 @@ const photoboothPreview = (function () {
4748 collageFrame ,
4849 retryGetMedia = 3 ;
4950
50- api . changeVideoMode = function ( mode ) {
51+ api . changeVideoMode = function ( mode ) {
5152 photoboothTools . console . logDev ( 'Preview: Changing video mode: ' + mode ) ;
5253 if ( mode !== CameraDisplayMode . BACKGROUND ) {
5354 loader . css ( '--stage-background' , 'transparent' ) ;
5455 }
5556 video . show ( ) ;
5657 } ;
5758
58- api . initializeMedia = function (
59+ api . initializeMedia = function (
5960 cb = ( ) => {
6061 return ;
6162 } ,
62- retry = 0
63+ retry = 0 ,
6364 ) {
6465 photoboothTools . console . logDev ( 'Preview: Trying to initialize media...' ) ;
6566 if (
@@ -103,37 +104,34 @@ const photoboothPreview = (function () {
103104 video : {
104105 width : videoWidth ,
105106 height : videoHeight ,
106- facingMode : config . preview . camera_mode
107- }
107+ facingMode : config . preview . camera_mode ,
108+ } ,
108109 } ;
109110
110- getMedia
111- . call ( navigator . mediaDevices , webcamConstraints )
112- . then ( function ( stream ) {
113- photoboothTools . console . logDev ( 'Preview: getMedia done!' ) ;
114- api . stream = stream ;
115- video . get ( 0 ) . srcObject = stream ;
116- cb ( ) ;
117- } )
118- . catch ( function ( error ) {
119- photoboothTools . console . log ( 'ERROR: Preview: Could not get user media: ' , error ) ;
120- if ( retry < retryGetMedia ) {
121- photoboothTools . console . logDev (
122- 'Preview: Retrying to get user media. Retry ' + retry + ' / ' + retryGetMedia
123- ) ;
124- retry += 1 ;
125- setTimeout ( function ( ) {
126- api . initializeMedia ( cb , retry ) ;
127- } , 1000 ) ;
128- } else {
129- photoboothTools . console . logDev (
130- 'ERROR: Preview: Unable to get user media. Failed retries: ' + retry
131- ) ;
132- }
133- } ) ;
111+ getMedia . call ( navigator . mediaDevices , webcamConstraints ) . then ( function ( stream ) {
112+ photoboothTools . console . logDev ( 'Preview: getMedia done!' ) ;
113+ api . stream = stream ;
114+ video . get ( 0 ) . srcObject = stream ;
115+ cb ( ) ;
116+ } ) . catch ( function ( error ) {
117+ photoboothTools . console . log ( 'ERROR: Preview: Could not get user media: ' , error ) ;
118+ if ( retry < retryGetMedia ) {
119+ photoboothTools . console . logDev (
120+ 'Preview: Retrying to get user media. Retry ' + retry + ' / ' + retryGetMedia ,
121+ ) ;
122+ retry += 1 ;
123+ setTimeout ( function ( ) {
124+ api . initializeMedia ( cb , retry ) ;
125+ } , 1000 ) ;
126+ } else {
127+ photoboothTools . console . logDev (
128+ 'ERROR: Preview: Unable to get user media. Failed retries: ' + retry ,
129+ ) ;
130+ }
131+ } ) ;
134132 } ;
135133
136- api . getAndDisplayMedia = function ( mode ) {
134+ api . getAndDisplayMedia = function ( mode ) {
137135 if ( api . stream && api . stream . active ) {
138136 api . changeVideoMode ( mode ) ;
139137 } else {
@@ -143,25 +141,23 @@ const photoboothPreview = (function () {
143141 }
144142 } ;
145143
146- api . runCmd = function ( mode ) {
144+ api . runCmd = function ( mode ) {
147145 const dataVideo = {
148146 play : mode ,
149- pid : pid
147+ pid : pid ,
150148 } ;
151149
152- jQuery
153- . post ( 'api/previewCamera.php' , dataVideo )
154- . done ( function ( result ) {
155- photoboothTools . console . log ( 'Preview: ' + dataVideo . play + ' webcam successfully.' ) ;
156- pid = result . pid ;
157- } )
150+ jQuery . post ( 'api/previewCamera.php' , dataVideo ) . done ( function ( result ) {
151+ photoboothTools . console . log ( 'Preview: ' + dataVideo . play + ' webcam successfully.' ) ;
152+ pid = result . pid ;
153+ } )
158154 // eslint-disable-next-line no-unused-vars
159- . fail ( function ( xhr , status , result ) {
155+ . fail ( function ( xhr , status , result ) {
160156 photoboothTools . console . log ( 'ERROR: Preview: Failed to ' + dataVideo . play + ' webcam!' ) ;
161157 } ) ;
162158 } ;
163159
164- api . startVideo = function ( mode , retry = 0 , maxGetMediaRetry = 3 ) {
160+ api . startVideo = function ( mode , retry = 0 , maxGetMediaRetry = 3 ) {
165161 retryGetMedia = maxGetMediaRetry ;
166162 photoboothTools . console . log ( 'Preview: startVideo mode: ' + mode ) ;
167163 if ( config . preview . mode !== PreviewMode . URL . valueOf ( ) ) {
@@ -202,9 +198,8 @@ const photoboothPreview = (function () {
202198 api . getAndDisplayMedia ( CameraDisplayMode . COUNTDOWN ) ;
203199 } else if ( config . preview . mode === PreviewMode . URL . valueOf ( ) ) {
204200 photoboothTools . console . logDev ( 'Preview: Preview at countdown from URL.' ) ;
205- setTimeout ( function ( ) {
206- url . css ( 'background-image' ,
207- 'url("' + getPreviewUrlWithCacheBusting ( ) + '")' ) ;
201+ setTimeout ( function ( ) {
202+ url . css ( 'background-image' , 'url("' + getPreviewUrlWithCacheBusting ( ) + '")' ) ;
208203 url . show ( ) ;
209204 url . addClass ( 'streaming' ) ;
210205 } , config . preview . url_delay ) ;
@@ -216,9 +211,8 @@ const photoboothPreview = (function () {
216211 api . getAndDisplayMedia ( CameraDisplayMode . TEST ) ;
217212 } else if ( config . preview . mode === PreviewMode . URL . valueOf ( ) ) {
218213 photoboothTools . console . logDev ( 'Preview: Preview from URL.' ) ;
219- setTimeout ( function ( ) {
220- url . css ( 'background-image' ,
221- 'url("' + getPreviewUrlWithCacheBusting ( ) + '")' ) ;
214+ setTimeout ( function ( ) {
215+ url . css ( 'background-image' , 'url("' + getPreviewUrlWithCacheBusting ( ) + '")' ) ;
222216 url . show ( ) ;
223217 url . addClass ( 'streaming' ) ;
224218 } , config . preview . url_delay ) ;
@@ -230,7 +224,7 @@ const photoboothPreview = (function () {
230224 }
231225 } ;
232226
233- api . stopPreview = function ( ) {
227+ api . stopPreview = function ( ) {
234228 if ( config . commands . preview_kill ) {
235229 api . runCmd ( 'stop' ) ;
236230 }
@@ -239,7 +233,7 @@ const photoboothPreview = (function () {
239233 }
240234 } ;
241235
242- api . stopVideo = function ( ) {
236+ api . stopVideo = function ( ) {
243237 loader . css ( '--stage-background' , 'var(--background-countdown-color)' ) ;
244238 if ( api . stream ) {
245239 const tracks = api . stream . getTracks ( ) ;
@@ -262,14 +256,14 @@ const photoboothPreview = (function () {
262256 collageFrame = $ ( '#previewframe--collage' ) ;
263257 } ;
264258
265- api . init = function ( ) {
259+ api . init = function ( ) {
266260 api . setElements ( ) ;
267261 } ;
268262
269263 return api ;
270264} ) ( ) ;
271265
272- $ ( function ( ) {
266+ $ ( function ( ) {
273267 photoboothPreview . init ( ) ;
274268 photoboothTools . console . log ( 'Preview: Preview functions available.' ) ;
275269} ) ;
0 commit comments