Built motion from commit 97153652.|2.6.26
[motion2.git] / snippet / 3.9.0 / scripts / chat-fecd0807.js
1 "use strict";(self.webpackChunkmotion_chat=self.webpackChunkmotion_chat||[]).push([["chat-fecd0807"],{"./src/js/input-recorder/input-recorder.service.js":(e,t,o)=>{function i(e,t,o){return t in e?Object.defineProperty(e,t,{value:o,enumerable:!0,configurable:!0,writable:!0}):e[t]=o,e}o.d(t,{t:()=>n});class n{constructor(){i(this,"conf",{}),i(this,"recordedBlobs",[]),i(this,"mediaStream",null),i(this,"mediaRecorder",null),this.initProps()}initProps(){this.conf={},this.recordedBlobs=[],this.mediaStream=null,this.mediaRecorder=null}clear(){this.initProps()}async init(){return this.initProps(),this.initMediaDevices()}async initMediaDevices(){if(console.log("initMediaDevices"),this.initDeviceInProgress=!0,"https:"!==location.protocol&&!location.host.includes("localhost"))return void alert("https or localhost required!");const e={audio:!0,video:!1};try{try{const t=await navigator.mediaDevices.getUserMedia(e);this.mediaStream=t}catch(e){console.error("Audio device not available"),console.error(e)}}finally{this.initDeviceInProgress=!1}}startRecording(){const e={mimeType:"audio/webm;codecs=opus"};this.recordedBlobs=[];try{this.mediaRecorder=new MediaRecorder(this.mediaStream,e)}catch(t){console.log("Unable to create MediaRecorder with options Object: ",e,t);try{this.mediaRecorder=new MediaRecorder(this.mediaStream)}catch(e){return alert("MediaRecorder is not supported by this browser."),alert('<iframe> should contain attribute allow="microphone"'),void console.error("Unable to create MediaRecorder",e)}}console.log("Created MediaRecorder",this.mediaRecorder,"with options",e),this.mediaRecorder.onstop=this.handleStop.bind(this),this.mediaRecorder.ondataavailable=this.handleDataAvailable.bind(this),this.mediaRecorder.start(200),console.log("MediaRecorder started",this.mediaRecorder)}stopRecording(){return this.mediaRecorder?(this.mediaRecorder.stop(),this.mediaStream.getAudioTracks().forEach((e=>e.stop())),this):this}handleStop(e){console.log("Recorder stopped: ",e)}handleDataAvailable(e){e.data&&e.data.size>0&&this.recordedBlobs.push(e.data)}download(){return new File(this.recordedBlobs,this.guid()+".ogg",{type:"audio/webm",lastModified:(new Date).getTime()})}guid(){const e=4294967295*Math.random()|0,t=4294967295*Math.random()|0,o=4294967295*Math.random()|0,i=4294967295*Math.random()|0,n=[];for(let e=0;e<256;e++)n[e]=(e<16?"0":"")+e.toString(16);return n[255&e]+n[e>>8&255]+n[e>>16&255]+n[e>>24&255]+"-"+n[255&t]+n[t>>8&255]+"-"+n[t>>16&15|64]+n[t>>24&255]+"-"+n[63&o|128]+n[o>>8&255]+"-"+n[o>>16&255]+n[o>>24&255]+n[255&i]+n[i>>8&255]+n[i>>16&255]+n[i>>24&255]}toHHMMSS(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];const o=parseInt(e+"",10),i=Math.floor(o/3600);let n=Math.floor((o-3600*i)/60),r=o-3600*i-60*n;return i&&(t=!0),n<10&&(n=t?"0"+n:n),r<10&&(r="0"+r),(i?i+":":"")+n+":"+r}}n.$inject=[]},"./src/js/media-viewer/media-viewer.controller.js":(e,t,o)=>{function i(e,t,o){return t in e?Object.defineProperty(e,t,{value:o,enumerable:!0,configurable:!0,writable:!0}):e[t]=o,e}o.d(t,{Z:()=>r});class n{constructor(e,t,o){i(this,"boxWidth",240),i(this,"boxHeight",140),i(this,"size",{width:this.boxWidth,height:this.boxHeight}),this.$scope=e,this.$element=t,this.typeFromMimeType=o}adjustImgSize(e){let t=!1;const o=e[0];if(!t){const e=this;o.onload=()=>{const i=e.calcImageInBox(o.width,o.height,e.boxWidth,e.boxHeight);e.size=i,t=!0}}}adjustVideoSize(e){let t=!1;const o=e[0];if(!t){const e=this;o.onloadedmetadata=()=>{const i=e.calcImageInBox(o.videoWidth,o.videoHeight,e.boxWidth,e.boxHeight);e.size=i,t=!0}}}$postLink(){console.debug("MediaViewerController.postLink")}$onDestroy(){console.debug("MediaViewerController.onDestroy")}downloadMedia(){const e=document.createElement("a"),t=this.source;e.href=t,e.target="_self",document.body.appendChild(e),e.click()}calcImageInBox(e,t,o,i){let n=!(arguments.length>4&&void 0!==arguments[4])||arguments[4];if(e<o&&t<i&&n)return{width:e,height:t};let r=o,s=i;return e/t>o/i?s=t*o/e|0:(r=e*i/t|0,r>o&&(s=s*o/r|0,r=o)),n&&r>=e&&s>=t&&(r=e,s=t),{width:r,height:s}}}n.$inject=["$scope","$element","typeFromMimeType"];const r=n},"./src/js/offline/offline.controller.js":(e,t,o)=>{o.d(t,{v:()=>p});var i=o("./node_modules/lodash.isnil/index.js"),n=o.n(i),r=o("./node_modules/lodash.merge/index.js"),s=o.n(r),a=o("./node_modules/lodash.random/index.js"),l=o.n(a),c=o("./node_modules/lodash.clonedeep/index.js"),d=o.n(c),m=o("./node_modules/json-form-data/src/jsonToFormData.js"),u=o.n(m);function p(e,t,o,i,r,a,c){const m=this;let p=null,f=null;t.typeField="";const h={showLeafArrayIndexes:!0,includeNullValues:!1,mapping:function(e){return"boolean"==typeof e?+e?"1":"0":e}};function g(){delete m.errors.submit,t.$emit("hide"),m.fields=d()(f),m.form={},m.userForm.$setPristine(),m.userForm.$setUntouched();const e=r.simple().textContent(t.settings.formSubmitSuccessMessage||"Form properly submitted").toastClass("md-success-toast size "+t.settings.header_shape).parent(angular.element(document.querySelector("#chat-toolbar")));r.show(e)}m.trustAsHtml=function(e){return o.trustAsHtml(e)},m.initUploadButton=function(o){const i=m.fields[o],n=a.find(".upload-item");if(n.length){const o=angular.element(n[0].querySelector(".upload-button")),s=angular.element(n[0].querySelector("input[type=file]")),a=o.find("label");a.length&&a.css("display","none"),o.on("click",(()=>{a.css("display","none"),"function"==typeof s.trigger?s.trigger("click"):s[0].click()})),s.on("change",(o=>{e.$apply((function(){"string"==typeof i.props.error&&(i.props.error=null);const e=Array.from(o.target.files),n=1048576*i.config.size;e.some((e=>e.size>=n))?(i.options=[],i.props.error=i.config.sizeErrMessage,function(e){m.errors={},t.$emit("hide");const o=r.simple().textContent("FILE TOO BIG: The max allowed size is "+e+"MB").toastClass("md-warning-toast size "+t.settings.header_shape).parent(angular.element(document.querySelector("#chat-toolbar")));r.show(o)}(i.config.size)):i.options=e.map((e=>{const{name:t,size:o,type:i}=e;return{name:t,size:o,type:i,file:e}})),m.form[i.props.title]=i.options}))}))}},m.removeFileItem=function(e,t){e.options.splice(t,1),m.form[e.props.title]=e.options},m.setupFileInput=function(e){console.log("form item setup",e);const t=a.find(".upload-item"),o=angular.element(t[0].querySelector("input[type=file]")),{multipleUpload:i,accept:n}=e.config;i&&o.attr("multiple","multiple"),n&&o[0].setAttribute("accept",n)},m.makeFileOptionsVisible=function(){const e=Array.from(a.find(".filename-label")),t=e[e.length-1];t&&t.scrollIntoView&&t.scrollIntoView()},m.$onInit=function(){console.debug("OfflineController::onInit() VISITOR",t.visitor),t.status="offline",m.visitor={id:t.settings.id,mapKeyOffline:"firstName",from:"Anonymous"+l()(1,1e6)},t.settings.showMenu=!1,t.loading=!1,i.chatWebsite.getFields({id:t.settings.id,online:!1}).$promise.then((function(e){e.count&&(p=e.fromKey,f=d()(e.rows),m.fields=d()(f))})).then((function(){for(let e=0;e<m.fields.length;e++){const o=m.fields[e];if(t.typeField+=o.type,void 0!==o.props&&o.props.helpText){const t=RegExp.prototype.test.bind(/(<([^>]+)>)/i);m.checkHTML[e]=t(o.props.helpText)}}})).catch((function(e){console.error(e)})).finally((function(){if(t.settings.outOfInterval){t.settings.outOfInterval=!1;const e=r.simple().textContent("Sorry, your message was not sent.\nWe are offline at the moment.").hideDelay(5e3).toastClass("md-warning-toast").parent(angular.element(document.querySelector("#chat-toolbar")));r.show(e)}}))},m.submit=function(){t.loading=!0;const e={...m.form};for(let o=0;o<m.fields.length;o++){const i=m.fields[o];i.props&&void 0!==e[i.props.title]&&(n()(i.cmField)||(m.visitor[i.cmField]=Array.isArray(e[i.props.title])?e[i.props.title].join():e[i.props.title]),o===p&&(n()(t.settings.mapKeyOffline)||(m.visitor.mapKeyOffline=t.settings.mapKeyOffline,m.visitor.from=Array.isArray(e[i.props.title])?e[i.props.title].join():e[i.props.title])),"upload"===i.type&&(e[i.props.title]=e[i.props.title].map((e=>e.file))))}const o=Array.isArray(m.fields)?m.fields.filter((e=>"upload"===e.type)):[],a=s()({body:e},m.visitor),l=null!=e&&o.length>0,d=null!==e&&"{}"!==JSON.stringify(e);var f,v;(l?(f=a,c({url:`${i.baseUrl}chat/websites/${f.id}/offline`,headers:{"Content-Type":void 0},data:u()(f,{...h,initialFormData:new FormData}),method:"POST"})):d?i.chatWebsite.offline(a).$promise:Promise.reject("INVALID_FORM")).then(g).catch((v="submit",function(e){const o=r.simple().textContent(t.settings.formSubmitFailureMessage||"Form submission error").toastClass("md-failure-toast size "+t.settings.header_shape).parent(angular.element(document.querySelector("#chat-toolbar")));r.show(o),m.errors[v]=e.data})).finally((()=>{m.form.invalid||(m.form={}),t.loading=!1}))},m.toggle=function(e,t){m.form[e]||(m.form[e]=[]);const o=m.form[e].indexOf(t);o>-1?m.form[e].splice(o,1):m.form[e].push(t)},m.exists=function(e,t){return m.form[e]||(m.form[e]=[]),m.form[e].indexOf(t)>-1},m.checkHTML=[],m.form={},m.errors={},m.userForm={}}p.$inject=["$scope","$rootScope","$sce","api","$mdToast","$element","$http"]},"./src/js/online/online.controller.js":(e,t,o)=>{o.d(t,{E:()=>c});var i=o("./node_modules/lodash.isnil/index.js"),n=o.n(i),r=o("./node_modules/lodash.merge/index.js"),s=o.n(r),a=o("./node_modules/lodash.random/index.js"),l=o.n(a);function c(e,t,o,i,r,a){const c=this;let d=null;function m(){e.settings.online?e.settings.enableCustomerWriting?t.go("app.chat",null,{location:"replace"}):t.go("app.waiting",null,{location:"replace"}):(e.settings.outOfInterval=!0,t.go("app.offline",null,{location:"replace"}))}function u(){return e.visitor={id:e.settings.id,mapKey:"firstName",from:"Anonymous"+l()(1,1e6)},e.settings.showMenu=!1,r.updateStorage(a,e.visitor).then((t=>(e.visitor=t,i.chatWebsite.getFields({id:e.settings.id,online:!0}).$promise.then((function(e){e.count&&(d=e.fromKey,c.fields=e.rows)})).then((function(){for(let e=0;e<c.fields.length;e++){const t=c.fields[e];if(t.props.helpText){const o=RegExp.prototype.test.bind(/(<([^>]+)>)/i);c.checkHTML[e]=o(t.props.helpText)}}})).catch((function(e){console.error(e)}))))).catch(r.onStorageError)}c.checkHTML=[],c.form={},c.errors={},c.userForm={},c.disableItem=!1,c.trustAsHtml=function(e){return o.trustAsHtml(e)},c.$onInit=function(){if(console.debug("OnlineController::onInit() VISITOR",e.visitor),e.status="online",e.visitor&&e.visitor.interaction)if(e.visitor.interaction.id)if(!0===e.visitor.interactionStarted)t.go("app.chat",null,{location:"replace"});else{var o,n;const t=e.visitor.interaction.id,r=null==e||null===(o=e.visitor)||void 0===o||null===(n=o.message)||void 0===n?void 0:n.id;if(r){const e={id:t,channel:"chat",interaction:{id:t},message:{id:r},disposition:"abandoned",closed:!0,closeReason:"contact"};i.chatInteraction.abandon(e).$promise.finally((()=>u()))}}else t.go("app.waiting",null,{location:"replace"});else u()},c.submit=function(){let t=`New chat request\nfrom: ${e.settings.address}\n`;for(let o=0;o<c.fields.length;o++){const i=c.fields[o];i.props&&void 0!==c.form[i.props.title]&&(n()(i.variable)||(e.visitor[i.variable]=Array.isArray(c.form[i.props.title])?c.form[i.props.title].join():c.form[i.props.title]),n()(i.cmField)||(e.visitor[i.cmField]=Array.isArray(c.form[i.props.title])?c.form[i.props.title].join():c.form[i.props.title]),o===d&&(n()(e.settings.mapKey)||(e.visitor.mapKey=e.settings.mapKey,e.visitor.from=Array.isArray(c.form[i.props.title])?c.form[i.props.title].join():c.form[i.props.title])),c.form[i.props.title]&&(t+=i.props.title+": "+c.form[i.props.title]+"\n"))}var o;o=s()({body:t,referer:e.settings.referer,customerIp:e.settings.customerIp},e.visitor),c.disableItem=!0,i.chatWebsite.notify(o).$promise.then((function(t){delete c.errors.chatMessageError,e.visitor.message={id:t.message.id},e.visitor.interaction={id:t.interaction.id},r.updateStorage(a,e.visitor).then((t=>{e.visitor=t})).catch(r.onStorageError),c.disableItem=!1,m()})).catch((function(t){var o,i,n;c.disableItem=!1,403===(null===(o=t.data)||void 0===o?void 0:o.code)&&"OutOfInterval"===(null===(i=t.data)||void 0===i||null===(n=i.details)||void 0===n?void 0:n.type)?(e.settings.online=!1,m()):console.error(t)}))},c.toggle=function(e,t){c.form[e]||(c.form[e]=[]);const o=c.form[e].indexOf(t);o>-1?c.form[e].splice(o,1):c.form[e].push(t)},c.exists=function(e,t){return c.form[e]||(c.form[e]=[]),c.form[e].indexOf(t)>-1}}c.$inject=["$rootScope","$state","$sce","api","RemoteStorageService","STORAGE_VISITOR"]},"./src/js/unmanaged/unmanaged.controller.js":(e,t,o)=>{function i(e,t,o,i,n,r,s,a){const l=this;function c(){e.settings.online?t.go("app.online",null,{location:"replace"}):t.go("app.offline",null,{location:"replace"})}function d(){l.form={},l.upColor=null,l.downColor=null,l.userForm.$setPristine(),l.userForm.$setUntouched(),e.visitor={},e.enableDownload=!1,e.$emit("hide")}function m(t){return function(i){l.errors[t]=i.data;const n=o.simple().textContent(e.settings.formSubmitFailureMessage||"Form submission error").toastClass("md-failure-toast").parent(angular.element(document.querySelector("#chat-toolbar")));o.show(n)}}function u(){e.loading=!1}l.form={},l.errors={},l.$onInit=function(){console.debug("UnmanagedController::onInit() VISITOR",e.visitor),e.status="unmanaged",n.all([r.removeItem(s).then((()=>console.debug("STORAGE_VISITOR cleared"))).catch(r.onStorageError),r.removeItem(a).then((()=>console.debug("STORAGE_LAYOUT cleared"))).catch(r.onStorageError)]).then((()=>e.loading=!1))},l.submit=function(){e.loading=!0,e.visitor.interaction&&e.visitor.interaction.id?i.chatInteraction.customUpdate({id:e.visitor.interaction.id,note:l.form.note}).$promise.then((function(){delete l.errors.submit;const t=o.simple().textContent(e.settings.formSubmitSuccessMessage||"Form properly submitted").toastClass("md-success-toast").parent(angular.element(document.querySelector("#chat-toolbar")));o.show(t)})).then(d).then(c).catch(m("submit")).finally(u):(u(),m("submit"))},l.skip=function(){d(),c()}}o.d(t,{g:()=>i}),i.$inject=["$rootScope","$state","$mdToast","api","$q","RemoteStorageService","STORAGE_VISITOR","STORAGE_LAYOUT"]},"./src/js/waiting/waiting.controller.js":(e,t,o)=>{function i(e,t,o,i,n,r,s){let a=null;function l(){let t={},o=!1;n.chatInteraction.get({id:e.visitor.interaction.id}).$promise.then((function(o){return t=o,n.chatInteraction.getMessages({intid:e.visitor.interaction.id}).$promise})).then((function(n){o=n.rows.length>1,t.closed?(e.visitor.interaction.closed=!0,r.updateStorage(s,e.visitor).then((o=>{e.visitor=o,"unmanaged"===t.disposition&&i.go("app.unmanaged",null,{location:"replace"})})).catch(r.onStorageError)):(t.UserId||o)&&(t.UserId&&(e.visitor.interaction.UserId=t.UserId),r.updateStorage(s,{...e.visitor,interactionStarted:!0}).then((t=>{e.visitor=t,i.go("app.chat",null,{location:"replace"})})).catch(r.onStorageError))})).catch((function(e){switch(e.status){case 403:i.go("app.closing",null,{location:"replace"});break;case 405:i.go("app.unmanaged",null,{location:"replace"});break;default:console.error(e)}}))}this.$onInit=function(){console.debug("WaitingController::onInit() VISITOR",e.visitor),e.status="waiting",e.visitor&&e.visitor.interaction&&e.visitor.interaction.id&&(a=o(l,3e3))},t.$on("$destroy",(function(){o.cancel(a)}))}o.d(t,{H:()=>i}),i.$inject=["$rootScope","$scope","$interval","$state","api","RemoteStorageService","STORAGE_VISITOR"]},"./src/js/media-viewer/media-viewer.tpl.html":(e,t,o)=>{e.exports=o.p+"templates/cd4ab380f3d41616949b.html"},"./src/js/offline/offline.tpl.html":(e,t,o)=>{e.exports=o.p+"templates/9962474df74f9405ac72.html"},"./src/js/online/online.tpl.html":(e,t,o)=>{e.exports=o.p+"templates/caf0e553108b226443aa.html"},"./src/js/unmanaged/unmanaged.tpl.html":(e,t,o)=>{e.exports=o.p+"templates/3f18dac5f545add792db.html"},"./src/js/waiting/waiting.tpl.html":(e,t,o)=>{e.exports=o.p+"templates/6043a16afdb829ba5934.html"}},e=>{var t=t=>e(e.s=t);e.O(0,["vendor-index","vendor-angular-76f2ed34","vendor-angular-58d021f3","vendor-ng-embed","vendor-moment","vendor-jquery","vendor-jquery.textcomplete","vendor-emojionearea","vendor-emojione","vendor-angular-sanitize","vendor-angular-resource","vendor-angular-messages","vendor-angular-material","vendor-angular-local-storage","vendor-angular-animate","vendor-urlMatcher","vendor-transition","vendor-stateService","vendor-stateDirectives","vendor-flow","chat-e96e9bea"],(()=>(t("./node_modules/jquery/dist/jquery.js"),t("./node_modules/angular/index-exposed.js"),t("./node_modules/moment/moment.js"),t("./node_modules/@flowjs/flow.js/src/flow.js"),t("./node_modules/emojione/lib/js/emojione.js"),t("./src/js/index.module.js")))),e.O()}]);
2 //# sourceMappingURL=chat-fecd0807.js.map