!function(e){function t(n){if(i[n])return i[n].exports;var a=i[n]={i:n,l:!1,exports:{}};return e[n].call(a.exports,a,a.exports,t),a.l=!0,a.exports}var i={};t.m=e,t.c=i,t.d=function(e,i,n){t.o(e,i)||Object.defineProperty(e,i,{configurable:!1,enumerable:!0,get:n})},t.n=function(e){var i=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(i,"a",i),i},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="/build/",t(t.s="ET/6")}({"3IRH":function(e,t){e.exports=function(e){return e.webpackPolyfill||(e.deprecate=function(){},e.paths=[],e.children||(e.children=[]),Object.defineProperty(e,"loaded",{enumerable:!0,get:function(){return e.l}}),Object.defineProperty(e,"id",{enumerable:!0,get:function(){return e.i}}),e.webpackPolyfill=1),e}},"438a":function(e,t,i){var n,a,o;"function"==typeof Symbol&&Symbol.iterator;!function(i){a=[],n=i,void 0!==(o="function"==typeof n?n.apply(t,a):n)&&(e.exports=o)}(function(){"use strict";function e(e,t,i,n,a,o,r){var s={debug:!1,containerSelector:"#ai-chat-avatar-container",videoInputWidth:640,videoInputHeight:360,videoOutputWidth:360,videoOutputHeight:360,videoContainerWidth:360,videoContainerHeight:360,verticalAvatarScale:.8,verticalAvatarScaleFullBodyMobile:.5,verticalAvatarScaleMobile:.65,rewindVideoSeconds:1.5,videoAlphaMaskMode:!0,drawMouthAlways:!0,useMorphFrames:!0,loadingColor:"0,103,176",origin:"",remoteBaseUrl:"https://app.humanbot.io/",urlAvatarData:"/campaign/pub/ai_avatar/",audioBaseUrl:"https://chatapi.humanbot.io/audio/mp3/",crossOrigin:"anonymous",resizeParentElement:!1,onEndedAudioAutoClean:!0,onPlayingBlocked:null,onAudioStarted:null,onAudioEnded:null};Object.assign(s,e);var l=void 0,u=void 0,c=void 0,d=void 0,h=void 0,p=void 0,m=1,f=0,g=t?t.src:"",y="",v="",A=!1,b=!1,S=!1,T=!1,C=null,w=null,E=!1,x=!0,_=!1,M=0,I=null,O=187,L=this,N=r||new Audio,k=new Image,P=null,D=["neutral","a","a","o","e","k","i","w","o","a","u","a","k","i","l","s","i","th","f","k","k","m"],R={alpha_mask:[0,0],neutral:[187,0],smile:[374,0],a:[561,0],e:[748,0],f:[935,0],i:[1122,0],k:[1309,0],l:[0,187],m:[187,187],n:[374,187],o:[561,187],p:[748,187],s:[935,187],th:[1122,187],u:[1309,187],v:[0,374],w:[187,374],a_neutral:[0,561],e_neutral:[0,748],f_neutral:[0,935],i_neutral:[0,1122],k_neutral:[0,1309],l_neutral:[0,1496],m_neutral:[0,1683],n_neutral:[0,1870],o_neutral:[0,2057],p_neutral:[0,2244],s_neutral:[0,2431],th_neutral:[0,2618],u_neutral:[0,2805],v_neutral:[0,2992],w_neutral:[0,3179]},F="",U="",B=null,q=null,H=null,j=-1,z=null,V=null,Y=null;this.faceLandmarksInitial=[],this.angleLipsInitial=0,this.widthLipsInitial=0,this.setAvatarData=function(e,t){m=e.full_body?this.getIsMobileView()?s.verticalAvatarScaleFullBodyMobile:s.verticalAvatarScale:this.getIsMobileView()?s.verticalAvatarScaleMobile:1,1!==m&&(e.landmarks=L.prepareFaceLandmarks(e.landmarks,m),e.crop_data=L.prepareCropData(e.crop_data,m),L.faceLandmarksInitial=e.landmarks[0]),B=e,this.faceLandmarksInitial=B.landmarks[0];var i=x?B.id+".webm":B.id+".mp4";this.setSpriteUrl(s.remoteBaseUrl+B.sprite),this.setVideoUrl(s.remoteBaseUrl+"chat_avatars/"+i,!!t)},this.loadAvatar=function(e,t){if(B&&B.name===e)return!1;if(!e)return B.name="",this.setVideoUrl(""),this.setSpriteUrl(""),!1;this.onLoadingStart();var i=new URL(s.origin+s.urlAvatarData+e);return fetch(i,{method:"GET",withCredentials:!0,crossorigin:!0}).then(function(e){return e.json()}).then(function(i){i.name=e,L.setAvatarData(i,!!t)}).catch(function(){B=null}),!0},this.getCenterPosition=function(e){return[e?.5*(Math.max(e[0][0],e[1][0])-Math.min(e[0][0],e[1][0]))+Math.min(e[0][0],e[1][0]):0,e?.5*(Math.max(e[0][1],e[1][1])-Math.min(e[0][1],e[1][1]))+Math.min(e[0][1],e[1][1]):0]},this.prepareTranscriptionData=function(e){return e.map(function(e){return e.chars=e.text?L.wordSplitChars(e.text):[""],e.frames=e.time.map(function(e){return Math.floor(e/1e3*25)}),e})},this.prepareFaceLandmarks=function(e,t){return e.map(function(e){return e=e.map(function(e){return[L.floatToPrecision(e[0]*t),L.floatToPrecision(e[1]*t)]})})},this.prepareCropData=function(e,t){return e.map(function(e){return L.floatToPrecision(e*t)})},this.prepareWord=function(e){return 0===e.length?e:(e=e.trim().toLowerCase(),e.replace(/[\\'.,!?]/g,""))},this.getIntersections=function(e,t){return e.filter(function(e){return t.includes(e)})},this.getCharAnalog=function(e){var t=["a","e","f","i","k","l","m","n","o","p","s","th","u","v","w"],i=[["a","y"],["p","b"],["f","v","ph"],["k","c","ch","d","g","h","j","ck","q"],["i","ee","ea","e","r","s","sh","zh","t","x","z"],["l","ll"],["m","p"],["n","ng","th","wh"],["o"],["u","w","y","oo","ou"],["v"]],n=i.findIndex(function(t){return t.indexOf(e)>-1});if(-1===n)return"neutral";var a=L.getIntersections(i[n],t);return a.length>0?a[0]:"neutral"},this.getPercentValue=function(e,t){return(t-=e[0])/(e[1]-e[0])},this.wordSplitChars=function(e){var t={en:["ch","ck","gh","ng","ph","sh","zh","th","wh","ea","ee","oo","ou","ll"]},i=[];if(e=L.prepareWord(e),0===e.length)return[""];for(;e.length>0;){var n=e.length>1&&t.en.indexOf(e.substring(0,2))>-1?e.substring(0,2):e.substring(0,1);e=e.substring(n.length),i.push(n)}return i},this.getCurrentViseme=function(e){var t=Y.findIndex(function(t){return t.frames[1]>e});return t>-1?(tz.frames[1]||r=V.frames[0]){u="neutral";var h=("neutral"===V.charFrom?V.charTo:V.charFrom)+"_neutral",p=0;c=R[h]?R[h].slice():R[u].slice(),(V.audioFrameNumber=V.duration||r>V.frames[1])&&(V=null)}u||(u=e?"neutral":L.getCurrentChar(r),c=R[u].slice());var m=B?B.landmarks[o]||null:null,f=m?L.angleForPoints(m[0],m[1]):0,g=(L.angleLipsInitial,m?m[2]:L.faceLandmarksInitial[2]),y=m?[g[0]-L.faceLandmarksInitial[2][0],g[1]-L.faceLandmarksInitial[2][1]]:[0,0],v=B.crop_data[0]+y[0],A=B.crop_data[1]+y[1],b=L.applyCanvasMask(k,[c[0],c[1],187,187],[0,0,187,187],O,O,[g[0]-v,g[1]-A],f);d.putImageData(b,0,0),a.style.transform="translate("+L.roundFloat(v,3)+"px, "+L.roundFloat(A,3)+"px)",F=u}},this.drawVideo=function(e){void 0!==e&&null===w&&(C=window.performance.now(),w=C,M=0);var i=void 0!==e?e-C:0;if(void 0!==e&&i>40){C=e-i%40;var n=e-w;Math.round(1e3/(n/++M)*100);L.renderFrame()}t.paused||window.requestAnimationFrame(L.drawVideo)},this.getSilenceDuration=function(e){if(!H||0===H.length)return 0;var t=H.findIndex(function(t){return t.time[1]>=e});return-1===t?0:H[t].time[1]-H[t].time[0]},this.getIsLoading=function(){return A||b},this.createCanvasElement=function(e,t,i,n){var a=document.createElement("canvas");return a.width=t,a.height=i,e.appendChild(a),n&&a.setAttribute("id",n),a},this.createVideoElement=function(e,t,i,n){var a=document.createElement("video");return a.setAttribute("crossorigin",s.crossOrigin),a.setAttribute("playsinline","playsinline"),a.setAttribute("webkit-playsinline","webkit-playsinline"),a.width=t,a.height=i,a.style.width=t+"px",a.style.height=i+"px",e.appendChild(a),n&&a.setAttribute("controls",""),a},this.createLoader=function(){var e=i.parentNode;P=document.createElement("div"),P.style.width="60px",P.style.height="60px",P.style.backgroundColor="rgba(255,255,255,0.5)",P.style.border="7px solid rgba("+s.loadingColor+",1)",P.style.borderTop="7px solid rgba("+s.loadingColor+",0.5)",P.style.borderRight="7px solid rgba("+s.loadingColor+",0.5)",P.style.borderRadius="50%",P.style.position="absolute",P.style.left="50%",P.style.top="50%",P.style.marginLeft="-30px",P.style.marginTop="-30px",P.style.boxShadow="0 0 0 5px rgba(255,255,255,0.5)",P.style.display="none",e.appendChild(P)},this.showLoading=function(e){if(T!==e){if(T=e,!e)return void(P.style.display="none");P.style.display="block";var t=void 0,i=0,n=function e(n){void 0===t&&(t=n),i=(n-t)/3,i>359&&(i%=360),P.style.transform="rotate("+i+"deg)",T&&window.requestAnimationFrame(e)};window.requestAnimationFrame(n)}},this.onLoadingStart=function(){this.showLoading(!0)},this.onLoaded=function(){this.showLoading(!1),this.renderFrame(),setTimeout(function(){L.renderFrame()},1e3)},this.onVideoLoaded=function(){h=s.videoAlphaMaskMode?[t.videoWidth,Math.floor(t.videoHeight/2)]:[t.videoWidth,t.videoHeight],s.videoInputWidth=h[0],s.videoInputHeight=h[1],L.updateCanvasSize(),f=t.duration,L.renderFrame(),b=!1,L.getIsLoading()||L.onLoaded(),t.paused&&(t.currentTime=s.rewindVideoSeconds),setTimeout(function(){t.paused&&(t.currentTime=s.rewindVideoSeconds)},1e3)},this.setVideoUrl=function(e,i){if(e&&g.substring(g.length-e.length)===e)return void(i&&this.playVideo());b=!0,this.onLoadingStart(),t.paused||t.pause(),g=e,t.src=g,g&&i&&this.playVideo()},this.setAudioUrl=function(e,t){return e?y.substring(y.length-e.length)===e?void(t&&this.playAudio()):(S=!0,this.onLoadingStart(),N.paused||N.pause(),y=e,N.src=y,void(t&&this.playAudio())):void(y=e)},this.muteAudioToggle=function(){N.muted=!N.muted},this.setSpriteUrl=function(e){e&&v.substring(v.length-e.length)===e||(A=!0,v=e,k.setAttribute("crossorigin",s.crossOrigin),k.src=v)},this.updateDataIndex=function(e){if(!q||0===q.length)return z=-1,void(z=null);if(j=q.findIndex(function(t){return t.frames[1]>=e}),z=j>-1?q[j]:null,j>-1&&q.length-1>j){var t=q[j+1];U=t.chars[0]}},this.createMorphData=function(e,t,i,n){if(!e&&!t||e===t)return void(V=null);var a=0,o=[0,0];if(n)a=8,o=[0,a];else if(-1!==j&&z||!Y)j>-1&&z&&("neutral"===e&&"silence"===z.content_type&&(a=Math.min(Math.ceil(z.frames[1]-z.frames[0]),4))%2>0&&a++,o=[Math.max(Math.ceil(z.frames[1])-a,0),Math.floor(z.frames[1])]);else{var r=this.getCurrentViseme(i),s=-1!==r[1]?Y[r[1]]:null;"neutral"===e&&s&&(a=Math.min(Math.ceil(s.frames[1]-s.frames[0]),4),a%2>0&&a++,o=[Math.max(Math.ceil(s.frames[1])-a,0),Math.floor(s.frames[1])])}if(0===a)return void(V=null);V={charFrom:e,charTo:t,frames:o,duration:a,frameCurrent:0,audioFrameNumber:i}},this.clearTranscriptionData=function(){q=null,j=-1,z=null},this.setTranscriptionData=function(e){if(this.clearVisemeData(),!e||0===e.length)return void this.clearTranscriptionData();q=this.prepareTranscriptionData(e.slice()),this.updateDataIndex(0)},this.clearVisemeData=function(){Y=null},this.setVisemeData=function(e){Y=e,Y.length>0&&Y[0].offset>0&&Y.unshift({offset:0,viseme_id:0}),Y.forEach(function(e,t){e.frames=[e.offset/1e3*25,t-1&&e.indexOf("mac os")>-1)return!1;var t=document.createElement("video");return t&&"probably"===t.canPlayType('video/webm; codecs="vp9, vorbis"')},this.destroy=function(){this.pauseAudio(),this.pauseVideo();var e=document.querySelector(s.containerSelector);e&&e.parentNode.removeChild(e),_=!0},this.init(),this.initAudio(),document.body.addEventListener("click",this.onAfterUserInteract)}return e})},C05R:function(e,t){var i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e};!function(e){var t=function e(){for(var t=arguments[0],n=[].slice.call(arguments,1),a=0;a
',!B.isFacebookMessengerEnabled){if(t+='
',B.translateSelect){var a=B.autoTranslateChat&&B.customerCountryCode?B.customerCountryCode:B.chatLanguage||"us",o=this.getFlagCountryCodeHtml(a);t+='"}t+='',t+='',t+="
"}t+="
",t+='",B.isFacebookMessengerEnabled||(t+=''+B.avatarName+""),t+='
',B.isFacebookMessengerEnabled&&(t+='
',t+='
',this.facebookScriptsInit()),t+='
',t+='
",t+='
',t+='',B.player.useVoiceTyping&&(t+='
",t+='
'}else"avatar"===B.type&&(t='
');i.innerHTML=t,n=i.querySelector(".cp-chat-body-b");U.indexOf(B.customerLanguage)>-1&&(B.autoTranslateChat||U.indexOf(B.chatLanguage)>-1)?i.classList.add("cp-chat-rtl"):i.classList.remove("cp-chat-rtl"),B.logoImageUrl&&(i.querySelector(".cp-chat-avatar-logo").style.backgroundImage="url('"+B.logoImageUrl+"')"),"chat"===B.type&&!this.isRestarted&&(this.isCompleted||e||!this.getIsMobileView()&&B.player.startMinimized||this.getIsMobileView()&&B.player.startMinimizedMobile)&&this.minimizeToggle(),this.colorsUpdate(),this.avatarVideoInit(),this.onWindowResize(),N.isRestarted||window.addEventListener("resize",this.onWindowResize.bind(this)),this.buttonsInit(),this.poweredByInit(),setTimeout(function(){N.isRestarted=!1,N.callToActionInit()},1e3)}},this.facebookScriptsInit=function(){!function(e,t,i){var n,a=e.getElementsByTagName(t)[0];e.getElementById(i)||(n=e.createElement(t),n.id=i,n.src="https://connect.facebook.net/en_US/sdk.js",a.parentNode.insertBefore(n,a))}(document,"script","facebook-jssdk"),function(e,t,i){var n,a=e.getElementsByTagName(t)[0];e.getElementById(i)||(n=e.createElement(t),n.id=i,n.src="https://connect.facebook.net/en_US/sdk/xfbml.customerchat.js",a.parentNode.insertBefore(n,a))}(document,"script","facebook-jssdk-customerchat"),window.fbAsyncInit=function(){FB.init({appId:B.fbAppId,autoLogAppEvents:!1,cookie:!0,xfbml:!1,version:"v4.0"}),FB.Event.subscribe("customerchat.load",function(){}),FB.Event.subscribe("customerchat.dialogShow",function(){N.getIsMinimized()&&N.minimizeToggle()}),FB.Event.subscribe("customerchat.dialogHide",function(){N.getIsMinimized()||N.minimizeToggle()}),FB.XFBML.parse(),N.isFacebookChatInitialized=!0}},this.blackoutHideToggle=function(e){e=e||!1;var t=document.querySelector(".cp-chat-blackout");t&&B.player.blackoutMode&&(e?this.addClass(t,"cp-chat-blackout-hidden"):this.removeClass(t,"cp-chat-blackout-hidden"))},this.reload=function(e){if(void 0===e&&(e=!0),this.debugLog("RELOAD",this.isInitialized),w&&4!==w.readyState&&w.abort(),i&&this.addClass(i,"cp-chat-loading"),clearInterval(void 0),clearTimeout(c),clearTimeout(d),clearTimeout(void 0),P&&P.length>0&&(P.forEach(function(e){clearTimeout(e)}),P=[]),x&&(x.destroy(),x=null),B.isLiveChatEnabled&&this.isLiveChatStarted&&this.xmppConnectionStatus===Strophe.Status.CONNECTED&&(this.isLiveChatRestarted=!0),this.isLiveChatDisabled=!1,this.isChatStarted=!1,this.isInitialized=!1,this.isRestarted=!0,this.isChatAnswered=!1,this.isExitMessageShown=!1,this.isClosed=!1,this.isVideoClosed=!1,this.isPlayStarted=!1,this.isPlayFinished=!1,this.isPromptChatStarted=!1,this.isBotChatStarted=!1,this.isCompleted=!1,this.promptChatAnswers=[],this.isBotAudioStarted=!1,!i||!document.body.querySelector(".cp-chat"))return void this.getOptions();a&&a.pause(),this.answerFieldRemove(),this.removeCompletedStatus(),window.sessionStorage&&window.sessionStorage.removeItem("isPlayedOnce"),this.liveChatExit(),e?this.isLiveChatRestarted||this.getOptions(!0):n.innerHTML=""},this.close=function(){this.debugLog("CLOSE",this.isInitialized,this.isClosed),this.isInitialized&&!this.isClosed&&(this.isClosed=!0,this.isInitialized=!1,a&&!a.paused&&a.pause(),i.style.display="none",this.blackoutHideToggle(!0),setTimeout(function(){N.isLiveChatStarted&&!N.isLiveChatDisabled&&N.liveChatExit(),N.removeEl(i),i=null},1))},this.colorsUpdate=function(e){e=e||Object.keys(B.colors);var t=[{name:"colorBackground",styles:[{selector:".cp-chat-body",style:"backgroundColor"}]},{name:"colorHeader",styles:[{selector:".cp-chat-header",style:"backgroundColor"}]},{name:"colorHeaderText",styles:[{selector:".cp-chat-header",style:"color"},{selector:".cp-chat-header .cp-btn",style:"color"},{selector:".cp-chat-header .cp-btn",style:"borderColor"}]},{name:"colorBorder",styles:[{selector:".cp-chat-body",style:"borderColor"}]},{name:"colorAvatarBubble",styles:[{selector:".cp-chat-bubble-primary .cp-chat-bubble-b",style:"backgroundColor"}]},{name:"colorAvatarBubbleText",styles:[{selector:".cp-chat-bubble-primary .cp-chat-bubble-b",style:"color"}]},{name:"colorCustomerBubble",styles:[{selector:".cp-chat-bubble:not(.cp-chat-bubble-primary) .cp-chat-bubble-b",style:"backgroundColor"}]},{name:"colorCustomerBubbleText",styles:[{selector:".cp-chat-bubble:not(.cp-chat-bubble-primary) .cp-chat-bubble-b",style:"color"}]},{name:"colorPrimaryButton",styles:[{selector:".cp-btn-primary",style:"backgroundColor"}]},{name:"colorPrimaryButtonText",styles:[{selector:".cp-btn-primary",style:"color"}]},{name:"colorCustomerInput",styles:[{selector:".cp-chat-answer-field .cp-text-field",style:"color"}]}];e.forEach(function(e){var n=t.findIndex(function(t){return t.name===e});n>-1&&i&&t[n].styles.forEach(function(t){Array.prototype.forEach.call(i.querySelectorAll(t.selector),function(i){i.style[t.style]=B.colors[e]})})})},this.chatInit=function(){this.debugLog("BEFORE CHAT INIT",this.isChatStarted),this.isChatStarted||"chat"!==B.type||this.getIsMinimized()||(this.isChatStarted=!0,B.isFacebookMessengerEnabled?this.facebookChatStart():this.chatGetMessage("first"))},this.chatGetMessage=function(e){if(this.debugLog("GET MESSAGE",e,t,"isBotAudioStarted: "+(this.isBotAudioStarted?"true":"false")),x&&this.isBotAudioStarted)return void this.afterBotAudioEnded(this.chatGetMessage.bind(this));e=e||"next";var i=[this.getBaseUrl(),B.messagesDataUrl,e+"/",B.embedId].join("");B.autoTranslateChat&&B.customerLanguage&&(i+="?lang="+B.customerLanguage),v&&v.name&&(i+=(i.indexOf("?")>-1?"&":"?")+"name="+v.name),this.ajax(i,function(e){if(N.isChatStarted&&e)if(e.completed)e.message&&N.createMessage(e.message),N.setCompletedStatus();else if(e.id){if("question"===e.type&&"name"===e.options.value&&v&&v.name)return void N.chatGetMessage("next");N.currentChatItem=e,e.translations&&e.translations.exitMessage&&(B.translations.exitMessage=e.translations.exitMessage),x&&N.currentChatItem.phrases&&N.currentChatItem.phrases.length>0?N.createTtsAudio():N.addToChat()}},{},"GET",!0)},this.validate=function(e,t,i){if(!e)return!1;var n,a=!0;switch(t){case"email":n=/^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/,a=n.test(e.toLowerCase());break;case"date":if(n=/^(\d{4})\-(\d{1,2})\-(\d{1,2})$/,(a=n.test(e.toLowerCase()))&&i){parseInt(i.dataset.allowPastDates)||(a=!N.getIsPastDate(e.toLowerCase()))}break;case"time":n=/^(\d{2}):(\d{2})$/,a=n.test(e.toLowerCase())}return a},this.getIsPastDate=function(e){var t=new Date(e);return t.setDate(t.getUTCDate()),t.setMonth(t.getUTCMonth()),t.setFullYear(t.getUTCFullYear()),(new Date).getTime()>t.getTime()},this.validateAvailableDates=function(e,t){var i=new Date(e);t=t.slice().map(function(e){return e.toLowerCase()});var n=i.toLocaleString("en-us",{weekday:"long",timeZone:"UTC"}).toLowerCase();return t.indexOf(n)>-1},this.validateAvailableTime=function(e,t){if(!e.match(/^\d{2}:\d{2}$/))return!1;var i=e.split(":"),n=new Date;n.setHours(parseInt(i[0]),parseInt(i[1]));var a=new Date;i=t[0].split(":"),a.setHours(parseInt(i[0]),parseInt(i[1]));var o=new Date;return i=t[1].split(":"),o.setHours(parseInt(i[0]),parseInt(i[1])),n.getTime()>=a.getTime()&&n.getTime()<=o.getTime()},this.transformUserData=function(e,t){switch(t){case"date":if(!this.validate(e,t))return e;var i=new Date(e.toLowerCase());i.setDate(i.getUTCDate()),i.setMonth(i.getUTCMonth()),i.setFullYear(i.getUTCFullYear()),e=B.autoTranslateChat&&B.customerLanguage?this.getLocaleDateString(i,B.customerLanguage):this.getLocaleDateString(i,B.chatLanguage);break;case"time":if(!this.validate(e,t))return e;var n,a,o,r=e.split(":");n=r[0],a=r[1],n>12?(o="PM",n-=12):n<12?(o="AM",0===n&&(n=12)):o="PM",e=n+":"+a+" "+o;break;case"phone":var s=["ru"].includes(B.customerLanguage)?"-":" ";e=N.phoneNumberFormat(e,s)}return e},this.phoneNumberFormat=function(e,t){return function e(t,i,n){n=n||1;var a=t.match(/[0-9]+$/),o="";if(null===a||a.index+2>=t.length)return t;if(a.index>0&&(o=t.substring(0,a.index),t=t.substring(a.index)),1===n&&(5===t.length||t.length>6))return o=t.substring(0,1)+i,e(o+t.substring(1),i,2);var r=t.length>=5&&(t.substr(3).length%2==0||t.substr(3).length>=5)?3:2;return o+=t.substring(0,r)+i,e(o+t.substring(r),i,2)}(e,t)},this.getLocalizedMonthName=function(e,t){var i=new Date;return i.setDate(1),i.setMonth(e-1),this.capitalizeString(i.toLocaleString(t,{month:"long"}))},this.getLocaleDateString=function(e,t){var i={year:"numeric",month:"long",day:"numeric"};return e.toLocaleDateString(t,i)},this.textFieldLoading=function(e){e=e||!1;var t=i.querySelector(".cp-chat-reply-block"),n=t.querySelector(".cp-text-field"),a=t.querySelector(".cp-btn-primary"),o=t.querySelector(".cp-chat-button-speech-typing");o&&(e?(o.classList.add("cp-chat-button-loading"),o.setAttribute("disabled","")):(o.classList.remove("cp-chat-button-loading"),o.removeAttribute("disabled"))),a&&(e?a.setAttribute("disabled",""):a.removeAttribute("disabled")),n&&(e?n.setAttribute("disabled",""):n.removeAttribute("disabled"))},this.sendTextAnswer=function(e){var t=i.querySelector(".cp-chat-reply-block"),n=t.querySelector(".cp-text-field"),a=i.querySelector(".cp-chat-answer-field"),o=a.className.split("-"),r=o.pop();N.sendAnswer(N.transformUserData(e,r)),N.removeClass(n,"cp-text-field-error"),n.value=""},this.sendAnswer=function(e,t){if(e){t=t||e;var i="next",a="",o=!1,s=-1,l="";if(this.answerFieldRemove(),this.isPromptChatStarted&&this.currentChatItem&&this.currentChatItem.options.items){var u,h=t.toLowerCase(),p=[],m=this.getChatItemOptions(this.currentChatItem);m&&!this.currentChatItem.optionsOriginal&&(this.currentChatItem.optionsOriginal=JSON.parse(JSON.stringify(m))),m.items=m.items.filter(function(e){return!!e.keywords});for(var f=0;f0?"
":"")+m.items[f].response)});if(p.length>0)if(m.leaveAfterFirstResponse)m.items=[];else{var g=[];m.items.forEach(function(e,t){-1===p.indexOf(t)&&g.push(e)}),m.items=g}else o||(a=m.unknown,l="unknown");m.items.length>0?i="save":this.isPromptChatStarted=!1}else if(this.isBotChatStarted){var y=N.findByKeywords(e,a);if(!y.isKeywordFound)return void N.tellBot(e);i="save",o=y.isKeywordFound,s=y.keyValueIndex,a=y.nextMessage,E||(E=[]),E.push({input:N.cleanString(e),response:a})}else{if(this.isLiveChatStarted&&!this.isLiveChatDisabled)return void this.xmppSendMessageToOwner(e);if("yes_no"===this.currentChatItem.type){var A=N.getChatItemOptions(this.currentChatItem);A.choice1.trim()===t.trim()&&A.choice1reply&&(a=A.choice1reply,s=0),A.choice2.trim()===t.trim()&&A.choice2reply&&(a=A.choice2reply,s=1)}}this.currentChatItem&&["question","buttons"].indexOf(this.currentChatItem.type)>-1&&this.saveCustomerAnswer(this.currentChatItem,e),this.isPromptChatStarted||(this.isChatAnswered=!0),this.buttonPromptChatToggle(null,!1),this.createMessage(t,"answer");var b=n.querySelector(".cp-chat-bubble:last-child");b&&N.scrollIfNeeded(n,b),this.isPromptChatStarted&&!o&&(a=this.promptChatAnswersTrigger(h,a));var S=[this.getBaseUrl(),B.messagesDataUrl,i+"/",B.embedId].join("");B.autoTranslateChat&&B.customerLanguage&&(S+="?lang="+B.customerLanguage),this.ajax(S,function(e){var t=0;if(e){if(a){if(t=80*a.length,l&&x)N.createTtsAudio(null,-1,l);else if(x&&s>-1){if("chat"===N.currentChatItem.type&&N.currentChatItem.optionsOriginal){var i=N.currentChatItem.optionsOriginal.items;s=i.findIndex(function(e){return e.response===a})}N.createTtsAudio(null,s)}else N.createMessage(a,"question",!0);if(N.isPromptChatStarted){var n=N.getChatItemOptions(N.currentChatItem);o&&n.prompt&&(c=setTimeout(function(){N.createMessage(n.prompt,"question",!0)},500)),n.buttonFinish&&(d=setTimeout(function(){N.buttonPromptChatToggle(n.buttonFinish)},540))}if(N.isBotChatStarted)return void N.answerFieldInit("text")}e.completed?(N.isPromptChatStarted=!1,e.message&&N.createMessage(e.message),N.setCompletedStatus()):e.id&&(e.options&&e.options.customerData&&("object"!==(void 0===v?"undefined":r(v))&&(v={}),N.extend(v,e.options.customerData)),N.isPromptChatStarted?a?N.startPromptChat(N.currentChatItem,!1):(N.typingAnimationToggle(!0),d=setTimeout(function(){N.typingAnimationToggle(!1),N.startPromptChat(N.currentChatItem)},2e3)):(N.currentChatItem=e,setTimeout(function(){x&&N.currentChatItem.phrases&&N.currentChatItem.phrases.length>0?N.createTtsAudio():N.addToChat()},t)))}},{answer:e,nextMessage:a},"POST",!0)}},this.findByKeywords=function(e,t,i){t=t||"",i=i||!1;var n=e.toLowerCase(),a=!1,o=-1,r=[],s=[],l=this.getChatItemOptions(this.currentChatItem);l.items||(l.items=[]),l.items=l.items.filter(function(e){return!!e.keywords});for(var u=0;u0?"
":"")+l.items[u].response)});if(s.length>0){if(l.leaveAfterFirstResponse)l.items=[];else if(i){var c=[];l.items.forEach(function(e,t){-1===s.indexOf(t)&&c.push(e)}),l.items=c}}else a||(t=l.unknown||"");return{isKeywordFound:a,keyValueIndex:o,nextMessage:t,itemsCount:l.items.length}},this.saveCustomerAnswer=function(e,t){var i=e.options||{};if(i.key&&("question"===e.type||"buttons"===e.type)){var n=N.capitalizeString(i.key||i.value);"object"!==(void 0===v?"undefined":r(v))&&(v={}),v[n]=t}},this.sendAudio=function(e,t,i){var n=new FormData;n.append("file",t),B.autoTranslateChat&&B.customerLanguage&&n.append("lang",B.customerLanguage),this.ajax(e,function(e){"function"==typeof i&&i(e)},n,"POST",!0)},this.sendAudioToSave=function(e,t){var i,a,o=[this.getBaseUrl(),B.messagesDataUrl,"next/",B.embedId].join(""),r="";this.sendAudio(o,e,function(e){e&&(t&&(i=e.outputFilePath?e.outputFilePath:e.options&&e.options.customerData?e.options.customerData.outputFilePath||"":"",r='
',r+='
",t.innerHTML=r,N.colorsUpdate(["colorPrimaryButton","colorPrimaryButtonText"]),N.scrollIfNeeded(n,t),t.querySelector("button").addEventListener("click",function(e){e.preventDefault();var t=this;a||(a=new Audio,a.addEventListener("play",function(){t.innerHTML=' '+N.getTranslation("pause")}),a.addEventListener("pause",function(){t.innerHTML=' '+N.getTranslation("play")}),a.src=i),a.paused?a.play():a.pause()})),e.id&&(N.currentChatItem=e,x&&N.currentChatItem.phrases&&N.currentChatItem.phrases.length>0?N.createTtsAudio():N.addToChat()))})},this.typingAnimationToggle=function(e){if(!B.typingAnimation)return!1;this.isChatStarted||(e=!1);var t;if(e){t='
',t=t.replace("<%- avatarThumbnailImageUrl %>",B.avatarThumbnailImageUrl);var i=this.append(n,this.createElement("div",{className:"cp-chat-bubble cp-chat-bubble-primary cp-chat-bubble-avatar cp-chat-bubble-left cp-chat-typing-container",innerHTML:t}));this.colorsUpdate(["colorAvatarBubble","colorAvatarBubbleText"]),N.scrollIfNeeded(n,i)}else{var a=n.querySelectorAll(".cp-chat-typing-container");Array.prototype.forEach.call(a,function(e){n.removeChild(e)})}return!0},this.autoPlayInit=function(){if(this.getIsMinimized())return this.blackoutHideToggle(!0),void(this.isAutoPlayAvailable||this.drawPoster());this.debugLog("BEFORE PLAY VIDEO");var e=function(e){N.debugLog("PLAY VIDEO ERROR"),e&&console.error(e),N.isPlayStarted||(B.player.autoPlay=!1,B.playButtonOverlay=!0,N.drawPoster())};if(this.device.isMobile&&this.device.isAndroid&&"firefox"===this.device.browser)return this.debugLog("IS MOBILE FIREFOX - NO AUTO PLAY"),void e();var t=a.play();void 0!==t?t.then(function(){N.debugLog("PLAY VIDEO SUCCESS"),N.isAutoPlayAvailable||N.addButtonOverlay(),N.chatInit()},e).catch(e):e()},this.addButtonOverlay=function(){var e=i.querySelector(".cp-chat-avatar-container");if(!e.querySelector(".cp-chat-video-autoplay-overlay")){var t="",n="";switch(B.player.autoPlayButtonStyle){case"play_button":t='';break;case"touch_finger":t='',t+="
"+B.player.autoPlayButtonText,n="
|
";break;case"text_only":t=B.player.autoPlayButtonText,n="
|
"}B.player.autoPlayAttentionGrabber&&(t=''+t+""),n.length>0&&(n=n.split("|"),t=n[0]+t+n[1]);var a=N.createElement("div",{className:"cp-chat-video-autoplay-overlay",innerHTML:'
'+t+"
"});e.appendChild(a);var o;o=f?2*Math.round(f-B.width/2):0,o>0?e.querySelector(".cp-chat-video-autoplay-overlay-c").style.paddingLeft=o+"px":e.querySelector(".cp-chat-video-autoplay-overlay-c").style.paddingRight=Math.abs(o)+"px",B.isAvatarFullBody&&(e.querySelector(".cp-chat-video-autoplay-overlay-c").style.paddingLeft="85px",e.querySelector(".cp-chat-video-autoplay-overlay-c").style.paddingBottom="100px"),a.addEventListener("click",function(e){e.preventDefault(),N.removeButtonOverlay()})}},this.removeButtonOverlay=function(){var e=i.querySelector(".cp-chat-avatar-container"),t=e.querySelector(".cp-chat-video-autoplay-overlay");t&&(a&&(a.pause(),a.muted=!1,a.currentTime=0,a.play()),N.removeEl(t),N.muteButtonToggle())},this.poweredByInit=function(){if(B.poweredByCompanyName){var e=i.querySelector(".cp-chat-poweredby-container"),t='';B.poweredByLinkUrl?(t='',t+="Powered By "+B.poweredByCompanyName+""):t="Powered By "+B.poweredByCompanyName+"",e.innerHTML=t}},this.callToActionInit=function(){if(B.isCallToActionEnabled&&B.callToActionButtonText&&!(B.callToActionShowAtTheEnd&&!this.isPlayFinished&&B.avatarVideoUrl||!B.callToActionShowAtTheEnd&&this.isPlayFinished&&B.avatarVideoUrl)){var e=B.avatarVideoUrl?i.querySelector(".cp-chat-avatar-container"):i;if(!e.querySelector(".cp-chat-button-call-to-action")){this.append(e,this.createElement("div",{className:"cp-chat-button-call-to-action"}));B.callToActionCountdownTimer?this.callToActionCountdownInit():this.callToActionButtonInit()}}},this.callToActionButtonInit=function(){var e=i.querySelector(".cp-chat-avatar-container .cp-chat-button-call-to-action");if(e){this.append(e,this.createElement("a",{innerHTML:""+this.getCampaignTranslation("callToActionButtonText",!1)+"",href:this.fixUrl(B.callToActionButtonLink),target:"_blank"},{backgroundColor:B.callToActionButtonColor,borderColor:B.callToActionButtonColor,color:B.callToActionButtonTextColor}));setTimeout(function(){N.addClass(e,"cp-chat-button-call-to-action-active")},100)}},this.callToActionCountdownInit=function(){var e=i.querySelector(".cp-chat-avatar-container .cp-chat-button-call-to-action");if(e){var t=0;B.callToActionCountdownMinutes&&/^[\d]+$/.test(B.callToActionCountdownMinutes)&&(t+=60*parseInt(B.callToActionCountdownMinutes)),B.callToActionCountdownSeconds&&/^[\d]+$/.test(B.callToActionCountdownSeconds)&&(t+=parseInt(B.callToActionCountdownSeconds)),t&&(C=new VPCountdown({containerSelector:".cp-chat-avatar-container .cp-chat-button-call-to-action",countdownDate:B.callToActionCountdownUseDate?B.callToActionCountdownDate:"",countDownType:B.callToActionCountdownUseDate?"days":"minutes",time:t,textContent:B.callToActionCountdownText,digitColor:B.callToActionCountdownNumbersColor,textColor:B.callToActionCountdownTextColor,callback:function(){N.callToActionButtonInit()}}),setTimeout(function(){N.addClass(e,"cp-chat-button-call-to-action-active")},100))}},this.emoticonsInit=function(e){e=e||"text";var t=i.querySelector(".cp-chat-reply-block"),n=t.querySelector(".cp-text-field"),a=t.querySelector(".cp-chat-emoticons-container");if(!this.isLiveChatOwnerOnline||"text"!==e)return void(a&&(a.style.display="none"));if(!a){this.addClass(t,"cp-chat-reply-block-buttons"),a=this.append(t,this.createElement("div",{className:"cp-chat-emoticons-container",innerHTML:'
    '}));var o=a.querySelector("ul"),r=a.querySelector("input");R.forEach(function(e,t){N.append(o,N.createElement("li",{innerHTML:' '+F[t]+' '}))}),a.querySelector(".button-emoticons").addEventListener("click",function(e){e.preventDefault(),o.style.display&&"none"!==o.style.display?o.style.display="none":o.style.display="block"}),r.addEventListener("change",function(e){if(0!==e.target.files.length){var t=e.target.files[0],i=[N.getBaseUrl(),"campaign/pub/media/",B.embedId].join("");N.chatServiceMessageToggle(N.getTranslation("sendingFile"));var n=new FormData;n.append("file",t,t.name),N.ajax(i,function(e){e&&e.success?(N.chatServiceMessageToggle(N.getTranslation("fileSuccessfullySent")),e.filePath&&N.isLiveChatStarted&&!N.isLiveChatDisabled&&N.xmppSendMessageToOwner(":SERVICE:FILE:"+e.filePath)):e&&e.error?N.chatServiceMessageToggle(N.getTranslation(e.error)):N.chatServiceMessageToggle("")},n,"POST",!0)}}),a.querySelector(".button-add-file").addEventListener("click",function(e){e.preventDefault(),r.click()}),o.addEventListener("mouseleave",function(e){e.stopPropagation(),o.style.display="none"}),o.addEventListener("click",function(e){var t=e.target;if("img"===t.tagName.toLowerCase()){e.preventDefault();var i=n.selectionStart||n.value.length,a=n.value.split(""),r=t.getAttribute("alt");a.length>0&&" "!==a[i-1]&&(r=" "+r),i-1||B.player.videoUrl.indexOf("youtu.be")>-1)?this.youtubeApiInit():B.player.videoUrl&&B.player.videoUrl.indexOf("vimeo.com")>-1&&this.vimeoApiInit()},this.buttonsInit=function(){this.debugLog("BEFORE BUTTONS INIT. querySelector typeof",r(i.querySelector));var e=i.querySelector(".cp-chat-avatar-container"),t=i.querySelectorAll(".cp-btn-minimize, .cp-btn-open"),n=i.querySelector(".cp-btn-close");if(Array.prototype.forEach.call(t,function(e){e.addEventListener("click",function(e){e.preventDefault(),N.minimizeToggle()})}),n&&(n.addEventListener("click",function(e){e.preventDefault(),N.close()}),this.isLiveChatStarted||(n.style.display="none")),"chat"===B.type){var o=i.querySelector(".cp-chat-reply-block"),s=o.querySelector("button"),l=o.querySelector(".cp-text-field"),u=i.querySelector(".cp-chat-exit-block .cp-btn-livechat-exit"),c=i.querySelector(".cp-chat-button-speech-typing"),d=function(){var e=i.querySelector(".cp-chat-answer-field"),t=e.className.split("-"),n=t.pop();if(N.validate(l.value,n,l)){var a=l.value.replace(/\/g,">"),N.sendAnswer(N.transformUserData(a,n)),N.removeClass(l,"cp-text-field-error"),l.value=""}else N.addClass(l,"cp-text-field-error"),l.focus()};s.addEventListener("click",function(e){e.preventDefault(),d()}),l.addEventListener("keyup",function(e){var t=e.which||null;if(l.value){if(l.className.indexOf("cp-text-field-error")>-1){var n=i.querySelector(".cp-chat-answer-field"),a=n.className.split("-"),o=a.pop();N.validate(l.value,o)&&N.removeClass(l,"cp-text-field-error")}N.isLiveChatStarted&&N.isLiveChatOwnerOnline&&N.liveChatTypingHandle(),13===t&&d()}}),u&&u.addEventListener("click",function(e){e.preventDefault(),B.isLiveChatEnabled&&N.isLiveChatStarted?N.liveChatExit():(N.setCompletedStatus(),N.isBotChatStarted=!1,v.name="",N.answerFieldRemove(),N.chatGetMessage("next"),x&&(x.setAudioUrl(""),x.clearVisemeData()))}),B.player.useVoiceTyping&&c&&c.addEventListener("click",function(e){e.preventDefault();var t=c.querySelector("i");N.recordingMicrophoneInit(function(){c.classList.add("active"),t&&(t.className="cp-icon-stop")},function(e){c.classList.remove("active"),t&&(t.className="cp-icon-mic"),setTimeout(function(){O=null,I=null,L=[]},2e3),N.textFieldLoading(!0),N.sendAudio(N.getBaseUrl()+B.speechTypingUrl,e,function(e){e&&e.textContent&&N.sendTextAnswer(e.textContent),N.textFieldLoading(!1)})})})}var h=this.append(e,this.createElement("DIV",{className:"cp-avatar-buttons"}));B.player.showMute&&this.appendButton(h,"Mute/Unmute",a&&a.muted?"cp-icon-volume-medium":"cp-icon-volume-mute","cp-btn cp-btn-circle cp-button-mute",function(e){e.preventDefault(),x?x.muteAudioToggle():a&&(a.muted=!a.muted),N.muteButtonToggle()}),this.appendButton(h,"Close Video","cp-icon-cross","cp-btn cp-btn-circle cp-button-close",function(e){e.preventDefault(),a&&!a.paused&&a.pause(),N.isVideoClosed=!0,x?(N.blackoutHideToggle(!0),N.avatarVideoClose(),x.destroy(),x=null):"avatar"===B.type?(N.blackoutHideToggle(!0),N.avatarVideoClose(),N.setCompletedStatus(),i.style.display="none"):N.onPlayingEnd(!0)})},this.createLanguagesSelectInput=function(){if(B.translateSelect&&"avatar"!==B.type){var e=i.querySelector(".cp-btn-language"),t=this.createElement("div",{className:"cp-chat-language"});this.append(i,t);var n="";B.languages.forEach(function(e){"chat"===B.type&&x&&e.visemeMissing||(n+="',n+='',n+="  "+e.name,n+="")}),t.innerHTML=n,e&&(e.addEventListener("click",function(e){e.preventDefault(),t.style.display="block"===t.style.display?"none":"block"},!1),Array.prototype.forEach.call(t.querySelectorAll("div"),function(i){i.addEventListener("click",function(i){i.preventDefault();var n=i.target||i.currentTarget;Array.prototype.forEach.call(t.querySelectorAll("div"),function(e){N.removeClass(e,"active")}),B.autoTranslateChat=!0,B.player.startMinimized=!1,B.customerLanguage=n.dataset.lang,B.customerCountryCode=n.dataset.countrycode,E=[],N.addClass(n,"active"),N.answerFieldRemove(),t.style.display="none",e.querySelector("span.cp-flag").style.backgroundImage="",e.querySelector("span.cp-flag").className="cp-flag bg-"+("en"===B.customerCountryCode?"us":B.customerCountryCode),N.reload()},!1)})),i.querySelector(".cp-chat-body").addEventListener("click",function(e){t.style.display="none"},!1)}},this.recordingMicrophoneInit=function(e,t){if(N.isAudioRecordStarted)N.isAudioRecordStarted=!1,I&&I.getAudioTracks()[0].stop(),O.finishRecording();else{if(O&&O.isRecording())return;var i=window.AudioContext||window.webkitAudioContext,n=new i;if(!navigator.mediaDevices)return void console.log("ERROR - non-HTTPS?");navigator.mediaDevices.getUserMedia({audio:!0,video:!1}).then(function(i){return I=i,O=new WebAudioRecorder(n.createMediaStreamSource(I),{workerUrl:N.getWorkerURL(N.getBaseUrl()+"js/web-audio-recorder/WebAudioRecorderWav.min.js"),encoding:"wav",numChannels:2,onEncoderLoading:function(e,t){},onEncoderLoaded:function(e,t){}}),O.onComplete=function(e,i){"function"==typeof t&&t(i)},O.setOptions({timeLimit:120,encodeAfterRecord:!0,ogg:{quality:.5},mp3:{bitRate:160}}),setTimeout(function(){L=[],N.isAudioRecordStarted=!0,O.startRecording(),"function"==typeof e&&e()},1),i},function(e){console.log(e),N.isAudioRecordStarted=!1}).catch(function(e){console.log(e)})}},this.minimizeToggle=function(e){if(void 0===e&&(e=!0),this.getIsMinimized()){this.deleteCookie("completed"+B.embedId),this.isCompleted=!1;var t=i.querySelector(".cp-chat-invitation-message");t&&this.removeEl(t),this.removeClass(i,"cp-minimized"),B.player.autoPlayAttentionGrabber&&this.removeClass(i,"cp-animation-shake"),this.blackoutHideToggle(),this.isVideoClosed||(this.isPlayStarted&&!this.isPlayFinished||!this.isPlayStarted&&B.player.autoPlay&&B.player.autoPlayStartMuted?(this.isCompleted=!1,e&&a&&a.play()):setTimeout(function(){N.drawPoster()},1)),this.isChatStarted||this.chatInit(),B.isFacebookMessengerEnabled&&void 0!==window.FB&&window.FB.CustomerChat.showDialog(),"chat"===B.type&&x&&x.playAudio()}else this.addClass(i,"cp-minimized"),a&&a.pause(),this.onMinimize()},this.getIsMinimized=function(){return i.className.indexOf("cp-minimized")>-1},this.getIsMobileView=function(){return window.innerWidth<=576},this.getIsLiveChatEnabled=function(){return!!B.isLiveChatEnabled&&(!this.isLiveChatDisabled||this.isLiveChatRestarted)},this.muteButtonToggle=function(){if(B.player.showMute){var e=i.querySelector(".cp-button-mute");if(e){var t=e.querySelector("i"),n=x?x.isAudioMuted():a.muted;t.className=n?"cp-icon-volume-medium":"cp-icon-volume-mute"}}},this.avatarVideoClose=function(){a&&!a.paused&&a.pause(),this.onPaused(),i.classList.remove("cp-chat-avatar-fullbody"),i.querySelector(".cp-chat-avatar-container").style.display="none"},this.appendButton=function(e,t,i,n,a){this.append(e,this.createElement("BUTTON",{type:"button",title:t,innerHTML:'',className:n})).addEventListener("click",a)},this.drawPoster=function(){this.debugLog("BEFORE DRAW POSTER",B.previewImageUrl);var e=function(e){N.debugLog("BEFORE DRAW POSTER IMAGE"),l.clearRect(0,0,o.width,o.height);var t=o.height*(e.width/e.height),i=(o.width-t)/2;l.drawImage(e,0,0,e.width,e.height,i,0,t,o.height),N.addButtonOverlay()};this.debugLog("VIDEO CAN PLAY?",this.isVideoCanPlay),this.debugLog("CROSS ORIGIN",B.crossOrigin),this.debugLog("VIDEO READYSTATE",a.readyState),this.debugLog("VIDEO MUTED?",a.muted),this.isVideoCanPlay?(l.clearRect(0,0,o.width,o.height),this.drawVideoWithAlpha(!0),this.addButtonOverlay()):B.previewImageUrl&&(m?e(m):(m=new Image,m.onload=function(){e(m)},m.src=B.previewImageUrl))},this.clickPlayOverlay=function(e){e.preventDefault(),e.stopPropagation(),N.removeClass(i,"cp-chat-poster");var t=i.querySelector(".cp-chat-avatar-container");N.removeClass(t,"cp-chat-play-layer"),a.currentTime=0,a.muted=!1,a.play()},this.createTtsAudio=function(e,t,i,n,a){if(e=e||this.currentChatItem,e.type){this.debugLog("CREATE_TTS_AUDIO",e.type,i),M=!0,N.typingAnimationToggle(!0);var o=this.getBaseUrl()+B.botTextToSpeechUrl+"/"+B.embedId+"/"+e.id;B.autoTranslateChat&&B.customerLanguage&&(o+="?lang="+B.customerLanguage);var r={keyValueIndex:void 0!==t&&t>-1?t:-1,optionKey:i||"",shortText:n||"",customerData:this.getCustomerData()};this.ajax(o,function(e){M=!1;var t="";if(e.audioUuid&&x){var i=x.getAudioUrl(e.audioUuid),n=e.audioViseme||[];n.length>0&&(x.setVisemeData(n),x.setAudioUrl(i,!0),N.onPlayStarted()),e.textMessage&&(t=e.textMessage)}N.typingAnimationToggle(!1),t?N.createMessage(t,"question",!0):N.addToChat(),"function"==typeof a&&a()},r,"POST")}},this.addToChat=function(e){if(e=e||this.currentChatItem,e.type){this.debugLog("ADD_TO_CHAT",e.type);var t,i=50;switch(e.type){case"question":t=function(){N.answerFieldInit(e.options.value,e.options);var t=n.querySelector(".cp-chat-bubble:last-child");t&&N.scrollIfNeeded(n,t)};break;case"yes_no":case"buttons":if(!e.options)break;t=function(){var t=[],i=[],a=e.options||{},o=N.getChatItemOptions(e);if("yes_no"===e.type){if(!a.choice1&&!a.choice2)return void setTimeout(N.chatGetMessage.bind(N),1200);a.choice1||(a.choice1=o.choice1="Yes"),a.choice2||(a.choice2=o.choice2="No"),t=[a.choice1,a.choice2],i=[o.choice1,o.choice2]}else if("buttons"===e.type){if(!a.buttons)return void setTimeout(N.chatGetMessage.bind(N),1200);t=a.buttons,i=o.buttons}var r=n.querySelector(".cp-chat-bubble:last-child"),s="
    ";i.forEach(function(e,i){e&&(s+='")}),s+="
    ";var l=N.createElement("DIV",{className:"cp-chat-answer-block",innerHTML:s});B.buttonsInsideBubble?N.append(r.querySelector(".cp-chat-bubble-b"),l):N.append(n,l),N.colorsUpdate(["colorPrimaryButton","colorPrimaryButtonText"]),Array.prototype.forEach.call(l.querySelectorAll("button"),function(e){e.addEventListener("click",function(e){e.preventDefault(),r=n.querySelector(".cp-chat-bubble:last-child"),B.buttonsInsideBubble?r.querySelector(".cp-chat-bubble-b").removeChild(l):n.removeChild(l);var t=this.dataset.original||this.value,i=this.value;N.sendAnswer(t,i)},!1)}),N.scrollIfNeeded(n,l)};break;case"picture":t=function(){var t=e.media;if(t){var i=N.getImageResizedUrl(t.filename,t.userId),n=N.getMediaFullUrl(t.filename,t.userId),a='
    ';N.createMessage(a,"question",!0)}setTimeout(N.chatGetMessage.bind(N),1200)};break;case"video":t=function(){var t=e.media,i="",n=t?N.getMediaFullUrl(t.filename,t.userId):"";!n&&e.options.mediaUrl&&(n=N.getFullUrl(e.options.mediaUrl));var a=e.options.url?N.getYoutubeVideoId(e.options.url):"",o=e.options.url?N.getVimeoVideoId(e.options.url):"";i='
    ',i+='
    ',"new_tab"===i?o+=' ':"download"===i&&(o+=' '),o+=s+"",a){var l=N.createElement("DIV",{className:"cp-chat-answer-block",innerHTML:o});N.append(n,l),N.colorsUpdate(["colorPrimaryButton","colorPrimaryButtonText"]),N.scrollIfNeeded(n,l)}else N.createMessage(o,"question",!0);setTimeout(N.chatGetMessage.bind(N),1200)};break;case"chat":t=function(){N.answerFieldInit("text"),N.startPromptChat(e)};break;case"live_chat_bot":case"bot":t=function(){N.isBotChatStarted||(N.debugLog("IS_BOT_AUDIO_STARTED",N.isBotAudioStarted),x&&N.isBotAudioStarted?N.afterBotAudioEnded(function(){N.startBotChat(e)}):N.startBotChat(e))};break;case"live_chat_human":t=function(){N.liveChatStart()};break;case"text":t=function(){setTimeout(N.chatGetMessage.bind(N),1200)};break;case"audio_record":t=function(){var e='
    ';e+='
    ";var t=N.createElement("DIV",{className:"cp-chat-answer-block cp-mb-3",innerHTML:e});N.append(n,t),N.scrollIfNeeded(n,t),N.colorsUpdate(["colorPrimaryButton","colorPrimaryButtonText"]);var i,a,o,r=t.querySelector(".cp-btn-primary");r.addEventListener("click",function(e){if(e.preventDefault(),N.isAudioRecordStarted)N.isAudioRecordStarted=!1,N.removeEl(r),t.innerHTML='',i.getAudioTracks()[0].stop(),a.finishRecording();else{if(a&&a.isRecording())return;var n=window.AudioContext||window.webkitAudioContext,s=new n;navigator.mediaDevices.getUserMedia({audio:!0,video:!1}).then(function(e){i=e;return a=new WebAudioRecorder(s.createMediaStreamSource(i),{workerUrl:N.getWorkerURL(N.getBaseUrl()+"js/web-audio-recorder/WebAudioRecorderWav.min.js"),encoding:"wav",numChannels:2,onEncoderLoading:function(e,t){},onEncoderLoaded:function(e,t){}}),a.onComplete=function(e,i){N.sendAudioToSave(i,t)},a.setOptions({timeLimit:120,encodeAfterRecord:!0,ogg:{quality:.5},mp3:{bitRate:160}}),setTimeout(function(){o=[],N.isAudioRecordStarted=!0,r.innerHTML=' '+N.getTranslation("stop"),a.startRecording()},1),e},function(e){console.log(e)})}})};break;case"slider":t=function(){var t=Math.ceil(253*e.options.items.length),i="",n="",a='
    ';a+='
    ',e.options.items.forEach(function(e){a+='
    ',e.mediaUrl&&(i=N.getMediaFullUrl(e.mediaUrl),n=N.getMediaFullUrl(e.previewMediaUrl),a+='',a+=""),a+='
    ',a+="

    "+e.title+"

    ",(e.price||!isNaN(e.price)&&parseInt(e.price))&&(a+='
    '+e.price+"
    "),e.linkText&&e.linkUrl&&(e.linkUrl=N.fixUrl(e.linkUrl.trim()),a+=''+e.linkText+""),a+="
    "}),a+="
    ",a+='',a+='',N.addContentHtml(a,"cp-chat-content-slider-container",e.type),setTimeout(N.chatGetMessage.bind(N),1200)}}if(e.phrases.length>0){N.typingAnimationToggle(!0);var a=B.autoTranslateChat&&e.translations?this.getChatTranslations(e,"phrases"):e.phrases,o=0;a.forEach(function(n,a){if(n){o+=B.typingAnimation?50*n.length:500;var r=setTimeout(function(){N.typingAnimationToggle(!1),N.createMessage(n),e.phrases.length>=a+2&&N.typingAnimationToggle(!0),e.phrases.length===a+1&&"function"==typeof t&&(i>50&&N.typingAnimationToggle(!0),setTimeout(function(){N.typingAnimationToggle(!1),t()},i))},o);P.push(r)}})}else"function"==typeof t&&(i>50&&N.typingAnimationToggle(!0),setTimeout(function(){N.typingAnimationToggle(!1),t()},i))}},this.answerFieldInit=function(e,t){var n="cp-chat-with-reply";this.isBotChatStarted&&B.chatTreeSize>1&&(n="cp-chat-with-reply-exit"),this.addClass(i,n);var a=i.querySelector(".cp-chat-answer-field"),o=a.querySelector(".cp-text-field");switch(a.className="cp-chat-answer-field",B.player.useVoiceTyping&&this.addClass(a,"cp-chat-answer-field-padding-right"),e&&["name","email","phone","location","date","time"].indexOf(e)>-1&&(this.addClass(a,"cp-chat-answer-field-with-icon"),this.addClass(a,"cp-chat-answer-field-icon-"+e)),e){case"date":o.type="date",o.removeAttribute("placeholder"),o.dataset.allowPastDates=t.allowPastDates?"1":"0";break;case"time":o.type="time",o.removeAttribute("placeholder");break;default:this.emoticonsInit(e),o.type="text",o.placeholder=this.getTranslation("enterText"),o.focus()}},this.answerFieldRemove=function(){this.removeClass(i,"cp-chat-with-reply"),this.removeClass(i,"cp-chat-with-reply-exit")},this.startPromptChat=function(e,t){void 0===t&&(t=!0);var n=this.getChatItemOptions(e);this.isPromptChatStarted=!0,this.addClass(i,"cp-chat-with-reply");var a=i.querySelector(".cp-chat-answer-field"),o=a.querySelector(".cp-text-field");a.className="cp-chat-answer-field",this.addClass(a,"cp-chat-answer-field-with-icon"),this.addClass(a,"cp-chat-answer-field-icon-text"),o.focus(),t&&(n.prompt&&(x?this.createTtsAudio(null,-1,"prompt"):this.createMessage(n.prompt,"question",!0)),this.buttonPromptChatToggle(n.buttonFinish,!0))},this.startBotChat=function(e){if(!this.isBotChatStarted){this.debugLog("START_BOT_CHAT"),this.isBotChatStarted=!0,void 0===v&&(v={});var t={name:v.name||"Stranger",bot_name:B.avatarName||"HumanPal",start:1};N.setCompletedStatus();var i=N.getTranslation("hello")+". "+N.getTranslation("myName").replace("[CUSTOMER_NAME]",t.name).trim(),a=N.getTranslation("chatGreeting").replace("[CUSTOMER_NAME]",t.name).trim();E=[],E.push({input:i,response:a});if(this.currentChatItem.options.skipAiWelcome||!1){this.answerFieldInit("text");var o=n.querySelector(".cp-chat-bubble:last-child");this.scrollIfNeeded(n,o)}else x?this.createTtsAudio(null,-1,"chatGreeting","",function(){N.answerFieldInit("text")}):(this.createMessage(a,"question"),this.answerFieldInit("text"))}},this.tellBot=function(e,t,i){void 0===t&&(t=!0),E||(E=[]),i=i||{};var n=this.getBaseUrl()+B.botConversationUrl;n+="/"+B.embedId,n+="?say=",B.autoTranslateChat&&B.customerLanguage&&(n+="&lang="+B.customerLanguage),Object.keys(i).forEach(function(e){n+="&"+e+"="+i[e]}),t&&N.createMessage(e,"answer",!0),this.typingAnimationToggle(!0),this.ajax(n,function(t){if(N.typingAnimationToggle(!1),t.response){if(t.audioUuid&&x){var i=x.getAudioUrl(t.audioUuid),n=t.audioViseme||null;x.setVisemeData(n),x.setAudioUrl(i,!0),N.onPlayStarted()}N.createMessage(t.response,"question",!0),E.push({input:N.cleanString(e),response:t.response})}N.answerFieldInit("text")},{say:N.cleanString(e),history:JSON.stringify(E)},"POST")},this.promptChatAnswersTrigger=function(e,t){if(0===this.promptChatAnswers.length)return t;var i,n="",a=[];return this.promptChatAnswers.forEach(function(t,o){i=t.keywords.toLowerCase().split(","),i=i.filter(function(e){return!!e}),i=i.map(function(e){return e.trim()}),i.forEach(function(i){new RegExp("(^|\\s)"+N.escapeRegExpString(i)+"($|\\s|,|\\.|!|\\?)","gmi").test(e)&&-1===a.indexOf(o)&&(a.push(o),n+=(n.length>0?"
    ":"")+t.response)})}),n||t},this.getChatItemOptions=function(e){return B.autoTranslateChat&&B.customerLanguage&&e.translations&&e.translations.options&&e.translations.options[B.customerLanguage]?e.translations.options[B.customerLanguage]:e.options},this.buttonPromptChatToggle=function(e,t){void 0===t&&(t=!0);var i=n.querySelector(".cp-chat-answer-block-prompt");if(!t)return void(i&&this.removeEl(i));if(!i){var a="
    ";a+='",a+="
    ",i=this.createElement("DIV",{className:"cp-chat-answer-block cp-chat-answer-block-prompt cp-mb-2",innerHTML:a}),this.append(n,i),this.colorsUpdate(["colorPrimaryButton","colorPrimaryButtonText"]),setTimeout(function(){N.scrollIfNeeded(n,i)},100),i.querySelector(".cp-btn").addEventListener("click",function(e){e.preventDefault(),N.isPromptChatStarted=!1,N.buttonPromptChatToggle(null,!1),N.sendAnswer(this.value)},!1)}},this.chatServiceMessageToggle=function(e,t){void 0===t&&(t=!0);var i=n.querySelector(".cp-chat-service-message");if(!t||!e)return void(i&&this.removeEl(i));i?i.innerHTML=e:(i=this.createElement("DIV",{className:"cp-chat-answer-block cp-chat-service-message cp-mb-2",innerHTML:e}),this.append(n,i),this.colorsUpdate(["colorPrimaryButton","colorPrimaryButtonText"])),setTimeout(function(){N.scrollIfNeeded(n,i)},1)},this.createMessage=function(e,t,i){t=t||"question",i=i||!1;var a=this.getIsSingleShortCode(e);i||(e=this.cleanString(e)),e=this.urlToHtmlAnchor(e),y&&(e=this.applyShortCodes(e)),N.chatServiceMessageToggle("");var o="",r="cp-chat-bubble";"question"===t?(r+=a?" cp-chat-bubble-single-smile":" cp-chat-bubble-primary",r+=" cp-chat-bubble-avatar cp-chat-bubble-left cp-animation cp-animation-scale-left",o+='
    ',o+='',o+='
    <%- message %>
    '):"answer"===t&&(r+=" cp-chat-bubble-right",o+='
    ',o+='
    <%- message %>
    '),o=o.replace("<%- message %>",e),o=o.replace("<%- avatarThumbnailImageUrl %>",B.avatarThumbnailImageUrl);var s=this.append(n,this.createElement("div",{innerHTML:o,className:r}));s.querySelector(".cp-chat-bubble-b img")&&(s.querySelector(".cp-chat-bubble-b img").addEventListener("load",function(){this.style.display="",s.querySelector(".cp-chat-bubble-b .cp-chat-spinner")&&(s.querySelector(".cp-chat-bubble-b .cp-chat-spinner").style.display="none"),N.scrollIfNeeded(n,s)}),s.querySelector(".cp-chat-bubble-b img").style.display="none"),s.querySelector(".cp-chat-bubble-b video")&&s.querySelector(".cp-chat-bubble-b video").addEventListener("loadedmetadata",function(){this.style.display="block",N.addClass(s,"cp-chat-bubble-full"),N.removeClass(s,"cp-chat-bubble-avatar"),s.querySelector(".cp-chat-bubble-b .cp-chat-spinner")&&(s.querySelector(".cp-chat-bubble-b .cp-chat-spinner").style.display="none"),N.scrollIfNeeded(n,s)}),s.querySelector(".cp-chat-bubble-b iframe")&&(N.addClass(s,"cp-chat-bubble-full"),N.removeClass(s,"cp-chat-bubble-avatar"),s.querySelector(".cp-chat-bubble-b .cp-chat-spinner")&&(s.querySelector(".cp-chat-bubble-b .cp-chat-spinner").style.display="none"),N.scrollIfNeeded(n,s)),this.colorsUpdate(["colorAvatarBubble","colorAvatarBubbleText","colorCustomerBubble","colorCustomerBubbleText"]),setTimeout(function(){var e=n.querySelectorAll(".cp-animation-scale-left:not(.cp-chat-typing-container)");e.length>0&&Array.prototype.forEach.call(e,function(e){N.addClass(e,"cp-animation-scale-left-do"),N.scrollIfNeeded(n,e)}),N.scrollIfNeeded(n,s)},40)},this.urlToHtmlAnchor=function(e){var t=/https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)/gi,i=/[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)?/gi,n=e.match(t),a=e.match(i);return n&&n.forEach(function(t,i){var n=new RegExp("(^|\\s)"+t+"(\\s|$)","gm");e=e.replace(n,' '+t+" ")}),a&&a.forEach(function(t,i){var n=new RegExp("(^|\\s)"+t+"(\\s|$)","gm"),a=t.indexOf("@")>-1?"mailto:":"https://",o=t.indexOf("@")>-1?"_self":"_blank";e=e.replace(n,' '+t+" ")}),e},this.addContentHtml=function(e,t,i){t=t||"cp-chat-bubble cp-chat-bubble-primary cp-chat-bubble-left cp-chat-bubble-full";var a=this.append(n,this.createElement("div",{innerHTML:e,className:t}));this.colorsUpdate(["colorAvatarBubble","colorAvatarBubbleText","colorCustomerBubble","colorCustomerBubbleText","colorPrimaryButton","colorPrimaryButtonText"]),N.scrollIfNeeded(n,a),setTimeout(function(){N.scrollIfNeeded(n,a)},40),"slider"===i&&this.sliderInit(a),"video"===i&&this.chatVideoInit(a)},this.chatVideoInit=function(e){new VideoPlayerApp({targetClassName:"videoplayerapp-element",autoPlay:!1,useIntersectionObserver:!1,skin:"lines",playImageUrl:"https://app.humanbot.io/img/play-circle.png",iconImageUrl:"https://app.humanbot.io/img/hand-pointer-dark.png",textPaused:"",textEnded:""})},this.sliderInit=function(e){var t=e.querySelector(".cp-chat-content-slider-b"),i=Array.from(e.querySelectorAll(".cp-chat-content-slider-nav-button")),n=Array.from(e.querySelectorAll(".cp-chat-content-slider-item")),a=0,o=!1,r=function(){0===a?i[0].classList.add("cp-btn-disabled"):i[0].classList.remove("cp-btn-disabled"),a===n.length-1?i[1].classList.add("cp-btn-disabled"):i[1].classList.remove("cp-btn-disabled"),t.classList.add("cp-chat-content-slider-move"),t.style.marginLeft=0-253*a+"px",o=!0,setTimeout(function(){t.classList.remove("cp-chat-content-slider-move"),o=!1},500)};i[1].addEventListener("click",function(){i[1].classList.contains("cp-btn-disabled")||o||(a++,r())}),i[0].addEventListener("click",function(){i[0].classList.contains("cp-btn-disabled")||o||(a--,r())});var s=null,l=null,u=function(e){s=e.touches?e.touches[0].clientX:e.clientX},c=function(e){if(null!==s){l=e.touches?e.touches[0].clientX:e.clientX;var i=s-l,n=253*a;t.style.marginLeft=0-(n+i)+"px",Math.abs(i)>3&&t.classList.add("cp-chat-content-slider-active")}},d=function(e){if(t.classList.remove("cp-chat-content-slider-active"),null===s||null===l)return s=null,void(l=null);var i=s-l;if(i<0&&0===a||i>0&&a===n.length-1)return s=null,l=null,void r();a+=i>0?1:-1,s=null,l=null,r()};t.addEventListener("touchstart",u,!1),t.addEventListener("mousedown",u,!1),t.addEventListener("touchmove",c,!1),t.addEventListener("mousemove",c,!1),t.addEventListener("touchend",d,!1),t.addEventListener("mouseup",d,!1),t.addEventListener("mouseleave",d,!1)},this.getIsSingleShortCode=function(e){return!!/^\[([^\]])+\]$/.test(e)&&!(["Avatar","Name","CountryDetected","Email","Phone","Date","Time","Location"].indexOf(e)>-1)},this.addExitMessage=function(){if(B.exitMessage&&!this.isExitMessageShown&&!this.isCompleted&&!B.isFacebookMessengerEnabled){var e=this.getCampaignTranslation("exitMessage");this.createMessage(''+e+"","question",!0),this.isExitMessageShown=!0,setTimeout(function(){Array.prototype.forEach.call(n.querySelectorAll(".cp-animation-shake"),function(e){N.removeClass(e,"cp-animation-shake")})},2500),this.getIsMinimized()&&this.minimizeToggle()}},this.getChatTranslations=function(e,t,i){return i=i||!1,i&&e.translations&&e.translations.options&&e.translations.options[B.customerLanguage]&&e.translations.options[B.customerLanguage][t]?e.translations.options[B.customerLanguage][t]:e.translations&&e.translations[t]&&e.translations[t][B.customerLanguage]?e.translations[t][B.customerLanguage]:i?e.options[t]||"":e[t]||""},this.getTranslation=function(e,t,i){return void 0===t&&(t=e),void 0===i&&(i=B.chatLanguage),B.autoTranslateChat&&D[B.customerLanguage]||D[i]?B.autoTranslateChat&&D[B.customerLanguage]?D[B.customerLanguage][e]:D[i][e]:D.en[e]||t},this.getChatCountryName=function(){return B.customerCountryName},this.getCampaignTranslation=function(e,t){this.debugLog("getCampaignTranslation",B.autoTranslateChat,e,B.customerLanguage),void 0===t&&(t=!0);var i=B[e]||"";return B.autoTranslateChat&&B.translations&&B.translations[e]&&B.translations[e][B.customerLanguage]&&(i=B.translations[e][B.customerLanguage]),t&&(i=this.applyShortCodes(i)),i},this.applyShortCodes=function(e){var t=this.extend({},y);return v&&Object.keys(v).length>0&&this.extend(t,v),Object.keys(t).forEach(function(i){var n=new RegExp("\\["+i+"\\]","ig");e=e.replace(n,t[i]||t[i.toLowerCase()]||"")}),["\\:\\)","\\;\\)","\\:D",";D","\\:\\(","\\^\\^","\\:P","\\;P","\\:S","\\:\\/","8\\)","\\$\\)","oO","\\:x","\\:666\\:","<3"].forEach(function(t,i){var n=new RegExp("(^|\\s)"+t+"(\\s|$)","gm");e=e.replace(n,' ')}),e},this.setCompletedStatus=function(){this.createCookie("completed"+B.embedId,1,7),this.isCompleted=!0},this.removeCompletedStatus=function(){this.deleteCookie("completed"+B.embedId),this.isCompleted=!1},this.getIsCompleted=function(e){return!!this.readCookie("completed"+B.embedId)&&(this.isCompleted=!0,!0)},this.extend=function(e,t){"object"!==(void 0===e?"undefined":r(e))&&(e={});for(var i in t)t.hasOwnProperty(i)&&(e[i]=t[i]);return e},this.drawVideo=function(e,t,i,n){if(e.paused||e.ended)return!1;t.drawImage(e,0,0,i,n,0,0,i,n),setTimeout(this.drawVideo.bind(this),20,e,t,i,n)},this.startDrawVideoWithAlpha=function(){N.drawVideoWithAlpha(),N.onPlaying(),N.isPlayFinished||window.requestAnimationFrame(N.startDrawVideoWithAlpha)},this.drawVideoWithAlpha=function(e){if(e=e||!1,void 0!==a.src&&!(a.readyState<=2)&&0!==a.videoWidth&&0!==a.videoHeight){var t;try{u.drawImage(a,0,0,B.width,2*B.height)}catch(e){return void console.error(e)}try{t=u.getImageData(0,0,B.width,B.height)}catch(e){return void console.error(e)}for(var i=t.data,n=u.getImageData(0,B.height,B.width,B.height).data,o=[B.width,0],r=3,s=i.length;r10&&(cB.width/2&&c>o[1]&&(o[1]=c))}i[r]=n[r-1]}l.putImageData(t,0,-2,0,1,B.width,B.height),e&&(f=o[0]+(o[1]-o[0])/2)}},this.setAbandoned=function(){if(!this.isCompleted){var e=[this.getBaseUrl(),"conversation/pub/abandoned/",B.embedId].join("");this.ajax(e,function(e){e&&e.success&&N.setCompletedStatus()},{},"POST")}},this.onMinimize=function(){if(!this.isChatStarted||this.isChatAnswered||this.isCompleted||this.setAbandoned(),B.player.autoPlayAttentionGrabber&&N.addClass(i,"cp-animation-shake"),this.getIsLiveChatEnabled()&&B.liveChatInvitationMessage){var e=i.querySelector(".cp-chat-header"),t=this.createElement("div",{className:"cp-chat-invitation-message",innerHTML:B.liveChatInvitationMessage});this.append(e,t),setTimeout(function(){N.addClass(i,"cp-chat-online-status-onhover")},3500)}x&&x.pauseAudio(),this.blackoutHideToggle(!0),B.isFacebookMessengerEnabled&&window.FB},this.onStartPlay=function(){this.onPlayStarted(),this.chatInit()},this.onPlayStarted=function(){if(this.isPlayStarted=x?!x.isAudioMuted():!a.muted,this.isPlayFinished=!1,this.debugLog("PLAY_STARTED",this.isPlayStarted),this.isPlayStarted&&B.player.playOnce&&window.sessionStorage.setItem("isPlayedOnce","1"),this.isPlayStarted){var e=i.querySelector(".cp-chat-avatar-container");this.removeClass(e,"cp-chat-muted")}},this.onPlaying=function(){},this.onPlayingEnd=function(e){clearInterval(void 0),clearTimeout(void 0),setTimeout(function(){N.drawVideoWithAlpha()},50),this.isPlayFinished=!0,"avatar"===B.type&&B.player.videoUrl?this.avatarReplaceToVideo(B.player.videoUrl):e&&(this.avatarVideoClose(),B.player.blackoutMode&&"avatar"===B.type&&(this.blackoutHideToggle(!0),i.style.display="none")),this.chatInit(),setTimeout(function(){N.callToActionInit()},100)},this.onWindowUnload=function(e){this.isInitialized&&(N.debugLog("ON WINDOW UNLOAD",N.isLiveChatStarted,e),N.isLiveChatStarted&&N.xmppConnectionStatus===Strophe.Status.CONNECTED&&N.liveChatExit())},this.avatarReplaceToVideo=function(e){if(e){var t,n=i.querySelector(".cp-chat-avatar-container"),a=n.querySelector(".cp-chat-video-player-container"),r=this.getYoutubeVideoId(e)?"youtube":"vimeo";if(this.removeEl(o),this.removeEl(s),this.addClass(i,"cp-chat-video-player"),B.player.position,B.isPlayerApiInitialized)switch(r){case"youtube":t=this.getYoutubeVideoId(e),g=new YT.Player(a,{width:B.videoIframeWidth,height:B.videoIframeHeight,videoId:t,playerVars:{autoplay:1,showinfo:0,rel:0},events:{onStateChange:function(e){e.data===YT.PlayerState.ENDED&&N.onExternalVideoEnded()}}});break;case"vimeo":t=this.getVimeoVideoId(e),g=new Vimeo.Player(a,{width:B.videoIframeWidth,height:B.videoIframeHeight,id:t,autoplay:!0}),g.on("ended",function(){N.onExternalVideoEnded()})}}},this.getVideoCode=function(e,t,i,n){t=t||"100%",i=i||"160",n=n||!1;var a,o="",r="";return N.getYoutubeVideoId(e)?(a=N.getYoutubeVideoId(e),r="https://www.youtube-nocookie.com/embed/"+a+"?showinfo=0"):N.getVimeoVideoId(e)&&(a=N.getVimeoVideoId(e),r="https://player.vimeo.com/video/"+a+"?title=0&byline=0&portrait=0"),r&&(n&&(r+="&autoplay=1"),o=''},this.demoModeInit=function(){s.disableSeek=!0,document.querySelectorAll("."+s.targetClassName).forEach(function(e){if(e.innerHTML="",s.posterUrl){var i=t.createElement("img",{src:s.posterUrl,id:"poster-"+t.generateUniqueString()},{position:"absolute",width:"100%",height:"100%",display:"block",left:"0",top:"0"});e.appendChild(i)}t.addOverlay(e),t.watermarkInit(e),t.fullScreenButtonInit(e),s.autoPlay||(t.progressBarInit(e),t.onPause(e));var n=e.querySelector(".video-autoplay-progress-line");n&&(n.style.width="30%")}),window.addEventListener("resize",this.onResize.bind(this)),setTimeout(this.onResize.bind(this),1)},this.onIframeLoad=function(e){if(e.getAttribute("src")){var t=e.id,i=this.getPlayerType(t);this.debugLog("[IFRAME_LOADED]",t,i,e.className),this.playersInit([t],i)}},this.getPlayerType=function(e,t,i){return e?e.dataset.vimeoId?"vimeo":e.dataset.videoUrl?"htmlvideo":"youtube":i?this.isHtmlPlayer(i)?"htmlvideo":this.isPlayerYouTube(i)?"youtube":"vimeo":0===t.indexOf("vimeo-")?"vimeo":0===t.indexOf("htmlvideo-")?"htmlvideo":"youtube"},this.playersInit=function(e,i){if(0!==e.length&&!(this.device.isMobileFirefox&&s.regularPlayerForMobileFirefox||"opera-touch"===t.device.browser)){if(t.debugLog("[PLAYERS_INIT] iframesIds: "+e.join(",")+" type: "+i),!("youtube"!==i||window.YT&&window.YT.loaded))return void t.debugLog("[IFRAME_ID] "+e.join(",")+" type: "+i+" - ERROR - YT JS not loaded");e.forEach(function(e){window.vpaPlayers[e]||t.createPlayer(e,i)})}},this.createPlayer=function(e,i){if(e&&window.vpaPlayers[e])return null;var n,a;if(!e&&i)if(e=this.prepareParentEl(i),0===e.indexOf("yt-")){var o=document.createElement("div");o.setAttribute("id",e),i.appendChild(o)}else i.setAttribute("id","player-"+e);else a=document.getElementById(e),i=a.parentNode;var r=this.getPlayerType(null,e);if(this.debugLog("[PLAYER_CREATE] "+e+" type: "+r),"htmlvideo"===r){var l=i.querySelector("video");if(!l){var u=this.getIframeHtml(i);i.innerHTML=u,l=i.querySelector("video"),e=l.getAttribute("id")}l.style.width="100%",l.style.height="100%",n=l,n.addEventListener("ended",function(){s.loop?(n.currentTime=0,n.play()):t.onStateChange(document.getElementById(e).parentNode,n,"ended")}),n.addEventListener("play",function(){t.onStateChange(document.getElementById(e).parentNode,n,"play")}),n.addEventListener("pause",function(){t.onStateChange(document.getElementById(e).parentNode,n,"pause")}),this.addOverlay(l.parentNode,n),this.overlayElementsInit(document.getElementById(e).parentNode,n)}else if("vimeo"===r){if(!document.getElementById(e)){var u=this.getIframeHtml(i);i.innerHTML=u}if(!window.Vimeo)return this.debugLog("[VIMEO_PLAYER_ERROR] JS not loaded"),null;var c=i.dataset.vimeoId||i.dataset.vimeoVideoId,d=i.dataset.vimeoPrivateId;n=new Vimeo.Player(i.querySelector("iframe"),{id:d?"":c,url:d?"https://player.vimeo.com/video/"+c+"?h="+d:"",autoplay:!(!parseInt(i.dataset.autoplay||"0")&&!s.autoPlay),controls:!!parseInt(i.dataset.controls||"0"),muted:s.startMuted,transparent:!1}),n.ready().then(function(){t.debugLog("[VIMEO_PLAYER] onReady"),window.vpaPlayers[e]=n,n.element.setAttribute("id",e),n.element.style.width="100%",n.element.style.height="100%",n.element.style.pointerEvents="none",t.addOverlay(document.getElementById(e).parentNode,n),t.overlayElementsInit(document.getElementById(e).parentNode,n)}),n.on("ended",function(){s.loop?(n.setCurrentTime(0),n.play()):t.onStateChange(document.getElementById(e).parentNode,n,"ended")}),n.on("play",function(){t.onStateChange(document.getElementById(e).parentNode,n,"play")}),n.on("pause",function(){t.onStateChange(document.getElementById(e).parentNode,n,"pause")})}else if("youtube"===r){if(!document.getElementById(e))return void this.debugLog("[IFRAME_ID] "+e+" type: "+r+" - element not found");if(!window.YT||!window.YT.loaded)return void this.debugLog("[YOUTUBE_PLAYER_ERROR] JS not loaded");n=new YT.Player(e,{videoId:i.dataset.youtubeId,height:"100%",width:"100%",playerVars:{id:e,origin:window.location.origin,rel:"0",controls:i.dataset.controls?"1":"0",autoplay:parseInt(i.dataset.autoplay||"0")||s.autoPlay?"1":"0",loop:i.dataset.loop||s.loop?"1":"0",muted:s.startMuted},events:{onReady:function(o){t.debugLog("[YOUTUBE_PLAYER] onReady",e),window.vpaPlayers[e]=n,a=document.getElementById(e),a.style.position="absolute",a.style.left="0",a.style.top="0",a.style.width="100%",a.style.height="100%",a.style.pointerEvents="none",t.getIsMuted(n,function(a){t.debugLog("[YOUTUBE_PLAYER] onReady - IS MUTED?",e,a),i.dataset.muted&&!a&&(t.debugLog("[YOUTUBE_PLAYER] onReady MUTE",e),n.mute())}),t.addOverlay(a.parentNode,n),t.overlayElementsInit(document.getElementById(e).parentNode,n)},onStateChange:function(i){if(t.debugLog("[YOUTUBE_PLAYER] onStateChange",i.data,i.data===YT.PlayerState.PLAYING?"PLAYING":"NOT_PLAYING",e),i.data===YT.PlayerState.ENDED&&s.loop)return n.seekTo(0),void n.playVideo();t.onStateChange(document.getElementById(e).parentNode,i.target,i.data)},onError:function(e){t.debugLog("[ERROR_YOUTUBE]",e)}}})}return n},this.addOverlay=function(e,i){var n=!(!parseInt(e.dataset.autoplay||"0")&&!s.autoPlay),a="
    "+this.sanitizeString(s.unmuteText)+"
    ";s.lottieFileUrl?a+='
    ':s.iconImageUrl&&(a+='
    '),a+="
    "+this.sanitizeString(s.unmuteTextSecondary)+"
    ";var o=t.createElement("div",{className:"video-autoplay-overlay"+(s.skin?" video-autoplay-overlay-"+s.skin:""),innerHTML:'
    '+a+"
    "},s.skin?{}:{position:"absolute",left:"0",top:"0",width:"100%",height:"100%",display:"block",boxSizing:"border-box",backgroundColor:s.unmuteBackgroundColor,color:s.unmuteTextColor,textAlign:"center",fontFamily:"sans-serif",fontSize:"20px",lineHeight:"1.4",padding:"0",cursor:"pointer"});s.unmuteTextColor&&(o.style.color=s.unmuteTextColor),e.appendChild(o),e.classList.add("video-autoplay-overlay-image-active"),n&&(s.autoPlayShakeAnimation&&o.querySelector(".video-autoplay-overlay-image").classList.add("video-autoplay-animation-shake"),this.lottePlayerInit(o),this.overlaySetSize(e.offsetHeight,o)),i&&o.addEventListener("click",function(n){n.preventDefault();var a=!e.querySelector(".video-autoplay-overlay-image");o.style.backgroundColor="transparent",e.querySelector(".video-autoplay-overlay-image")&&t.removeEl(e.querySelector(".video-autoplay-overlay-image")),e.classList.remove("video-autoplay-overlay-image-active"),t.playingId=null;var r=t.getClicks(e);if(t.increaseClick(e),t.debugLog("[CLICKS] "+r),a)t.playToggle(e,i);else{var s=t.getPlayerType(null,null,i);"htmlvideo"===s?(i.pause(),i.currentTime=0,i.volume=1,i.play()):"youtube"===s?(i.pauseVideo(),i.seekTo(0),i.unMute(),i.setVolume(100),i.playVideo(),setTimeout(function(){i.getPlayerState()!==YT.PlayerState.PLAYING&&i.playVideo()},200)):(i.pause(),i.setCurrentTime(0),i.setVolume(1),i.play(),setTimeout(function(){i.getPaused().then(function(e){e&&i.play()})},200))}})},this.overlayElementsInit=function(e,i){var n=!(!parseInt(e.dataset.autoplay||"0")&&!s.autoPlay);e.dataset.muted;n&&!this.playingId&&!this.device.isMobileFirefox&&this.isPlayerYouTube(i)?setTimeout(function(){i.getPlayerState()!==YT.PlayerState.PLAYING?(i.mute(),i.playVideo(),t.debugLog("[START_AUTOPLAY]",t.getElementVideoIframeId(e))):(!i.isMuted()||i.getVolume()>0)&&e.querySelector(".video-autoplay-overlay")&&!s.skin&&(e.querySelector(".video-autoplay-overlay").style.backgroundColor="transparent")},1500):t.isHtmlPlayer(i)?i.paused&&t.onPause(e,i):t.isPlayerYouTube(i)?i.getPlayerState()!==YT.PlayerState.PLAYING&&t.onPause(e,i):i.getPaused().then(function(n){n&&t.onPause(e,i)}),this.volumeInputInit(e,i),this.watermarkInit(e,i),this.fullScreenButtonInit(e,i)},this.playToggle=function(e,t){var i=this.getPlayerType(null,null,t);this.debugLog("[PLAY_TOGGLE]",i),"htmlvideo"===i?t.paused?t.play():t.pause():"youtube"===i?t.getPlayerState()!==YT.PlayerState.PLAYING?t.playVideo():t.pauseVideo():t.getPaused().then(function(e){e?t.play():t.pause()})},this.updateProgress=function(e,i,n){void 0===n&&(n=!0);var a=e.querySelector(".video-autoplay-progress-line");if(a){var o,r,s,l=this.getPlayerType(null,null,i);"htmlvideo"===l?(o=i.duration,r=i.currentTime,s=i.currentTime==i.duration?100:Math.round(100/(o/r)),a.style.width=s+"%",clearTimeout(t.timers[t.getTimerKey(e,i,"progress-")]),n&&(t.timers[t.getTimerKey(e,i,"progress-")]=setTimeout(function(){t.updateProgress(e,i)},200))):"youtube"===l?(o=i.getDuration(),r=i.getCurrentTime(),s=i.getPlayerState()===YT.PlayerState.ENDED?100:Math.round(100/(o/r)),a.style.width=s+"%",clearTimeout(t.timers[t.getTimerKey(e,i,"progress-")]),n&&(t.timers[t.getTimerKey(e,i,"progress-")]=setTimeout(function(){t.updateProgress(e,i)},200))):i.getCurrentTime().then(function(o){i.getDuration().then(function(r){s=Math.round(100/(r/o)),a.style.width=s+"%",clearTimeout(t.timers[t.getTimerKey(e,i,"progress-")]),n&&(t.timers[t.getTimerKey(e,i,"progress-")]=setTimeout(function(){t.updateProgress(e,i)},200))})})}},this.progressBarInit=function(e,i){var n=t.getPlayerType(null,null,i);this.debugLog("[PROGRESS_BAR_INIT]",n);var a=e.querySelector(".video-autoplay-overlay");if(a){if(!a.querySelector(".video-autoplay-progress-line")){var r=s.skin?'style="background-color: '+s.colorProgressBarTotal+';"':' style="height: 10px; width: 100%; background-color: '+s.colorProgressBarTotal+';"',l=s.skin?'style="background-color: '+s.colorProgressBar+';"':'style="height: 10px; width: 0%; pointer-events: none; background-color: '+s.colorProgressBar+';"',u=this.createElement("div",{className:o,innerHTML:'
    "},s.skin?{}:{position:"absolute",left:0,bottom:0,width:"100%",height:"10px",color:"#fff",fontSize:"20px",boxSizing:"border-box"});u.style.backgroundColor=s.colorBars,a.appendChild(u),s.disableSeek||a.querySelector(".video-autoplay-progress").addEventListener("click",function(a){a.preventDefault(),a.stopPropagation();var o=a.target.getBoundingClientRect(),r=o.width,s=a.clientX-o.left,l=100/(r/s);if("htmlvideo"===n){var u=i.duration,c=u/(100/l);i.currentTime=c,setTimeout(function(){t.updateProgress(e,i,!1)},200)}else if("youtube"===n){var u=i.getDuration(),c=u/(100/l);i.seekTo(c),setTimeout(function(){t.updateProgress(e,i,!1)},200)}else i.getDuration().then(function(n){var a=n/(100/l);i.setCurrentTime(a),setTimeout(function(){t.updateProgress(e,i,!1)},200)})})}i&&("htmlvideo"===n?(t.debugLog("[VIDEO_PLAYER] progressBarInit - paused?",i.paused),i.paused||e.querySelector(".video-autoplay-overlay-image")||this.updateProgress(e,i)):"youtube"===n?(t.debugLog("[YOUTUBE_PLAYER] progressBarInit - paused?",i.getPlayerState()!==YT.PlayerState.PLAYING),i.getPlayerState()!==YT.PlayerState.PLAYING||e.querySelector(".video-autoplay-overlay-image")||this.updateProgress(e,i)):i.getPaused().then(function(n){t.debugLog("[VIMEO_PLAYER] progressBarInit - paused?",n),n||e.querySelector(".video-autoplay-overlay-image")||t.updateProgress(e,i)}))}},this.colorsUpdate=function(){var e,t=document.querySelectorAll("."+s.targetClassName);t.forEach(function(t){e=t.querySelector(".video-autoplay-overlay"),e.querySelector(".video-autoplay-progress")&&(e.querySelector(".video-autoplay-progress").style.backgroundColor=s.colorProgressBarTotal,e.querySelector(".video-autoplay-progress-line").style.backgroundColor=s.colorProgressBar),e.querySelector("."+r)&&(e.querySelector("."+r).style.backgroundColor=s.colorPlayButton,e.querySelector("."+a).style.backgroundColor=s.colorBars,e.querySelector("."+o).style.backgroundColor=s.colorBars)})},this.onStateChange=function(e,t,i){this.isPlayerYouTube(t)?i===YT.PlayerState.PLAYING?this.onPlay(e,t):i===YT.PlayerState.PAUSED?this.onPause(e,t):i===YT.PlayerState.ENDED&&(this.debugLog("[ENDED]"),this.playingId=null,e.querySelector(".video-autoplay-overlay-image")&&this.removeEl(e.querySelector(".video-autoplay-overlay-image")),this.onPause(e,t,s.textEnded),this.updateProgress(e,t,!1)):"play"===i?this.onPlay(e,t):"pause"===i?this.onPause(e,t):"ended"===i&&(this.debugLog("[ENDED]"),this.playingId=null,e.querySelector(".video-autoplay-overlay-image")&&this.removeEl(e.querySelector(".video-autoplay-overlay-image")),this.onPause(e,t,s.textEnded),this.updateProgress(e,t,!1))},this.onPlay=function(e,i){var n=this.getPlayerType(null,null,i);this.debugLog("[ON_PLAY]",n),s.pauseOthersWhenPlaying&&this.getIsMuted(i,function(i){t.debugLog("[ON_PLAY] IS MUTED?",i),i||(t.playingId=t.getElementVideoIframeId(e),t.pauseOthers())});var l=function(){e.querySelector(".video-autoplay-overlay-image")&&t.removeEl(e.querySelector(".video-autoplay-overlay-image")),e.querySelector(".video-autoplay-overlay")&&(e.querySelector(".video-autoplay-overlay").style.backgroundColor="transparent"),clearTimeout(t.timers[t.getTimerKey(e,i,"play-")]),t.timers[t.getTimerKey(e,i,"play-")]=setTimeout(function(){e.classList.remove("video-autoplay-paused"),s.skin||(e.querySelector("."+a)&&(e.querySelector("."+a).style.display="none"),e.querySelector("."+r)&&(e.querySelector("."+r).style.display="none"),e.querySelector("."+o)&&(e.querySelector("."+o).style.display="block",e.querySelector("."+o).style.height="10px")),t.watermarkInit(e,i),t.fullScreenButtonInit(e,i),t.volumeButtonInit(e,i)},500),t.progressBarInit(e,i)},u=function(){clearTimeout(t.timers[t.getTimerKey(e,i,"play-")]),t.timers[t.getTimerKey(e,i,"play-")]=setTimeout(function(){e.querySelector("."+a)&&(e.querySelector("."+a).style.display="none"),e.querySelector("."+r)&&(e.querySelector("."+r).style.display="none"),e.querySelector("."+o)&&(e.querySelector("."+o).style.display="none"),t.watermarkInit(e,i),t.fullScreenButtonInit(e,i),t.volumeButtonInit(e,i)},500)};if("htmlvideo"===n)i.volume>0?l():u();else if("youtube"===n){var c=this.getClicks(e);this.increaseClick(e),t.debugLog("[YOUTUBE_MUTED_VOLUME]",i.isMuted(),i.getVolume(),c),!i.isMuted()&&i.getVolume()>0||c>0?l():u()}else i.getVolume().then(function(e){t.debugLog("[VIMEO_VOLUME]",e),e>0?l():u()})},this.onPause=function(e,i,n){var l=this.getPlayerType(null,null,i);this.debugLog("[ON_PAUSE]",l);var u=t.getClicks(e);if(this.increaseClick(e),0===u&&this.getIsAutoplay(e))return this.debugLog("[ON_PAUSE_PLAY_AGAIN]",l),t.mute(e,i),void t.playToggle(e,i);e.classList.add("video-autoplay-paused"),clearTimeout(t.timers[t.getTimerKey(e,i,"play-")]),clearTimeout(t.timers[t.getTimerKey(e,i,"progress-")]),void 0===n&&(n=s.textPaused),this.progressBarInit(e,i);var c=e.querySelector(".video-autoplay-overlay");if(c){if(e.querySelector(".video-autoplay-overlay-image")&&t.removeEl(e.querySelector(".video-autoplay-overlay-image")),c.querySelector("."+a))s.skin||(c.querySelector("."+a).textContent=n,c.querySelector("."+a).style.display="block",c.querySelector("."+r).style.display="block");else{var d=this.createElement("div",{className:a,textContent:n},s.skin?{}:{position:"absolute",left:0,top:0,width:"100%",height:"60px",padding:"0 30px",textAlign:"left",backgroundColor:s.colorBars,color:"#fff",fontSize:"20px",lineHeight:"60px",boxSizing:"border-box",pointerEvents:"none"});c.appendChild(d);var h=c.offsetHeight>250?120:80,p=this.createElement("div",{className:r},s.skin?{}:{position:"absolute",left:"50%",top:"50%",width:h+"px",height:h+"px",margin:"-"+h/2+"px 0 0 -"+h/2+"px",background:'url("'+s.defaultPlayImageUrl+'") no-repeat 50% 50% '+s.colorPlayButton,color:"#fff",boxSizing:"border-box",borderRadius:"50%",pointerEvents:"none",boxShadow:"0 0 15px rgba(0,0,0,0.2)"});s.playImageUrl&&this.css(p,{background:'url("'+s.playImageUrl+'") no-repeat 50% 50% '+s.colorPlayButton}),p.style.backgroundColor=s.colorPlayButton,c.appendChild(p)}s.skin||c.querySelector("."+o)&&(c.querySelector("."+o).style.height="60px"),this.watermarkInit(e,i),t.fullScreenButtonInit(e,i),t.volumeButtonInit(e,i)}},this.pauseOthers=function(){this.playingId&&(t.debugLog("[PAUSE_OTHERS] playing: ",this.playingId),Object.keys(window.vpaPlayers).forEach(function(e){if(e!==t.playingId){var i=window.vpaPlayers[e];if(i){var n=document.getElementById(e).parentNode;clearTimeout(t.timers[t.getTimerKey(n,i,"pause-others-")]),t.timers[t.getTimerKey(n,i,"pause-others-")]=setTimeout(function(){t.getIsMuted(i,function(n){t.debugLog("[PAUSE_OTHERS] IS MUTED?",e,n),n||(t.isPlayerYouTube(i)?i.getPlayerState&&i.getPlayerState()===YT.PlayerState.PLAYING&&i.pauseVideo():i.getPaused().then(function(e){e||i.pause()}))}),t.debugLog("[PAUSE_OTHERS] video paused:",e),t.watermarkInit(n,i),t.fullScreenButtonInit(n,i),t.volumeButtonInit(n,i)})}}}))},this.getVideoTypes=function(){var e=document.querySelectorAll("."+s.targetClassName),t=[];return e.forEach(function(e){(!s.allow||s.allow.indexOf("youtube")>-1&&e.dataset.youtubeId)&&t.push("youtube"),(!s.allow||s.allow.indexOf("vimeo")>-1&&(e.dataset.vimeoId||e.dataset.vimeoVideoId))&&t.push("vimeo"),(!s.allow||s.allow.indexOf("htmlvideo")>-1&&e.dataset.videoUrl)&&t.push("htmlvideo")}),t},this.thirdPartyScriptsLoad=function(e){var a=this.getVideoTypes("youtube");this.debugLog("[THIRDPARTY_SCRIPTS_LOAD]",a);var o=0;return a.indexOf("youtube")>-1&&!i&&(!window.YT||window.YT&&!window.YT.loaded)?this.loadScript(s.youtubeScriptUrl,function(){window.onYouTubeIframeAPIReady=function(){t.debugLog("[YOUTUBE_PLAYER] READY"),o++,i=!0,2===o&&e()}}):o++,a.indexOf("vimeo")>-1&&!n&&!window.Vimeo?this.loadScript(s.vimeoScriptUrl,function(){o++,n=!0,2===o&&e()}):o++,2===o},this.isHtmlPlayer=function(e){return e instanceof HTMLVideoElement},this.isPlayerYouTube=function(e){return!(!e||e instanceof HTMLVideoElement)&&!!(window.YT&&e instanceof YT.Player)},this.getClicks=function(e){e.dataset.clicks||(e.dataset.clicks="0");var t=e.dataset.clicks;return parseInt(t,10)},this.increaseClick=function(e){var t=this.getClicks(e);e.dataset.clicks=String(++t)},this.getIsAutoplay=function(e){return e.dataset.autoplay?!!parseInt(e.dataset.autoplay,10):s.autoPlay},this.createElement=function(e,t,i){var n=document.createElement(e);return t&&Object.keys(t).forEach(function(e){null!==t[e]&&(["className","innerHTML","outerHTML","innerText","textContent"].indexOf(e)>-1?n[e]=t[e]:n.setAttribute(e,t[e]))}),this.css(n,i),n},this.css=function(e,t){e&&t&&Object.keys(t).forEach(function(i){e.style[i]=t[i]})},this.removeEl=function(e){e.parentNode.removeChild(e)},this.getIsAutoPlayAvailable=function(e,i){if(this.debugLog("[CALL-isAutoPlayAvailable]"),this.device.isMobile)return void e();var n=this.createElement("video",{src:"data:video/mp4;base64,AAAAIGZ0eXBpc29tAAACAGlzb21pc28yYXZjMW1wNDEAAAAIZnJlZQAAAs1tZGF0AAACrgYF//+q3EXpvebZSLeWLNgg2SPu73gyNjQgLSBjb3JlIDE0OCByMjYwMSBhMGNkN2QzIC0gSC4yNjQvTVBFRy00IEFWQyBjb2RlYyAtIENvcHlsZWZ0IDIwMDMtMjAxNSAtIGh0dHA6Ly93d3cudmlkZW9sYW4ub3JnL3gyNjQuaHRtbCAtIG9wdGlvbnM6IGNhYmFjPTEgcmVmPTMgZGVibG9jaz0xOjA6MCBhbmFseXNlPTB4MzoweDExMyBtZT1oZXggc3VibWU9NyBwc3k9MSBwc3lfcmQ9MS4wMDowLjAwIG1peGVkX3JlZj0xIG1lX3JhbmdlPTE2IGNocm9tYV9tZT0xIHRyZWxsaXM9MSA4eDhkY3Q9MSBjcW09MCBkZWFkem9uZT0yMSwxMSBmYXN0X3Bza2lwPTEgY2hyb21hX3FwX29mZnNldD0tMiB0aHJlYWRzPTEgbG9va2FoZWFkX3RocmVhZHM9MSBzbGljZWRfdGhyZWFkcz0wIG5yPTAgZGVjaW1hdGU9MSBpbnRlcmxhY2VkPTAgYmx1cmF5X2NvbXBhdD0wIGNvbnN0cmFpbmVkX2ludHJhPTAgYmZyYW1lcz0zIGJfcHlyYW1pZD0yIGJfYWRhcHQ9MSBiX2JpYXM9MCBkaXJlY3Q9MSB3ZWlnaHRiPTEgb3Blbl9nb3A9MCB3ZWlnaHRwPTIga2V5aW50PTI1MCBrZXlpbnRfbWluPTEwIHNjZW5lY3V0PTQwIGludHJhX3JlZnJlc2g9MCByY19sb29rYWhlYWQ9NDAgcmM9Y3JmIG1idHJlZT0xIGNyZj0yMy4wIHFjb21wPTAuNjAgcXBtaW49MCBxcG1heD02OSBxcHN0ZXA9NCBpcF9yYXRpbz0xLjQwIGFxPTE6MS4wMACAAAAAD2WIhAA3//728P4FNjuZQQAAAu5tb292AAAAbG12aGQAAAAAAAAAAAAAAAAAAAPoAAAAZAABAAABAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACAAACGHRyYWsAAABcdGtoZAAAAAMAAAAAAAAAAAAAAAEAAAAAAAAAZAAAAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAEAAAAAAAgAAAAIAAAAAACRlZHRzAAAAHGVsc3QAAAAAAAAAAQAAAGQAAAAAAAEAAAAAAZBtZGlhAAAAIG1kaGQAAAAAAAAAAAAAAAAAACgAAAAEAFXEAAAAAAAtaGRscgAAAAAAAAAAdmlkZQAAAAAAAAAAAAAAAFZpZGVvSGFuZGxlcgAAAAE7bWluZgAAABR2bWhkAAAAAQAAAAAAAAAAAAAAJGRpbmYAAAAcZHJlZgAAAAAAAAABAAAADHVybCAAAAABAAAA+3N0YmwAAACXc3RzZAAAAAAAAAABAAAAh2F2YzEAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAgACAEgAAABIAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAY//8AAAAxYXZjQwFkAAr/4QAYZ2QACqzZX4iIhAAAAwAEAAADAFA8SJZYAQAGaOvjyyLAAAAAGHN0dHMAAAAAAAAAAQAAAAEAAAQAAAAAHHN0c2MAAAAAAAAAAQAAAAEAAAABAAAAAQAAABRzdHN6AAAAAAAAAsUAAAABAAAAFHN0Y28AAAAAAAAAAQAAADAAAABidWR0YQAAAFptZXRhAAAAAAAAACFoZGxyAAAAAAAAAABtZGlyYXBwbAAAAAAAAAAAAAAAAC1pbHN0AAAAJal0b28AAAAdZGF0YQAAAAEAAAAATGF2ZjU2LjQwLjEwMQ==",width:"200",height:"100",id:"cp-test-video"},{opacity:"0.01",position:"fixed",right:0,bottom:0,pointerEvents:"none"}),a=function(e){t.debugLog("[VIDEO CHECK AUTOPLAY] FAIL",e&&e.message?e.message:"ERROR"),t.removeEl(document.getElementById("cp-test-video")),i()};document.body.appendChild(n);var o="";try{t.debugLog("[INSIDE_TRY]"),setTimeout(function(){t.debugLog("[TIMEOUT]",o),o||a()},1e3),n.play().then(function(){t.debugLog("[VIDEO CHECK AUTOPLAY] SUCCESS"),t.removeEl(document.getElementById("cp-test-video")),o="resolved",e()}).catch(function(e){o="rejected",a(e)}).finally(function(e){t.debugLog("[PLAY_PROMISE_FINALLY]",e,o)})}catch(e){t.debugLog("[PLAY PROMISE ERROR]"),o="rejected",a(e)}finally{t.debugLog("[TRY_FINALLY]",o)}this.debugLog("[AFTER-isAutoPlayAvailable]")},this.createAnimationStyleSheet=function(){var e=document.createElement("style");e.setAttribute("type","text/css"),document.querySelector("head").appendChild(e);e.appendChild(document.createTextNode(".video-autoplay-animation-shake { display: block; animation: shake 1.5s; animation-iteration-count: infinite; }\n@keyframes shake {\n 0% { transform: translate(1px, 1px) rotate(0deg); }\n 10% { transform: translate(-2px, -3px) rotate(-2deg); }\n 20% { transform: translate(-4px, 0px) rotate(2deg); }\n 30% { transform: translate(4px, 2px) rotate(0deg); }\n 40% { transform: translate(2px, -2px) rotate(2deg); }\n 50% { transform: translate(-2px, 3px) rotate(-2deg); }\n 60% { transform: translate(-4px, 2px) rotate(0deg); }\n 70% { transform: translate(4px, 2px) rotate(-2deg); }\n 80% { transform: translate(-2px, -2px) rotate(2deg); }\n 90% { transform: translate(2px, 3px) rotate(0deg); }\n 100% { transform: translate(2px, 2px) rotate(-2deg); }\n}"))},this.getElementVideoIframeId=function(e){return e.querySelector("video")?e.querySelector("video").id:e.querySelector("iframe")?e.querySelector("iframe").id:e.querySelector("img").id},this.getTimerKey=function(e,t,i){var n=this.getElementVideoIframeId(e);return this.timers[i+n]||(this.timers[i+n]=null),i+n},this.deviceDetectInit=function(){var e=window.navigator.userAgent.toLowerCase(),i=window.navigator.platform;if(this.device.isAndroid=e.indexOf("android")>-1,this.device.isIOS=/iP(hone|od|ad)/.test(i),this.device.isMobile=/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(e),this.device.isEdge=!(-1===navigator.userAgent.indexOf("Edge")||!navigator.msSaveOrOpenBlob&&!navigator.msSaveBlob),this.device.browser="",this.device.version=0,this.device.isAutoPlayAvailable=!this.device.isMobile,e.indexOf("firefox")>-1)this.device.browser="firefox";else if(-1!==e.indexOf(" opt/"))this.device.browser="opera-touch";else if(e.indexOf("chrome")>-1||e.indexOf("crios")>-1)this.device.browser="chrome",this.device.isAutoPlayAvailable=!1;else if(-1!==e.indexOf("safari")){this.device.browser="safari";var n=/version\/(\d+)/.exec(e);this.device.version=n.length>=1?parseInt(n[1]):0,"safari"===this.device.browser&&11===this.device.version&&(this.device.isAutoPlayAvailable=!1)}this.device.isMobileFirefox=!(!t.device.isMobile||"firefox"!==t.device.browser)},this.onResize=function(){document.querySelectorAll("."+s.targetClassName).forEach(function(e){if(e.querySelector(".video-autoplay-overlay")){var i=e.querySelector(".video-autoplay-overlay"),n=i.offsetHeight;i.querySelector(".video-autoplay-overlay-image")&&t.overlaySetSize(n,i)}})},this.overlaySetSize=function(e,t){if(t){var i=t.querySelector("div"),n=t.querySelector("div > img"),a=i.clientHeight;i.style.width="200px",i.style.margin="-"+Math.ceil(a/2)+"px 0 0 -100px",e>0&&e<185?(i.style.fontSize="16px",n&&(n.style.width="auto",n.style.height="60px")):(i.style.fontSize="20px",n&&(n.style.width="auto",n.style.height="100px"))}},this.isOverlayImageMode=function(e){return!!e.querySelector(".video-autoplay-overlay-image")},this.lottePlayerInit=function(e){var t=e.querySelector(".video-autoplay-overlay-lottie");if(t&&window.lottie){t.style.width="200px",t.style.height="200px",t.style.margin="-20px 0";var i=t.dataset.lottieFileUrl,n=window.lottie.loadAnimation({container:t,renderer:"svg",loop:!0,autoplay:!0,path:i});n.addEventListener("loopComplete",function(e){n.wrapper.dataset.loopCopleted="1"}),n.addEventListener("DOMLoaded",function(e){var t,i,a=0;n.wrapper.querySelectorAll("g").forEach(function(e,n){e.style.display="block";for(var o=0;o=e.video.duration}function c(e){var t=this;t.video.readyState>=t.video.HAVE_FUTURE_DATA?(t.hasAudio||(t.driver.currentTime=t.video.currentTime+e*t.video.playbackRate/1e3,t.video.loop&&u(t)&&(t.driver.currentTime=0)),l(t.video,t.driver.currentTime)):t.video.networkState===t.video.NETWORK_IDLE&&0===t.video.buffered.length&&t.video.load(),t.video.ended&&(delete t.video[b],t.video.pause(!0))}function d(){var e=this,t=e[A];if(e.webkitDisplayingFullscreen)return void e[S]();"data:"!==t.driver.src&&t.driver.src!==e.src&&(l(e,0,!0),t.driver.src=e.src),e.paused&&(t.paused=!1,0===e.buffered.length&&e.load(),t.driver.play(),t.updater.start(),t.hasAudio||(o(e,"play"),t.video.readyState>=t.video.HAVE_ENOUGH_DATA&&o(e,"playing")))}function h(e){var t=this,i=t[A];i.driver.pause(),i.updater.stop(),t.webkitDisplayingFullscreen&&t[T](),i.paused&&!e||(i.paused=!0,i.hasAudio||o(t,"pause"),t.ended&&!t.webkitDisplayingFullscreen&&(t[b]=!0,o(t,"ended")))}function p(e,i){var n={};e[A]=n,n.paused=!0,n.hasAudio=i,n.video=e,n.updater=t(c.bind(n)),i?n.driver=s(e):(e.addEventListener("canplay",function(){e.paused||o(e,"playing")}),n.driver={src:e.src||e.currentSrc||"data:",muted:!0,paused:!0,pause:function(){n.driver.paused=!0},play:function(){n.driver.paused=!1,u(n)&&l(e,0)},get ended(){return u(n)}}),e.addEventListener("emptied",function(){var t=!n.driver.src||"data:"===n.driver.src;n.driver.src&&n.driver.src!==e.src&&(l(e,0,!0),n.driver.src=e.src,t||!i&&e.autoplay?n.driver.play():n.updater.stop())},!1),e.addEventListener("webkitbeginfullscreen",function(){e.paused?i&&0===n.driver.buffered.length&&n.driver.load():(e.pause(),e[S]())}),i&&(e.addEventListener("webkitendfullscreen",function(){n.driver.currentTime=e.currentTime}),e.addEventListener("seeking",function(){C.indexOf(100*e.currentTime|0)<0&&(n.driver.currentTime=e.currentTime)}))}function m(e){var t=e[b];return delete e[b],!e.webkitDisplayingFullscreen&&!t}function f(e){var t=e[A];e[S]=e.play,e[T]=e.pause,e.play=d,e.pause=h,n(e,"paused",t.driver),n(e,"muted",t.driver,!0),n(e,"playbackRate",t.driver,!0),n(e,"ended",t.driver),n(e,"loop",t.driver,!0),i(e,"seeking",function(e){return!e.webkitDisplayingFullscreen}),i(e,"seeked",function(e){return!e.webkitDisplayingFullscreen}),i(e,"timeupdate",m),i(e,"ended",m)}function g(e,t){if(void 0===t&&(t={}),!e[A]){if(!t.everywhere){if(!v)return;if(!(t.iPad||t.ipad?/iPhone|iPod|iPad/:/iPhone|iPod/).test(navigator.userAgent))return}e.pause();var i=e.autoplay;e.autoplay=!1,p(e,!e.muted),f(e),e.classList.add("IIV"),e.muted&&i&&(e.play(),e.addEventListener("playing",function t(){e.autoplay=!0,e.removeEventListener("playing",t)})),/iPhone|iPod|iPad/.test(navigator.platform)||console.warn("iphone-inline-video is not guaranteed to work in emulated environments")}}var y,v="object"===("undefined"==typeof document?"undefined":r(document))&&"object-fit"in document.head.style&&!matchMedia("(-webkit-video-playable-inline)").matches,A="bfred-it:iphone-inline-video",b="bfred-it:iphone-inline-video:event",S="bfred-it:iphone-inline-video:nativeplay",T="bfred-it:iphone-inline-video:nativepause",C=[],w=0;return g})},"d8+S":function(e,t,i){(function(e){var i,n,a,o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e};!function(r,s){"object"===o(t)&&"object"===o(e)?e.exports=s():(n=[],i=s,void 0!==(a="function"==typeof i?i.apply(t,n):i)&&(e.exports=a))}(window,function(){return function(e){function t(n){if(i[n])return i[n].exports;var a=i[n]={i:n,l:!1,exports:{}};return e[n].call(a.exports,a,a.exports,t),a.l=!0,a.exports}var i={};return t.m=e,t.c=i,t.d=function(e,i,n){t.o(e,i)||Object.defineProperty(e,i,{enumerable:!0,get:n})},t.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},t.t=function(e,i){if(1&i&&(e=t(e)),8&i)return e;if(4&i&&"object"===(void 0===e?"undefined":o(e))&&e&&e.__esModule)return e;var n=Object.create(null);if(t.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&i&&"string"!=typeof e)for(var a in e)t.d(n,a,function(t){return e[t]}.bind(null,a));return n},t.n=function(e){var i=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(i,"a",i),i},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s="./src/strophe.js")}({"./node_modules/webpack/buildin/global.js":/*!***********************************!*\ !*** (webpack)/buildin/global.js ***! \***********************************/ /*! no static exports found */ function(e,t){var i;i=function(){return this}();try{i=i||Function("return this")()||(0,eval)("this")}catch(e){"object"===("undefined"==typeof window?"undefined":o(window))&&(i=window)}e.exports=i},"./src/bosh.js":/*!*********************!*\ !*** ./src/bosh.js ***! \*********************/ /*! no exports provided */ function(e,t,i){"use strict";i.r(t);var n=i(/*! core */"./src/core.js"),a=n.default.Strophe,o=n.default.$build;a.Request=function(e,t,i,n){this.id=++a._requestId,this.xmlData=e,this.data=a.serialize(e),this.origFunc=t,this.func=t,this.rid=i,this.date=NaN,this.sends=n||0,this.abort=!1,this.dead=null,this.age=function(){return this.date?(new Date-this.date)/1e3:0},this.timeDead=function(){return this.dead?(new Date-this.dead)/1e3:0},this.xhr=this._newXHR()},a.Request.prototype={getResponse:function(){var e=null;if(this.xhr.responseXML&&this.xhr.responseXML.documentElement){if(e=this.xhr.responseXML.documentElement,"parsererror"===e.tagName)throw a.error("invalid response received"),a.error("responseText: "+this.xhr.responseText),a.error("responseXML: "+a.serialize(this.xhr.responseXML)),new Error("parsererror")}else if(this.xhr.responseText){if(a.debug("Got responseText but no responseXML; attempting to parse it with DOMParser..."),!(e=(new DOMParser).parseFromString(this.xhr.responseText,"application/xml").documentElement))throw new Error("Parsing produced null node");if(e.querySelector("parsererror")){a.error("invalid response received: "+e.querySelector("parsererror").textContent),a.error("responseText: "+this.xhr.responseText);var t=new Error;throw t.name=a.ErrorCondition.BAD_FORMAT,t}}return e},_newXHR:function(){var e=null;return window.XMLHttpRequest?(e=new XMLHttpRequest,e.overrideMimeType&&e.overrideMimeType("text/xml; charset=utf-8")):window.ActiveXObject&&(e=new ActiveXObject("Microsoft.XMLHTTP")),e.onreadystatechange=this.func.bind(null,this),e}},a.Bosh=function(e){this._conn=e,this.rid=Math.floor(4294967295*Math.random()),this.sid=null,this.hold=1,this.wait=60,this.window=5,this.errors=0,this.inactivity=null,this.lastResponseHeaders=null,this._requests=[]},a.Bosh.prototype={strip:null,_buildBody:function(){var e=o("body",{rid:this.rid++,xmlns:a.NS.HTTPBIND});return null!==this.sid&&e.attrs({sid:this.sid}),this._conn.options.keepalive&&this._conn._sessionCachingSupported()&&this._cacheSession(),e},_reset:function(){this.rid=Math.floor(4294967295*Math.random()),this.sid=null,this.errors=0,this._conn._sessionCachingSupported()&&window.sessionStorage.removeItem("strophe-bosh-session"),this._conn.nextValidRid(this.rid)},_connect:function(e,t,i){this.wait=e||this.wait,this.hold=t||this.hold,this.errors=0;var n=this._buildBody().attrs({to:this._conn.domain,"xml:lang":"en",wait:this.wait,hold:this.hold,content:"text/xml; charset=utf-8",ver:"1.6","xmpp:version":"1.0","xmlns:xmpp":a.NS.BOSH});i&&n.attrs({route:i});var o=this._conn._connect_cb;this._requests.push(new a.Request(n.tree(),this._onRequestStateChange.bind(this,o.bind(this._conn)),n.tree().getAttribute("rid"))),this._throttledRequestHandler()},_attach:function(e,t,i,n,o,r,s){this._conn.jid=e,this.sid=t,this.rid=i,this._conn.connect_callback=n,this._conn.domain=a.getDomainFromJid(this._conn.jid),this._conn.authenticated=!0,this._conn.connected=!0,this.wait=o||this.wait,this.hold=r||this.hold,this.window=s||this.window,this._conn._changeConnectStatus(a.Status.ATTACHED,null)},_restore:function(e,t,i,n,o){var r=JSON.parse(window.sessionStorage.getItem("strophe-bosh-session"));if(!(void 0!==r&&null!==r&&r.rid&&r.sid&&r.jid&&(void 0===e||null===e||a.getBareJidFromJid(r.jid)===a.getBareJidFromJid(e)||null===a.getNodeFromJid(e)&&a.getDomainFromJid(r.jid)===e))){var s=new Error("_restore: no restoreable session.");throw s.name="StropheSessionError",s}this._conn.restored=!0,this._attach(r.jid,r.sid,r.rid,t,i,n,o)},_cacheSession:function(){this._conn.authenticated?this._conn.jid&&this.rid&&this.sid&&window.sessionStorage.setItem("strophe-bosh-session",JSON.stringify({jid:this._conn.jid,rid:this.rid,sid:this.sid})):window.sessionStorage.removeItem("strophe-bosh-session")},_connect_cb:function(e){var t=e.getAttribute("type");if(null!==t&&"terminate"===t){var i=e.getAttribute("condition");a.error("BOSH-Connection failed: "+i);var n=e.getElementsByTagName("conflict");return null!==i?("remote-stream-error"===i&&n.length>0&&(i="conflict"),this._conn._changeConnectStatus(a.Status.CONNFAIL,i)):this._conn._changeConnectStatus(a.Status.CONNFAIL,"unknown"),this._conn._doDisconnect(i),a.Status.CONNFAIL}this.sid||(this.sid=e.getAttribute("sid"));var o=e.getAttribute("requests");o&&(this.window=parseInt(o,10));var r=e.getAttribute("hold");r&&(this.hold=parseInt(r,10));var s=e.getAttribute("wait");s&&(this.wait=parseInt(s,10));var l=e.getAttribute("inactivity");l&&(this.inactivity=parseInt(l,10))},_disconnect:function(e){this._sendTerminate(e)},_doDisconnect:function(){this.sid=null,this.rid=Math.floor(4294967295*Math.random()),this._conn._sessionCachingSupported()&&window.sessionStorage.removeItem("strophe-bosh-session"),this._conn.nextValidRid(this.rid)},_emptyQueue:function(){return 0===this._requests.length},_callProtocolErrorHandlers:function(e){var t=this._getRequestStatus(e),i=this._conn.protocolErrorHandlers.HTTP[t];i&&i.call(this,t)},_hitError:function(e){this.errors++,a.warn("request errored, status: "+e+", number of errors: "+this.errors),this.errors>4&&this._conn._onDisconnectTimeout()},_no_auth_received:function(e){a.warn("Server did not yet offer a supported authentication mechanism. Sending a blank poll request."),e=e?e.bind(this._conn):this._conn._connect_cb.bind(this._conn);var t=this._buildBody();this._requests.push(new a.Request(t.tree(),this._onRequestStateChange.bind(this,e),t.tree().getAttribute("rid"))),this._throttledRequestHandler()},_onDisconnectTimeout:function(){this._abortAllRequests()},_abortAllRequests:function(){for(;this._requests.length>0;){var e=this._requests.pop();e.abort=!0,e.xhr.abort(),e.xhr.onreadystatechange=function(){}}},_onIdle:function(){var e=this._conn._data;if(this._conn.authenticated&&0===this._requests.length&&0===e.length&&!this._conn.disconnecting&&(a.debug("no requests during idle cycle, sending blank request"),e.push(null)),!this._conn.paused){if(this._requests.length<2&&e.length>0){for(var t=this._buildBody(),i=0;i0){var n=this._requests[0].age();null!==this._requests[0].dead&&this._requests[0].timeDead()>Math.floor(a.SECONDARY_TIMEOUT*this.wait)&&this._throttledRequestHandler(),n>Math.floor(a.TIMEOUT*this.wait)&&(a.warn("Request "+this._requests[0].id+" timed out, over "+Math.floor(a.TIMEOUT*this.wait)+" seconds since last activity"),this._throttledRequestHandler())}}},_getRequestStatus:function(e,t){var i;if(4===e.xhr.readyState)try{i=e.xhr.status}catch(e){a.error("Caught an error while retrieving a request's status, reqStatus: "+i)}return void 0===i&&(i="number"==typeof t?t:0),i},_onRequestStateChange:function(e,t){if(a.debug("request id "+t.id+"."+t.sends+" state changed to "+t.xhr.readyState),t.abort)return void(t.abort=!1);if(4===t.xhr.readyState){var i=this._getRequestStatus(t);if(this.lastResponseHeaders=t.xhr.getAllResponseHeaders(),this.disconnecting&&i>=400)return this._hitError(i),void this._callProtocolErrorHandlers(t);var n=i>0&&i<500,o=t.sends>this._conn.maxRetries;if((n||o)&&(this._removeRequest(t),a.debug("request id "+t.id+" should now be removed")),200===i){var r=this._requests[0]===t;(this._requests[1]===t||r&&this._requests.length>0&&this._requests[0].age()>Math.floor(a.SECONDARY_TIMEOUT*this.wait))&&this._restartRequest(0),this._conn.nextValidRid(Number(t.rid)+1),a.debug("request id "+t.id+"."+t.sends+" got 200"),e(t),this.errors=0}else 0===i||i>=400&&i<600||i>=12e3?(a.error("request id "+t.id+"."+t.sends+" error "+i+" happened"),this._hitError(i),this._callProtocolErrorHandlers(t),i>=400&&i<500&&(this._conn._changeConnectStatus(a.Status.DISCONNECTING,null),this._conn._doDisconnect())):a.error("request id "+t.id+"."+t.sends+" error "+i+" happened");n||o?o&&!this._conn.connected&&this._conn._changeConnectStatus(a.Status.CONNFAIL,"giving-up"):this._throttledRequestHandler()}},_processRequest:function(e){var t=this,i=this._requests[e],n=this._getRequestStatus(i,-1);if(i.sends>this._conn.maxRetries)return void this._conn._onDisconnectTimeout();var o=i.age(),r=!isNaN(o)&&o>Math.floor(a.TIMEOUT*this.wait),s=null!==i.dead&&i.timeDead()>Math.floor(a.SECONDARY_TIMEOUT*this.wait),l=4===i.xhr.readyState&&(n<1||n>=500);if((r||s||l)&&(s&&a.error("Request ".concat(this._requests[e].id," timed out (secondary), restarting")),i.abort=!0,i.xhr.abort(),i.xhr.onreadystatechange=function(){},this._requests[e]=new a.Request(i.xmlData,i.origFunc,i.rid,i.sends),i=this._requests[e]),0===i.xhr.readyState){a.debug("request id "+i.id+"."+i.sends+" posting");try{var u=this._conn.options.contentType||"text/xml; charset=utf-8";i.xhr.open("POST",this._conn.service,!this._conn.options.sync),void 0!==i.xhr.setRequestHeader&&i.xhr.setRequestHeader("Content-Type",u),this._conn.options.withCredentials&&(i.xhr.withCredentials=!0)}catch(e){return a.error("XHR open failed: "+e.toString()),this._conn.connected||this._conn._changeConnectStatus(a.Status.CONNFAIL,"bad-service"),void this._conn.disconnect()}var c=function(){if(i.date=new Date,t._conn.options.customHeaders){var e=t._conn.options.customHeaders;for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&i.xhr.setRequestHeader(n,e[n])}i.xhr.send(i.data)};if(i.sends>1){var d=1e3*Math.min(Math.floor(a.TIMEOUT*this.wait),Math.pow(i.sends,3));setTimeout(function(){c()},d)}else c();i.sends++,this._conn.xmlOutput!==a.Connection.prototype.xmlOutput&&(i.xmlData.nodeName===this.strip&&i.xmlData.childNodes.length?this._conn.xmlOutput(i.xmlData.childNodes[0]):this._conn.xmlOutput(i.xmlData)),this._conn.rawOutput!==a.Connection.prototype.rawOutput&&this._conn.rawOutput(i.data)}else a.debug("_processRequest: "+(0===e?"first":"second")+" request has readyState of "+i.xhr.readyState)},_removeRequest:function(e){a.debug("removing request");for(var t=this._requests.length-1;t>=0;t--)e===this._requests[t]&&this._requests.splice(t,1);e.xhr.onreadystatechange=function(){},this._throttledRequestHandler()},_restartRequest:function(e){var t=this._requests[e];null===t.dead&&(t.dead=new Date),this._processRequest(e)},_reqToData:function(e){try{return e.getResponse()}catch(e){if("parsererror"!==e.message)throw e;this._conn.disconnect("strophe-parsererror")}},_sendTerminate:function(e){a.debug("_sendTerminate was called");var t=this._buildBody().attrs({type:"terminate"});e&&t.cnode(e.tree());var i=new a.Request(t.tree(),this._onRequestStateChange.bind(this,this._conn._dataRecv.bind(this._conn)),t.tree().getAttribute("rid"));this._requests.push(i),this._throttledRequestHandler()},_send:function(){var e=this;clearTimeout(this._conn._idleTimeout),this._throttledRequestHandler(),this._conn._idleTimeout=setTimeout(function(){return e._conn._onIdle()},100)},_sendRestart:function(){this._throttledRequestHandler(),clearTimeout(this._conn._idleTimeout)},_throttledRequestHandler:function(){this._requests?a.debug("_throttledRequestHandler called with "+this._requests.length+" requests"):a.debug("_throttledRequestHandler called with undefined requests"),this._requests&&0!==this._requests.length&&(this._requests.length>0&&this._processRequest(0),this._requests.length>1&&Math.abs(this._requests[0].rid-this._requests[1].rid)0)for(var i=0;i/g,">"),e=e.replace(/'/g,"'"),e=e.replace(/"/g,""")},xmlunescape:function(e){return e=e.replace(/\&/g,"&"),e=e.replace(/</g,"<"),e=e.replace(/>/g,">"),e=e.replace(/'/g,"'"),e=e.replace(/"/g,'"')},xmlTextNode:function(e){return g.xmlGenerator().createTextNode(e)},xmlHtmlNode:function(e){var t;if(DOMParser){t=(new DOMParser).parseFromString(e,"text/xml")}else t=new ActiveXObject("Microsoft.XMLDOM"),t.async="false",t.loadXML(e);return t},getText:function(e){if(!e)return null;var t="";0===e.childNodes.length&&e.nodeType===g.ElementType.TEXT&&(t+=e.nodeValue);for(var i=0;i0&&(o=r.join("; "),t.setAttribute(a,o))}else t.setAttribute(a,o)}for(var p=0;p/g,"\\3e").replace(/@/g,"\\40")},unescapeNode:function(e){return"string"!=typeof e?e:e.replace(/\\20/g," ").replace(/\\22/g,'"').replace(/\\26/g,"&").replace(/\\27/g,"'").replace(/\\2f/g,"/").replace(/\\3a/g,":").replace(/\\3c/g,"<").replace(/\\3e/g,">").replace(/\\40/g,"@").replace(/\\5c/g,"\\")},getNodeFromJid:function(e){return e.indexOf("@")<0?null:e.split("@")[0]},getDomainFromJid:function(e){var t=g.getBareJidFromJid(e);if(t.indexOf("@")<0)return t;var i=t.split("@");return i.splice(0,1),i.join("@")},getResourceFromJid:function(e){if(!e)return null;var t=e.split("/");return t.length<2?null:(t.splice(0,1),t.join("/"))},getBareJidFromJid:function(e){return e?e.split("/")[0]:null},_handleError:function(e){void 0!==e.stack&&g.fatal(e.stack),e.sourceURL?g.fatal("error: "+this.handler+" "+e.sourceURL+":"+e.line+" - "+e.name+": "+e.message):e.fileName?g.fatal("error: "+this.handler+" "+e.fileName+":"+e.lineNumber+" - "+e.name+": "+e.message):g.fatal("error: "+e.message)},log:function(e,t){e===this.LogLevel.FATAL&&"object"===l(window.console)&&"function"==typeof window.console.error&&window.console.error(t)},debug:function(e){this.log(this.LogLevel.DEBUG,e)},info:function(e){this.log(this.LogLevel.INFO,e)},warn:function(e){this.log(this.LogLevel.WARN,e)},error:function(e){this.log(this.LogLevel.ERROR,e)},fatal:function(e){this.log(this.LogLevel.FATAL,e)},serialize:function(e){if(!e)return null;"function"==typeof e.tree&&(e=e.tree());var t=n(Array(e.attributes.length).keys()).map(function(t){return e.attributes[t].nodeName});t.sort();var i=t.reduce(function(t,i){return"".concat(t," ").concat(i,'="').concat(g.xmlescape(e.attributes.getNamedItem(i).value),'"')},"<".concat(e.nodeName));if(e.childNodes.length>0){i+=">";for(var a=0;a"}}i+=""}else i+="/>";return i},_requestId:0,_connectionPlugins:{},addConnectionPlugin:function(e,t){g._connectionPlugins[e]=t}};g.Builder=function(e,t){"presence"!==e&&"message"!==e&&"iq"!==e||(t&&!t.xmlns?t.xmlns=g.NS.CLIENT:t||(t={xmlns:g.NS.CLIENT})),this.nodeTree=g.xmlElement(e,t),this.node=this.nodeTree},g.Builder.prototype={tree:function(){return this.nodeTree},toString:function(){return g.serialize(this.nodeTree)},up:function(){return this.node=this.node.parentNode,this},root:function(){return this.node=this.nodeTree,this},attrs:function(e){for(var t in e)Object.prototype.hasOwnProperty.call(e,t)&&(void 0===e[t]?this.node.removeAttribute(t):this.node.setAttribute(t,e[t]));return this},c:function(e,t,i){var n=g.xmlElement(e,t,i);return this.node.appendChild(n),"string"!=typeof i&&"number"!=typeof i&&(this.node=n),this},cnode:function(e){var t,i=g.xmlGenerator();try{t=void 0!==i.importNode}catch(e){t=!1}var n=t?i.importNode(e,!0):g.copyElement(e);return this.node.appendChild(n),this.node=n,this},t:function(e){var t=g.xmlTextNode(e);return this.node.appendChild(t),this},h:function(e){var t=document.createElement("body");t.innerHTML=e;for(var i=g.createHtml(t);i.childNodes.length>0;)this.node.appendChild(i.childNodes[0]);return this}},g.Handler=function(e,t,i,n,a,o,r){this.handler=e,this.ns=t,this.name=i,this.type=n,this.id=a,this.options=r||{matchBareFromJid:!1,ignoreNamespaceFragment:!1},this.options.matchBare&&(g.warn('The "matchBare" option is deprecated, use "matchBareFromJid" instead.'),this.options.matchBareFromJid=this.options.matchBare,delete this.options.matchBare),this.options.matchBareFromJid?this.from=o?g.getBareJidFromJid(o):null:this.from=o,this.user=!0},g.Handler.prototype={getNamespace:function(e){var t=e.getAttribute("xmlns");return t&&this.options.ignoreNamespaceFragment&&(t=t.split("#")[0]),t},namespaceMatch:function(e){var t=this,i=!1;return!this.ns||(g.forEachChild(e,null,function(e){t.getNamespace(e)===t.ns&&(i=!0)}),i||this.getNamespace(e)===this.ns)},isMatch:function(e){var t=e.getAttribute("from");this.options.matchBareFromJid&&(t=g.getBareJidFromJid(t));var i=e.getAttribute("type");return!(!this.namespaceMatch(e)||this.name&&!g.isTagEqual(e,this.name)||this.type&&(Array.isArray(this.type)?-1===this.type.indexOf(i):i!==this.type)||this.id&&e.getAttribute("id")!==this.id||this.from&&t!==this.from)},run:function(e){var t=null;try{t=this.handler(e)}catch(e){throw g._handleError(e),e}return t},toString:function(){return"{Handler: "+this.handler+"("+this.name+","+this.id+","+this.ns+")}"}},g.TimedHandler=function(e,t){this.period=e,this.handler=t,this.lastCalled=(new Date).getTime(),this.user=!0},g.TimedHandler.prototype={run:function(){return this.lastCalled=(new Date).getTime(),this.handler()},reset:function(){this.lastCalled=(new Date).getTime()},toString:function(){return"{TimedHandler: "+this.handler+"("+this.period+")}"}},g.Connection=function(e,t){var i=this;this.service=e,this.options=t||{};var n=this.options.protocol||"";0===e.indexOf("ws:")||0===e.indexOf("wss:")||0===n.indexOf("ws")?this._proto=new g.Websocket(this):this._proto=new g.Bosh(this),this.jid="",this.domain=null,this.features=null,this._sasl_data={},this.do_session=!1,this.do_bind=!1,this.timedHandlers=[],this.handlers=[],this.removeTimeds=[],this.removeHandlers=[],this.addTimeds=[],this.addHandlers=[],this.protocolErrorHandlers={HTTP:{},websocket:{}},this._idleTimeout=null,this._disconnectTimeout=null,this.authenticated=!1,this.connected=!1,this.disconnecting=!1,this.do_authentication=!0,this.paused=!1,this.restored=!1,this._data=[],this._uniqueId=0,this._sasl_success_handler=null,this._sasl_failure_handler=null,this._sasl_challenge_handler=null,this.maxRetries=5,this._idleTimeout=setTimeout(function(){return i._onIdle()},100),f.default.addCookies(this.options.cookies),this.registerSASLMechanisms(this.options.mechanisms);for(var a in g._connectionPlugins)if(Object.prototype.hasOwnProperty.call(g._connectionPlugins,a)){var o=function(){};o.prototype=g._connectionPlugins[a],this[a]=new o,this[a].init(this)}},g.Connection.prototype={reset:function(){this._proto._reset(),this.do_session=!1,this.do_bind=!1,this.timedHandlers=[],this.handlers=[],this.removeTimeds=[],this.removeHandlers=[],this.addTimeds=[],this.addHandlers=[],this.authenticated=!1,this.connected=!1,this.disconnecting=!1,this.restored=!1,this._data=[],this._requests=[],this._uniqueId=0},pause:function(){this.paused=!0},resume:function(){this.paused=!1},getUniqueId:function(e){var t="xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(e){var t=16*Math.random()|0;return("x"===e?t:3&t|8).toString(16)});return"string"==typeof e||"number"==typeof e?t+":"+e:t+""},addProtocolErrorHandler:function(e,t,i){this.protocolErrorHandlers[e][t]=i},connect:function(e,t,i,n,a,o,r){this.jid=e,this.authzid=g.getBareJidFromJid(this.jid),this.authcid=r||g.getNodeFromJid(this.jid),this.pass=t,this.servtype="xmpp",this.connect_callback=i,this.disconnecting=!1,this.connected=!1,this.authenticated=!1,this.restored=!1,this.domain=g.getDomainFromJid(this.jid),this._changeConnectStatus(g.Status.CONNECTING,null),this._proto._connect(n,a,o)},attach:function(e,t,i,n,a,o,r){if(!(this._proto instanceof g.Bosh)){var s=new Error('The "attach" method can only be used with a BOSH connection.');throw s.name="StropheSessionError",s}this._proto._attach(e,t,i,n,a,o,r)},restore:function(e,t,i,n,a){if(!this._sessionCachingSupported()){var o=new Error('The "restore" method can only be used with a BOSH connection.');throw o.name="StropheSessionError",o}this._proto._restore(e,t,i,n,a)},_sessionCachingSupported:function(){if(this._proto instanceof g.Bosh){if(!JSON)return!1;try{sessionStorage.setItem("_strophe_","_strophe_"),sessionStorage.removeItem("_strophe_")}catch(e){return!1}return!0}return!1},xmlInput:function(e){},xmlOutput:function(e){},rawInput:function(e){},rawOutput:function(e){},nextValidRid:function(e){},send:function(e){if(null!==e){if("function"==typeof e.sort)for(var t=0;t=0&&this.addHandlers.splice(t,1)},registerSASLMechanisms:function(e){this.mechanisms={},e=e||[g.SASLAnonymous,g.SASLExternal,g.SASLMD5,g.SASLOAuthBearer,g.SASLXOAuth2,g.SASLPlain,g.SASLSHA1],e.forEach(this.registerSASLMechanism.bind(this))},registerSASLMechanism:function(e){this.mechanisms[e.prototype.name]=e},disconnect:function(e){if(this._changeConnectStatus(g.Status.DISCONNECTING,e),g.warn("Disconnect was called because: "+e),this.connected){var t=!1;this.disconnecting=!0,this.authenticated&&(t=h({xmlns:g.NS.CLIENT,type:"unavailable"})),this._disconnectTimeout=this._addSysTimedHandler(3e3,this._onDisconnectTimeout.bind(this)),this._proto._disconnect(t)}else g.warn("Disconnect was called before Strophe connected to the server"),this._proto._abortAllRequests(),this._doDisconnect()},_changeConnectStatus:function(e,t,i){for(var n in g._connectionPlugins)if(Object.prototype.hasOwnProperty.call(g._connectionPlugins,n)){var a=this[n];if(a.statusChanged)try{a.statusChanged(e,t)}catch(e){g.error("".concat(n," plugin caused an exception changing status: ").concat(e))}}if(this.connect_callback)try{this.connect_callback(e,t,i)}catch(e){g._handleError(e),g.error("User connection callback caused an exception: ".concat(e))}},_doDisconnect:function(e){"number"==typeof this._idleTimeout&&clearTimeout(this._idleTimeout),null!==this._disconnectTimeout&&(this.deleteTimedHandler(this._disconnectTimeout),this._disconnectTimeout=null),g.debug("_doDisconnect was called"),this._proto._doDisconnect(),this.authenticated=!1,this.disconnecting=!1,this.restored=!1,this.handlers=[],this.timedHandlers=[],this.removeTimeds=[],this.removeHandlers=[],this.addTimeds=[],this.addHandlers=[],this._changeConnectStatus(g.Status.DISCONNECTED,e),this.connected=!1},_dataRecv:function(e,t){var i=this;g.debug("_dataRecv called");var n=this._proto._reqToData(e);if(null!==n){for(this.xmlInput!==g.Connection.prototype.xmlInput&&(n.nodeName===this._proto.strip&&n.childNodes.length?this.xmlInput(n.childNodes[0]):this.xmlInput(n)),this.rawInput!==g.Connection.prototype.rawInput&&(t?this.rawInput(t):this.rawInput(g.serialize(n)));this.removeHandlers.length>0;){var a=this.removeHandlers.pop(),o=this.handlers.indexOf(a);o>=0&&this.handlers.splice(o,1)}for(;this.addHandlers.length>0;)this.handlers.push(this.addHandlers.pop());if(this.disconnecting&&this._proto._emptyQueue())return void this._doDisconnect();var r=n.getAttribute("type");if(null!==r&&"terminate"===r){if(this.disconnecting)return;var s=n.getAttribute("condition"),l=n.getElementsByTagName("conflict");return null!==s?("remote-stream-error"===s&&l.length>0&&(s="conflict"),this._changeConnectStatus(g.Status.CONNFAIL,s)):this._changeConnectStatus(g.Status.CONNFAIL,g.ErrorCondition.UNKOWN_REASON),void this._doDisconnect(s)}g.forEachChild(n,null,function(e){var t=i.handlers;i.handlers=[];for(var n=0;n0:n.getElementsByTagName("stream:features").length>0||n.getElementsByTagName("features").length>0))return void this._proto._no_auth_received(t);var a=[],o=n.getElementsByTagName("mechanism");if(o.length>0)for(var r=0;re[i].prototype.priority&&(i=n);if(i!==t){var a=e[t];e[t]=e[i],e[i]=a}}return e},_attemptSASLAuth:function(e){e=this.sortMechanismsByPriority(e||[]);for(var t=!1,i=0;i0&&(t=g.ErrorCondition.CONFLICT),this._changeConnectStatus(g.Status.AUTHFAIL,t,e),!1}var n=e.getElementsByTagName("bind");if(!(n.length>0))return g.warn("SASL binding failed."),this._changeConnectStatus(g.Status.AUTHFAIL,null,e),!1;var a=n[0].getElementsByTagName("jid");a.length>0&&(this.jid=g.getText(a[0]),this.do_session?(this._addSysHandler(this._sasl_session_cb.bind(this),null,null,null,"_session_auth_2"),this.send(d({type:"set",id:"_session_auth_2"}).c("session",{xmlns:g.NS.SESSION}).tree())):(this.authenticated=!0,this._changeConnectStatus(g.Status.CONNECTED,null)))},_sasl_session_cb:function(e){if("result"===e.getAttribute("type"))this.authenticated=!0,this._changeConnectStatus(g.Status.CONNECTED,null);else if("error"===e.getAttribute("type"))return g.warn("Session creation failed."),this._changeConnectStatus(g.Status.AUTHFAIL,null,e),!1;return!1},_sasl_failure_cb:function(e){return this._sasl_success_handler&&(this.deleteHandler(this._sasl_success_handler),this._sasl_success_handler=null),this._sasl_challenge_handler&&(this.deleteHandler(this._sasl_challenge_handler),this._sasl_challenge_handler=null),this._sasl_mechanism&&this._sasl_mechanism.onFailure(),this._changeConnectStatus(g.Status.AUTHFAIL,null,e),!1},_auth2_cb:function(e){return"result"===e.getAttribute("type")?(this.authenticated=!0,this._changeConnectStatus(g.Status.CONNECTED,null)):"error"===e.getAttribute("type")&&(this._changeConnectStatus(g.Status.AUTHFAIL,null,e),this.disconnect("authentication failed")),!1},_addSysTimedHandler:function(e,t){var i=new g.TimedHandler(e,t);return i.user=!1,this.addTimeds.push(i),i},_addSysHandler:function(e,t,i,n,a){var o=new g.Handler(e,t,i,n,a);return o.user=!1,this.addHandlers.push(o),o},_onDisconnectTimeout:function(){return g.debug("_onDisconnectTimeout was called"),this._changeConnectStatus(g.Status.CONNTIMEOUT,null),this._proto._onDisconnectTimeout(),this._doDisconnect(),!1},_onIdle:function(){for(var e=this;this.addTimeds.length>0;)this.timedHandlers.push(this.addTimeds.pop());for(;this.removeTimeds.length>0;){var t=this.removeTimeds.pop(),i=this.timedHandlers.indexOf(t);i>=0&&this.timedHandlers.splice(i,1)}for(var n=(new Date).getTime(),a=[],o=0;o>16)+(t>>16)+(i>>16)<<16|65535&i},a=function(e,t){return e<>>32-t},o=function(e){if("string"!=typeof e)throw new Error("str2binl was passed a non-string");for(var t=[],i=0;i<8*e.length;i+=8)t[i>>5]|=(255&e.charCodeAt(i/8))<>5]>>>i%32&255);return t},s=function(e){for(var t="0123456789abcdef",i="",n=0;n<4*e.length;n++)i+=t.charAt(e[n>>2]>>n%4*8+4&15)+t.charAt(e[n>>2]>>n%4*8&15);return i},l=function(e,t,i,o,r,s){return n(a(n(n(t,e),n(o,s)),r),i)},u=function(e,t,i,n,a,o,r){return l(t&i|~t&n,e,t,a,o,r)},c=function(e,t,i,n,a,o,r){return l(t&n|i&~n,e,t,a,o,r)},d=function(e,t,i,n,a,o,r){return l(t^i^n,e,t,a,o,r)},h=function(e,t,i,n,a,o,r){return l(i^(t|~n),e,t,a,o,r)},p=function(e,t){e[t>>5]|=128<>>9<<4)]=t;for(var i,a,o,r,s=1732584193,l=-271733879,p=-1732584194,m=271733878,f=0;f>5]|=128<<24-t%32,e[15+(t+64>>9<<4)]=t;var i,n,r,u,c,d,h,p,m=new Array(80),f=1732584193,g=-271733879,y=-1732584194,v=271733878,A=-1009589776;for(i=0;i16&&(i=n(i,8*e.length));for(var a=new Array(16),o=new Array(16),r=0;r<16;r++)a[r]=909522486^i[r],o[r]=1549556828^i[r];var s=n(a.concat(u(t)),512+8*t.length);return n(o.concat(s),672)}function s(e,t){var i=(65535&e)+(65535&t);return(e>>16)+(t>>16)+(i>>16)<<16|65535&i}function l(e,t){return e<>>32-t}function u(e){for(var t=[],i=0;i<8*e.length;i+=8)t[i>>5]|=(255&e.charCodeAt(i/8))<<24-i%32;return t}function c(e){for(var t,i,n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",a="",o=0;o<4*e.length;o+=3)for(t=(e[o>>2]>>8*(3-o%4)&255)<<16|(e[o+1>>2]>>8*(3-(o+1)%4)&255)<<8|e[o+2>>2]>>8*(3-(o+2)%4)&255,i=0;i<4;i++)8*o+6*i>32*e.length?a+="=":a+=n.charAt(t>>6*(3-i)&63);return a}function d(e){for(var t="",i=0;i<32*e.length;i+=8)t+=String.fromCharCode(e[i>>5]>>>24-i%32&255);return t}i.r(t),i.d(t,"default",function(){return h});var h={b64_hmac_sha1:function(e,t){return c(r(e,t))},b64_sha1:function(e){return c(n(u(e),8*e.length))},binb2str:d,core_hmac_sha1:r,str_hmac_sha1:function(e,t){return d(r(e,t))},str_sha1:function(e){return d(n(u(e),8*e.length))}}},"./src/strophe.js":/*!************************!*\ !*** ./src/strophe.js ***! \************************/ /*! exports provided: default */ function(e,t,i){"use strict";i.r(t),function(e){var n=i(/*! core */"./src/core.js");i(/*! bosh */"./src/bosh.js"),i(/*! websocket */"./src/websocket.js");i.d(t,"default",function(){return n.default}),e.Strophe=n.default.Strophe,e.$build=n.default.$build,e.$iq=n.default.$iq,e.$msg=n.default.$msg,e.$pres=n.default.$pres}.call(this,i(/*! ./../node_modules/webpack/buildin/global.js */"./node_modules/webpack/buildin/global.js"))},"./src/utils.js":/*!**********************!*\ !*** ./src/utils.js ***! \**********************/ /*! exports provided: default */ function(e,t,i){"use strict";function n(e){return(n="function"==typeof Symbol&&"symbol"===o(Symbol.iterator)?function(e){return void 0===e?"undefined":o(e)}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":void 0===e?"undefined":o(e)})(e)}i.r(t),i.d(t,"default",function(){return a});var a={utf16to8:function(e){var t,i,n="",a=e.length;for(t=0;t=0&&i<=127?n+=e.charAt(t):i>2047?(n+=String.fromCharCode(224|i>>12&15),n+=String.fromCharCode(128|i>>6&63),n+=String.fromCharCode(128|i>>0&63)):(n+=String.fromCharCode(192|i>>6&31),n+=String.fromCharCode(128|i>>0&63));return n},addCookies:function(e){e=e||{};for(var t in e)if(Object.prototype.hasOwnProperty.call(e,t)){var i="",a="",o="",r=e[t],s="object"===n(r),l=escape(unescape(s?r.value:r));s&&(i=r.expires?";expires="+r.expires:"",a=r.domain?";domain="+r.domain:"",o=r.path?";path="+r.path:""),document.cookie=t+"="+l+i+a+o}}}},"./src/websocket.js":/*!**************************!*\ !*** ./src/websocket.js ***! \**************************/ /*! no exports provided */ function(e,t,i){"use strict";i.r(t);var n=i(/*! core */"./src/core.js"),a=n.default.Strophe,o=n.default.$build;a.Websocket=function(e){this._conn=e,this.strip="wrapper";var t=e.service;if(0!==t.indexOf("ws:")&&0!==t.indexOf("wss:")){var i="";"ws"===e.options.protocol&&"https:"!==window.location.protocol?i+="ws":i+="wss",i+="://"+window.location.host,0!==t.indexOf("/")?i+=window.location.pathname+t:i+=t,e.service=i}},a.Websocket.prototype={_buildStream:function(){return o("open",{xmlns:a.NS.FRAMING,to:this._conn.domain,version:"1.0"})},_check_streamerror:function(e,t){var i;if(i=e.getElementsByTagNameNS?e.getElementsByTagNameNS(a.NS.STREAM,"error"):e.getElementsByTagName("stream:error"),0===i.length)return!1;for(var n=i[0],o="",r="",s=0;s: "+i);var n=e.getAttribute("version");return"string"!=typeof n?t="Missing version in ":"1.0"!==n&&(t="Wrong version in : "+n),!t||(this._conn._changeConnectStatus(a.Status.CONNFAIL,t),this._conn._doDisconnect(),!1)},_connect_cb_wrapper:function(e){if(0===e.data.indexOf("\s*)*/,"");if(""===t)return;var i=(new DOMParser).parseFromString(t,"text/xml").documentElement;this._conn.xmlInput(i),this._conn.rawInput(e.data),this._handleStreamStart(i)&&this._connect_cb(i)}else if(0===e.data.indexOf("=0&&o.indexOf("wss:")>=0||r.indexOf("ws:")>=0;s&&(this._conn._changeConnectStatus(a.Status.REDIRECT,"Received see-other-uri, resetting connection"),this._conn.reset(),this._conn.service=o,this._connect())}else this._conn._changeConnectStatus(a.Status.CONNFAIL,"Received closing stream"),this._conn._doDisconnect()}else{var l=this._streamWrap(e.data),u=(new DOMParser).parseFromString(l,"text/xml").documentElement;this.socket.onmessage=this._onMessage.bind(this),this._conn._connect_cb(u,null,e.data)}},_disconnect:function(e){if(this.socket&&this.socket.readyState!==WebSocket.CLOSED){e&&this._conn.send(e);var t=o("close",{xmlns:a.NS.FRAMING});this._conn.xmlOutput(t.tree());var i=a.serialize(t);this._conn.rawOutput(i);try{this.socket.send(i)}catch(e){a.warn("Couldn't send tag.")}}this._conn._doDisconnect()},_doDisconnect:function(){a.debug("WebSockets _doDisconnect was called"),this._closeSocket()},_streamWrap:function(e){return""+e+""},_closeSocket:function(){if(this.socket)try{this.socket.onerror=null,this.socket.close()}catch(e){a.debug(e.message)}this.socket=null},_emptyQueue:function(){return!0},_onClose:function(e){this._conn.connected&&!this._conn.disconnecting?(a.error("Websocket closed unexpectedly"),this._conn._doDisconnect()):e&&1006===e.code&&!this._conn.connected&&this.socket?(a.error("Websocket closed unexcectedly"),this._conn._changeConnectStatus(a.Status.CONNFAIL,"The WebSocket connection could not be established or was disconnected."),this._conn._doDisconnect()):a.debug("Websocket closed")},_no_auth_received:function(e){a.error("Server did not offer a supported authentication mechanism"),this._changeConnectStatus(a.Status.CONNFAIL,a.ErrorCondition.NO_AUTH_MECH),e&&e.call(this._conn),this._conn._doDisconnect()},_onDisconnectTimeout:function(){},_abortAllRequests:function(){},_onError:function(e){a.error("Websocket error "+e),this._conn._changeConnectStatus(a.Status.CONNFAIL,"The WebSocket connection could not be established or was disconnected."),this._disconnect()},_onIdle:function(){var e=this._conn._data;if(e.length>0&&!this._conn.paused){for(var t=0;t