diff --git a/assets/js/core.js b/assets/js/core.js index e0b9e6636..1ef84b82e 100644 --- a/assets/js/core.js +++ b/assets/js/core.js @@ -499,112 +499,118 @@ const photoBooth = (function () { return; } - api.navbar.close(); - api.reset(); - api.closeGallery(); - api.clearLoaderImage(); - - remoteBuzzerClient.inProgress(photoStyle); - api.takingPic = true; - photoboothTools.console.logDev('Taking picture in progress: ' + api.takingPic); - - if (api.isTimeOutPending()) { - api.resetTimeOut(); - } - if (config.commands.pre_photo) { - api.shellCommand('pre-command'); - } + try { + api.navbar.close(); + api.reset(); + api.closeGallery(); + api.clearLoaderImage(); - if (currentCollageFile && api.nextCollageNumber) { - photoStyle = PhotoStyle.COLLAGE; - } + remoteBuzzerClient.inProgress(photoStyle); + api.takingPic = true; + photoboothTools.console.logDev('Taking picture in progress: ' + api.takingPic); - if (chromaFile) { - photoStyle = PhotoStyle.CHROMA; - } - api.photoStyle = photoStyle; - photoboothTools.console.log('PhotoStyle: ' + api.photoStyle); - - let countdownTime; - switch (api.photoStyle) { - case PhotoStyle.COLLAGE: - countdownTime = config.collage.cntdwn_time; - break; - case PhotoStyle.VIDEO: - countdownTime = config.video.cntdwn_time; - break; - case PhotoStyle.CUSTOM: - countdownTime = config.custom.cntdwn_time; - break; - case PhotoStyle.PHOTO: - default: - countdownTime = config.picture.cntdwn_time; - break; - } + if (api.isTimeOutPending()) { + api.resetTimeOut(); + } - let maxGetMediaRetry = Math.max(countdownTime - 1, 0); - if (config.commands.preview_kill && maxGetMediaRetry > 0) { - maxGetMediaRetry = Math.max(countdownTime - parseInt(config.preview.stop_time, 10), 0); - } - photoboothPreview.startVideo(CameraDisplayMode.COUNTDOWN, retry, maxGetMediaRetry); + if (config.commands.pre_photo) { + api.shellCommand('pre-command'); + } - if ( - config.preview.mode !== PreviewMode.NONE.valueOf() && - (config.preview.style === PreviewStyle.CONTAIN.valueOf() || - config.preview.style === PreviewStyle.SCALE_DOWN.valueOf()) && - config.preview.showFrame - ) { - if ( - (api.photoStyle === PhotoStyle.PHOTO || api.photoStyle === PhotoStyle.CUSTOM) && - config.picture.take_frame - ) { - previewFramePicture.show(); - } else if ( - api.photoStyle === PhotoStyle.COLLAGE && - config.collage.take_frame === CollageFrameMode.ALWAYS.valueOf() - ) { - previewFrameCollage.show(); + if (currentCollageFile && api.nextCollageNumber) { + photoStyle = PhotoStyle.COLLAGE; } - } - videoBackground.hide(); - startPage.removeClass('stage--active'); - loader.addClass('stage--active'); - api.screensaver.hide(); + if (chromaFile) { + photoStyle = PhotoStyle.CHROMA; + } + api.photoStyle = photoStyle; + photoboothTools.console.log('PhotoStyle: ' + api.photoStyle); - if (config.get_request.countdown) { - let getMode; + let countdownTime; switch (api.photoStyle) { case PhotoStyle.COLLAGE: - getMode = config.get_request.collage; + countdownTime = config.collage.cntdwn_time; break; case PhotoStyle.VIDEO: - getMode = config.get_request.video; + countdownTime = config.video.cntdwn_time; break; case PhotoStyle.CUSTOM: - getMode = config.get_request.custom; + countdownTime = config.custom.cntdwn_time; break; case PhotoStyle.PHOTO: default: - getMode = config.get_request.picture; + countdownTime = config.picture.cntdwn_time; break; } - const getUrl = config.get_request.server + '/' + getMode; - photoboothTools.getRequest(getUrl); - } - await api.countdown.start(countdownTime); - await api.cheese.start(); + let maxGetMediaRetry = Math.max(countdownTime - 1, 0); + if (config.commands.preview_kill && maxGetMediaRetry > 0) { + maxGetMediaRetry = Math.max(countdownTime - parseInt(config.preview.stop_time, 10), 0); + } + photoboothPreview.startVideo(CameraDisplayMode.COUNTDOWN, retry, maxGetMediaRetry); - if (config.preview.camTakesPic && !photoboothPreview.stream && !config.dev.demo_images) { - api.errorPic({ - error: 'No preview by device cam available!' - }); - } else if (api.photoStyle === PhotoStyle.VIDEO) { - api.takeVideo(retry); - } else { - api.takePic(retry); + if ( + config.preview.mode !== PreviewMode.NONE.valueOf() && + (config.preview.style === PreviewStyle.CONTAIN.valueOf() || + config.preview.style === PreviewStyle.SCALE_DOWN.valueOf()) && + config.preview.showFrame + ) { + if ( + (api.photoStyle === PhotoStyle.PHOTO || api.photoStyle === PhotoStyle.CUSTOM) && + config.picture.take_frame + ) { + previewFramePicture.show(); + } else if ( + api.photoStyle === PhotoStyle.COLLAGE && + config.collage.take_frame === CollageFrameMode.ALWAYS.valueOf() + ) { + previewFrameCollage.show(); + } + } + + videoBackground.hide(); + startPage.removeClass('stage--active'); + loader.addClass('stage--active'); + api.screensaver.hide(); + + if (config.get_request.countdown) { + let getMode; + switch (api.photoStyle) { + case PhotoStyle.COLLAGE: + getMode = config.get_request.collage; + break; + case PhotoStyle.VIDEO: + getMode = config.get_request.video; + break; + case PhotoStyle.CUSTOM: + getMode = config.get_request.custom; + break; + case PhotoStyle.PHOTO: + default: + getMode = config.get_request.picture; + break; + } + const getUrl = config.get_request.server + '/' + getMode; + photoboothTools.getRequest(getUrl); + } + + await api.countdown.start(countdownTime); + await api.cheese.start(); + + if (config.preview.camTakesPic && !photoboothPreview.stream && !config.dev.demo_images) { + api.errorPic({ + error: 'No preview by device cam available!' + }); + } else if (api.photoStyle === PhotoStyle.VIDEO) { + api.takeVideo(retry); + } else { + api.takePic(retry); + } + } catch (error) { + photoboothTools.console.log('thrill: unexpected error:', error); + api.errorPic({ error: error.message || 'Unexpected error in thrill' }); } }; @@ -617,29 +623,34 @@ const photoBooth = (function () { }; api.takePic = function (retry) { - remoteBuzzerClient.inProgress('in-progress'); + try { + remoteBuzzerClient.inProgress('in-progress'); - api.stopPreviewAndCaptureFromVideo(); + api.stopPreviewAndCaptureFromVideo(); - const data = { - filter: imgFilter, - style: api.photoStyle, - canvasimg: videoSensor.get(0).toDataURL('image/jpeg') - }; + const data = { + filter: imgFilter, + style: api.photoStyle, + canvasimg: videoSensor.get(0).toDataURL('image/jpeg') + }; - if (api.photoStyle === PhotoStyle.COLLAGE) { - data.file = currentCollageFile; - data.collageNumber = api.nextCollageNumber; - data.collageLimit = api.collageLimit; - } + if (api.photoStyle === PhotoStyle.COLLAGE) { + data.file = currentCollageFile; + data.collageNumber = api.nextCollageNumber; + data.collageLimit = api.collageLimit; + } - if (api.photoStyle === PhotoStyle.CHROMA) { - data.file = chromaFile; - } + if (api.photoStyle === PhotoStyle.CHROMA) { + data.file = chromaFile; + } - loader.css('--stage-background', 'var(--background-countdown-color)'); + loader.css('--stage-background', 'var(--background-countdown-color)'); - api.callTakePicApi(data, retry); + api.callTakePicApi(data, retry); + } catch (error) { + photoboothTools.console.log('takePic: unexpected error:', error); + api.errorPic({ error: error.message || 'Unexpected error in takePic' }); + } }; api.retryTakePic = function (retry) { @@ -664,152 +675,163 @@ const photoBooth = (function () { timeout: 25000 }) .done(async (result) => { - api.cheese.destroy(); - if (config.ui.shutter_animation) { - await api.shutter.start(); - await api.shutter.stop(); - } - endTime = new Date().getTime(); - totalTime = endTime - startTime; - photoboothTools.console.log('Took ' + data.style, result); - photoboothTools.console.logDev('Taking picture took ' + totalTime + 'ms'); - imgFilter = config.filters.defaults; - $('#filternav .sidenav-list-item--active').removeClass('sidenav-list-item--active'); - $('.sidenav-list-item[data-filter="' + imgFilter + '"]').addClass('sidenav-list-item--active'); - previewFrameCollage.hide(); - previewFramePicture.hide(); - if (result.error) { - photoboothTools.console.logDev('Error while taking picture.'); - if (config.picture.retry_on_error > 0 && retry < config.picture.retry_on_error) { - api.retryTakePic(retry); - } else { - api.errorPic(result); + try { + api.cheese.destroy(); + if (config.ui.shutter_animation) { + await api.shutter.start(); + await api.shutter.stop(); } - } else if (result.success === PhotoStyle.COLLAGE) { - currentCollageFile = result.file; - api.nextCollageNumber = result.current + 1; - - loaderButtonBar.empty(); - loaderMessage.empty(); - videoSensor.hide(); - previewVideo.hide(); - - let imageUrl = environment.publicFolders.tmp + '/' + result.collage_file; - const preloadImage = new Image(); - const picdate = Date.now().toString(); - preloadImage.onload = () => { - loaderImage.attr('data-img', picdate); - loaderImage.css('background-image', `url(${imageUrl}?filter=${imgFilter}&v=${picdate})`); - }; - preloadImage.src = imageUrl; - - loaderImage.show(); + endTime = new Date().getTime(); + totalTime = endTime - startTime; + photoboothTools.console.log('Took ' + data.style, result); + photoboothTools.console.logDev('Taking picture took ' + totalTime + 'ms'); + imgFilter = config.filters.defaults; + $('#filternav .sidenav-list-item--active').removeClass('sidenav-list-item--active'); + $('.sidenav-list-item[data-filter="' + imgFilter + '"]').addClass('sidenav-list-item--active'); + previewFrameCollage.hide(); + previewFramePicture.hide(); + if (result.error) { + photoboothTools.console.logDev('Error while taking picture.'); + if (config.picture.retry_on_error > 0 && retry < config.picture.retry_on_error) { + api.retryTakePic(retry); + } else { + api.errorPic(result); + } + } else if (result.success === PhotoStyle.COLLAGE) { + currentCollageFile = result.file; + api.nextCollageNumber = result.current + 1; + + loaderButtonBar.empty(); + loaderMessage.empty(); + videoSensor.hide(); + previewVideo.hide(); + + let imageUrl = environment.publicFolders.tmp + '/' + result.collage_file; + const preloadImage = new Image(); + const picdate = Date.now().toString(); + preloadImage.onload = () => { + loaderImage.attr('data-img', picdate); + loaderImage.css('background-image', `url(${imageUrl}?filter=${imgFilter}&v=${picdate})`); + }; + preloadImage.src = imageUrl; + + loaderImage.show(); - photoboothTools.console.logDev( - 'Taken collage photo number: ' + (result.current + 1) + ' / ' + api.collageLimit - ); + photoboothTools.console.logDev( + 'Taken collage photo number: ' + (result.current + 1) + ' / ' + api.collageLimit + ); - if (result.current + 1 < api.collageLimit) { - photoboothTools.console.logDev('core: initialize Media.'); - photoboothPreview.initializeMedia(); - api.takingPic = false; - } + if (result.current + 1 < api.collageLimit) { + photoboothTools.console.logDev('core: initialize Media.'); + photoboothPreview.initializeMedia(); + api.takingPic = false; + } - if (config.collage.continuous) { - loaderMessage.append($('

').text(photoboothTools.getTranslation('wait_message'))); - setTimeout(() => { - api.clearLoaderImage(); - imageUrl = ''; + if (config.collage.continuous) { + loaderMessage.append($('

').text(photoboothTools.getTranslation('wait_message'))); + setTimeout(() => { + api.clearLoaderImage(); + imageUrl = ''; + if (result.current + 1 < api.collageLimit) { + api.thrill(PhotoStyle.COLLAGE); + } else { + currentCollageFile = ''; + api.nextCollageNumber = 0; + api.processPic(result); + } + }, continuousCollageTime); + } else { + // collage with interruption if (result.current + 1 < api.collageLimit) { - api.thrill(PhotoStyle.COLLAGE); + const takePictureButton = $( + '