Files
Testing/videocalls/sinch.min.js

7 lines
205 KiB
JavaScript
Raw Permalink Normal View History

2026-11-17 16:15:01 -05:00
function unique(){return"x"+ ++NOW+ +new Date}function rnow(){return+new Date}function build_url(a,b){var c=a.join(URLBIT),d=[];return b?(each(b,function(a,b){var c="object"==typeof b?JSON.stringify(b):b;"undefined"!=typeof b&&null!=b&&encode(c).length>0&&d.push(a+"="+encode(c))}),c+="?"+d.join(PARAMSBIT)):c}function updater(a,b){var c,d=0,e=function(){d+b>rnow()?(clearTimeout(c),c=setTimeout(e,b)):(d=rnow(),a())};return e}function grep(a,b){var c=[];return each(a||[],function(a){b(a)&&c.push(a)}),c}function supplant(a,b){return a.replace(REPL,function(a,c){return b[c]||a})}function timeout(a,b){return setTimeout(a,b)}function uuid(a){var b="xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(a){var b=16*Math.random()|0,c="x"==a?b:3&b|8;return c.toString(16)});return a&&a(b),b}function isArray(a){return!!a&&Array.isArray&&Array.isArray(a)}function each(a,b){if(a&&b)if(isArray(a))for(var c=0,d=a.length;d>c;)b.call(a[c],a[c],c++);else for(var c in a)a.hasOwnProperty&&a.hasOwnProperty(c)&&b.call(a[c],c,a[c])}function map(a,b){var c=[];return each(a||[],function(a,d){c.push(b(a,d))}),c}function encode(a){return encodeURIComponent(a)}function generate_channel_list(a,b){var c=[];return each(a,function(a,d){b?a.search("-pnpres")<0&&d.subscribed&&c.push(a):d.subscribed&&c.push(a)}),c.sort()}function generate_channel_groups_list(a,b){var c=[];return each(a,function(a,d){b?channel.search("-pnpres")<0&&d.subscribed&&c.push(a):d.subscribed&&c.push(a)}),c.sort()}function ready(){timeout(function(){READY||(READY=1,each(READY_BUFFER,function(a){a()}))},SECOND)}function PNmessage(a){return msg=a||{apns:{}},msg.getPubnubMessage=function(){var a={};if(Object.keys(msg.apns).length){a.pn_apns={aps:{alert:msg.apns.alert,badge:msg.apns.badge}};for(var b in msg.apns)a.pn_apns[b]=msg.apns[b];var c=["badge","alert"];for(var b in c)delete a.pn_apns[c[b]]}msg.gcm&&(a.pn_gcm={data:msg.gcm});for(var b in msg)a[b]=msg[b];var d=["apns","gcm","publish","channel","callback","error"];for(var b in d)delete a[d[b]];return a},msg.publish=function(){var a=msg.getPubnubMessage();msg.pubnub&&msg.channel&&msg.pubnub.publish({message:a,channel:msg.channel,callback:msg.callback,error:msg.error})},msg}function PN_API(a){function b(a){return a||(a={}),each(da,function(b,c){b in a||(a[b]=c)}),a}function c(a){var b=[];return each(a,function(a,c){b.push(a)}),b}function d(a){return c(a).sort()}function e(a){var b="",c=d(a);for(var e in c){var f=c[e];b+=f+"="+encode(a[f]),e!=c.length-1&&(b+="&")}return b}function f(a,b,c){var d=!1;if("number"==typeof a)d=a>PRESENCE_HB_THRESHOLD||0==a?!1:!0;else{if("boolean"==typeof a)return a?PRESENCE_HB_DEFAULT:0;d=!0}return d?(c&&c("Presence Heartbeat value invalid. Valid range ( x > "+PRESENCE_HB_THRESHOLD+" or x = 0). Current Value : "+(b||PRESENCE_HB_THRESHOLD)),b||PRESENCE_HB_THRESHOLD):a}function g(a,b){return ka.encrypt(a,b||ia)||a}function h(a,b){return ka.decrypt(a,b||ia)||ka.decrypt(a,ia)||a}function i(){return clearTimeout(Y),!$||$>=500||1>$||!generate_channel_list(V,!0).length?void(_=!1):(_=!0,void la.presence_heartbeat({callback:function(a){Y=timeout(i,$*SECOND)},error:function(a){ea&&ea("Presence Heartbeat unable to reach Pubnub servers."+JSON.stringify(a)),Y=timeout(i,$*SECOND)}}))}function j(){!_&&i()}function l(a){if(aa){if(!M.length)return}else{if(a&&(M.sending=0),M.sending||!M.length)return;M.sending=1}ca(M.shift())}function m(a){var b=0;return each(generate_channel_list(V),function(c){var d=V[c];d&&(b++,(a||function(){})(d))}),b}function o(a,b,c){if("object"==typeof a){if(a.error&&a.message&&a.payload)return void c({message:a.message,payload:a.payload});if(a.payload)return void b(a.payload)}b(a)}function p(a,b){b("object"==typeof a&&a.error&&a.message&&a.payload?{message:a.message,payload:a.payload}:a)}function q(a,c,d,e){var c=a.callback||c,f=a.error||ea,g=ga(),h=[J,"v1","channel-registration","sub-key",D];h.push.apply(h,d),ca({callback:g,data:b(e),success:function(a){o(a,c,f)},fail:function(a){p(a,f)},url:h})}function r(){fa()||t(1,{error:"Offline. Please check your network settings. "}),w&&clearTimeou
e[2]=a.indexOf(b.charAt(c+2)),e[3]=a.indexOf(b.charAt(c+3)),f[0]=e[0]<<2|e[1]>>4,f[1]=(15&e[1])<<4|e[2]>>2,f[2]=(3&e[2])<<6|e[3],d.push(f[0],f[1],f[2]);return d=d.slice(0,d.length-d.length%16)};return"function"==typeof Array.indexOf&&(a=b),{encode:c,decode:d}}();return{size:l,h2a:j,expandKey:x,encryptBlock:q,decryptBlock:r,Decrypt:c,s2a:k,rawEncrypt:o,rawDecrypt:p,dec:O,openSSLKey:n,a2h:h,enc:N,Hash:{MD5:P},Base64:Q}}();window.PUBNUB||function(){function a(a,b){var c=CryptoJS.HmacSHA256(a,b);return c.toString(CryptoJS.enc.Base64)}function b(a){return document.getElementById(a)}function c(a){console.error(a)}function d(a,b){var c=[];return each(a.split(/\s+/),function(a){each((b||document).getElementsByTagName(a),function(a){c.push(a)})}),c}function e(a,b,c){each(a.split(","),function(a){var d=function(a){a||(a=window.event),c(a)||(a.cancelBubble=!0,a.preventDefault&&a.preventDefault(),a.stopPropagation&&a.stopPropagation())};b.addEventListener?b.addEventListener(a,d,!1):b.attachEvent?b.attachEvent("on"+a,d):b["on"+a]=d})}function f(){return d("head")[0]}function g(a,b,c){return c?void a.setAttribute(b,c):a&&a.getAttribute&&a.getAttribute(b)}function h(a,b){for(var c in b)if(b.hasOwnProperty(c))try{a.style[c]=b[c]+("|width|height|top|left|".indexOf(c)>0&&"number"==typeof b[c]?"px":"")}catch(d){}}function i(a){return document.createElement(a)}function j(){return s||n()?0:unique()}function k(a){if(s||n())return l(a);var c=i("script"),d=a.callback,e=unique(),h=0,j=a.timeout||DEF_TIMEOUT,k=timeout(function(){t(1,{message:"timeout"})},j),m=a.fail||function(){},o=a.data||{},q=a.success||function(){},r=function(){f().appendChild(c)},t=function(a,d){h||(h=1,c.onerror=null,clearTimeout(k),a||!d||q(d),timeout(function(){a&&m();var c=b(e),d=c&&c.parentNode;d&&d.removeChild(c)},SECOND))};return window[d]=function(a){t(0,a)},a.blocking||(c[p]=p),c.onerror=function(){t(1)},c.src=build_url(a.url,o),g(c,"id",e),r(),t}function l(a){var b,c,d=function(){if(!f){f=1,clearTimeout(h);try{c=JSON.parse(b.responseText)}catch(a){return o(1)}e=1,l(c)}},e=0,f=0,g=a.timeout||DEF_TIMEOUT,h=timeout(function(){o(1,{message:"timeout"})},g),i=a.fail||function(){},j=a.data||{},l=a.success||function(){},m=!a.blocking,o=function(a,c){e||(e=1,clearTimeout(h),b&&(b.onerror=b.onload=null,b.abort&&b.abort(),b=null),a&&i(c))};try{b=n()||window.XDomainRequest&&new XDomainRequest||new XMLHttpRequest,b.onerror=b.onabort=function(){o(1,b.responseText||{error:"Network Connection Error"})},b.onload=b.onloadend=d,b.onreadystatechange=function(){if(b&&4==b.readyState)switch(b.status){case 401:case 402:case 403:try{c=JSON.parse(b.responseText),o(1,c)}catch(a){return o(1,b.responseText)}}};var p=build_url(a.url,j);b.open("GET",p,m),m&&(b.timeout=g),b.send()}catch(q){return o(0),s=0,k(a)}return o}function m(){return"onLine"in navigator?navigator.onLine:1}function n(){if(!y||!y.get)return 0;var a={id:n.id++,send:function(){},abort:function(){a.id={}},open:function(b,c){n[a.id]=a,y.get(a.id,c)}};return a}var o="https://pubnub.a.ssl.fastly.net/pubnub.swf",p="async",q=navigator.userAgent,r="PubNub-JS-Web/3.7.2",s=-1==q.indexOf("MSIE 6");window.console||(window.console=window.console||{}),console.log||(console.log=console.error=(window.opera||{}).postError||function(){});var t=function(){var a={},b=!1;try{b=window.localStorage}catch(c){}var d=function(a){return-1==document.cookie.indexOf(a)?null:((document.cookie||"").match(RegExp(a+"=([^;]+)"))||[])[1]||null},e=function(a,b){document.cookie=a+"="+b+"; expires=Thu, 1 Aug 2030 20:00:00 UTC; path=/"},f=function(){try{return e("pnctest","1"),"1"===d("pnctest")}catch(a){return!1}}();return{get:function(c){try{return b?b.getItem(c):f?d(c):a[c]}catch(e){return a[c]}},set:function(c,d){try{if(b)return b.setItem(c,d)&&0;f&&e(c,d),a[c]=d}catch(g){a[c]=d}}}}(),u={list:{},unbind:function(a){u.list[a]=[]},bind:function(a,b){(u.list[a]=u.list[a]||[]).push(b)},fire:function(a,b){each(u.list[a]||[],function(a){a(b)})}},v=b("pubnub")||0,w=function(l){l.jsonp&&(s=0);var n=l.subscribe_key||"",o=((+l.keepalive||DEF_KEEPALIVE)*SECOND,l.uuid||t.get
a.inspect=_.inspect,a.toArrayBuffer=_.toArrayBuffer,a};var aa=/[^+\/0-9A-Za-z-_]/g}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"base64-js":4,ieee754:5,isarray:6}],4:[function(a,b,c){var d="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";!function(a){"use strict";function b(a){var b=a.charCodeAt(0);return b===g||b===l?62:b===h||b===m?63:i>b?-1:i+10>b?b-i+26+26:k+26>b?b-k:j+26>b?b-j+26:void 0}function c(a){function c(a){j[l++]=a}var d,e,g,h,i,j;if(a.length%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var k=a.length;i="="===a.charAt(k-2)?2:"="===a.charAt(k-1)?1:0,j=new f(3*a.length/4-i),g=i>0?a.length-4:a.length;var l=0;for(d=0,e=0;g>d;d+=4,e+=3)h=b(a.charAt(d))<<18|b(a.charAt(d+1))<<12|b(a.charAt(d+2))<<6|b(a.charAt(d+3)),c((16711680&h)>>16),c((65280&h)>>8),c(255&h);return 2===i?(h=b(a.charAt(d))<<2|b(a.charAt(d+1))>>4,c(255&h)):1===i&&(h=b(a.charAt(d))<<10|b(a.charAt(d+1))<<4|b(a.charAt(d+2))>>2,c(h>>8&255),c(255&h)),j}function e(a){function b(a){return d.charAt(a)}function c(a){return b(a>>18&63)+b(a>>12&63)+b(a>>6&63)+b(63&a)}var e,f,g,h=a.length%3,i="";for(e=0,g=a.length-h;g>e;e+=3)f=(a[e]<<16)+(a[e+1]<<8)+a[e+2],i+=c(f);switch(h){case 1:f=a[a.length-1],i+=b(f>>2),i+=b(f<<4&63),i+="==";break;case 2:f=(a[a.length-2]<<8)+a[a.length-1],i+=b(f>>10),i+=b(f>>4&63),i+=b(f<<2&63),i+="="}return i}var f="undefined"!=typeof Uint8Array?Uint8Array:Array,g="+".charCodeAt(0),h="/".charCodeAt(0),i="0".charCodeAt(0),j="a".charCodeAt(0),k="A".charCodeAt(0),l="-".charCodeAt(0),m="_".charCodeAt(0);a.toByteArray=c,a.fromByteArray=e}("undefined"==typeof c?this.base64js={}:c)},{}],5:[function(a,b,c){c.read=function(a,b,c,d,e){var f,g,h=8*e-d-1,i=(1<<h)-1,j=i>>1,k=-7,l=c?e-1:0,m=c?-1:1,n=a[b+l];for(l+=m,f=n&(1<<-k)-1,n>>=-k,k+=h;k>0;f=256*f+a[b+l],l+=m,k-=8);for(g=f&(1<<-k)-1,f>>=-k,k+=d;k>0;g=256*g+a[b+l],l+=m,k-=8);if(0===f)f=1-j;else{if(f===i)return g?NaN:(n?-1:1)*(1/0);g+=Math.pow(2,d),f-=j}return(n?-1:1)*g*Math.pow(2,f-d)},c.write=function(a,b,c,d,e,f){var g,h,i,j=8*f-e-1,k=(1<<j)-1,l=k>>1,m=23===e?Math.pow(2,-24)-Math.pow(2,-77):0,n=d?0:f-1,o=d?1:-1,p=0>b||0===b&&0>1/b?1:0;for(b=Math.abs(b),isNaN(b)||b===1/0?(h=isNaN(b)?1:0,g=k):(g=Math.floor(Math.log(b)/Math.LN2),b*(i=Math.pow(2,-g))<1&&(g--,i*=2),b+=g+l>=1?m/i:m*Math.pow(2,1-l),b*i>=2&&(g++,i/=2),g+l>=k?(h=0,g=k):g+l>=1?(h=(b*i-1)*Math.pow(2,e),g+=l):(h=b*Math.pow(2,l-1)*Math.pow(2,e),g=0));e>=8;a[c+n]=255&h,n+=o,h/=256,e-=8);for(g=g<<e|h,j+=e;j>0;a[c+n]=255&g,n+=o,g/=256,j-=8);a[c+n-o]|=128*p}},{}],6:[function(a,b,c){var d={}.toString;b.exports=Array.isArray||function(a){return"[object Array]"==d.call(a)}},{}],7:[function(a,b,c){function d(){throw new Error("setTimeout has not been defined")}function e(){throw new Error("clearTimeout has not been defined")}function f(a){if(l===setTimeout)return setTimeout(a,0);if((l===d||!l)&&setTimeout)return l=setTimeout,setTimeout(a,0);try{return l(a,0)}catch(b){try{return l.call(null,a,0)}catch(b){return l.call(this,a,0)}}}function g(a){if(m===clearTimeout)return clearTimeout(a);if((m===e||!m)&&clearTimeout)return m=clearTimeout,clearTimeout(a);try{return m(a)}catch(b){try{return m.call(null,a)}catch(b){return m.call(this,a)}}}function h(){q&&o&&(q=!1,o.length?p=o.concat(p):r=-1,p.length&&i())}function i(){if(!q){var a=f(h);q=!0;for(var b=p.length;b;){for(o=p,p=[];++r<b;)o&&o[r].run();r=-1,b=p.length}o=null,q=!1,g(a)}}function j(a,b){this.fun=a,this.array=b}function k(){}var l,m,n=b.exports={};!function(){try{l="function"==typeof setTimeout?setTimeout:d}catch(a){l=d}try{m="function"==typeof clearTimeout?clearTimeout:e}catch(a){m=e}}();var o,p=[],q=!1,r=-1;n.nextTick=function(a){var b=new Array(arguments.length-1);if(arguments.length>1)for(var c=1;c<arguments.length;c++)b[c-1]=arguments[c];p.push(new j(a,b)),1!==p.length||q||f(i)},j.prototype.run=function(){this.fun.apply(null,this.array)},n.title="browser",n.browser=!0,n.env={},n.argv=[],n.version="",n.versions={},n.on=k,n.addListener=k,n.once=k,n.off=k,n.removeListener=k,n.removeAl
this.iceMapTx=[],this.activeInstance=void 0,this.pcMap={},this.dataChannels={},this.proxyUrl=void 0,this.customHeaders=void 0,this.sdpAnswerBuffer={},this.joinBuffer={};var j={onCallEnded:function(a){this.sinch.mxp.unsubscribe("signalPubNub")}.bind(this)};this.addEventListener(j);var k="web",l="0";try{k=d().split("/")[0],l=d().split("/")[1]}catch(m){}var n={onCallEnded:function(b){var c=b.getDetails();if(c.startedTime){var d={callId:b.callId,domain:b.callDomain,outbound:b.callOutbound,fromId:b.fromId,toId:b.toId,callTime:new Date(c.startedTime).toISOString(),duration:c.duration,setupDuration:(b.timeEstablished-b.timeProgressing)/1e3||0,result:b.callEndCause,deviceInformation:{ModelId:e()||"unknown",OSName:k,OSVersion:l,SDKPlatform:"js",SDKPlatformVersion:a.getVersion()}};b.sinch.callReporting(d).fail(function(){console.error("Could not report call!")})}b.ffIceTimer&&clearInterval(b.ffIceTimer)}};this.addEventListener(n)}function h(a,b,c,d,e){this._version=a,this._type=b,this._sessionId=c,this._created=d,this._externalId=e,this._bytes=[],this.Encoded=function(){return this.encodeChar(this._version),this.encodeChar(this._type),this.encodeSessionId(this._sessionId),this.encodeTimestamp(this._created/1e3),this.encodeChar(this.getUserIdTypeAndLength(0,this._externalId.length)),this.encodeString(this._externalId),this.base64Encode()},this.encodeChar=function(a){this._bytes.push(a)},this.encodeSessionId=function(a){var b=0;for(this._bytes.push(a==a.toLowerCase()?1:2);b<a.length;)"-"!=a.substring(b,b+1)?(this._bytes.push(parseInt(a.substr(b,2),16)),b+=2):++b},this.encodeTimestamp=function(a){this.encodeChar(255&a),this.encodeChar((65280&a)>>8),this.encodeChar((16711680&a)>>16),this.encodeChar((4278190080&a)>>24)},this.encodeString=function(a){for(var b=0;b<a.length;++b)this._bytes.push(a.charCodeAt(b))},this.getUserIdTypeAndLength=function(a,b){return 127&b|a<<7},this.base64Encode=function(){for(var a,b="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",c=b.split(""),d=this._bytes,e="",f=0;f<d.length;f+=3)e+=c[d[f]>>2],e+=c[(3&d[f])<<4|d[f+1]>>4],e+=void 0!==d[f+1]?c[(15&d[f+1])<<2|d[f+2]>>6]:"=",e+=void 0!==d[f+2]?c[63&d[f+2]]:"=";for(a=e.slice(0,64),f=1;f<Math.ceil(e.length/64);f++)a+=e.slice(64*f,64*f+64)+(Math.ceil(e.length/64)==f+1?"":"\n");return a}}function i(a){this.endCause=a.endCause,this.endedTime=a.endedTime,this.error=a.error,this.establishedTime=a.establishedTime,this.startedTime=a.startedTime,this.duration=a.duration}function j(a,b){if(!(a instanceof f))throw new Error("CallClient can't be instantiated, use getCallClient in an SinchClient instance");var c=navigator.userAgent.toLowerCase();if(c.indexOf("msie")>-1||/Apple Computer/.test(navigator.vendor))throw new Error("SinchClient can't be started with calling capability. Browser not supported.");this.sinch=a,this.eventListeners=[],this.callBuffert={},this.localMediaStream=void 0,this.incomingCallCustomStream=b,this.groupChannel=void 0}function k(a,b,c){if(!(a instanceof f))throw new SinchError(y.ErrorDomainVerification,z.VerificationInvalidInput,"Invalid input to constructor. VerificationClient can not be instantiated, use createSmsVerification in an SinchClient instance",error);if("undefined"==typeof b||0==b.toString().length)throw new SinchError(y.ErrorDomainVerification,z.VerificationInvalidInput,"Invalid input to constructor. Valid phone number required (E.164 format ideally)",b);this.sinch=a,this.number=b||null,this.custom=c||null,this.flagVerified=!1}function l(a,b,c){if(!(a instanceof f))throw new SinchError(y.ErrorDomainVerification,z.VerificationInvalidInput,"Invalid input to constructor. VerificationClient can not be instantiated, use createSmsVerification in an SinchClient instance",error);if("undefined"==typeof b||0==b.toString().length)throw new SinchError(y.ErrorDomainVerification,z.VerificationInvalidInput,"Invalid input to constructor. Valid phone number required (E.164 format ideally)",b);this.sinch=a,this.number=b||null,this.custom=c||null,this.flagVerified=!1}function m(a,b){this.sinch=a,this.callClient=a.callClient,this.groupC
new SinchError(y.ErrorDomainSDK,z.SDKInternalOther,"Can not process JOIN, call in unexpected state.");this.activeInstance=a.getSenderId(),this.sinch.mxp.callJoined(this).then(function(){this.sinch.log(new Notification(0,1,"Successfully sent JOINED",this)),this.earlymedia||this.establish()}.bind(this)).fail(function(a){console.error("Unhandled error in call.mxpJoin.",a)})}.bind(this)).fail(function(a){console.error("Error processing JOIN",a)})},g.prototype.mxpJoined=function(a){if(this.sinch.log(new Notification(0,1,"Call JOINED Received",a)),this.callState==I.INITIATING||this.callState==I.PROGRESSING){var b=JSON.parse(a.decrypted.bd);if(b.fi!=this.sinch._sessionId+":"+this.sinch._subInstanceId)this.setEndCause(J.OTHER_DEVICE_ANSWERED),this.mxpHangup();else if(this.callState==I.PROGRESSING){var c=a.getSenderId();if(this.sinch.firefox)for(;(this.iceMapRx[c]||[]).length;){var d=this.iceMapRx[c].pop();this.injectIce(a.getSenderId(),d),this.sinch.log(new Notification(0,1,"Injected ice from Ice Rx buffert",d))}if(0==((this.pcMap[c]||{}).proxyIce||[]).length)if(console.error("Warning, no proxy configured (2). Will try to add candidate without srflx reference",this.pcMap[c]),this.proxyUrl){var e=this.proxyUrl.split("/")[3].split(":");this.pcMap[c].proxyIce=this.pcMap[c].proxyIce||[],this.pcMap[c].proxyIce.push(new G({sdpMid:"audio",sdpMLI:0,sdpMLineIndex:0,candidate:M.generateIceCandidate(e[0],e[1])}))}else console.error("Warning, no proxyUrl configured!");((this.pcMap[c]||{}).proxyIce||[]).forEach(function(a){this.sinch.log(new Notification(0,1,"Adding buffered proxy ICE candidate",a)),this.pcMap[c].addIceCandidate(a,function(){this.sinch.log(new Notification(0,1,"Successfully added proxy ICE candidate",a))}.bind(this),function(a){throw new SinchError(y.ErrorDomainSDK,z.SDKInternalOther,"Failed to add proxy ICE candidate when processing JOINED",a)})}.bind(this)),this.establish()}}else console.log("Call state already ESTABLISHED (or ENDED), cant process second JOIN")},g.prototype.mxpHangup=function(a){if(this.callState!=I.ENDED){this.sinch.log(new Notification(0,1,"Call HANGUP Received",a)),this.callState==I.ESTABLISHED?this.setEndCause(J.HUNG_UP):this.setEndCause(J.CANCELED),this.timeEnded=new Date,this.callState=I.ENDED,this.execListener("onCallEnded"),this.pc&&"closed"!=this.pc.signalingState&&this.pc.close(),delete this.pc;for(var b in this.pcMap)delete this.pcMap[b]}},g.prototype.mxpDeny=function(a){if(this.callState!=I.ENDED){if(this.sinch.log(new Notification(0,1,"Call DENIED Received",a)),this.setEndCause(J.DENIED),"error/json"==a.decrypted.bt){this.error=new SinchError(y.ErrorDomainApi,z.ApiApiCallFailed,"");var b=JSON.parse(a.decrypted.bd);for(var c in b)this.error[c]=b[c];this.error.message=b.code+" "+b.reason,this.error.mxp=a.decrypted}this.callState==I.INITIATING?(this.autoHangup=!0,this.progress(!0)):this.hangup()}},g.prototype.mxpCancel=function(a){if(this.callState!=I.ENDED){this.sinch.log(new Notification(0,1,"Call CANCEL Received",a)),this.timeEnded=new Date,this.callState=I.ENDED;Date.now();this.setEndCause(J.CANCELED),this.execListener("onCallEnded"),this.pc&&"closed"!=this.pc.signalingState&&this.pc.close(),delete this.pc;for(var b in this.pcMap)delete this.pcMap[b]}},g.prototype.mxpFail=function(a){if(this.sinch.log(new Notification(0,1,"Call FAILURE Received",a)),"message"==a.decrypted.bt)this.error=new SinchError(y.ErrorDomainApi,z.ApiApiCallFailed,""),this.error.message=a.decrypted.bd,this.error.mxp=a.decrypted;else if("error/json"==a.decrypted.bt){this.error=new SinchError(y.ErrorDomainApi,z.ApiApiCallFailed,"");var b=JSON.parse(a.decrypted.bd);for(var c in b)this.error[c]=b[c];this.error.message=b.code+" "+b.reason,this.error.mxp=a.decrypted}this.callFailure()},g.prototype.callFailure=function(){this.timeEnded=new Date,this.callState=I.ENDED,this.setEndCause(J.FAILURE),this.execListener("onCallEnded"),this.pc&&"closed"!=this.pc.signalingState&&this.pc.close(),delete this.pc;for(var a in this.pcMap)delete this.pcMap[a]},g.prototype.addEventListenerPrototype=function(a){a.onOpen&&(this.onopen=a.onOpen),
}},c.identities.push({type:"email",endpoint:a.email})),a.username&&c.identities.push({type:"username",endpoint:a.username}),a.number&&c.identities.push({type:"number",endpoint:a.number}),this.sinch.createUser(c).then(function(a){this.userObj=a,this.userId=a.user.identities.reduce(function(a,b){return"username"===b.type?b.endpoint:a+""},""),b.resolve(a)}.bind(this)).fail(function(a){b.reject(new SinchError(y.ErrorDomainApi,z.ApiApiCallFailed,a.data.errorCode+" "+a.data.message,a.data))}),b.promise},q.prototype.authenticate=function(a){if("object"!=typeof a)throw new SinchError(y.ErrorDomainSDK,z.SDKMissingParameter,'No valid identity or authentication ticket. If you are passing your own authentication tickets, ensure it is an object on the format {"userTicket":SOME_TICKET}',a);if(a.expiresIn=a.expiresIn||86400,a.sessionId&&a.sessionSecret)return a;var b=v.defer(),c="";if(this.sinch._appSecret)a=x(this.sinch._appKey,this.sinch._appSecret,a);else if("email"in a){if(c=this.sinch.authenticate,""==a.email)return b.reject(new SinchError(y.ErrorDomainSDK,z.SDKMissingParameter,"Email is empty",a)),b.promise}else if("username"in a){if(c=this.sinch.authenticateUsername,""==a.username)return b.reject(new SinchError(y.ErrorDomainSDK,z.SDKMissingParameter,"Username is empty",a)),b.promise}else if("number"in a&&(c=this.sinch.authenticateNumber,""==a.number))return b.reject(new SinchError(y.ErrorDomainSDK,z.SDKMissingParameter,"Number is empty",a)),b.promise;if(a.authorization||a.userTicket){if(a.userTicket&&!a.user){var d=a.userTicket.split(":"),e=JSON.parse(atob(d[0]));"username"===!e.identity.type&&b.reject(new SinchError(y.ErrorDomainSDK,z.SDKMissingParameter,"Username missing in userTicket JSON object.",a)),a.user={identities:[e.identity]}}this.userObj=a,this.userObj.authorization=a.authorization||a.userTicket,this.userId=a.user.identities.reduce(function(a,b){return"username"===b.type?b.endpoint:a+""},""),b.resolve()}else c?c(a).then(function(a){this.userObj=a,this.userId=a.user.identities.reduce(function(a,b){return"username"===b.type?b.endpoint:a+""},""),b.resolve()}.bind(this)).fail(function(a){b.reject(new SinchError(y.ErrorDomainApi,z.ApiApiCallFailed,a.data.errorCode+" "+a.data.message,a.data))}):b.reject(new SinchError(y.ErrorDomainSDK,z.SDKMissingParameter,"No valid identity or authentication ticket",a));return b.promise},q.prototype.initSessKeySecret=function(){var a=v.defer(),b={};b.version={os:d()||"unknown",platform:e()||"unknown",sdk:"js/"+this.sinch.getVersion()},b.services={calling:[]},this.sinch._onlineCapability&&b.services.calling.push("online"),this.sinch.capabilities.messaging&&b.services.calling.push("im"),this.sinch.capabilities.calling&&(b.services.calling.push("voip"),b.services.calling.push("p2p"),b.services.calling.push("srtp")),b.authorization=this.userObj.authorization;var c=""!==this.sinch._sessionId;return c&&(b.instanceId=this.sinch._sessionId),b.expiresIn=31536e3,this.sinch[c?"renewSecret":"getInstance"](b).then(function(b){this.sinch.config({sessionId:b.id,sessionSecret:b.secret}),a.resolve()}.bind(this)).fail(function(b){this.sinch._sessionId="",this.sinch._sessionSecret="",a.reject(new SinchError(y.ErrorDomainApi,z.ApiApiCallFailed,b.data.errorCode+" "+b.data.message,b.data))}.bind(this)),a.promise},q.prototype.resumeSession=function(a){var b=v.defer();return this.userId=a.userId,this.sinch.config(a),this.sinch.getUserProfile().then(function(a){this.userObj=a,b.resolve()}.bind(this)).fail(function(a){a instanceof SinchError?b.reject(a):b.reject(new SinchError(y.ErrorDomainApi,z.ApiApiCallFailed,a.data.errorCode+" "+a.data.message,a.data))}),b.promise},q.prototype.getMXPConf=function(){var a=v.defer();return this.sinch.getConfiguration().then(function(b){this.mxpConfig=b,a.resolve()}.bind(this)).fail(function(b){a.reject(new SinchError(y.ErrorDomainApi,z.ApiApiCallFailed,b.data.errorCode+" "+b.data.message,b.data))}),a.promise},r.prototype.request=function(a,b){var c=v.defer();if(this.flagVerified){var f=new SinchError(y.ErrorDomainVerification,z.VerificationUnexpectedInitiateError,"Verification
}}),h=c.enc={},i=h.Hex={stringify:function(a){var b=a.words;a=a.sigBytes;for(var c=[],d=0;a>d;d++){var e=b[d>>>2]>>>24-8*(d%4)&255;c.push((e>>>4).toString(16)),c.push((15&e).toString(16))}return c.join("")},parse:function(a){for(var b=a.length,c=[],d=0;b>d;d+=2)c[d>>>3]|=parseInt(a.substr(d,2),16)<<24-4*(d%8);return new g.init(c,b/2)}},j=h.Latin1={stringify:function(a){var b=a.words;a=a.sigBytes;for(var c=[],d=0;a>d;d++)c.push(String.fromCharCode(b[d>>>2]>>>24-8*(d%4)&255));return c.join("")},parse:function(a){for(var b=a.length,c=[],d=0;b>d;d++)c[d>>>2]|=(255&a.charCodeAt(d))<<24-8*(d%4);return new g.init(c,b)}},k=h.Utf8={stringify:function(a){try{return decodeURIComponent(escape(j.stringify(a)))}catch(b){throw Error("Malformed UTF-8 data")}},parse:function(a){return j.parse(unescape(encodeURIComponent(a)))}},l=d.BufferedBlockAlgorithm=f.extend({reset:function(){this._data=new g.init,this._nDataBytes=0},_append:function(a){"string"==typeof a&&(a=k.parse(a)),this._data.concat(a),this._nDataBytes+=a.sigBytes},_process:function(b){var c=this._data,d=c.words,e=c.sigBytes,f=this.blockSize,h=e/(4*f),h=b?a.ceil(h):a.max((0|h)-this._minBufferSize,0);if(b=h*f,e=a.min(4*b,e),b){for(var i=0;b>i;i+=f)this._doProcessBlock(d,i);i=d.splice(0,b),c.sigBytes-=e}return new g.init(i,e)},clone:function(){var a=f.clone.call(this);return a._data=this._data.clone(),a},_minBufferSize:0});d.Hasher=l.extend({cfg:f.extend(),init:function(a){this.cfg=this.cfg.extend(a),this.reset()},reset:function(){l.reset.call(this),this._doReset()},update:function(a){return this._append(a),this._process(),this},finalize:function(a){return a&&this._append(a),this._doFinalize()},blockSize:16,_createHelper:function(a){return function(b,c){return new a.init(c).finalize(b)}},_createHmacHelper:function(a){return function(b,c){return new m.HMAC.init(a,c).finalize(b)}}});var m=c.algo={};return c}(Math);!function(a){for(var b=X,c=b.lib,d=c.WordArray,e=c.Hasher,c=b.algo,f=[],g=[],h=function(a){return 4294967296*(a-(0|a))|0},i=2,j=0;64>j;){var k;a:{k=i;for(var l=a.sqrt(k),m=2;l>=m;m++)if(!(k%m)){k=!1;break a}k=!0}k&&(8>j&&(f[j]=h(a.pow(i,.5))),g[j]=h(a.pow(i,1/3)),j++),i++}var n=[],c=c.SHA256=e.extend({_doReset:function(){this._hash=new d.init(f.slice(0))},_doProcessBlock:function(a,b){for(var c=this._hash.words,d=c[0],e=c[1],f=c[2],h=c[3],i=c[4],j=c[5],k=c[6],l=c[7],m=0;64>m;m++){if(16>m)n[m]=0|a[b+m];else{var o=n[m-15],p=n[m-2];n[m]=((o<<25|o>>>7)^(o<<14|o>>>18)^o>>>3)+n[m-7]+((p<<15|p>>>17)^(p<<13|p>>>19)^p>>>10)+n[m-16]}o=l+((i<<26|i>>>6)^(i<<21|i>>>11)^(i<<7|i>>>25))+(i&j^~i&k)+g[m]+n[m],p=((d<<30|d>>>2)^(d<<19|d>>>13)^(d<<10|d>>>22))+(d&e^d&f^e&f),l=k,k=j,j=i,i=h+o|0,h=f,f=e,e=d,d=o+p|0}c[0]=c[0]+d|0,c[1]=c[1]+e|0,c[2]=c[2]+f|0,c[3]=c[3]+h|0,c[4]=c[4]+i|0,c[5]=c[5]+j|0,c[6]=c[6]+k|0,c[7]=c[7]+l|0},_doFinalize:function(){var b=this._data,c=b.words,d=8*this._nDataBytes,e=8*b.sigBytes;return c[e>>>5]|=128<<24-e%32,c[(e+64>>>9<<4)+14]=a.floor(d/4294967296),c[(e+64>>>9<<4)+15]=d,b.sigBytes=4*c.length,this._process(),this._hash},clone:function(){var a=e.clone.call(this);return a._hash=this._hash.clone(),a}});b.SHA256=e._createHelper(c),b.HmacSHA256=e._createHmacHelper(c)}(Math),function(){var a=X,b=a.enc.Utf8;a.algo.HMAC=a.lib.Base.extend({init:function(a,c){a=this._hasher=new a.init,"string"==typeof c&&(c=b.parse(c));var d=a.blockSize,e=4*d;c.sigBytes>e&&(c=a.finalize(c)),c.clamp();for(var f=this._oKey=c.clone(),g=this._iKey=c.clone(),h=f.words,i=g.words,j=0;d>j;j++)h[j]^=1549556828,i[j]^=909522486;f.sigBytes=g.sigBytes=e,this.reset()},reset:function(){var a=this._hasher;a.reset(),a.update(this._iKey)},update:function(a){return this._hasher.update(a),this},finalize:function(a){var b=this._hasher;return a=b.finalize(a),b.reset(),b.finalize(this._oKey.clone().concat(a))}})}(),function(){var a=X,b=a.lib.WordArray;a.enc.Base64={stringify:function(a){var b=a.words,c=a.sigBytes,d=this._map;a.clamp(),a=[];for(var e=0;c>e;e+=3)for(var f=(b[e>>>2]>>>24-8*(e%4)&255)<<16|(b[e+1>>>2]>>>24-8*((e+1)%4)&255)<<8|b[e+2>>>2]>>>24-8*((e+2)%4)&255,g=0;4>g&&c>e+.75*g;g++)a.push(d.charAt(f>>>