forked from possan/sinch-js-rtc
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsinch.min.js
1 lines (1 loc) · 207 KB
/
sinch.min.js
1
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.PUBNUB=t():e.PUBNUB=t()}(this,function(){return function(e){function t(i){if(n[i])return n[i].exports;var r=n[i]={exports:{},id:i,loaded:!1};return e[i].call(r.exports,r,r.exports,t),r.loaded=!0,r.exports}var n={};return t.m=e,t.c=n,t.p="",t(0)}([function(e,t,n){function i(e,t){return g.HmacSHA256(e,t).toString(g.enc.Base64)}function r(e){return document.getElementById(e)}function s(e,t){var n=[];return y.each(e.split(/\s+/),function(e){y.each((t||document).getElementsByTagName(e),function(e){n.push(e)})}),n}function o(e,t,n){y.each(e.split(","),function(e){var i=function(e){e||(e=window.event),n(e)||(e.cancelBubble=!0,e.preventDefault&&e.preventDefault(),e.stopPropagation&&e.stopPropagation())};t.addEventListener?t.addEventListener(e,i,!1):t.attachEvent?t.attachEvent("on"+e,i):t["on"+e]=i})}function a(){return s("head")[0]}function c(e,t,n){if(!n)return e&&e.getAttribute&&e.getAttribute(t);e.setAttribute(t,n)}function u(e,t){for(var n in t)if(t.hasOwnProperty(n))try{e.style[n]=t[n]+("|width|height|top|left|".indexOf(n)>0&&"number"==typeof t[n]?"px":"")}catch(e){return}}function h(e){return document.createElement(e)}function l(e){var t,n,i=0,r=0,s=e.timeout||y.DEF_TIMEOUT,o=e.data||{},a=e.fail||function(){},c=e.success||function(){},u=function(e,r){i||(i=1,clearTimeout(n),t&&(t.onerror=t.onload=null,t.abort&&t.abort(),t=null),e&&a(r))};n=y.timeout(function(){u(1)},s);try{(t="undefined"!=typeof XDomainRequest&&new XDomainRequest||new XMLHttpRequest).onerror=t.onabort=function(){u(1,t.responseText||{error:"Network Connection Error"})},t.onload=t.onloadend=function(){if(!r){var e;r=1,clearTimeout(n);try{e=JSON.parse(t.responseText)}catch(e){return u(1)}c(e)}};var h=y.build_url(e.url,o);t.open("GET",h,!0),t.timeout=s,t.send()}catch(e){u(1,{error:"XHR Failed",stacktrace:e})}return u}function f(){if(!("onLine"in navigator))return 1;try{return navigator.onLine}catch(e){return!0}}function p(e){return"sendBeacon"in navigator&&navigator.sendBeacon(e)}n(1);var d=n(2),g=n(3),y=n(4),m=n(8);window.console||(window.console=window.console||{}),console.log||(console.log=console.error=(window.opera||{}).postError||function(){});var v=function(){var e={},t=!1;try{t=window.localStorage}catch(e){return}var n=function(e){return-1===document.cookie.indexOf(e)?null:((document.cookie||"").match(RegExp(e+"=([^;]+)"))||[])[1]||null},i=function(e,t){document.cookie=e+"="+t+"; expires=Thu, 1 Aug "+((new Date).getFullYear()+1)+" 20:00:00 UTC; path=/"},r=function(){try{return i("pnctest","1"),"1"===n("pnctest")}catch(e){return!1}}();return{get:function(i){try{return t?t.getItem(i):r?n(i):e[i]}catch(t){return e[i]}},set:function(n,s){try{if(t)return t.setItem(n,s)&&0;r&&i(n,s),e[n]=s}catch(t){e[n]=s}}}}(),b={list:{},unbind:function(e){b.list[e]=[]},bind:function(e,t){(b.list[e]=b.list[e]||[]).push(t)},fire:function(e,t){y.each(b.list[e]||[],function(e){e(t)})}},w=function(e){var t=e.leave_on_unload||0;e.xdr=l,e.db=v,e.error=e.error||function(e){console.error(e)},e._is_online=f,e.hmac_SHA256=i,e.crypto_obj=d(),e.sendBeacon=p,e.sdk_family="Web";var n=function(e){return w(e)},g=y.PN_API(e);for(var S in g)g.hasOwnProperty(S)&&(n[S]=g[S]);return n.css=u,n.$=r,n.create=h,n.bind=o,n.head=a,n.search=s,n.attr=c,n.events=b,n.init=n,n.secure=n,n.crypto_obj=d(),n.WS=m,n.PNmessage=y.PNmessage,n.supplant=y.supplant,o("beforeunload",window,function(){return t&&n["each-channel"](function(e){n.LEAVE(e.name,0)}),!0}),n.ready(),e.notest?n:(o("offline",window,n.offline),o("offline",document,n.offline),n)};w.init=w,w.secure=w,w.crypto_obj=d(),w.WS=m,w.db=v,w.PNmessage=y.PNmessage,w.uuid=y.uuid,w.css=u,w.$=r,w.create=r,w.bind=o,w.head=a,w.search=s,w.attr=c,w.events=b,w.map=y.map,w.each=y.each,w.grep=y.grep,w.supplant=y.supplant,w.now=y.now,w.unique=y.unique,w.updater=y.updater,window.jQuery&&(window.jQuery.PUBNUB=w),e.exports=w},function(module,exports){(function(){window.JSON&&window.JSON.stringify||function(){function toJSON(e){try{return this.valueOf()}catch(e){return null}}function quote(e){return escapable.lastIndex=0,escapable.test(e)?'"'+e.replace(escapable,function(e){var t=meta[e];return"string"==typeof t?t:"\\u"+("0000"+e.charCodeAt(0).toString(16)).slice(-4)})+'"':'"'+e+'"'}function str(e,t){var n,i,r,s,o,a=gap,c=t[e];switch(c&&"object"==typeof c&&(c=toJSON.call(c,e)),"function"==typeof rep&&(c=rep.call(t,e,c)),typeof c){case"string":return quote(c);case"number":return isFinite(c)?String(c):"null";case"boolean":case"null":return String(c);case"object":if(!c)return"null";if(gap+=indent,o=[],"[object Array]"===Object.prototype.toString.apply(c)){for(s=c.length,n=0;n<s;n+=1)o[n]=str(n,c)||"null";return r=0===o.length?"[]":gap?"[\n"+gap+o.join(",\n"+gap)+"\n"+a+"]":"["+o.join(",")+"]",gap=a,r}if(rep&&"object"==typeof rep)for(s=rep.length,n=0;n<s;n+=1)"string"==typeof(i=rep[n])&&(r=str(i,c))&&o.push(quote(i)+(gap?": ":":")+r);else for(i in c)Object.hasOwnProperty.call(c,i)&&(r=str(i,c))&&o.push(quote(i)+(gap?": ":":")+r);return r=0===o.length?"{}":gap?"{\n"+gap+o.join(",\n"+gap)+"\n"+a+"}":"{"+o.join(",")+"}",gap=a,r}}window.JSON||(window.JSON={});var cx=/[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,escapable=/[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,gap,indent,meta={"\b":"\\b","\t":"\\t","\n":"\\n","\f":"\\f","\r":"\\r",'"':'\\"',"\\":"\\\\"},rep;"function"!=typeof JSON.stringify&&(JSON.stringify=function(e,t,n){var i;if(gap="",indent="","number"==typeof n)for(i=0;i<n;i+=1)indent+=" ";else"string"==typeof n&&(indent=n);if(rep=t,t&&"function"!=typeof t&&("object"!=typeof t||"number"!=typeof t.length))throw new Error("JSON.stringify");return str("",{"":e})}),"function"!=typeof JSON.parse&&(JSON.parse=function(text){return eval("("+text+")")})}()}).call(window)},function(e,t,n){var i=n(3);e.exports=function(){function e(e){return(e=e||{}).hasOwnProperty("encryptKey")||(e.encryptKey=u.encryptKey),e.hasOwnProperty("keyEncoding")||(e.keyEncoding=u.keyEncoding),e.hasOwnProperty("keyLength")||(e.keyLength=u.keyLength),e.hasOwnProperty("mode")||(e.mode=u.mode),-1==o.indexOf(e.keyEncoding.toLowerCase())&&(e.keyEncoding=u.keyEncoding),-1==a.indexOf(parseInt(e.keyLength,10))&&(e.keyLength=u.keyLength),-1==c.indexOf(e.mode.toLowerCase())&&(e.mode=u.mode),e}function t(e,t){return e=function(e,t){return"base64"===t.keyEncoding?i.enc.Base64.parse(e):"hex"===t.keyEncoding?i.enc.Hex.parse(e):e}(e,t),t.encryptKey?i.enc.Utf8.parse(function(e){return i.SHA256(e).toString(i.enc.Hex)}(e).slice(0,32)):e}function n(e){return"ecb"===e.mode?i.mode.ECB:i.mode.CBC}function r(e){return"cbc"===e.mode?i.enc.Utf8.parse(s):null}var s="0123456789012345",o=["hex","utf8","base64","binary"],a=[128,256],c=["ecb","cbc"],u={encryptKey:!0,keyEncoding:"utf8",keyLength:256,mode:"cbc"};return{encrypt:function(s,o,a){if(!o)return s;var c=r(a=e(a)),u=n(a),h=t(o,a),l=JSON.stringify(s);return i.AES.encrypt(l,h,{iv:c,mode:u}).ciphertext.toString(i.enc.Base64)||s},decrypt:function(s,o,a){if(!o)return s;var c=r(a=e(a)),u=n(a),h=t(o,a);try{var l=i.enc.Base64.parse(s),f=i.AES.decrypt({ciphertext:l},h,{iv:c,mode:u}).toString(i.enc.Utf8);return JSON.parse(f)}catch(e){return}}}}},function(e,t){var n=n||function(e,t){var n={},i=n.lib={},r=function(){},s=i.Base={extend:function(e){r.prototype=this;var t=new r;return e&&t.mixIn(e),t.hasOwnProperty("init")||(t.init=function(){t.$super.init.apply(this,arguments)}),t.init.prototype=t,t.$super=this,t},create:function(){var e=this.extend();return e.init.apply(e,arguments),e},init:function(){},mixIn:function(e){for(var t in e)e.hasOwnProperty(t)&&(this[t]=e[t]);e.hasOwnProperty("toString")&&(this.toString=e.toString)},clone:function(){return this.init.prototype.extend(this)}},o=i.WordArray=s.extend({init:function(e,t){e=this.words=e||[],this.sigBytes=void 0!=t?t:4*e.length},toString:function(e){return(e||c).stringify(this)},concat:function(e){var t=this.words,n=e.words,i=this.sigBytes;if(e=e.sigBytes,this.clamp(),i%4)for(var r=0;r<e;r++)t[i+r>>>2]|=(n[r>>>2]>>>24-r%4*8&255)<<24-(i+r)%4*8;else if(65535<n.length)for(r=0;r<e;r+=4)t[i+r>>>2]=n[r>>>2];else t.push.apply(t,n);return this.sigBytes+=e,this},clamp:function(){var t=this.words,n=this.sigBytes;t[n>>>2]&=4294967295<<32-n%4*8,t.length=e.ceil(n/4)},clone:function(){var e=s.clone.call(this);return e.words=this.words.slice(0),e},random:function(t){for(var n=[],i=0;i<t;i+=4)n.push(4294967296*e.random()|0);return new o.init(n,t)}}),a=n.enc={},c=a.Hex={stringify:function(e){var t=e.words;e=e.sigBytes;for(var n=[],i=0;i<e;i++){var r=t[i>>>2]>>>24-i%4*8&255;n.push((r>>>4).toString(16)),n.push((15&r).toString(16))}return n.join("")},parse:function(e){for(var t=e.length,n=[],i=0;i<t;i+=2)n[i>>>3]|=parseInt(e.substr(i,2),16)<<24-i%8*4;return new o.init(n,t/2)}},u=a.Latin1={stringify:function(e){var t=e.words;e=e.sigBytes;for(var n=[],i=0;i<e;i++)n.push(String.fromCharCode(t[i>>>2]>>>24-i%4*8&255));return n.join("")},parse:function(e){for(var t=e.length,n=[],i=0;i<t;i++)n[i>>>2]|=(255&e.charCodeAt(i))<<24-i%4*8;return new o.init(n,t)}},h=a.Utf8={stringify:function(e){try{return decodeURIComponent(escape(u.stringify(e)))}catch(e){throw Error("Malformed UTF-8 data")}},parse:function(e){return u.parse(unescape(encodeURIComponent(e)))}},l=i.BufferedBlockAlgorithm=s.extend({reset:function(){this._data=new o.init,this._nDataBytes=0},_append:function(e){"string"==typeof e&&(e=h.parse(e)),this._data.concat(e),this._nDataBytes+=e.sigBytes},_process:function(t){var n=this._data,i=n.words,r=n.sigBytes,s=this.blockSize,a=r/(4*s);if(t=(a=t?e.ceil(a):e.max((0|a)-this._minBufferSize,0))*s,r=e.min(4*t,r),t){for(var c=0;c<t;c+=s)this._doProcessBlock(i,c);c=i.splice(0,t),n.sigBytes-=r}return new o.init(c,r)},clone:function(){var e=s.clone.call(this);return e._data=this._data.clone(),e},_minBufferSize:0});i.Hasher=l.extend({cfg:s.extend(),init:function(e){this.cfg=this.cfg.extend(e),this.reset()},reset:function(){l.reset.call(this),this._doReset()},update:function(e){return this._append(e),this._process(),this},finalize:function(e){return e&&this._append(e),this._doFinalize()},blockSize:16,_createHelper:function(e){return function(t,n){return new e.init(n).finalize(t)}},_createHmacHelper:function(e){return function(t,n){return new f.HMAC.init(e,n).finalize(t)}}});var f=n.algo={};return n}(Math);!function(e){for(var t=n,i=(s=t.lib).WordArray,r=s.Hasher,s=t.algo,o=[],a=[],c=function(e){return 4294967296*(e-(0|e))|0},u=2,h=0;64>h;){var l;e:{l=u;for(var f=e.sqrt(l),p=2;p<=f;p++)if(!(l%p)){l=!1;break e}l=!0}l&&(8>h&&(o[h]=c(e.pow(u,.5))),a[h]=c(e.pow(u,1/3)),h++),u++}var d=[],s=s.SHA256=r.extend({_doReset:function(){this._hash=new i.init(o.slice(0))},_doProcessBlock:function(e,t){for(var n=this._hash.words,i=n[0],r=n[1],s=n[2],o=n[3],c=n[4],u=n[5],h=n[6],l=n[7],f=0;64>f;f++){if(16>f)d[f]=0|e[t+f];else{var p=d[f-15],g=d[f-2];d[f]=((p<<25|p>>>7)^(p<<14|p>>>18)^p>>>3)+d[f-7]+((g<<15|g>>>17)^(g<<13|g>>>19)^g>>>10)+d[f-16]}p=l+((c<<26|c>>>6)^(c<<21|c>>>11)^(c<<7|c>>>25))+(c&u^~c&h)+a[f]+d[f],g=((i<<30|i>>>2)^(i<<19|i>>>13)^(i<<10|i>>>22))+(i&r^i&s^r&s),l=h,h=u,u=c,c=o+p|0,o=s,s=r,r=i,i=p+g|0}n[0]=n[0]+i|0,n[1]=n[1]+r|0,n[2]=n[2]+s|0,n[3]=n[3]+o|0,n[4]=n[4]+c|0,n[5]=n[5]+u|0,n[6]=n[6]+h|0,n[7]=n[7]+l|0},_doFinalize:function(){var t=this._data,n=t.words,i=8*this._nDataBytes,r=8*t.sigBytes;return n[r>>>5]|=128<<24-r%32,n[14+(r+64>>>9<<4)]=e.floor(i/4294967296),n[15+(r+64>>>9<<4)]=i,t.sigBytes=4*n.length,this._process(),this._hash},clone:function(){var e=r.clone.call(this);return e._hash=this._hash.clone(),e}});t.SHA256=r._createHelper(s),t.HmacSHA256=r._createHmacHelper(s)}(Math),function(){var e=n,t=e.enc.Utf8;e.algo.HMAC=e.lib.Base.extend({init:function(e,n){e=this._hasher=new e.init,"string"==typeof n&&(n=t.parse(n));var i=e.blockSize,r=4*i;n.sigBytes>r&&(n=e.finalize(n)),n.clamp();for(var s=this._oKey=n.clone(),o=this._iKey=n.clone(),a=s.words,c=o.words,u=0;u<i;u++)a[u]^=1549556828,c[u]^=909522486;s.sigBytes=o.sigBytes=r,this.reset()},reset:function(){var e=this._hasher;e.reset(),e.update(this._iKey)},update:function(e){return this._hasher.update(e),this},finalize:function(e){var t=this._hasher;return e=t.finalize(e),t.reset(),t.finalize(this._oKey.clone().concat(e))}})}(),function(){var e=n,t=e.lib.WordArray;e.enc.Base64={stringify:function(e){var t=e.words,n=e.sigBytes,i=this._map;e.clamp(),e=[];for(var r=0;r<n;r+=3)for(var s=(t[r>>>2]>>>24-r%4*8&255)<<16|(t[r+1>>>2]>>>24-(r+1)%4*8&255)<<8|t[r+2>>>2]>>>24-(r+2)%4*8&255,o=0;4>o&&r+.75*o<n;o++)e.push(i.charAt(s>>>6*(3-o)&63));if(t=i.charAt(64))for(;e.length%4;)e.push(t);return e.join("")},parse:function(e){var n=e.length,i=this._map;(r=i.charAt(64))&&-1!=(r=e.indexOf(r))&&(n=r);for(var r=[],s=0,o=0;o<n;o++)if(o%4){var a=i.indexOf(e.charAt(o-1))<<o%4*2,c=i.indexOf(e.charAt(o))>>>6-o%4*2;r[s>>>2]|=(a|c)<<24-s%4*8,s++}return t.create(r,s)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="}}(),function(e){function t(e,t,n,i,r,s,o){return((e=e+(t&n|~t&i)+r+o)<<s|e>>>32-s)+t}function i(e,t,n,i,r,s,o){return((e=e+(t&i|n&~i)+r+o)<<s|e>>>32-s)+t}function r(e,t,n,i,r,s,o){return((e=e+(t^n^i)+r+o)<<s|e>>>32-s)+t}function s(e,t,n,i,r,s,o){return((e=e+(n^(t|~i))+r+o)<<s|e>>>32-s)+t}for(var o=n,a=(u=o.lib).WordArray,c=u.Hasher,u=o.algo,h=[],l=0;64>l;l++)h[l]=4294967296*e.abs(e.sin(l+1))|0;u=u.MD5=c.extend({_doReset:function(){this._hash=new a.init([1732584193,4023233417,2562383102,271733878])},_doProcessBlock:function(e,n){for(o=0;16>o;o++){c=e[a=n+o];e[a]=16711935&(c<<8|c>>>24)|4278255360&(c<<24|c>>>8)}var o=this._hash.words,a=e[n+0],c=e[n+1],u=e[n+2],l=e[n+3],f=e[n+4],p=e[n+5],d=e[n+6],g=e[n+7],y=e[n+8],m=e[n+9],v=e[n+10],b=e[n+11],w=e[n+12],S=e[n+13],I=e[n+14],_=e[n+15],C=o[0],x=o[1],E=o[2],k=o[3],x=s(x=s(x=s(x=s(x=r(x=r(x=r(x=r(x=i(x=i(x=i(x=i(x=t(x=t(x=t(x=t(x,E=t(E,k=t(k,C=t(C,x,E,k,a,7,h[0]),x,E,c,12,h[1]),C,x,u,17,h[2]),k,C,l,22,h[3]),E=t(E,k=t(k,C=t(C,x,E,k,f,7,h[4]),x,E,p,12,h[5]),C,x,d,17,h[6]),k,C,g,22,h[7]),E=t(E,k=t(k,C=t(C,x,E,k,y,7,h[8]),x,E,m,12,h[9]),C,x,v,17,h[10]),k,C,b,22,h[11]),E=t(E,k=t(k,C=t(C,x,E,k,w,7,h[12]),x,E,S,12,h[13]),C,x,I,17,h[14]),k,C,_,22,h[15]),E=i(E,k=i(k,C=i(C,x,E,k,c,5,h[16]),x,E,d,9,h[17]),C,x,b,14,h[18]),k,C,a,20,h[19]),E=i(E,k=i(k,C=i(C,x,E,k,p,5,h[20]),x,E,v,9,h[21]),C,x,_,14,h[22]),k,C,f,20,h[23]),E=i(E,k=i(k,C=i(C,x,E,k,m,5,h[24]),x,E,I,9,h[25]),C,x,l,14,h[26]),k,C,y,20,h[27]),E=i(E,k=i(k,C=i(C,x,E,k,S,5,h[28]),x,E,u,9,h[29]),C,x,g,14,h[30]),k,C,w,20,h[31]),E=r(E,k=r(k,C=r(C,x,E,k,p,4,h[32]),x,E,y,11,h[33]),C,x,b,16,h[34]),k,C,I,23,h[35]),E=r(E,k=r(k,C=r(C,x,E,k,c,4,h[36]),x,E,f,11,h[37]),C,x,g,16,h[38]),k,C,v,23,h[39]),E=r(E,k=r(k,C=r(C,x,E,k,S,4,h[40]),x,E,a,11,h[41]),C,x,l,16,h[42]),k,C,d,23,h[43]),E=r(E,k=r(k,C=r(C,x,E,k,m,4,h[44]),x,E,w,11,h[45]),C,x,_,16,h[46]),k,C,u,23,h[47]),E=s(E,k=s(k,C=s(C,x,E,k,a,6,h[48]),x,E,g,10,h[49]),C,x,I,15,h[50]),k,C,p,21,h[51]),E=s(E,k=s(k,C=s(C,x,E,k,w,6,h[52]),x,E,l,10,h[53]),C,x,v,15,h[54]),k,C,c,21,h[55]),E=s(E,k=s(k,C=s(C,x,E,k,y,6,h[56]),x,E,_,10,h[57]),C,x,d,15,h[58]),k,C,S,21,h[59]),E=s(E,k=s(k,C=s(C,x,E,k,f,6,h[60]),x,E,b,10,h[61]),C,x,u,15,h[62]),k,C,m,21,h[63]);o[0]=o[0]+C|0,o[1]=o[1]+x|0,o[2]=o[2]+E|0,o[3]=o[3]+k|0},_doFinalize:function(){var t=this._data,n=t.words,i=8*this._nDataBytes,r=8*t.sigBytes;n[r>>>5]|=128<<24-r%32;var s=e.floor(i/4294967296);for(n[15+(r+64>>>9<<4)]=16711935&(s<<8|s>>>24)|4278255360&(s<<24|s>>>8),n[14+(r+64>>>9<<4)]=16711935&(i<<8|i>>>24)|4278255360&(i<<24|i>>>8),t.sigBytes=4*(n.length+1),this._process(),n=(t=this._hash).words,i=0;4>i;i++)r=n[i],n[i]=16711935&(r<<8|r>>>24)|4278255360&(r<<24|r>>>8);return t},clone:function(){var e=c.clone.call(this);return e._hash=this._hash.clone(),e}}),o.MD5=c._createHelper(u),o.HmacMD5=c._createHmacHelper(u)}(Math),function(){var e=n,t=e.lib,i=t.Base,r=t.WordArray,s=(t=e.algo).EvpKDF=i.extend({cfg:i.extend({keySize:4,hasher:t.MD5,iterations:1}),init:function(e){this.cfg=this.cfg.extend(e)},compute:function(e,t){for(var n=(a=this.cfg).hasher.create(),i=r.create(),s=i.words,o=a.keySize,a=a.iterations;s.length<o;){c&&n.update(c);var c=n.update(e).finalize(t);n.reset();for(var u=1;u<a;u++)c=n.finalize(c),n.reset();i.concat(c)}return i.sigBytes=4*o,i}});e.EvpKDF=function(e,t,n){return s.create(n).compute(e,t)}}(),n.lib.Cipher||function(e){var t=(d=n).lib,i=t.Base,r=t.WordArray,s=t.BufferedBlockAlgorithm,o=d.enc.Base64,a=d.algo.EvpKDF,c=t.Cipher=s.extend({cfg:i.extend(),createEncryptor:function(e,t){return this.create(this._ENC_XFORM_MODE,e,t)},createDecryptor:function(e,t){return this.create(this._DEC_XFORM_MODE,e,t)},init:function(e,t,n){this.cfg=this.cfg.extend(n),this._xformMode=e,this._key=t,this.reset()},reset:function(){s.reset.call(this),this._doReset()},process:function(e){return this._append(e),this._process()},finalize:function(e){return e&&this._append(e),this._doFinalize()},keySize:4,ivSize:4,_ENC_XFORM_MODE:1,_DEC_XFORM_MODE:2,_createHelper:function(e){return{encrypt:function(t,n,i){return("string"==typeof n?g:p).encrypt(e,t,n,i)},decrypt:function(t,n,i){return("string"==typeof n?g:p).decrypt(e,t,n,i)}}}});t.StreamCipher=c.extend({_doFinalize:function(){return this._process(!0)},blockSize:1});var u=d.mode={},h=function(e,t,n){var i=this._iv;i?this._iv=void 0:i=this._prevBlock;for(var r=0;r<n;r++)e[t+r]^=i[r]},l=(t.BlockCipherMode=i.extend({createEncryptor:function(e,t){return this.Encryptor.create(e,t)},createDecryptor:function(e,t){return this.Decryptor.create(e,t)},init:function(e,t){this._cipher=e,this._iv=t}})).extend();l.Encryptor=l.extend({processBlock:function(e,t){var n=this._cipher,i=n.blockSize;h.call(this,e,t,i),n.encryptBlock(e,t),this._prevBlock=e.slice(t,t+i)}}),l.Decryptor=l.extend({processBlock:function(e,t){var n=this._cipher,i=n.blockSize,r=e.slice(t,t+i);n.decryptBlock(e,t),h.call(this,e,t,i),this._prevBlock=r}}),u=u.CBC=l,l=(d.pad={}).Pkcs7={pad:function(e,t){for(var n=4*t,i=(n=n-e.sigBytes%n)<<24|n<<16|n<<8|n,s=[],o=0;o<n;o+=4)s.push(i);n=r.create(s,n),e.concat(n)},unpad:function(e){e.sigBytes-=255&e.words[e.sigBytes-1>>>2]}},t.BlockCipher=c.extend({cfg:c.cfg.extend({mode:u,padding:l}),reset:function(){c.reset.call(this);var e=(t=this.cfg).iv,t=t.mode;if(this._xformMode==this._ENC_XFORM_MODE)var n=t.createEncryptor;else n=t.createDecryptor,this._minBufferSize=1;this._mode=n.call(t,this,e&&e.words)},_doProcessBlock:function(e,t){this._mode.processBlock(e,t)},_doFinalize:function(){var e=this.cfg.padding;if(this._xformMode==this._ENC_XFORM_MODE){e.pad(this._data,this.blockSize);var t=this._process(!0)}else t=this._process(!0),e.unpad(t);return t},blockSize:4});var f=t.CipherParams=i.extend({init:function(e){this.mixIn(e)},toString:function(e){return(e||this.formatter).stringify(this)}}),u=(d.format={}).OpenSSL={stringify:function(e){var t=e.ciphertext;return((e=e.salt)?r.create([1398893684,1701076831]).concat(e).concat(t):t).toString(o)},parse:function(e){var t=(e=o.parse(e)).words;if(1398893684==t[0]&&1701076831==t[1]){var n=r.create(t.slice(2,4));t.splice(0,4),e.sigBytes-=16}return f.create({ciphertext:e,salt:n})}},p=t.SerializableCipher=i.extend({cfg:i.extend({format:u}),encrypt:function(e,t,n,i){i=this.cfg.extend(i);var r=e.createEncryptor(n,i);return t=r.finalize(t),r=r.cfg,f.create({ciphertext:t,key:n,iv:r.iv,algorithm:e,mode:r.mode,padding:r.padding,blockSize:e.blockSize,formatter:i.format})},decrypt:function(e,t,n,i){return i=this.cfg.extend(i),t=this._parse(t,i.format),e.createDecryptor(n,i).finalize(t.ciphertext)},_parse:function(e,t){return"string"==typeof e?t.parse(e,this):e}}),d=(d.kdf={}).OpenSSL={execute:function(e,t,n,i){return i||(i=r.random(8)),e=a.create({keySize:t+n}).compute(e,i),n=r.create(e.words.slice(t),4*n),e.sigBytes=4*t,f.create({key:e,iv:n,salt:i})}},g=t.PasswordBasedCipher=p.extend({cfg:p.cfg.extend({kdf:d}),encrypt:function(e,t,n,i){return i=this.cfg.extend(i),n=i.kdf.execute(n,e.keySize,e.ivSize),i.iv=n.iv,(e=p.encrypt.call(this,e,t,n.key,i)).mixIn(n),e},decrypt:function(e,t,n,i){return i=this.cfg.extend(i),t=this._parse(t,i.format),n=i.kdf.execute(n,e.keySize,e.ivSize,t.salt),i.iv=n.iv,p.decrypt.call(this,e,t,n.key,i)}})}(),function(){for(var e=n,t=e.lib.BlockCipher,i=e.algo,r=[],s=[],o=[],a=[],c=[],u=[],h=[],l=[],f=[],p=[],d=[],g=0;256>g;g++)d[g]=128>g?g<<1:g<<1^283;for(var y=0,m=0,g=0;256>g;g++){var v=(v=m^m<<1^m<<2^m<<3^m<<4)>>>8^255&v^99;r[y]=v,s[v]=y;var b=d[y],w=d[b],S=d[w],I=257*d[v]^16843008*v;o[y]=I<<24|I>>>8,a[y]=I<<16|I>>>16,c[y]=I<<8|I>>>24,u[y]=I,I=16843009*S^65537*w^257*b^16843008*y,h[v]=I<<24|I>>>8,l[v]=I<<16|I>>>16,f[v]=I<<8|I>>>24,p[v]=I,y?(y=b^d[d[d[S^b]]],m^=d[d[m]]):y=m=1}var _=[0,1,2,4,8,16,32,64,128,27,54],i=i.AES=t.extend({_doReset:function(){for(var e=(n=this._key).words,t=n.sigBytes/4,n=4*((this._nRounds=t+6)+1),i=this._keySchedule=[],s=0;s<n;s++)if(s<t)i[s]=e[s];else{var o=i[s-1];s%t?6<t&&4==s%t&&(o=r[o>>>24]<<24|r[o>>>16&255]<<16|r[o>>>8&255]<<8|r[255&o]):(o=o<<8|o>>>24,o=r[o>>>24]<<24|r[o>>>16&255]<<16|r[o>>>8&255]<<8|r[255&o],o^=_[s/t|0]<<24),i[s]=i[s-t]^o}for(e=this._invKeySchedule=[],t=0;t<n;t++)s=n-t,o=t%4?i[s]:i[s-4],e[t]=4>t||4>=s?o:h[r[o>>>24]]^l[r[o>>>16&255]]^f[r[o>>>8&255]]^p[r[255&o]]},encryptBlock:function(e,t){this._doCryptBlock(e,t,this._keySchedule,o,a,c,u,r)},decryptBlock:function(e,t){var n=e[t+1];e[t+1]=e[t+3],e[t+3]=n,this._doCryptBlock(e,t,this._invKeySchedule,h,l,f,p,s),n=e[t+1],e[t+1]=e[t+3],e[t+3]=n},_doCryptBlock:function(e,t,n,i,r,s,o,a){for(var c=this._nRounds,u=e[t]^n[0],h=e[t+1]^n[1],l=e[t+2]^n[2],f=e[t+3]^n[3],p=4,d=1;d<c;d++)var g=i[u>>>24]^r[h>>>16&255]^s[l>>>8&255]^o[255&f]^n[p++],y=i[h>>>24]^r[l>>>16&255]^s[f>>>8&255]^o[255&u]^n[p++],m=i[l>>>24]^r[f>>>16&255]^s[u>>>8&255]^o[255&h]^n[p++],f=i[f>>>24]^r[u>>>16&255]^s[h>>>8&255]^o[255&l]^n[p++],u=g,h=y,l=m;g=(a[u>>>24]<<24|a[h>>>16&255]<<16|a[l>>>8&255]<<8|a[255&f])^n[p++],y=(a[h>>>24]<<24|a[l>>>16&255]<<16|a[f>>>8&255]<<8|a[255&u])^n[p++],m=(a[l>>>24]<<24|a[f>>>16&255]<<16|a[u>>>8&255]<<8|a[255&h])^n[p++],f=(a[f>>>24]<<24|a[u>>>16&255]<<16|a[h>>>8&255]<<8|a[255&l])^n[p++],e[t]=g,e[t+1]=y,e[t+2]=m,e[t+3]=f},keySize:8});e.AES=t._createHelper(i)}(),n.mode.ECB=function(){var e=n.lib.BlockCipherMode.extend();return e.Encryptor=e.extend({processBlock:function(e,t){this._cipher.encryptBlock(e,t)}}),e.Decryptor=e.extend({processBlock:function(e,t){this._cipher.decryptBlock(e,t)}}),e}(),e.exports=n},function(e,t,n){function i(){return"x"+ ++h+ +new Date}function r(e,t){var n=[];return u.each(e,function(e,i){t?e.search("-pnpres")<0&&i.subscribed&&n.push(e):i.subscribed&&n.push(e)}),n.sort()}function s(e,t){var n=[];return u.each(e,function(e,i){t?e.search("-pnpres")<0&&i.subscribed&&n.push(e):i.subscribed&&n.push(e)}),n.sort()}function o(){l||(l=1,u.each(f,function(e){e()}))}var a=n(5),c=n(6),u=n(7),h=1,l=!1,f=[],p="-pnpres",d=10,g=310,y=60,m=1e3,v=5,b=30,w=a.version,S=function(){var e=Math.floor(20*Math.random());return function(t){var n=t.split("://")[0],i=t.split("://")[1];return i.match("^ps")?n+"://"+i.replace("ps","ps"+(++e<20?e:e=1)):i.match("^pubsub")?n+"://"+i.replace("pubsub","ps"+(++e<20?e:e=1)):t}}();e.exports={PN_API:function(e){function t(e){return e||(e={}),u.each(me,function(t,n){t in e||(e[t]=n)}),e.pnsdk=function(){var e="PubNub-JS-"+Ee;return xe&&(e+="-"+xe),e+="/"+w}(),e}function n(e){return function(e){var t=[];return u.each(e,function(e,n){t.push(e)}),t}(e).sort()}function a(e,t,n){var i=!1;if(void 0===e)return t;if("number"==typeof e)i=!(e>v||0==e);else{if("boolean"==typeof e)return e?b:0;i=!0}return i?(n&&n("Presence Heartbeat value invalid. Valid range ( x > "+v+" or x = 0). Current Value : "+(t||v)),t||v):e}function c(e,t){return Oe.encrypt(e,t||Ie)||e}function h(e,t){return Oe.decrypt(e,t||Ie)||Oe.decrypt(e,Ie)||e}function I(){clearTimeout(he),!fe||fe>=500||fe<1||!r(ae,!0).length&&!s(ce,!0).length?pe=!1:(pe=!0,Be.presence_heartbeat({callback:function(e){he=u.timeout(I,fe*m)},error:function(e){ve&&ve("Presence Heartbeat unable to reach Pubnub servers."+JSON.stringify(e)),he=u.timeout(I,fe*m)}}))}function _(){!pe&&I()}function C(e){if(de){if(!Y.length)return}else{if(e&&(Y.sending=0),Y.sending||!Y.length)return;Y.sending=1}M(Y.shift())}function x(e){var t=0;return u.each(s(ce),function(n){var i=ce[n];i&&(t++,(e||function(){})(i))}),t}function E(e){var t=0;return u.each(r(ae),function(n){var i=ae[n];i&&(t++,(e||function(){})(i))}),t}function k(e,t,n){if("object"==typeof e){if(e.error){var i={};return e.message&&(i.message=e.message),e.payload&&(i.payload=e.payload),void(n&&n(i))}if(e.payload)return void(e.next_page?t&&t(e.payload,e.next_page):t&&t(e.payload))}t&&t(e)}function D(e,t){if("object"==typeof e&&e.error){var n={};return e.message&&(n.message=e.message),e.payload&&(n.payload=e.payload),void(t&&t(n))}t&&t(e)}function M(e){var t=e.operation,i=Math.floor((new Date).getTime()/1e3),r=e.data||{};if(V){r.auth||delete r.auth,r.timestamp=i;var s=z+"\n"+F+"\n";if("PNAccessManagerGrant"===t)s+="grant\n";else if("PNAccessManagerAudit"===t)s+="audit\n";else{var o=e.url.slice();o.shift(),s+="/"+o.join("/")+"\n"}s+=function(e){var t="",i=n(e);for(var r in i){var s=i[r];t+=s+"="+u.pamEncode(e[s]),r!=i.length-1&&(t+="&")}return t}(r);var a=J(s,V);a=(a=a.replace(/\+/g,"-")).replace(/\//g,"_"),r.signature=a,e.data=r}return ye(e)}function O(e,n,i,r){var n=e.callback||n,s=e.error||ve,o=we();(r=r||{}).auth||(r.auth=e.auth_key||G);var a=[q,"v1","channel-registration","sub-key",z];a.push.apply(a,i),o&&(r.callback=o),M({callback:o,data:t(r),success:function(e){k(e,n,s)},fail:function(e){D(e,s)},url:a})}function B(){be()||A(1,{error:"Offline. Please check your network settings."}),N&&clearTimeout(N),N=u.timeout(B,m)}function T(){K&&Be.time(function(e){P(function(){},e),e||A(1,{error:"Heartbeat failed to connect to Pubnub Servers.Please check your network settings."}),j&&clearTimeout(j),j=u.timeout(T,U)})}function A(e,t){ie&&ie(e,t),ie=null,clearTimeout(N),clearTimeout(j)}function P(e,t){function n(t){if(t){var n=t/1e4,r=(u.rnow()-i)/2;ee=u.rnow()-(n+r),e&&e(ee)}}var i=u.rnow();t&&n(t)||Be.time(n)}var N,j,R=+e.windowing||d,L=(+e.timeout||g)*m,U=(+e.keepalive||y)*m,K=e.timecheck||0,H=e.noleave||0,F=e.publish_key,z=e.subscribe_key,G=e.auth_key||"",V=e.secret_key||"",J=e.hmac_SHA256,W=e.ssl?"s":"",X="http"+W+"://"+(e.origin||"pubsub.pubnub.com"),q=S(X),Q=S(X),$=function(){},Y=[],Z=!0,ee=0,te=0,ne=0,ie=0,re=e.restore||0,se=0,oe=!1,ae={},ce={},ue={},he=null,le=a(e.heartbeat||e.pnexpires||0,e.error),fe=e.heartbeat_interval||le/2-1,pe=!1,de=e.no_wait_for_pending,ge=e["compatible_3.5"]||!1,ye=e.xdr,me=e.params||{},ve=e.error||function(){},be=e._is_online||function(){return 1},we=e.jsonp_cb||function(){return 0},Se=e.db||{get:function(){},set:function(){}},Ie=e.cipher_key,_e=e.uuid||!e.unique_uuid&&Se&&Se.get(z+"uuid")||"",Ce=e.instance_id||!1,xe=e.partner_id,Ee=e.sdk_family,ke="",De=e.shutdown,Me=void 0===e.use_send_beacon||e.use_send_beacon?e.sendBeacon:null;2===le&&(fe=1);var Oe=e.crypto_obj||{encrypt:function(e,t){return e},decrypt:function(e,t){return e}},Be={LEAVE:function(e,n,i,r,s){var o,a,c={uuid:_e,auth:i||G},h=S(X),r=r||function(){},l=s||function(){},f=we();if(e.indexOf(p)>0)return!0;if(ge){if(!W)return!1;if("0"==f)return!1}if(H)return!1;if("0"!=f&&(c.callback=f),Ce&&(c.instanceid=ke),o=[h,"v2","presence","sub_key",z,"channel",u.encode(e),"leave"],a=t(c),Me){var d=u.buildURL(o,a);if(Me(d))return r&&r({status:200,action:"leave",message:"OK",service:"Presence"}),!0}return M({blocking:n||W,callback:f,data:a,success:function(e){k(e,r,l)},fail:function(e){D(e,l)},url:o}),!0},LEAVE_GROUP:function(e,n,i,r,s){var o,a,c={uuid:_e,auth:i||G},h=S(X),r=r||function(){},l=s||function(){},f=we();if(e.indexOf(p)>0)return!0;if(ge){if(!W)return!1;if("0"==f)return!1}if(H)return!1;if("0"!=f&&(c.callback=f),e&&e.length>0&&(c["channel-group"]=e),Ce&&(c.instanceid=ke),o=[h,"v2","presence","sub_key",z,"channel",u.encode(","),"leave"],a=t(c),Me){var d=u.buildURL(o,a);if(Me(d))return r&&r({status:200,action:"leave",message:"OK",service:"Presence"}),!0}return M({blocking:n||W,callback:f,data:a,success:function(e){k(e,r,l)},fail:function(e){D(e,l)},url:o}),!0},set_resumed:function(e){oe=e},get_cipher_key:function(){return Ie},set_cipher_key:function(e){Ie=e},raw_encrypt:function(e,t){return c(e,t)},raw_decrypt:function(e,t){return h(e,t)},get_heartbeat:function(){return le},set_heartbeat:function(e,t){le=a(e,le,ve),fe=t||le/2-1,2==le&&(fe=1),$(),I()},get_heartbeat_interval:function(){return fe},set_heartbeat_interval:function(e){fe=e,I()},get_version:function(){return w},getGcmMessageObject:function(e){return{data:e}},getApnsMessageObject:function(e){var t={aps:{badge:1,alert:""}};for(var n in e)n[t]=e[n];return t},_add_param:function(e,t){me[e]=t},channel_group:function(e,t){var n,i,r=e.channel_group,t=t||e.callback,s=e.channels||e.channel,o=e.cloak,a=[],c={},h=e.mode||"add";if(r){var l=r.split(":");l.length>1?(n="*"===l[0]?null:l[0],i=l[1]):i=l[0]}n&&a.push("namespace")&&a.push(u.encode(n)),a.push("channel-group"),i&&"*"!==i&&a.push(i),s?(u.isArray(s)&&(s=s.join(",")),c[h]=s,c.cloak=Z?"true":"false"):"remove"===h&&a.push("remove"),void 0!==o&&(c.cloak=o?"true":"false"),O(e,t,a,c)},channel_group_list_groups:function(e,t){var n;(n=e.namespace||e.ns||e.channel_group||null)&&(e.channel_group=n+":*"),Be.channel_group(e,t)},channel_group_list_channels:function(e,t){if(!e.channel_group)return ve("Missing Channel Group");Be.channel_group(e,t)},channel_group_remove_channel:function(e,t){return e.channel_group?e.channel||e.channels?(e.mode="remove",void Be.channel_group(e,t)):ve("Missing Channel"):ve("Missing Channel Group")},channel_group_remove_group:function(e,t){return e.channel_group?e.channel?ve("Use channel_group_remove_channel if you want to remove a channel from a group."):(e.mode="remove",void Be.channel_group(e,t)):ve("Missing Channel Group")},channel_group_add_channel:function(e,t){return e.channel_group?e.channel||e.channels?void Be.channel_group(e,t):ve("Missing Channel"):ve("Missing Channel Group")},channel_group_cloak:function(e,t){void 0!==e.cloak?(Z=e.cloak,Be.channel_group(e,t)):t(Z)},channel_group_list_namespaces:function(e,t){O(e,t,["namespace"])},channel_group_remove_namespace:function(e,t){O(e,t,["namespace",e.namespace,"remove"])},history:function(e,n){var n=e.callback||n,i=e.count||e.limit||100,r=e.reverse||"false",s=e.error||function(){},o=e.auth_key||G,a=e.cipher_key,c=e.channel,l=e.channel_group,f=e.start,p=e.end,d=e.include_token,g=e.string_message_token||!1,y={},m=we();return c||l?n?z?(y.stringtoken="true",y.count=i,y.reverse=r,y.auth=o,l&&(y["channel-group"]=l,c||(c=",")),m&&(y.callback=m),f&&(y.start=f),p&&(y.end=p),d&&(y.include_token="true"),g&&(y.string_message_token="true"),void M({callback:m,data:t(y),success:function(e){if("object"==typeof e&&e.error)s({message:e.message,payload:e.payload});else{for(var t=e[0],i=[],r=0;r<t.length;r++)if(d){var o=h(t[r].message,a),c=t[r].timetoken;try{i.push({message:JSON.parse(o),timetoken:c})}catch(e){i.push({message:o,timetoken:c})}}else{o=h(t[r],a);try{i.push(JSON.parse(o))}catch(e){i.push(o)}}n([i,e[1],e[2]])}},fail:function(e){D(e,s)},url:[q,"v2","history","sub-key",z,"channel",u.encode(c)]})):ve("Missing Subscribe Key"):ve("Missing Callback"):ve("Missing Channel")},replay:function(e,n){var n=n||e.callback||function(){},i=e.auth_key||G,r=e.source,s=e.destination,o=e.error||e.error||function(){},a=e.stop,c=e.start,u=e.end,h=e.reverse,l=e.limit,f=we(),p={};return r?s?F?z?("0"!=f&&(p.callback=f),a&&(p.stop="all"),h&&(p.reverse="true"),c&&(p.start=c),u&&(p.end=u),l&&(p.count=l),p.auth=i,void M({callback:f,success:function(e){k(e,n,o)},fail:function(){n([0,"Disconnected"])},url:[q,"v1","replay",F,z,r,s],data:t(p)})):ve("Missing Subscribe Key"):ve("Missing Publish Key"):ve("Missing Destination Channel"):ve("Missing Source Channel")},auth:function(e){G=e,$()},time:function(e){var n=we(),i={uuid:_e,auth:G};Ce&&(i.instanceid=ke),M({callback:n,data:t(i),url:[q,"time",n],success:function(t){e(t[0])},fail:function(){e(0)}})},publish:function(e,n){var i=e.message;if(!i)return ve("Missing Message");var r,s,n=n||e.callback||i.callback||e.success||function(){},o=e.channel||i.channel,a=e.meta||e.metadata,h=e.auth_key||G,l=e.cipher_key,f=e.error||i.error||function(){},p=e.post||!1,d=!("store_in_history"in e)||e.store_in_history,g=!("replicate"in e)||e.replicate,y=we(),m="push";return e.prepend&&(m="unshift"),o?F?z?(i.getPubnubMessage&&(i=i.getPubnubMessage()),i=JSON.stringify(c(i,l)),s=[q,"publish",F,z,0,u.encode(o),y,u.encode(i)],r={uuid:_e,auth:h},a&&"object"==typeof a&&(r.meta=JSON.stringify(a)),d||(r.store="0"),g||(r.norep="true"),Ce&&(r.instanceid=ke),Y[m]({callback:y,url:s,data:t(r),fail:function(e){D(e,f),C(1)},success:function(e){k(e,n,f),C(1)},mode:p?"POST":"GET"}),void C()):ve("Missing Subscribe Key"):ve("Missing Publish Key"):ve("Missing Channel")},fire:function(e,t){e.store_in_history=!1,e.replicate=!1,Be.publish(e,t)},unsubscribe:function(e,t){var n=e.channel,i=e.channel_group,r=e.auth_key||G,t=t||e.callback||function(){},s=e.error||function(){};if(!n&&!i)return ve("Missing Channel or Channel Group");if(!z)return ve("Missing Subscribe Key");if(n){var o=u.isArray(n)?n:(""+n).split(","),a=[],c=[];if(u.each(o,function(e){ae[e]&&a.push(e)}),0==a.length)return void t({action:"leave"});u.each(a,function(e){c.push(e+p)}),u.each(a.concat(c),function(e){e in ae&&delete ae[e],e in ue&&delete ue[e]}),0===ae.length&&0===ce.length&&(se=0),g=!0,l&&(g=Be.LEAVE(a.join(","),0,r,t,s)),g||t({action:"leave"})}if(i){var h=u.isArray(i)?i:(""+i).split(","),f=[],d=[];if(u.each(h,function(e){ce[e]&&f.push(e)}),0==f.length)return void t({action:"leave"});u.each(f,function(e){d.push(e+p)}),u.each(f.concat(d),function(e){e in ce&&delete ce[e],e in ue&&delete ue[e]}),0===ae.length&&0===ce.length&&(se=0);var g=!0;l&&(g=Be.LEAVE_GROUP(f.join(","),0,r,t,s)),g||t({action:"leave"})}$()},subscribe:function(e,n){function i(e){e?u.timeout($,B):(q=S(X),Q=S(X),u.timeout(function(){Be.time(i)},m)),E(function(t){if(e&&t.disconnected)return t.disconnected=0,t.reconnect(t.name);e||t.disconnected||(t.disconnected=1,t.disconnect(t.name))}),x(function(t){if(e&&t.disconnected)return t.disconnected=0,t.reconnect(t.name);e||t.disconnected||(t.disconnected=1,t.disconnect(t.name))})}function o(){var e=we(),n=r(ae).join(","),a=s(ce).join(",");if(n||a){n||(n=","),A();var c=t({uuid:_e,auth:G});a&&(c["channel-group"]=a),JSON.stringify(ue).length>2&&(c.state=JSON.stringify(ue)),le&&(c.heartbeat=le),Ce&&(c.instanceid=ke),_(),ie=M({timeout:O,callback:e,fail:function(e){e&&e.error&&e.service?(D(e,v),i(!1)):Be.time(function(t){!t&&D(e,v),i(t)})},data:t(c),url:[Q,"subscribe",z,u.encode(n),e,se],success:function(e){if(!e||"object"==typeof e&&"error"in e&&e.error)return v(e),u.timeout($,m);if(b(e[1]),se=!se&&re&&Se.get(z)||e[1],E(function(e){e.connected||(e.connected=1,e.connect(e.name))}),x(function(e){e.connected||(e.connected=1,e.connect(e.name))}),oe&&!re)return se=0,oe=!1,Se.set(z,0),void u.timeout(o,B);C&&(se=1e4,C=0),Se.set(z,e[1]);var t=function(){var t="",n="";e.length>3?(t=e[3],n=e[2]):t=e.length>2?e[2]:u.map(r(ae),function(t){return u.map(Array(e[0].length).join(",").split(","),function(){return t})}).join(",");var i=t.split(","),s=n?n.split(","):[];return function(){var e=i.shift()||ne,t=s.shift(),n={},r={callback:function(){}};t?(e&&e.indexOf("-pnpres")>=0&&t.indexOf("-pnpres")<0&&(t+="-pnpres"),n=ce[t]||ae[t]||r):n=ae[e]||r;var o=[n.callback||te,e.split(p)[0]];return t&&o.push(t.split(p)[0]),o}}(),n=function(e){return u.rnow()-ee-e/1e4}(+e[1]);u.each(e[0],function(i){var r=t(),s=h(i,ae[r[1]]?ae[r[1]].cipher_key:null);r[0]&&r[0](s,e,r[2]||r[1],n,r[1])}),u.timeout(o,B)}})}}var a=e.channel,c=e.channel_group,n=(n=n||e.callback)||e.message,d=e.connect||function(){},g=e.reconnect||function(){},y=e.disconnect||function(){},v=e.error||v||function(){},b=e.idle||function(){},w=e.presence||0,I=e.noheresync||0,C=e.backfill||0,k=e.timetoken||0,O=e.timeout||L,B=e.windowing||R,T=e.state,P=e.heartbeat||e.pnexpires,N=e.heartbeat_interval,j=e.restore||re;return G=e.auth_key||G,re=j,se=k,a||c?n?z?((P||0===P||N||0===N)&&Be.set_heartbeat(P,N),a&&u.each((a.join?a.join(","):""+a).split(","),function(i){var r=ae[i]||{};ae[ne=i]={name:i,connected:r.connected,disconnected:r.disconnected,subscribed:1,callback:te=n,cipher_key:e.cipher_key,connect:d,disconnect:y,reconnect:g},T&&(ue[i]=i in T?T[i]:T),w&&(Be.subscribe({channel:i+p,callback:w,restore:j}),r.subscribed||I||Be.here_now({channel:i,data:t({uuid:_e,auth:G}),callback:function(e){u.each("uuids"in e?e.uuids:[],function(t){w({action:"join",uuid:t,timestamp:Math.floor(u.rnow()/1e3),occupancy:e.occupancy||1},e,i)})}}))}),c&&u.each((c.join?c.join(","):""+c).split(","),function(i){var r=ce[i]||{};ce[i]={name:i,connected:r.connected,disconnected:r.disconnected,subscribed:1,callback:te=n,cipher_key:e.cipher_key,connect:d,disconnect:y,reconnect:g},w&&(Be.subscribe({channel_group:i+p,callback:w,restore:j,auth_key:G}),r.subscribed||I||Be.here_now({channel_group:i,data:t({uuid:_e,auth:G}),callback:function(e){u.each("uuids"in e?e.uuids:[],function(t){w({action:"join",uuid:t,timestamp:Math.floor(u.rnow()/1e3),occupancy:e.occupancy||1},e,i)})}}))}),$=function(){A(),u.timeout(o,B)},l?void $():f.push($)):ve("Missing Subscribe Key"):ve("Missing Callback"):ve("Missing Channel")},here_now:function(e,n){var n=e.callback||n,i=e.debug,r=e.error||function(){},s=e.auth_key||G,o=e.channel,a=e.channel_group,c=we(),h=!("uuids"in e)||e.uuids,l=e.state,f={uuid:_e,auth:s};if(h||(f.disable_uuids=1),l&&(f.state=1),!n)return ve("Missing Callback");if(!z)return ve("Missing Subscribe Key");var p=[q,"v2","presence","sub_key",z];o&&p.push("channel")&&p.push(u.encode(o)),"0"!=c&&(f.callback=c),a&&(f["channel-group"]=a,!o&&p.push("channel")&&p.push(",")),Ce&&(f.instanceid=ke),M({callback:c,data:t(f),success:function(e){k(e,n,r)},fail:function(e){D(e,r)},debug:i,url:p})},where_now:function(e,n){var n=e.callback||n,i=e.error||function(){},r=e.auth_key||G,s=we(),o=e.uuid||_e,a={auth:r};return n?z?("0"!=s&&(a.callback=s),Ce&&(a.instanceid=ke),void M({callback:s,data:t(a),success:function(e){k(e,n,i)},fail:function(e){D(e,i)},url:[q,"v2","presence","sub_key",z,"uuid",u.encode(o)]})):ve("Missing Subscribe Key"):ve("Missing Callback")},state:function(e,n){var i,n=e.callback||n||function(e){},r=e.error||function(){},s=e.auth_key||G,o=we(),a=e.state,c=e.uuid||_e,h=e.channel,l=e.channel_group,f=t({auth:s});return z?c?h||l?("0"!=o&&(f.callback=o),void 0!==h&&ae[h]&&ae[h].subscribed&&a&&(ue[h]=a),void 0!==l&&ce[l]&&ce[l].subscribed&&(a&&(ue[l]=a),f["channel-group"]=l,h||(h=",")),f.state=JSON.stringify(a),Ce&&(f.instanceid=ke),i=a?[q,"v2","presence","sub-key",z,"channel",h,"uuid",c,"data"]:[q,"v2","presence","sub-key",z,"channel",h,"uuid",u.encode(c)],void M({callback:o,data:t(f),success:function(e){k(e,n,r)},fail:function(e){D(e,r)},url:i})):ve("Missing Channel"):ve("Missing UUID"):ve("Missing Subscribe Key")},grant:function(e,n){var n=e.callback||n,i=e.error||function(){},r=e.channel||e.channels,s=e.channel_group,o=we(),a=e.ttl,c=e.read?"1":"0",h=e.write?"1":"0",l=e.manage?"1":"0",f=e.auth_key||e.auth_keys;if(!n)return ve("Missing Callback");if(!z)return ve("Missing Subscribe Key");if(!F)return ve("Missing Publish Key");if(!V)return ve("Missing Secret Key");var p={w:h,r:c};e.manage&&(p.m=l),u.isArray(r)&&(r=r.join(",")),u.isArray(f)&&(f=f.join(",")),void 0!==r&&null!=r&&r.length>0&&(p.channel=r),void 0!==s&&null!=s&&s.length>0&&(p["channel-group"]=s),"0"!=o&&(p.callback=o),(a||0===a)&&(p.ttl=a),f&&(p.auth=f),p=t(p),f||delete p.auth,M({operation:"PNAccessManagerGrant",callback:o,data:p,success:function(e){k(e,n,i)},fail:function(e){D(e,i)},url:[q,"v1","auth","grant","sub-key",z]})},mobile_gw_provision:function(e){var t,n,i=e.callback||function(){},r=e.auth_key||G,s=e.error||function(){},o=we(),a=e.channel,c=e.op,u=e.gw_type,h=e.device_id;return h?u?c?a?z?(n=[q,"v1/push/sub-key",z,"devices",h],t={uuid:_e,auth:r,type:u},"add"==c?t.add=a:"remove"==c&&(t.remove=a),Ce&&(t.instanceid=ke),void M({callback:o,data:t,success:function(e){k(e,i,s)},fail:function(e){D(e,s)},url:n})):ve("Missing Subscribe Key"):ve("Missing gw destination Channel (channel)"):ve("Missing GW Operation (op: add or remove)"):ve("Missing GW Type (gw_type: gcm or apns)"):ve("Missing Device ID (device_id)")},audit:function(e,n){var n=e.callback||n,i=e.error||function(){},r=e.channel,s=e.channel_group,o=e.auth_key,a=we();if(!n)return ve("Missing Callback");if(!z)return ve("Missing Subscribe Key");if(!F)return ve("Missing Publish Key");if(!V)return ve("Missing Secret Key");var c={};"0"!=a&&(c.callback=a),void 0!==r&&null!=r&&r.length>0&&(c.channel=r),void 0!==s&&null!=s&&s.length>0&&(c["channel-group"]=s),o&&(c.auth=o),c=t(c),o||delete c.auth,M({operation:"PNAccessManagerAudit",callback:a,data:c,success:function(e){k(e,n,i)},fail:function(e){D(e,i)},url:[q,"v1","auth","audit","sub-key",z]})},revoke:function(e,t){e.read=!1,e.write=!1,Be.grant(e,t)},set_uuid:function(e){_e=e,$()},get_uuid:function(){return _e},isArray:function(e){return u.isArray(e)},get_subscribed_channels:function(){return r(ae,!0)},presence_heartbeat:function(e){var n=e.callback||function(){},i=e.error||function(){},o=we(),a={uuid:_e,auth:G};JSON.stringify(ue).length>2&&(a.state=JSON.stringify(ue)),le>0&&le<320&&(a.heartbeat=le),"0"!=o&&(a.callback=o);var c=u.encode(r(ae,!0).join(",")),h=s(ce,!0).join(",");c||(c=","),h&&(a["channel-group"]=h),Ce&&(a.instanceid=ke),M({callback:o,data:t(a),url:[q,"v2","presence","sub-key",z,"channel",c,"heartbeat"],success:function(e){k(e,n,i)},fail:function(e){D(e,i)}})},stop_timers:function(){clearTimeout(N),clearTimeout(j),clearTimeout(he)},shutdown:function(){Be.stop_timers(),De&&De()},xdr:ye,ready:o,db:Se,uuid:u.generateUUID,map:u.map,each:u.each,"each-channel":E,grep:u.grep,offline:function(){A(1,{message:"Offline. Please check your network settings."})},supplant:u.supplant,now:u.rnow,unique:i,updater:u.updater};return _e||(_e=Be.uuid()),ke||(ke=Be.uuid()),Se.set(z+"uuid",_e),N=u.timeout(B,m),j=u.timeout(T,U),he=u.timeout(_,(fe-3)*m),P(),Be},unique:i,PNmessage:function(e){var t=e||{apns:{}};return t.getPubnubMessage=function(){var e={};if(Object.keys(t.apns).length){e.pn_apns={aps:{alert:t.apns.alert,badge:t.apns.badge,sound:t.apns.sound}};for(var n in t.apns)e.pn_apns[n]=t.apns[n];var i=["badge","alert","sound"];for(var n in i)delete e.pn_apns[i[n]]}t.gcm&&(e.pn_gcm={data:t.gcm});for(var n in t)e[n]=t[n];var r=["apns","gcm","publish","channel","callback","error"];for(var n in r)delete e[r[n]];return e},t.publish=function(){var e=t.getPubnubMessage();t.pubnub&&t.channel&&t.pubnub.publish({message:e,channel:t.channel,callback:t.callback,error:t.error})},t},DEF_TIMEOUT:15e3,timeout:u.timeout,build_url:u.buildURL,each:u.each,uuid:u.generateUUID,URLBIT:c.URLBIT,grep:u.grep,supplant:u.supplant,now:u.rnow,updater:u.updater,map:u.map}},function(e,t){e.exports={name:"pubnub",preferGlobal:!1,version:"3.16.5",author:"PubNub <[email protected]>",description:"Publish & Subscribe Real-time Messaging with PubNub",contributors:[{name:"Stephen Blum",email:"[email protected]"}],bin:{},scripts:{test:"grunt test --force"},main:"./node.js/pubnub.js",browser:"./modern/dist/pubnub.js",repository:{type:"git",url:"git://github.com/pubnub/javascript.git"},keywords:["cloud","publish","subscribe","websockets","comet","bosh","xmpp","real-time","messaging"],dependencies:{agentkeepalive:"~0.2",lodash:"^4.1.0"},noAnalyze:!1,devDependencies:{chai:"^3.5.0",eslint:"2.4.0","eslint-config-airbnb":"^6.0.2","eslint-plugin-flowtype":"^2.1.0","eslint-plugin-mocha":"^2.0.0","eslint-plugin-react":"^4.1.0","flow-bin":"^0.22.0",grunt:"^0.4.5","grunt-contrib-clean":"^1.0.0","grunt-contrib-copy":"^0.8.2","grunt-contrib-uglify":"^0.11.1","grunt-env":"^0.4.4","grunt-eslint":"^18.0.0","grunt-flow":"^1.0.3","grunt-karma":"^0.12.1","grunt-mocha-istanbul":"^3.0.1","grunt-text-replace":"^0.4.0","grunt-webpack":"^1.0.11","imports-loader":"^0.6.5",isparta:"^4.0.0","json-loader":"^0.5.4",karma:"^0.13.21","karma-chai":"^0.1.0","karma-mocha":"^0.2.1","karma-phantomjs-launcher":"^1.0.0","karma-spec-reporter":"0.0.24","load-grunt-tasks":"^3.4.0",mocha:"^2.4.5",nock:"^1.1.0","node-uuid":"^1.4.7",nodeunit:"^0.9.0","phantomjs-prebuilt":"^2.1.4",proxyquire:"^1.7.4",sinon:"^1.17.2","uglify-js":"^2.6.1",underscore:"^1.7.0",webpack:"^1.12.13","webpack-dev-server":"^1.14.1"},bundleDependencies:[],license:"MIT",engine:{node:">=0.8"},files:["core","node.js","modern","CHANGELOG","FUTURE.md","LICENSE","README.md"]}},function(e,t){e.exports={PARAMSBIT:"&",URLBIT:"/"}},function(e,t,n){function i(){return+new Date}function r(e){return!!e&&"string"!=typeof e&&(Array.isArray&&Array.isArray(e)||"number"==typeof e.length)}function s(e,t){if(e&&t)if(r(e))for(var n=0,i=e.length;n<i;)t.call(e[n],e[n],n++);else for(var n in e)e.hasOwnProperty&&e.hasOwnProperty(n)&&t.call(e[n],n,e[n])}function o(e){return encodeURIComponent(e)}var a=n(6),c=/{([\w\-]+)}/g;e.exports={buildURL:function(e,t){var n=e.join(a.URLBIT),i=[];return t?(s(t,function(e,t){var n="object"==typeof t?JSON.stringify(t):t;void 0!==t&&null!==t&&o(n).length>0&&i.push(e+"="+o(n))}),n+="?"+i.join(a.PARAMSBIT)):n},encode:o,each:s,updater:function(e,t){var n,r=0,s=function(){r+t>i()?(clearTimeout(n),n=setTimeout(s,t)):(r=i(),e())};return s},rnow:i,isArray:r,map:function(e,t){var n=[];return s(e||[],function(e,i){n.push(t(e,i))}),n},pamEncode:function(e){return encodeURIComponent(e).replace(/[!'()*~]/g,function(e){return"%"+e.charCodeAt(0).toString(16).toUpperCase()})},generateUUID: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 e&&e(t),t},timeout:function(e,t){if("undefined"!=typeof setTimeout)return setTimeout(e,t)},supplant:function(e,t){return e.replace(c,function(e,n){return t[n]||e})},grep:function(e,t){var n=[];return s(e||[],function(e){t(e)&&n.push(e)}),n}}},function(e,t){var n=function(e,t){if(!(this instanceof n))return new n(e,t);var i=this,e=i.url=e||"",r=(i.protocol=t||"Sec-WebSocket-Protocol",e.split("/")),s={ssl:"wss:"===r[0],origin:r[2],publish_key:r[3],subscribe_key:r[4],channel:r[5]};if(i.CONNECTING=0,i.OPEN=1,i.CLOSING=2,i.CLOSED=3,i.CLOSE_NORMAL=1e3,i.CLOSE_GOING_AWAY=1001,i.CLOSE_PROTOCOL_ERROR=1002,i.CLOSE_UNSUPPORTED=1003,i.CLOSE_TOO_LARGE=1004,i.CLOSE_NO_STATUS=1005,i.CLOSE_ABNORMAL=1006,i.onclose=i.onerror=i.onmessage=i.onopen=i.onsend=function(){},i.binaryType="",i.extensions="",i.bufferedAmount=0,i.trasnmitting=!1,i.buffer=[],i.readyState=i.CONNECTING,!e)return i.readyState=i.CLOSED,i.onclose({code:i.CLOSE_ABNORMAL,reason:"Missing URL",wasClean:!0}),i;i.pubnub=PUBNUB.init(s),i.pubnub.setup=s,i.setup=s,i.pubnub.subscribe({restore:!1,channel:s.channel,disconnect:i.onerror,reconnect:i.onopen,error:function(){i.onclose({code:i.CLOSE_ABNORMAL,reason:"Missing URL",wasClean:!1})},callback:function(e){i.onmessage({data:e})},connect:function(){i.readyState=i.OPEN,i.onopen()}})};n.prototype.send=function(e){var t=this;t.pubnub.publish({channel:t.pubnub.setup.channel,message:e,callback:function(e){t.onsend({data:e})}})},n.prototype.close=function(){this.pubnub.unsubscribe({channel:this.pubnub.setup.channel}),this.readyState=this.CLOSED,this.onclose({})},e.exports=n}])}),function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).SinchClient=e()}}(function(){return function e(t,n,i){function r(o,a){if(!n[o]){if(!t[o]){var c="function"==typeof require&&require;if(!a&&c)return c(o,!0);if(s)return s(o,!0);var u=new Error("Cannot find module '"+o+"'");throw u.code="MODULE_NOT_FOUND",u}var h=n[o]={exports:{}};t[o][0].call(h.exports,function(e){var n=t[o][1][e];return r(n||e)},h,h.exports,e,t,n,i)}return n[o].exports}for(var s="function"==typeof require&&require,o=0;o<i.length;o++)r(i[o]);return r}({1:[function(e,t,n){VERSION=["1.4.7-0-g5f65b78","1.4.7","0","5f65b78",null],n.version=VERSION},{}],2:[function(e,t,n){"use strict";function i(e){var t=e.length;if(t%4>0)throw new Error("Invalid string. Length must be a multiple of 4");return"="===e[t-2]?2:"="===e[t-1]?1:0}function r(e){return o[e>>18&63]+o[e>>12&63]+o[e>>6&63]+o[63&e]}function s(e,t,n){for(var i,s=[],o=t;o<n;o+=3)i=(e[o]<<16)+(e[o+1]<<8)+e[o+2],s.push(r(i));return s.join("")}n.byteLength=function(e){return 3*e.length/4-i(e)},n.toByteArray=function(e){var t,n,r,s,o,u=e.length;s=i(e),o=new c(3*u/4-s),n=s>0?u-4:u;var h=0;for(t=0;t<n;t+=4)r=a[e.charCodeAt(t)]<<18|a[e.charCodeAt(t+1)]<<12|a[e.charCodeAt(t+2)]<<6|a[e.charCodeAt(t+3)],o[h++]=r>>16&255,o[h++]=r>>8&255,o[h++]=255&r;return 2===s?(r=a[e.charCodeAt(t)]<<2|a[e.charCodeAt(t+1)]>>4,o[h++]=255&r):1===s&&(r=a[e.charCodeAt(t)]<<10|a[e.charCodeAt(t+1)]<<4|a[e.charCodeAt(t+2)]>>2,o[h++]=r>>8&255,o[h++]=255&r),o},n.fromByteArray=function(e){for(var t,n=e.length,i=n%3,r="",a=[],c=0,u=n-i;c<u;c+=16383)a.push(s(e,c,c+16383>u?u:c+16383));return 1===i?(t=e[n-1],r+=o[t>>2],r+=o[t<<4&63],r+="=="):2===i&&(t=(e[n-2]<<8)+e[n-1],r+=o[t>>10],r+=o[t>>4&63],r+=o[t<<2&63],r+="="),a.push(r),a.join("")};for(var o=[],a=[],c="undefined"!=typeof Uint8Array?Uint8Array:Array,u="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",h=0,l=u.length;h<l;++h)o[h]=u[h],a[u.charCodeAt(h)]=h;a["-".charCodeAt(0)]=62,a["_".charCodeAt(0)]=63},{}],3:[function(e,t,n){(function(e){!function(){"use strict";t.exports=function(t){return(t instanceof e?t:new e(t.toString(),"binary")).toString("base64")}}()}).call(this,e("buffer").Buffer)},{buffer:4}],4:[function(e,t,n){"use strict";function i(e){if(e>N)throw new RangeError("Invalid typed array length");var t=new Uint8Array(e);return t.__proto__=r.prototype,t}function r(e,t,n){if("number"==typeof e){if("string"==typeof t)throw new Error("If encoding is specified then the first argument must be a string");return a(e)}return s(e,t,n)}function s(e,t,n){if("number"==typeof e)throw new TypeError('"value" argument must not be a number');return O(e)?function(e,t,n){if(t<0||e.byteLength<t)throw new RangeError("'offset' is out of bounds");if(e.byteLength<t+(n||0))throw new RangeError("'length' is out of bounds");var i;i=void 0===t&&void 0===n?new Uint8Array(e):void 0===n?new Uint8Array(e,t):new Uint8Array(e,t,n);return i.__proto__=r.prototype,i}(e,t,n):"string"==typeof e?function(e,t){"string"==typeof t&&""!==t||(t="utf8");if(!r.isEncoding(t))throw new TypeError('"encoding" must be a valid string encoding');var n=0|h(e,t),s=i(n),o=s.write(e,t);o!==n&&(s=s.slice(0,o));return s}(e,t):function(e){if(r.isBuffer(e)){var t=0|u(e.length),n=i(t);return 0===n.length?n:(e.copy(n,0,0,t),n)}if(e){if(B(e)||"length"in e)return"number"!=typeof e.length||T(e.length)?i(0):c(e);if("Buffer"===e.type&&Array.isArray(e.data))return c(e.data)}throw new TypeError("First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.")}(e)}function o(e){if("number"!=typeof e)throw new TypeError('"size" argument must be a number');if(e<0)throw new RangeError('"size" argument must not be negative')}function a(e){return o(e),i(e<0?0:0|u(e))}function c(e){for(var t=e.length<0?0:0|u(e.length),n=i(t),r=0;r<t;r+=1)n[r]=255&e[r];return n}function u(e){if(e>=N)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+N.toString(16)+" bytes");return 0|e}function h(e,t){if(r.isBuffer(e))return e.length;if(B(e)||O(e))return e.byteLength;"string"!=typeof e&&(e=""+e);var n=e.length;if(0===n)return 0;for(var i=!1;;)switch(t){case"ascii":case"latin1":case"binary":return n;case"utf8":case"utf-8":case void 0:return k(e).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*n;case"hex":return n>>>1;case"base64":return D(e).length;default:if(i)return k(e).length;t=(""+t).toLowerCase(),i=!0}}function l(e,t,n){var i=!1;if((void 0===t||t<0)&&(t=0),t>this.length)return"";if((void 0===n||n>this.length)&&(n=this.length),n<=0)return"";if(n>>>=0,t>>>=0,n<=t)return"";for(e||(e="utf8");;)switch(e){case"hex":return function(e,t,n){var i=e.length;(!t||t<0)&&(t=0);(!n||n<0||n>i)&&(n=i);for(var r="",s=t;s<n;++s)r+=function(e){return e<16?"0"+e.toString(16):e.toString(16)}(e[s]);return r}(this,t,n);case"utf8":case"utf-8":return S(this,t,n);case"ascii":return function(e,t,n){var i="";n=Math.min(e.length,n);for(var r=t;r<n;++r)i+=String.fromCharCode(127&e[r]);return i}(this,t,n);case"latin1":case"binary":return function(e,t,n){var i="";n=Math.min(e.length,n);for(var r=t;r<n;++r)i+=String.fromCharCode(e[r]);return i}(this,t,n);case"base64":return function(e,t,n){return 0===t&&n===e.length?A.fromByteArray(e):A.fromByteArray(e.slice(t,n))}(this,t,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return function(e,t,n){for(var i=e.slice(t,n),r="",s=0;s<i.length;s+=2)r+=String.fromCharCode(i[s]+256*i[s+1]);return r}(this,t,n);default:if(i)throw new TypeError("Unknown encoding: "+e);e=(e+"").toLowerCase(),i=!0}}function f(e,t,n){var i=e[t];e[t]=e[n],e[n]=i}function p(e,t,n,i,s){if(0===e.length)return-1;if("string"==typeof n?(i=n,n=0):n>2147483647?n=2147483647:n<-2147483648&&(n=-2147483648),n=+n,T(n)&&(n=s?0:e.length-1),n<0&&(n=e.length+n),n>=e.length){if(s)return-1;n=e.length-1}else if(n<0){if(!s)return-1;n=0}if("string"==typeof t&&(t=r.from(t,i)),r.isBuffer(t))return 0===t.length?-1:d(e,t,n,i,s);if("number"==typeof t)return t&=255,"function"==typeof Uint8Array.prototype.indexOf?s?Uint8Array.prototype.indexOf.call(e,t,n):Uint8Array.prototype.lastIndexOf.call(e,t,n):d(e,[t],n,i,s);throw new TypeError("val must be string, number or Buffer")}function d(e,t,n,i,r){function s(e,t){return 1===o?e[t]:e.readUInt16BE(t*o)}var o=1,a=e.length,c=t.length;if(void 0!==i&&("ucs2"===(i=String(i).toLowerCase())||"ucs-2"===i||"utf16le"===i||"utf-16le"===i)){if(e.length<2||t.length<2)return-1;o=2,a/=2,c/=2,n/=2}var u;if(r){var h=-1;for(u=n;u<a;u++)if(s(e,u)===s(t,-1===h?0:u-h)){if(-1===h&&(h=u),u-h+1===c)return h*o}else-1!==h&&(u-=u-h),h=-1}else for(n+c>a&&(n=a-c),u=n;u>=0;u--){for(var l=!0,f=0;f<c;f++)if(s(e,u+f)!==s(t,f)){l=!1;break}if(l)return u}return-1}function g(e,t,n,i){n=Number(n)||0;var r=e.length-n;i?(i=Number(i))>r&&(i=r):i=r;var s=t.length;if(s%2!=0)throw new TypeError("Invalid hex string");i>s/2&&(i=s/2);for(var o=0;o<i;++o){var a=parseInt(t.substr(2*o,2),16);if(T(a))return o;e[n+o]=a}return o}function y(e,t,n,i){return M(k(t,e.length-n),e,n,i)}function m(e,t,n,i){return M(function(e){for(var t=[],n=0;n<e.length;++n)t.push(255&e.charCodeAt(n));return t}(t),e,n,i)}function v(e,t,n,i){return m(e,t,n,i)}function b(e,t,n,i){return M(D(t),e,n,i)}function w(e,t,n,i){return M(function(e,t){for(var n,i,r,s=[],o=0;o<e.length&&!((t-=2)<0);++o)n=e.charCodeAt(o),i=n>>8,r=n%256,s.push(r),s.push(i);return s}(t,e.length-n),e,n,i)}function S(e,t,n){n=Math.min(e.length,n);for(var i=[],r=t;r<n;){var s=e[r],o=null,a=s>239?4:s>223?3:s>191?2:1;if(r+a<=n){var c,u,h,l;switch(a){case 1:s<128&&(o=s);break;case 2:128==(192&(c=e[r+1]))&&(l=(31&s)<<6|63&c)>127&&(o=l);break;case 3:c=e[r+1],u=e[r+2],128==(192&c)&&128==(192&u)&&(l=(15&s)<<12|(63&c)<<6|63&u)>2047&&(l<55296||l>57343)&&(o=l);break;case 4:c=e[r+1],u=e[r+2],h=e[r+3],128==(192&c)&&128==(192&u)&&128==(192&h)&&(l=(15&s)<<18|(63&c)<<12|(63&u)<<6|63&h)>65535&&l<1114112&&(o=l)}}null===o?(o=65533,a=1):o>65535&&(o-=65536,i.push(o>>>10&1023|55296),o=56320|1023&o),i.push(o),r+=a}return function(e){var t=e.length;if(t<=j)return String.fromCharCode.apply(String,e);var n="",i=0;for(;i<t;)n+=String.fromCharCode.apply(String,e.slice(i,i+=j));return n}(i)}function I(e,t,n){if(e%1!=0||e<0)throw new RangeError("offset is not uint");if(e+t>n)throw new RangeError("Trying to access beyond buffer length")}function _(e,t,n,i,s,o){if(!r.isBuffer(e))throw new TypeError('"buffer" argument must be a Buffer instance');if(t>s||t<o)throw new RangeError('"value" argument is out of bounds');if(n+i>e.length)throw new RangeError("Index out of range")}function C(e,t,n,i,r,s){if(n+i>e.length)throw new RangeError("Index out of range");if(n<0)throw new RangeError("Index out of range")}function x(e,t,n,i,r){return t=+t,n>>>=0,r||C(e,0,n,4),P.write(e,t,n,i,23,4),n+4}function E(e,t,n,i,r){return t=+t,n>>>=0,r||C(e,0,n,8),P.write(e,t,n,i,52,8),n+8}function k(e,t){t=t||1/0;for(var n,i=e.length,r=null,s=[],o=0;o<i;++o){if((n=e.charCodeAt(o))>55295&&n<57344){if(!r){if(n>56319){(t-=3)>-1&&s.push(239,191,189);continue}if(o+1===i){(t-=3)>-1&&s.push(239,191,189);continue}r=n;continue}if(n<56320){(t-=3)>-1&&s.push(239,191,189),r=n;continue}n=65536+(r-55296<<10|n-56320)}else r&&(t-=3)>-1&&s.push(239,191,189);if(r=null,n<128){if((t-=1)<0)break;s.push(n)}else if(n<2048){if((t-=2)<0)break;s.push(n>>6|192,63&n|128)}else if(n<65536){if((t-=3)<0)break;s.push(n>>12|224,n>>6&63|128,63&n|128)}else{if(!(n<1114112))throw new Error("Invalid code point");if((t-=4)<0)break;s.push(n>>18|240,n>>12&63|128,n>>6&63|128,63&n|128)}}return s}function D(e){return A.toByteArray(function(e){if((e=e.trim().replace(R,"")).length<2)return"";for(;e.length%4!=0;)e+="=";return e}(e))}function M(e,t,n,i){for(var r=0;r<i&&!(r+n>=t.length||r>=e.length);++r)t[r+n]=e[r];return r}function O(e){return e instanceof ArrayBuffer||null!=e&&null!=e.constructor&&"ArrayBuffer"===e.constructor.name&&"number"==typeof e.byteLength}function B(e){return"function"==typeof ArrayBuffer.isView&&ArrayBuffer.isView(e)}function T(e){return e!=e}var A=e("base64-js"),P=e("ieee754");n.Buffer=r,n.SlowBuffer=function(e){return+e!=e&&(e=0),r.alloc(+e)},n.INSPECT_MAX_BYTES=50;var N=2147483647;n.kMaxLength=N,(r.TYPED_ARRAY_SUPPORT=function(){try{var e=new Uint8Array(1);return e.__proto__={__proto__:Uint8Array.prototype,foo:function(){return 42}},42===e.foo()}catch(e){return!1}}())||"undefined"==typeof console||"function"!=typeof console.error||console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support."),"undefined"!=typeof Symbol&&Symbol.species&&r[Symbol.species]===r&&Object.defineProperty(r,Symbol.species,{value:null,configurable:!0,enumerable:!1,writable:!1}),r.poolSize=8192,r.from=function(e,t,n){return s(e,t,n)},r.prototype.__proto__=Uint8Array.prototype,r.__proto__=Uint8Array,r.alloc=function(e,t,n){return function(e,t,n){return o(e),e<=0?i(e):void 0!==t?"string"==typeof n?i(e).fill(t,n):i(e).fill(t):i(e)}(e,t,n)},r.allocUnsafe=function(e){return a(e)},r.allocUnsafeSlow=function(e){return a(e)},r.isBuffer=function(e){return null!=e&&!0===e._isBuffer},r.compare=function(e,t){if(!r.isBuffer(e)||!r.isBuffer(t))throw new TypeError("Arguments must be Buffers");if(e===t)return 0;for(var n=e.length,i=t.length,s=0,o=Math.min(n,i);s<o;++s)if(e[s]!==t[s]){n=e[s],i=t[s];break}return n<i?-1:i<n?1:0},r.isEncoding=function(e){switch(String(e).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},r.concat=function(e,t){if(!Array.isArray(e))throw new TypeError('"list" argument must be an Array of Buffers');if(0===e.length)return r.alloc(0);var n;if(void 0===t)for(t=0,n=0;n<e.length;++n)t+=e[n].length;var i=r.allocUnsafe(t),s=0;for(n=0;n<e.length;++n){var o=e[n];if(!r.isBuffer(o))throw new TypeError('"list" argument must be an Array of Buffers');o.copy(i,s),s+=o.length}return i},r.byteLength=h,r.prototype._isBuffer=!0,r.prototype.swap16=function(){var e=this.length;if(e%2!=0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(var t=0;t<e;t+=2)f(this,t,t+1);return this},r.prototype.swap32=function(){var e=this.length;if(e%4!=0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(var t=0;t<e;t+=4)f(this,t,t+3),f(this,t+1,t+2);return this},r.prototype.swap64=function(){var e=this.length;if(e%8!=0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(var t=0;t<e;t+=8)f(this,t,t+7),f(this,t+1,t+6),f(this,t+2,t+5),f(this,t+3,t+4);return this},r.prototype.toString=function(){var e=this.length;return 0===e?"":0===arguments.length?S(this,0,e):l.apply(this,arguments)},r.prototype.equals=function(e){if(!r.isBuffer(e))throw new TypeError("Argument must be a Buffer");return this===e||0===r.compare(this,e)},r.prototype.inspect=function(){var e="",t=n.INSPECT_MAX_BYTES;return this.length>0&&(e=this.toString("hex",0,t).match(/.{2}/g).join(" "),this.length>t&&(e+=" ... ")),"<Buffer "+e+">"},r.prototype.compare=function(e,t,n,i,s){if(!r.isBuffer(e))throw new TypeError("Argument must be a Buffer");if(void 0===t&&(t=0),void 0===n&&(n=e?e.length:0),void 0===i&&(i=0),void 0===s&&(s=this.length),t<0||n>e.length||i<0||s>this.length)throw new RangeError("out of range index");if(i>=s&&t>=n)return 0;if(i>=s)return-1;if(t>=n)return 1;if(t>>>=0,n>>>=0,i>>>=0,s>>>=0,this===e)return 0;for(var o=s-i,a=n-t,c=Math.min(o,a),u=this.slice(i,s),h=e.slice(t,n),l=0;l<c;++l)if(u[l]!==h[l]){o=u[l],a=h[l];break}return o<a?-1:a<o?1:0},r.prototype.includes=function(e,t,n){return-1!==this.indexOf(e,t,n)},r.prototype.indexOf=function(e,t,n){return p(this,e,t,n,!0)},r.prototype.lastIndexOf=function(e,t,n){return p(this,e,t,n,!1)},r.prototype.write=function(e,t,n,i){if(void 0===t)i="utf8",n=this.length,t=0;else if(void 0===n&&"string"==typeof t)i=t,n=this.length,t=0;else{if(!isFinite(t))throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");t>>>=0,isFinite(n)?(n>>>=0,void 0===i&&(i="utf8")):(i=n,n=void 0)}var r=this.length-t;if((void 0===n||n>r)&&(n=r),e.length>0&&(n<0||t<0)||t>this.length)throw new RangeError("Attempt to write outside buffer bounds");i||(i="utf8");for(var s=!1;;)switch(i){case"hex":return g(this,e,t,n);case"utf8":case"utf-8":return y(this,e,t,n);case"ascii":return m(this,e,t,n);case"latin1":case"binary":return v(this,e,t,n);case"base64":return b(this,e,t,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return w(this,e,t,n);default:if(s)throw new TypeError("Unknown encoding: "+i);i=(""+i).toLowerCase(),s=!0}},r.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var j=4096;r.prototype.slice=function(e,t){var n=this.length;e=~~e,t=void 0===t?n:~~t,e<0?(e+=n)<0&&(e=0):e>n&&(e=n),t<0?(t+=n)<0&&(t=0):t>n&&(t=n),t<e&&(t=e);var i=this.subarray(e,t);return i.__proto__=r.prototype,i},r.prototype.readUIntLE=function(e,t,n){e>>>=0,t>>>=0,n||I(e,t,this.length);for(var i=this[e],r=1,s=0;++s<t&&(r*=256);)i+=this[e+s]*r;return i},r.prototype.readUIntBE=function(e,t,n){e>>>=0,t>>>=0,n||I(e,t,this.length);for(var i=this[e+--t],r=1;t>0&&(r*=256);)i+=this[e+--t]*r;return i},r.prototype.readUInt8=function(e,t){return e>>>=0,t||I(e,1,this.length),this[e]},r.prototype.readUInt16LE=function(e,t){return e>>>=0,t||I(e,2,this.length),this[e]|this[e+1]<<8},r.prototype.readUInt16BE=function(e,t){return e>>>=0,t||I(e,2,this.length),this[e]<<8|this[e+1]},r.prototype.readUInt32LE=function(e,t){return e>>>=0,t||I(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+16777216*this[e+3]},r.prototype.readUInt32BE=function(e,t){return e>>>=0,t||I(e,4,this.length),16777216*this[e]+(this[e+1]<<16|this[e+2]<<8|this[e+3])},r.prototype.readIntLE=function(e,t,n){e>>>=0,t>>>=0,n||I(e,t,this.length);for(var i=this[e],r=1,s=0;++s<t&&(r*=256);)i+=this[e+s]*r;return r*=128,i>=r&&(i-=Math.pow(2,8*t)),i},r.prototype.readIntBE=function(e,t,n){e>>>=0,t>>>=0,n||I(e,t,this.length);for(var i=t,r=1,s=this[e+--i];i>0&&(r*=256);)s+=this[e+--i]*r;return r*=128,s>=r&&(s-=Math.pow(2,8*t)),s},r.prototype.readInt8=function(e,t){return e>>>=0,t||I(e,1,this.length),128&this[e]?-1*(255-this[e]+1):this[e]},r.prototype.readInt16LE=function(e,t){e>>>=0,t||I(e,2,this.length);var n=this[e]|this[e+1]<<8;return 32768&n?4294901760|n:n},r.prototype.readInt16BE=function(e,t){e>>>=0,t||I(e,2,this.length);var n=this[e+1]|this[e]<<8;return 32768&n?4294901760|n:n},r.prototype.readInt32LE=function(e,t){return e>>>=0,t||I(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24},r.prototype.readInt32BE=function(e,t){return e>>>=0,t||I(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]},r.prototype.readFloatLE=function(e,t){return e>>>=0,t||I(e,4,this.length),P.read(this,e,!0,23,4)},r.prototype.readFloatBE=function(e,t){return e>>>=0,t||I(e,4,this.length),P.read(this,e,!1,23,4)},r.prototype.readDoubleLE=function(e,t){return e>>>=0,t||I(e,8,this.length),P.read(this,e,!0,52,8)},r.prototype.readDoubleBE=function(e,t){return e>>>=0,t||I(e,8,this.length),P.read(this,e,!1,52,8)},r.prototype.writeUIntLE=function(e,t,n,i){if(e=+e,t>>>=0,n>>>=0,!i){_(this,e,t,n,Math.pow(2,8*n)-1,0)}var r=1,s=0;for(this[t]=255&e;++s<n&&(r*=256);)this[t+s]=e/r&255;return t+n},r.prototype.writeUIntBE=function(e,t,n,i){if(e=+e,t>>>=0,n>>>=0,!i){_(this,e,t,n,Math.pow(2,8*n)-1,0)}var r=n-1,s=1;for(this[t+r]=255&e;--r>=0&&(s*=256);)this[t+r]=e/s&255;return t+n},r.prototype.writeUInt8=function(e,t,n){return e=+e,t>>>=0,n||_(this,e,t,1,255,0),this[t]=255&e,t+1},r.prototype.writeUInt16LE=function(e,t,n){return e=+e,t>>>=0,n||_(this,e,t,2,65535,0),this[t]=255&e,this[t+1]=e>>>8,t+2},r.prototype.writeUInt16BE=function(e,t,n){return e=+e,t>>>=0,n||_(this,e,t,2,65535,0),this[t]=e>>>8,this[t+1]=255&e,t+2},r.prototype.writeUInt32LE=function(e,t,n){return e=+e,t>>>=0,n||_(this,e,t,4,4294967295,0),this[t+3]=e>>>24,this[t+2]=e>>>16,this[t+1]=e>>>8,this[t]=255&e,t+4},r.prototype.writeUInt32BE=function(e,t,n){return e=+e,t>>>=0,n||_(this,e,t,4,4294967295,0),this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e,t+4},r.prototype.writeIntLE=function(e,t,n,i){if(e=+e,t>>>=0,!i){var r=Math.pow(2,8*n-1);_(this,e,t,n,r-1,-r)}var s=0,o=1,a=0;for(this[t]=255&e;++s<n&&(o*=256);)e<0&&0===a&&0!==this[t+s-1]&&(a=1),this[t+s]=(e/o>>0)-a&255;return t+n},r.prototype.writeIntBE=function(e,t,n,i){if(e=+e,t>>>=0,!i){var r=Math.pow(2,8*n-1);_(this,e,t,n,r-1,-r)}var s=n-1,o=1,a=0;for(this[t+s]=255&e;--s>=0&&(o*=256);)e<0&&0===a&&0!==this[t+s+1]&&(a=1),this[t+s]=(e/o>>0)-a&255;return t+n},r.prototype.writeInt8=function(e,t,n){return e=+e,t>>>=0,n||_(this,e,t,1,127,-128),e<0&&(e=255+e+1),this[t]=255&e,t+1},r.prototype.writeInt16LE=function(e,t,n){return e=+e,t>>>=0,n||_(this,e,t,2,32767,-32768),this[t]=255&e,this[t+1]=e>>>8,t+2},r.prototype.writeInt16BE=function(e,t,n){return e=+e,t>>>=0,n||_(this,e,t,2,32767,-32768),this[t]=e>>>8,this[t+1]=255&e,t+2},r.prototype.writeInt32LE=function(e,t,n){return e=+e,t>>>=0,n||_(this,e,t,4,2147483647,-2147483648),this[t]=255&e,this[t+1]=e>>>8,this[t+2]=e>>>16,this[t+3]=e>>>24,t+4},r.prototype.writeInt32BE=function(e,t,n){return e=+e,t>>>=0,n||_(this,e,t,4,2147483647,-2147483648),e<0&&(e=4294967295+e+1),this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e,t+4},r.prototype.writeFloatLE=function(e,t,n){return x(this,e,t,!0,n)},r.prototype.writeFloatBE=function(e,t,n){return x(this,e,t,!1,n)},r.prototype.writeDoubleLE=function(e,t,n){return E(this,e,t,!0,n)},r.prototype.writeDoubleBE=function(e,t,n){return E(this,e,t,!1,n)},r.prototype.copy=function(e,t,n,i){if(n||(n=0),i||0===i||(i=this.length),t>=e.length&&(t=e.length),t||(t=0),i>0&&i<n&&(i=n),i===n)return 0;if(0===e.length||0===this.length)return 0;if(t<0)throw new RangeError("targetStart out of bounds");if(n<0||n>=this.length)throw new RangeError("sourceStart out of bounds");if(i<0)throw new RangeError("sourceEnd out of bounds");i>this.length&&(i=this.length),e.length-t<i-n&&(i=e.length-t+n);var r,s=i-n;if(this===e&&n<t&&t<i)for(r=s-1;r>=0;--r)e[r+t]=this[r+n];else if(s<1e3)for(r=0;r<s;++r)e[r+t]=this[r+n];else Uint8Array.prototype.set.call(e,this.subarray(n,n+s),t);return s},r.prototype.fill=function(e,t,n,i){if("string"==typeof e){if("string"==typeof t?(i=t,t=0,n=this.length):"string"==typeof n&&(i=n,n=this.length),1===e.length){var s=e.charCodeAt(0);s<256&&(e=s)}if(void 0!==i&&"string"!=typeof i)throw new TypeError("encoding must be a string");if("string"==typeof i&&!r.isEncoding(i))throw new TypeError("Unknown encoding: "+i)}else"number"==typeof e&&(e&=255);if(t<0||this.length<t||this.length<n)throw new RangeError("Out of range index");if(n<=t)return this;t>>>=0,n=void 0===n?this.length:n>>>0,e||(e=0);var o;if("number"==typeof e)for(o=t;o<n;++o)this[o]=e;else{var a=r.isBuffer(e)?e:new r(e,i),c=a.length;for(o=0;o<n-t;++o)this[o+t]=a[o%c]}return this};var R=/[^+/0-9A-Za-z-_]/g},{"base64-js":2,ieee754:11}],5:[function(e,t,n){!function(e,i){"object"==typeof n?t.exports=n=i():e.CryptoJS=i()}(this,function(){var e=e||function(e,t){var n=Object.create||function(){function e(){}return function(t){var n;return e.prototype=t,n=new e,e.prototype=null,n}}(),i={},r=i.lib={},s=r.Base={extend:function(e){var t=n(this);return e&&t.mixIn(e),t.hasOwnProperty("init")&&this.init!==t.init||(t.init=function(){t.$super.init.apply(this,arguments)}),t.init.prototype=t,t.$super=this,t},create:function(){var e=this.extend();return e.init.apply(e,arguments),e},init:function(){},mixIn:function(e){for(var t in e)e.hasOwnProperty(t)&&(this[t]=e[t]);e.hasOwnProperty("toString")&&(this.toString=e.toString)},clone:function(){return this.init.prototype.extend(this)}},o=r.WordArray=s.extend({init:function(e,t){e=this.words=e||[],this.sigBytes=void 0!=t?t:4*e.length},toString:function(e){return(e||c).stringify(this)},concat:function(e){var t=this.words,n=e.words,i=this.sigBytes,r=e.sigBytes;if(this.clamp(),i%4)for(o=0;o<r;o++){var s=n[o>>>2]>>>24-o%4*8&255;t[i+o>>>2]|=s<<24-(i+o)%4*8}else for(var o=0;o<r;o+=4)t[i+o>>>2]=n[o>>>2];return this.sigBytes+=r,this},clamp:function(){var t=this.words,n=this.sigBytes;t[n>>>2]&=4294967295<<32-n%4*8,t.length=e.ceil(n/4)},clone:function(){var e=s.clone.call(this);return e.words=this.words.slice(0),e},random:function(t){for(var n,i=[],r=function(t){var t=t,n=987654321;return function(){var i=((n=36969*(65535&n)+(n>>16)&4294967295)<<16)+(t=18e3*(65535&t)+(t>>16)&4294967295)&4294967295;return i/=4294967296,(i+=.5)*(e.random()>.5?1:-1)}},s=0;s<t;s+=4){var a=r(4294967296*(n||e.random()));n=987654071*a(),i.push(4294967296*a()|0)}return new o.init(i,t)}}),a=i.enc={},c=a.Hex={stringify:function(e){for(var t=e.words,n=e.sigBytes,i=[],r=0;r<n;r++){var s=t[r>>>2]>>>24-r%4*8&255;i.push((s>>>4).toString(16)),i.push((15&s).toString(16))}return i.join("")},parse:function(e){for(var t=e.length,n=[],i=0;i<t;i+=2)n[i>>>3]|=parseInt(e.substr(i,2),16)<<24-i%8*4;return new o.init(n,t/2)}},u=a.Latin1={stringify:function(e){for(var t=e.words,n=e.sigBytes,i=[],r=0;r<n;r++){var s=t[r>>>2]>>>24-r%4*8&255;i.push(String.fromCharCode(s))}return i.join("")},parse:function(e){for(var t=e.length,n=[],i=0;i<t;i++)n[i>>>2]|=(255&e.charCodeAt(i))<<24-i%4*8;return new o.init(n,t)}},h=a.Utf8={stringify:function(e){try{return decodeURIComponent(escape(u.stringify(e)))}catch(e){throw new Error("Malformed UTF-8 data")}},parse:function(e){return u.parse(unescape(encodeURIComponent(e)))}},l=r.BufferedBlockAlgorithm=s.extend({reset:function(){this._data=new o.init,this._nDataBytes=0},_append:function(e){"string"==typeof e&&(e=h.parse(e)),this._data.concat(e),this._nDataBytes+=e.sigBytes},_process:function(t){var n=this._data,i=n.words,r=n.sigBytes,s=this.blockSize,a=r/(4*s),c=(a=t?e.ceil(a):e.max((0|a)-this._minBufferSize,0))*s,u=e.min(4*c,r);if(c){for(var h=0;h<c;h+=s)this._doProcessBlock(i,h);var l=i.splice(0,c);n.sigBytes-=u}return new o.init(l,u)},clone:function(){var e=s.clone.call(this);return e._data=this._data.clone(),e},_minBufferSize:0}),f=(r.Hasher=l.extend({cfg:s.extend(),init:function(e){this.cfg=this.cfg.extend(e),this.reset()},reset:function(){l.reset.call(this),this._doReset()},update:function(e){return this._append(e),this._process(),this},finalize:function(e){e&&this._append(e);return this._doFinalize()},blockSize:16,_createHelper:function(e){return function(t,n){return new e.init(n).finalize(t)}},_createHmacHelper:function(e){return function(t,n){return new f.HMAC.init(e,n).finalize(t)}}}),i.algo={});return i}(Math);return e})},{}],6:[function(e,t,n){!function(i,r){"object"==typeof n?t.exports=n=r(e("./core")):r(i.CryptoJS)}(this,function(e){return function(){var t=e,n=t.lib.WordArray;t.enc.Base64={stringify:function(e){var t=e.words,n=e.sigBytes,i=this._map;e.clamp();for(var r=[],s=0;s<n;s+=3)for(var o=(t[s>>>2]>>>24-s%4*8&255)<<16|(t[s+1>>>2]>>>24-(s+1)%4*8&255)<<8|t[s+2>>>2]>>>24-(s+2)%4*8&255,a=0;a<4&&s+.75*a<n;a++)r.push(i.charAt(o>>>6*(3-a)&63));var c=i.charAt(64);if(c)for(;r.length%4;)r.push(c);return r.join("")},parse:function(e){var t=e.length,i=this._map,r=this._reverseMap;if(!r){r=this._reverseMap=[];for(var s=0;s<i.length;s++)r[i.charCodeAt(s)]=s}var o=i.charAt(64);if(o){var a=e.indexOf(o);-1!==a&&(t=a)}return function(e,t,i){for(var r=[],s=0,o=0;o<t;o++)if(o%4){var a=i[e.charCodeAt(o-1)]<<o%4*2,c=i[e.charCodeAt(o)]>>>6-o%4*2;r[s>>>2]|=(a|c)<<24-s%4*8,s++}return n.create(r,s)}(e,t,r)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="}}(),e.enc.Base64})},{"./core":5}],7:[function(e,t,n){!function(i,r){"object"==typeof n?t.exports=n=r(e("./core")):r(i.CryptoJS)}(this,function(e){return e.enc.Utf8})},{"./core":5}],8:[function(e,t,n){!function(i,r,s){"object"==typeof n?t.exports=n=r(e("./core"),e("./sha256"),e("./hmac")):r(i.CryptoJS)}(this,function(e){return e.HmacSHA256})},{"./core":5,"./hmac":9,"./sha256":10}],9:[function(e,t,n){!function(i,r){"object"==typeof n?t.exports=n=r(e("./core")):r(i.CryptoJS)}(this,function(e){!function(){var t=e,n=t.lib.Base,i=t.enc.Utf8;t.algo.HMAC=n.extend({init:function(e,t){e=this._hasher=new e.init,"string"==typeof t&&(t=i.parse(t));var n=e.blockSize,r=4*n;t.sigBytes>r&&(t=e.finalize(t)),t.clamp();for(var s=this._oKey=t.clone(),o=this._iKey=t.clone(),a=s.words,c=o.words,u=0;u<n;u++)a[u]^=1549556828,c[u]^=909522486;s.sigBytes=o.sigBytes=r,this.reset()},reset:function(){var e=this._hasher;e.reset(),e.update(this._iKey)},update:function(e){return this._hasher.update(e),this},finalize:function(e){var t=this._hasher,n=t.finalize(e);t.reset();return t.finalize(this._oKey.clone().concat(n))}})}()})},{"./core":5}],10:[function(e,t,n){!function(i,r){"object"==typeof n?t.exports=n=r(e("./core")):r(i.CryptoJS)}(this,function(e){return function(t){var n=e,i=n.lib,r=i.WordArray,s=i.Hasher,o=n.algo,a=[],c=[];!function(){function e(e){for(var n=t.sqrt(e),i=2;i<=n;i++)if(!(e%i))return!1;return!0}function n(e){return 4294967296*(e-(0|e))|0}for(var i=2,r=0;r<64;)e(i)&&(r<8&&(a[r]=n(t.pow(i,.5))),c[r]=n(t.pow(i,1/3)),r++),i++}();var u=[],h=o.SHA256=s.extend({_doReset:function(){this._hash=new r.init(a.slice(0))},_doProcessBlock:function(e,t){for(var n=this._hash.words,i=n[0],r=n[1],s=n[2],o=n[3],a=n[4],h=n[5],l=n[6],f=n[7],p=0;p<64;p++){if(p<16)u[p]=0|e[t+p];else{var d=u[p-15],g=(d<<25|d>>>7)^(d<<14|d>>>18)^d>>>3,y=u[p-2],m=(y<<15|y>>>17)^(y<<13|y>>>19)^y>>>10;u[p]=g+u[p-7]+m+u[p-16]}var v=i&r^i&s^r&s,b=(i<<30|i>>>2)^(i<<19|i>>>13)^(i<<10|i>>>22),w=f+((a<<26|a>>>6)^(a<<21|a>>>11)^(a<<7|a>>>25))+(a&h^~a&l)+c[p]+u[p];f=l,l=h,h=a,a=o+w|0,o=s,s=r,r=i,i=w+(b+v)|0}n[0]=n[0]+i|0,n[1]=n[1]+r|0,n[2]=n[2]+s|0,n[3]=n[3]+o|0,n[4]=n[4]+a|0,n[5]=n[5]+h|0,n[6]=n[6]+l|0,n[7]=n[7]+f|0},_doFinalize:function(){var e=this._data,n=e.words,i=8*this._nDataBytes,r=8*e.sigBytes;return n[r>>>5]|=128<<24-r%32,n[14+(r+64>>>9<<4)]=t.floor(i/4294967296),n[15+(r+64>>>9<<4)]=i,e.sigBytes=4*n.length,this._process(),this._hash},clone:function(){var e=s.clone.call(this);return e._hash=this._hash.clone(),e}});n.SHA256=s._createHelper(h),n.HmacSHA256=s._createHmacHelper(h)}(Math),e.SHA256})},{"./core":5}],11:[function(e,t,n){n.read=function(e,t,n,i,r){var s,o,a=8*r-i-1,c=(1<<a)-1,u=c>>1,h=-7,l=n?r-1:0,f=n?-1:1,p=e[t+l];for(l+=f,s=p&(1<<-h)-1,p>>=-h,h+=a;h>0;s=256*s+e[t+l],l+=f,h-=8);for(o=s&(1<<-h)-1,s>>=-h,h+=i;h>0;o=256*o+e[t+l],l+=f,h-=8);if(0===s)s=1-u;else{if(s===c)return o?NaN:1/0*(p?-1:1);o+=Math.pow(2,i),s-=u}return(p?-1:1)*o*Math.pow(2,s-i)},n.write=function(e,t,n,i,r,s){var o,a,c,u=8*s-r-1,h=(1<<u)-1,l=h>>1,f=23===r?Math.pow(2,-24)-Math.pow(2,-77):0,p=i?0:s-1,d=i?1:-1,g=t<0||0===t&&1/t<0?1:0;for(t=Math.abs(t),isNaN(t)||t===1/0?(a=isNaN(t)?1:0,o=h):(o=Math.floor(Math.log(t)/Math.LN2),t*(c=Math.pow(2,-o))<1&&(o--,c*=2),(t+=o+l>=1?f/c:f*Math.pow(2,1-l))*c>=2&&(o++,c/=2),o+l>=h?(a=0,o=h):o+l>=1?(a=(t*c-1)*Math.pow(2,r),o+=l):(a=t*Math.pow(2,l-1)*Math.pow(2,r),o=0));r>=8;e[n+p]=255&a,p+=d,a/=256,r-=8);for(o=o<<r|a,u+=r;u>0;e[n+p]=255&o,p+=d,o/=256,u-=8);e[n+p-d]|=128*g}},{}],12:[function(e,t,n){function i(){throw new Error("setTimeout has not been defined")}function r(){throw new Error("clearTimeout has not been defined")}function s(e){if(h===setTimeout)return setTimeout(e,0);if((h===i||!h)&&setTimeout)return h=setTimeout,setTimeout(e,0);try{return h(e,0)}catch(t){try{return h.call(null,e,0)}catch(t){return h.call(this,e,0)}}}function o(){g&&p&&(g=!1,p.length?d=p.concat(d):y=-1,d.length&&a())}function a(){if(!g){var e=s(o);g=!0;for(var t=d.length;t;){for(p=d,d=[];++y<t;)p&&p[y].run();y=-1,t=d.length}p=null,g=!1,function(e){if(l===clearTimeout)return clearTimeout(e);if((l===r||!l)&&clearTimeout)return l=clearTimeout,clearTimeout(e);try{l(e)}catch(t){try{return l.call(null,e)}catch(t){return l.call(this,e)}}}(e)}}function c(e,t){this.fun=e,this.array=t}function u(){}var h,l,f=t.exports={};!function(){try{h="function"==typeof setTimeout?setTimeout:i}catch(e){h=i}try{l="function"==typeof clearTimeout?clearTimeout:r}catch(e){l=r}}();var p,d=[],g=!1,y=-1;f.nextTick=function(e){var t=new Array(arguments.length-1);if(arguments.length>1)for(var n=1;n<arguments.length;n++)t[n-1]=arguments[n];d.push(new c(e,t)),1!==d.length||g||s(a)},c.prototype.run=function(){this.fun.apply(null,this.array)},f.title="browser",f.browser=!0,f.env={},f.argv=[],f.version="",f.versions={},f.on=u,f.addListener=u,f.once=u,f.off=u,f.removeListener=u,f.removeAllListeners=u,f.emit=u,f.prependListener=u,f.prependOnceListener=u,f.listeners=function(e){return[]},f.binding=function(e){throw new Error("process.binding is not supported")},f.cwd=function(){return"/"},f.chdir=function(e){throw new Error("process.chdir is not supported")},f.umask=function(){return 0}},{}],13:[function(e,t,n){(function(e){!function(e){"use strict";if("function"==typeof bootstrap)bootstrap("promise",e);else if("object"==typeof n&&"object"==typeof t)t.exports=e();else if("undefined"!=typeof ses){if(!ses.ok())return;ses.makeQ=e}else{if("undefined"==typeof window&&"undefined"==typeof self)throw new Error("This environment was not anticipated by Q. Please file a bug.");var i="undefined"!=typeof window?window:self,r=i.Q;i.Q=e(),i.Q.noConflict=function(){return i.Q=r,this}}}(function(){"use strict";function t(e){return function(){return D.apply(e,arguments)}}function n(e,t){if(I&&t.stack&&"object"==typeof e&&null!==e&&e.stack){for(var n=[],r=t;r;r=r.source)r.stack&&(!e.__minimumStackCounter__||e.__minimumStackCounter__>r.stackCounter)&&(P(e,"__minimumStackCounter__",{value:r.stackCounter,configurable:!0}),n.unshift(r.stack));n.unshift(e.stack);var s=function(e){for(var t=e.split("\n"),n=[],r=0;r<t.length;++r){var s=t[r];(function(e){var t=i(e);if(!t)return!1;var n=t[0],r=t[1];return n===_&&r>=x&&r<=G})(s)||function(e){return-1!==e.indexOf("(module.js:")||-1!==e.indexOf("(node.js:")}(s)||!s||n.push(s)}return n.join("\n")}(n.join("\n"+L+"\n"));P(e,"stack",{value:s,configurable:!0})}}function i(e){var t=/at .+ \((.+):(\d+):(?:\d+)\)$/.exec(e);if(t)return[t[1],Number(t[2])];var n=/at ([^ ]+):(\d+):(?:\d+)$/.exec(e);if(n)return[n[1],Number(n[2])];var i=/.*@(.+):(\d+)$/.exec(e);return i?[i[1],Number(i[2])]:void 0}function r(){if(I)try{throw new Error}catch(n){var e=n.stack.split("\n"),t=i(e[0].indexOf("@")>0?e[1]:e[2]);if(!t)return;return _=t[0],t[1]}}function s(e){return e instanceof u?e:p(e)?function(e){var t=o();return s.nextTick(function(){try{e.then(t.resolve,t.reject,t.notify)}catch(e){t.reject(e)}}),t.promise}(e):y(e)}function o(){function e(e){t=e,s.longStackSupport&&I&&(a.source=e),O(n,function(t,n){s.nextTick(function(){e.promiseDispatch.apply(e,n)})},void 0),n=void 0,i=void 0}var t,n=[],i=[],r=A(o.prototype),a=A(u.prototype);if(a.promiseDispatch=function(e,r,o){var a=M(arguments);n?(n.push(a),"when"===r&&o[1]&&i.push(o[1])):s.nextTick(function(){t.promiseDispatch.apply(t,a)})},a.valueOf=function(){if(n)return a;var e=l(t);return f(e)&&(t=e),e},a.inspect=function(){return t?t.inspect():{state:"pending"}},s.longStackSupport&&I)try{throw new Error}catch(e){a.stack=e.stack.substring(e.stack.indexOf("\n")+1),a.stackCounter=U++}return r.promise=a,r.resolve=function(n){t||e(s(n))},r.fulfill=function(n){t||e(y(n))},r.reject=function(n){t||e(g(n))},r.notify=function(e){t||O(i,function(t,n){s.nextTick(function(){n(e)})},void 0)},r}function a(e){if("function"!=typeof e)throw new TypeError("resolver must be a function.");var t=o();try{e(t.resolve,t.reject,t.notify)}catch(e){t.reject(e)}return t.promise}function c(e){return a(function(t,n){for(var i=0,r=e.length;i<r;i++)s(e[i]).then(t,n)})}function u(e,t,n){void 0===t&&(t=function(e){return g(new Error("Promise does not support operation: "+e))}),void 0===n&&(n=function(){return{state:"unknown"}});var i=A(u.prototype);if(i.promiseDispatch=function(n,r,s){var o;try{o=e[r]?e[r].apply(i,s):t.call(i,r,s)}catch(e){o=g(e)}n&&n(o)},i.inspect=n,n){var r=n();"rejected"===r.state&&(i.exception=r.reason),i.valueOf=function(){var e=n();return"pending"===e.state||"rejected"===e.state?i:e.value}}return i}function h(e,t,n,i){return s(e).then(t,n,i)}function l(e){if(f(e)){var t=e.inspect();if("fulfilled"===t.state)return t.value}return e}function f(e){return e instanceof u}function p(e){return function(e){return e===Object(e)}(e)&&"function"==typeof e.then}function d(){K.length=0,H.length=0,z||(z=!0)}function g(t){var n=u({when:function(n){return n&&function(t){if(z){var n=B(H,t);-1!==n&&("object"==typeof e&&"function"==typeof e.emit&&s.nextTick.runAfter(function(){var i=B(F,t);-1!==i&&(e.emit("rejectionHandled",K[n],t),F.splice(i,1))}),H.splice(n,1),K.splice(n,1))}}(this),n?n(t):this}},function(){return this},function(){return{state:"rejected",reason:t}});return function(t,n){z&&("object"==typeof e&&"function"==typeof e.emit&&s.nextTick.runAfter(function(){-1!==B(H,t)&&(e.emit("unhandledRejection",n,t),F.push(t))}),H.push(t),n&&void 0!==n.stack?K.push(n.stack):K.push("(no stack) "+n))}(n,t),n}function y(e){return u({when:function(){return e},get:function(t){return e[t]},set:function(t,n){e[t]=n},delete:function(t){delete e[t]},post:function(t,n){return null===t||void 0===t?e.apply(void 0,n):e[t].apply(e,n)},apply:function(t,n){return e.apply(t,n)},keys:function(){return j(e)}},void 0,function(){return{state:"fulfilled",value:e}})}function m(e,t,n){return s(e).spread(t,n)}function v(e,t,n){return s(e).dispatch(t,n)}function b(e){return h(e,function(e){var t=0,n=o();return O(e,function(i,r,s){var o;f(r)&&"fulfilled"===(o=r.inspect()).state?e[s]=o.value:(++t,h(r,function(i){e[s]=i,0==--t&&n.resolve(e)},n.reject,function(e){n.notify({index:s,value:e})}))},void 0),0===t&&n.resolve(e),n.promise})}function w(e){if(0===e.length)return s.resolve();var t=s.defer(),n=0;return O(e,function(i,r,s){var o=e[s];n++,h(o,function(e){t.resolve(e)},function(e){if(0==--n){var i=e||new Error(""+e);i.message="Q can't get fulfillment value from any promise, all promises were rejected. Last error message: "+i.message,t.reject(i)}},function(e){t.notify({index:s,value:e})})},void 0),t.promise}function S(e){return h(e,function(e){return e=T(e,s),h(b(T(e,function(e){return h(e,E,E)})),function(){return e})})}var I=!1;try{throw new Error}catch(e){I=!!e.stack}var _,C,x=r(),E=function(){},k=function(){function t(){for(var e,t;i.next;)e=(i=i.next).task,i.task=void 0,(t=i.domain)&&(i.domain=void 0,t.enter()),n(e,t);for(;c.length;)n(e=c.pop());s=!1}function n(e,n){try{e()}catch(e){if(a)throw n&&n.exit(),setTimeout(t,0),n&&n.enter(),e;setTimeout(function(){throw e},0)}n&&n.exit()}var i={task:void 0,next:null},r=i,s=!1,o=void 0,a=!1,c=[];if(k=function(t){r=r.next={task:t,domain:a&&e.domain,next:null},s||(s=!0,o())},"object"==typeof e&&"[object process]"===e.toString()&&e.nextTick)a=!0,o=function(){e.nextTick(t)};else if("function"==typeof setImmediate)o="undefined"!=typeof window?setImmediate.bind(window,t):function(){setImmediate(t)};else if("undefined"!=typeof MessageChannel){var u=new MessageChannel;u.port1.onmessage=function(){o=h,u.port1.onmessage=t,t()};var h=function(){u.port2.postMessage(0)};o=function(){setTimeout(t,0),h()}}else o=function(){setTimeout(t,0)};return k.runAfter=function(e){c.push(e),s||(s=!0,o())},k}(),D=Function.call,M=t(Array.prototype.slice),O=t(Array.prototype.reduce||function(e,t){var n=0,i=this.length;if(1===arguments.length)for(;;){if(n in this){t=this[n++];break}if(++n>=i)throw new TypeError}for(;n<i;n++)n in this&&(t=e(t,this[n],n));return t}),B=t(Array.prototype.indexOf||function(e){for(var t=0;t<this.length;t++)if(this[t]===e)return t;return-1}),T=t(Array.prototype.map||function(e,t){var n=this,i=[];return O(n,function(r,s,o){i.push(e.call(t,s,o,n))},void 0),i}),A=Object.create||function(e){function t(){}return t.prototype=e,new t},P=Object.defineProperty||function(e,t,n){return e[t]=n.value,e},N=t(Object.prototype.hasOwnProperty),j=Object.keys||function(e){var t=[];for(var n in e)N(e,n)&&t.push(n);return t},R=t(Object.prototype.toString);C="undefined"!=typeof ReturnValue?ReturnValue:function(e){this.value=e};var L="From previous event:";s.resolve=s,s.nextTick=k,s.longStackSupport=!1;var U=1;"object"==typeof e&&e&&e.env&&e.env.Q_DEBUG&&(s.longStackSupport=!0),s.defer=o,o.prototype.makeNodeResolver=function(){var e=this;return function(t,n){t?e.reject(t):arguments.length>2?e.resolve(M(arguments,1)):e.resolve(n)}},s.Promise=a,s.promise=a,a.race=c,a.all=b,a.reject=g,a.resolve=s,s.passByCopy=function(e){return e},u.prototype.passByCopy=function(){return this},s.join=function(e,t){return s(e).join(t)},u.prototype.join=function(e){return s([this,e]).spread(function(e,t){if(e===t)return e;throw new Error("Q can't join: not the same: "+e+" "+t)})},s.race=c,u.prototype.race=function(){return this.then(s.race)},s.makePromise=u,u.prototype.toString=function(){return"[object Promise]"},u.prototype.then=function(e,t,i){var r=this,a=o(),c=!1;return s.nextTick(function(){r.promiseDispatch(function(t){c||(c=!0,a.resolve(function(t){try{return"function"==typeof e?e(t):t}catch(e){return g(e)}}(t)))},"when",[function(e){c||(c=!0,a.resolve(function(e){if("function"==typeof t){n(e,r);try{return t(e)}catch(e){return g(e)}}return g(e)}(e)))}])}),r.promiseDispatch(void 0,"when",[void 0,function(e){var t,n=!1;try{t=function(e){return"function"==typeof i?i(e):e}(e)}catch(e){if(n=!0,!s.onerror)throw e;s.onerror(e)}n||a.notify(t)}]),a.promise},s.tap=function(e,t){return s(e).tap(t)},u.prototype.tap=function(e){return e=s(e),this.then(function(t){return e.fcall(t).thenResolve(t)})},s.when=h,u.prototype.thenResolve=function(e){return this.then(function(){return e})},s.thenResolve=function(e,t){return s(e).thenResolve(t)},u.prototype.thenReject=function(e){return this.then(function(){throw e})},s.thenReject=function(e,t){return s(e).thenReject(t)},s.nearer=l,s.isPromise=f,s.isPromiseAlike=p,s.isPending=function(e){return f(e)&&"pending"===e.inspect().state},u.prototype.isPending=function(){return"pending"===this.inspect().state},s.isFulfilled=function(e){return!f(e)||"fulfilled"===e.inspect().state},u.prototype.isFulfilled=function(){return"fulfilled"===this.inspect().state},s.isRejected=function(e){return f(e)&&"rejected"===e.inspect().state},u.prototype.isRejected=function(){return"rejected"===this.inspect().state};var K=[],H=[],F=[],z=!0;s.resetUnhandledRejections=d,s.getUnhandledReasons=function(){return K.slice()},s.stopUnhandledRejectionTracking=function(){d(),z=!1},d(),s.reject=g,s.fulfill=y,s.master=function(e){return u({isDef:function(){}},function(t,n){return v(e,t,n)},function(){return s(e).inspect()})},s.spread=m,u.prototype.spread=function(e,t){return this.all().then(function(t){return e.apply(void 0,t)},t)},s.async=function(e){return function(){function t(e,t){var o;if("undefined"==typeof StopIteration){try{o=n[e](t)}catch(e){return g(e)}return o.done?s(o.value):h(o.value,i,r)}try{o=n[e](t)}catch(e){return function(e){return"[object StopIteration]"===R(e)||e instanceof C}(e)?s(e.value):g(e)}return h(o,i,r)}var n=e.apply(this,arguments),i=t.bind(t,"next"),r=t.bind(t,"throw");return i()}},s.spawn=function(e){s.done(s.async(e)())},s.return=function(e){throw new C(e)},s.promised=function(e){return function(){return m([this,b(arguments)],function(t,n){return e.apply(t,n)})}},s.dispatch=v,u.prototype.dispatch=function(e,t){var n=this,i=o();return s.nextTick(function(){n.promiseDispatch(i.resolve,e,t)}),i.promise},s.get=function(e,t){return s(e).dispatch("get",[t])},u.prototype.get=function(e){return this.dispatch("get",[e])},s.set=function(e,t,n){return s(e).dispatch("set",[t,n])},u.prototype.set=function(e,t){return this.dispatch("set",[e,t])},s.del=s.delete=function(e,t){return s(e).dispatch("delete",[t])},u.prototype.del=u.prototype.delete=function(e){return this.dispatch("delete",[e])},s.mapply=s.post=function(e,t,n){return s(e).dispatch("post",[t,n])},u.prototype.mapply=u.prototype.post=function(e,t){return this.dispatch("post",[e,t])},s.send=s.mcall=s.invoke=function(e,t){return s(e).dispatch("post",[t,M(arguments,2)])},u.prototype.send=u.prototype.mcall=u.prototype.invoke=function(e){return this.dispatch("post",[e,M(arguments,1)])},s.fapply=function(e,t){return s(e).dispatch("apply",[void 0,t])},u.prototype.fapply=function(e){return this.dispatch("apply",[void 0,e])},s.try=s.fcall=function(e){return s(e).dispatch("apply",[void 0,M(arguments,1)])},u.prototype.fcall=function(){return this.dispatch("apply",[void 0,M(arguments)])},s.fbind=function(e){var t=s(e),n=M(arguments,1);return function(){return t.dispatch("apply",[this,n.concat(M(arguments))])}},u.prototype.fbind=function(){var e=this,t=M(arguments);return function(){return e.dispatch("apply",[this,t.concat(M(arguments))])}},s.keys=function(e){return s(e).dispatch("keys",[])},u.prototype.keys=function(){return this.dispatch("keys",[])},s.all=b,u.prototype.all=function(){return b(this)},s.any=w,u.prototype.any=function(){return w(this)},s.allResolved=function(e,t,n){return function(){return"undefined"!=typeof console&&"function"==typeof console.warn&&console.warn(t+" is deprecated, use "+n+" instead.",new Error("").stack),e.apply(e,arguments)}}(S,"allResolved","allSettled"),u.prototype.allResolved=function(){return S(this)},s.allSettled=function(e){return s(e).allSettled()},u.prototype.allSettled=function(){return this.then(function(e){return b(T(e,function(e){function t(){return e.inspect()}return(e=s(e)).then(t,t)}))})},s.fail=s.catch=function(e,t){return s(e).then(void 0,t)},u.prototype.fail=u.prototype.catch=function(e){return this.then(void 0,e)},s.progress=function(e,t){return s(e).then(void 0,void 0,t)},u.prototype.progress=function(e){return this.then(void 0,void 0,e)},s.fin=s.finally=function(e,t){return s(e).finally(t)},u.prototype.fin=u.prototype.finally=function(e){if(!e||"function"!=typeof e.apply)throw new Error("Q can't apply finally callback");return e=s(e),this.then(function(t){return e.fcall().then(function(){return t})},function(t){return e.fcall().then(function(){throw t})})},s.done=function(e,t,n,i){return s(e).done(t,n,i)},u.prototype.done=function(t,i,r){var o=function(e){s.nextTick(function(){if(n(e,a),!s.onerror)throw e;s.onerror(e)})},a=t||i||r?this.then(t,i,r):this;"object"==typeof e&&e&&e.domain&&(o=e.domain.bind(o)),a.then(void 0,o)},s.timeout=function(e,t,n){return s(e).timeout(t,n)},u.prototype.timeout=function(e,t){var n=o(),i=setTimeout(function(){t&&"string"!=typeof t||((t=new Error(t||"Timed out after "+e+" ms")).code="ETIMEDOUT"),n.reject(t)},e);return this.then(function(e){clearTimeout(i),n.resolve(e)},function(e){clearTimeout(i),n.reject(e)},n.notify),n.promise},s.delay=function(e,t){return void 0===t&&(t=e,e=void 0),s(e).delay(t)},u.prototype.delay=function(e){return this.then(function(t){var n=o();return setTimeout(function(){n.resolve(t)},e),n.promise})},s.nfapply=function(e,t){return s(e).nfapply(t)},u.prototype.nfapply=function(e){var t=o(),n=M(e);return n.push(t.makeNodeResolver()),this.fapply(n).fail(t.reject),t.promise},s.nfcall=function(e){var t=M(arguments,1);return s(e).nfapply(t)},u.prototype.nfcall=function(){var e=M(arguments),t=o();return e.push(t.makeNodeResolver()),this.fapply(e).fail(t.reject),t.promise},s.nfbind=s.denodeify=function(e){if(void 0===e)throw new Error("Q can't wrap an undefined function");var t=M(arguments,1);return function(){var n=t.concat(M(arguments)),i=o();return n.push(i.makeNodeResolver()),s(e).fapply(n).fail(i.reject),i.promise}},u.prototype.nfbind=u.prototype.denodeify=function(){var e=M(arguments);return e.unshift(this),s.denodeify.apply(void 0,e)},s.nbind=function(e,t){var n=M(arguments,2);return function(){var i=n.concat(M(arguments)),r=o();return i.push(r.makeNodeResolver()),s(function(){return e.apply(t,arguments)}).fapply(i).fail(r.reject),r.promise}},u.prototype.nbind=function(){var e=M(arguments,0);return e.unshift(this),s.nbind.apply(void 0,e)},s.nmapply=s.npost=function(e,t,n){return s(e).npost(t,n)},u.prototype.nmapply=u.prototype.npost=function(e,t){var n=M(t||[]),i=o();return n.push(i.makeNodeResolver()),this.dispatch("post",[e,n]).fail(i.reject),i.promise},s.nsend=s.nmcall=s.ninvoke=function(e,t){var n=M(arguments,2),i=o();return n.push(i.makeNodeResolver()),s(e).dispatch("post",[t,n]).fail(i.reject),i.promise},u.prototype.nsend=u.prototype.nmcall=u.prototype.ninvoke=function(e){var t=M(arguments,1),n=o();return t.push(n.makeNodeResolver()),this.dispatch("post",[e,t]).fail(n.reject),n.promise},s.nodeify=function(e,t){return s(e).nodeify(t)},u.prototype.nodeify=function(e){if(!e)return this;this.then(function(t){s.nextTick(function(){e(null,t)})},function(t){s.nextTick(function(){e(t)})})},s.noConflict=function(){throw new Error("Q.noConflict only works when Q is used as a global")};var G=r();return s})}).call(this,e("_process"))},{_process:12}],14:[function(e,t,n){var i=e("btoa"),r=(e("atob"),e("crypto-js/hmac-sha256")),s=e("crypto-js/enc-base64");e("crypto-js/enc-utf8");t.exports=function(e,t,n,o){var a={applicationKey:e,identity:{type:"username",endpoint:n.username},created:o||(new Date).toISOString(),expiresIn:86400},c=JSON.stringify(a).replace(" ","");return{userTicket:i(c)+":"+r(c,s.parse(t)).toString(s)}}},{atob:15,btoa:3,"crypto-js/enc-base64":6,"crypto-js/enc-utf8":7,"crypto-js/hmac-sha256":8}],15:[function(e,t,n){(function(e){!function(){"use strict";t.exports=function(t){return new e(t,"base64").toString("binary")}}()}).call(this,e("buffer").Buffer)},{buffer:4}],16:[function(e,t,n){function Notification(e,t,n,i){this.progress=e/t,this.message=n,this.object=i}function i(){var e,t=navigator.userAgent,n=t.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i)||t.match(/(applewebkit(?=\/))\/?\s*(\d+)/i)||[];return/trident/i.test(n[1])?"IE "+((e=/\brv[ :]+(\d+)/g.exec(t)||[])[1]||""):"Chrome"===n[1]&&null!=(e=t.match(/\bOPR\/(\d+)/))?"Opera "+e[1]:(n=n[2]?[n[1],n[2]]:[navigator.appName,navigator.appVersion,"-?"],null!=(e=t.match(/version\/(\d+)/i))&&n.splice(1,1,e[1]),n.join("/").substring(0,50))}function r(){return navigator.platform}function s(e){if(!e)throw new TypeError("Could not create SinchClient, configuration not provided.");if(e.capabilities=e.capabilities||{},"string"!=typeof e.applicationKey)throw new TypeError("Could not create SinchClient, applicationKey is not a string");this.capabilities=e.capabilities,this._appKey=e.applicationKey||"",this._appSecret=e.applicationSecret||void 0,this._sessionId="",this._sessionSecret="",this._logHandler=e.onLogMessage||function(){},this._logMxpHandler=e.onLogMxpMessage||function(){},this._onlineCapability=e.startActiveConnection||e.supportActiveConnection||!1,this._autoStartMxp=e.startActiveConnection||!1,this._expiresIn=e.expiresIn||86400,this._subInstanceId=Math.round(Math.random()*Math.pow(2,32)),this._customStream=e.customStream||void 0,this._supportVideo=e.capabilities.video||!1,this._multiCall=e.capabilities.multiCall||!1,this.applicationKey=this._appKey,this._supportManagedPush=e.supportManagedPush,this._progressTimeout=e.progressTimeout||10500,this.firefox=!1,"undefined"!=typeof navigator&&(this.firefox=(navigator||{userAgent:""}).userAgent.indexOf("Firefox")>0),this._url={base:"https://api.sinch.com/v1/",user:"https://userapi.sinch.com/v1/",portal:"https://portalapi.sinch.com/v1/",reporting:"https://reportingapi.sinch.com/v1/",reporting_v2:"https://reportingapi.sinch.com/v2/",calling:"https://callingapi.sinch.com/v1/",messaging:"https://messagingapi.sinch.com/v1/",verification:"https://verificationapi-v1.sinch.com/verification/v1/"},this.setUrl(e.urlObj||{}),this.loadPAPIUrl(),this.loadTimeDelta(),this.user=new g(this),"messaging"in this.capabilities&&this.capabilities.messaging&&(this.messageClient=new d(this)),"calling"in this.capabilities&&this.capabilities.calling&&(this.callClient=new c(this,e.customStream)),"stealth"in this.capabilities&&this.capabilities.stealth&&(this.callClient=new c(this,e.customStream))}function o(e,t,n){this.sinch=e,this.eventListeners=[],this.callId=n||E(),this.callDomain="None",this.callOutbound=void 0,this.fromId="",this.toId="",this.sinch.firefox,this.webRtcConfig={iceServers:[{urls:["stun:23.21.150.121","stun:stun.l.google.com:19302"]}]};var s=navigator.userAgent.match(/Chrom[e|ium]\/([0-9]+)\./),o=!!s&&parseInt(s[1],10),a=navigator.userAgent.match(/Firefox\/([0-9]+)\./),c=!!a&&parseInt(a[1],10);(o>=48||c>=42)&&(this.sinch.log(new Notification(0,1,"Chrome >= 48 or FF >= 42 detected, will generate certificate manually for better compatibility")),D.generateCertificate({name:"ECDSA",namedCurve:"P-256"}).then(function(e){this.sinch.log(new Notification(0,1,"New certificate generated and configured!")),this.webRtcConfig.certificates=[e]}.bind(this))),this.outgoingStream=void 0,this.outgoingStreamURL=void 0,this.incomingStream=void 0,this.incomingStreamURL=void 0,this.earlymedia=void 0,this.callState=T.INITIATING,this.callEndCause=A.NONE,this.timeProgressing=null,this.timeEstablished=null,this.timeEnded=null,this.error=null,this.autoAnswer=!1,this.autoHangup=!1,this.videoSupport=t||!1,this.clientMap={},this.instanceMap={},this.sdpMap={},this.iceMapRx={},this.iceMapTx=[],this.activeInstance=void 0,this.pcMap={},this.dataChannels={},this.proxyUrl=void 0,this.customHeaders=void 0,this.sdpAnswerBuffer={},this.joinBuffer={};var u={onCallEnded:function(e){this.sinch.mxp.unsubscribe("signalPubNub")}.bind(this)};this.addEventListener(u);var h="web",l="0";try{h=i().split("/")[0],l=i().split("/")[1]}catch(e){}var f={onCallEnded:function(t){var n=t.getDetails();if(n.startedTime){var i={callId:t.callId,domain:t.callDomain,outbound:t.callOutbound,fromId:t.fromId,toId:t.toId,callTime:new Date(n.startedTime).toISOString(),duration:n.duration,setupDuration:(t.timeEstablished-t.timeProgressing)/1e3||0,result:t.callEndCause,deviceInformation:{ModelId:r()||"unknown",OSName:h,OSVersion:l,SDKPlatform:"js",SDKPlatformVersion:e.getVersion()}};t.sinch.callReporting(i).fail(function(){console.error("Could not report call!")})}t.ffIceTimer&&clearInterval(t.ffIceTimer)}};this.addEventListener(f)}function a(e){this.endCause=e.endCause,this.endedTime=e.endedTime,this.error=e.error,this.establishedTime=e.establishedTime,this.startedTime=e.startedTime,this.duration=e.duration}function c(e,t){if(!(e instanceof s))throw new Error("CallClient can't be instantiated, use getCallClient in an SinchClient instance");var n=navigator.userAgent.toLowerCase();if(n.indexOf("msie")>-1||/Apple Computer/.test(navigator.vendor)||/Edge/.test(n))throw new Error("SinchClient can't be started with calling capability. Browser not supported.");this.sinch=e,this.eventListeners=[],this.callBuffert={},this.localMediaStream=void 0,this.incomingCallCustomStream=t,this.groupChannel=void 0}function u(e,t,n){if(!(e instanceof s))throw new SinchError(_.ErrorDomainVerification,C.VerificationInvalidInput,"Invalid input to constructor. VerificationClient can not be instantiated, use createSmsVerification in an SinchClient instance",error);if(void 0===t||0==t.toString().length)throw new SinchError(_.ErrorDomainVerification,C.VerificationInvalidInput,"Invalid input to constructor. Valid phone number required (E.164 format ideally)",t);this.sinch=e,this.number=t||null,this.custom=n||null,this.flagVerified=!1}function h(e,t,n){if(!(e instanceof s))throw new SinchError(_.ErrorDomainVerification,C.VerificationInvalidInput,"Invalid input to constructor. VerificationClient can not be instantiated, use createSmsVerification in an SinchClient instance",error);if(void 0===t||0==t.toString().length)throw new SinchError(_.ErrorDomainVerification,C.VerificationInvalidInput,"Invalid input to constructor. Valid phone number required (E.164 format ideally)",t);this.sinch=e,this.number=t||null,this.custom=n||null,this.flagVerified=!1}function l(e,t){this.sinch=e,this.callClient=e.callClient,this.groupChannel=t,this.eventListeners=[],this.callBuffert=[],this.callListeners={onCallProgressing:function(e){this.sinch.log(new Notification(0,1,"Call progressing",e))}.bind(this),onCallEstablished:function(e){this.sinch.log(new Notification(0,1,"Call established",e)),this.execListener("onGroupRemoteCallAdded",e)}.bind(this),onCallEnded:function(e){this.sinch.log(new Notification(0,1,"Call ended",e)),this.execListener("onGroupRemoteCallRemoved",e)}.bind(this)},this.groupListener={onIncomingCall:function(e){e.addEventListener(this.callListeners),setTimeout(function(){e.answer()},450*Object.keys(this.callBuffert).length+Math.random())}.bind(this)},this.callClient.addEventListener(this.groupListener),this.sinch.callClient.initStream().then(function(e){this.sinch.log(new Notification(0,1,"Media stream successfully created",e)),this.execListener("onGroupLocalMediaAdded",e),this.sinch.mxp.broadcastPubNub.publish({channel:t,message:this.sinch.user.userId}),this.sinch.mxp.subscribeNotificationChannel(t)}.bind(this)),this.sinch.onnotification=function(e,n){t==e&&n!=this.sinch.user.userId&&(this.sinch.log(new Notification(0,1,"Will call user in group, after random timeout",n)),setTimeout(function(){var e=this.callClient.callUser(n);this.callBuffert.push(e),e.addEventListener(this.callListeners)}.bind(this),300+Math.round(500*Math.random())))}.bind(this)}function f(e,t){if(this.delivered=[],this.direction=!t,e instanceof v){this.messageId=e.mxpSessionId;var n=JSON.parse(e.decrypted.bd);this.textBody=n.t,this.recipientIds=e.recipientIds,this.senderId=e.decrypted.fu;try{this.headers=e.decrypted.nvps.ph}catch(e){}this.timestamp=new Date}else{if(!(e instanceof Object))throw new SinchError(_.ErrorDomainSDK,C.SDKMissingParameter,"Unsupported message parameters",e);this.messageId=E(),this.recipientIds=e.recipientIds,this.textBody=e.textBody,this.senderId=e.senderId,this.headers=e.publicHeaders,this.timestamp=new Date}}function p(e,t){this.messageId=t,this.recipientId=e,this.timestamp=new Date}function d(e){if(!(e instanceof s))throw new Error("MessageClient can't be instantiated, use getMessageClient in an SinchClient instance");this.sinch=e,this.eventListeners=[],this.messageBuffert={},this.ackBuffert={},this.onMessageDelivered=[],this.emptyLog(),this.messageLogInterval=setInterval(this.commitLog.bind(this),3e4)}function SinchError(e,t,n,i){this.name="SinchError",this.domain=e||-1,this.code=t||0,this.response=i||{},this.message=n||"General sinch error",this.stack=new Error(n).stack}function g(e){this.userObj={},this.sinch=e}function y(e,t,n,i){if(!(e instanceof s))throw new SinchError(_.ErrorDomainVerification,C.VerificationInvalidInput,"Invalid input to constructor. VerificationClient can not be instantiated, use createSmsVerification in an SinchClient instance",error);if(void 0===t||0==t.toString().length)throw new SinchError(_.ErrorDomainVerification,C.VerificationInvalidInput,"Invalid input to constructor. Valid phone number required (E.164 format ideally)",t);this.method=i||"sms",this.sinch=e,this.number=t||null,this.custom=n||null,this.flagVerified=!1}function m(e,t,n,i){this.name="MXPError",this.domain=e||-1,this.code=t||0,this.response=i||{},this.message=n||"General MXP error",this.stack=new Error(n).stack}function v(e,t){this.decrypted={};for(var n in e)if("object"==typeof e[n]){e[n]instanceof Array?this[n]=[]:this[n]={};for(var i in e[n])this[n][i]=e[n][i]}else this[n]=e[n];if(t instanceof o){t.activeInstance&&(this.decrypted.nvps=this.decrypted.nvps||{},this.decrypted.nvps.to=t.activeInstance),this.txChannels=[];for(var r in t.clientMap)"virtual"!=r&&-1===this.txChannels.indexOf(t.clientMap[r].fs)&&this.txChannels.push(t.clientMap[r].fs);0==this.txChannels.length&&"virtual"in t.clientMap&&this.txChannels.push(t.clientMap.virtual.fs),this.sub="signalPubNub"}}function b(e){this.sinch=e,this.user=e.user,this.rtcConfiguration=e.user.mxpConfig.rtcConfiguration,this.rtcProfile=e.user.mxpConfig.rtcProfile,this.broadcastPubNub=PUBNUB({publish_key:this.rtcConfiguration.broadcastNetwork.publishKey,subscribe_key:this.rtcConfiguration.broadcastNetwork.subscribeKey,ssl:!0,origin:this.rtcConfiguration.broadcastNetwork.host}),this.signalPubNub=PUBNUB({publish_key:this.rtcConfiguration.signalNetwork.publishKey,subscribe_key:this.rtcConfiguration.signalNetwork.subscribeKey,ssl:!0,origin:this.rtcConfiguration.signalNetwork.host}),this.messageBuffert={},this.transportBuffert={},this.sessionBuffert={},this.unencryptedFrames={},this.broadcastPubNub.sinchStack={},this.broadcastPubNub.sinchStack[this.rtcProfile.broadcastChannel]=[],this.broadcastPubNub.sinchStack[this.rtcProfile.transportChannel]=[],this.signalPubNub.sinchStack={},this.signalPubNub.sinchStack[this.rtcProfile.signalChannel]=[]}function MXPError(e,t,n,i){this.name="MXPError",this.domain=e||-1,this.code=t||0,this.response=i||{},this.message=n||"General MXP error",this.stack=new Error(n).stack}function MXPLog(e,t){this.message=e,this.object=t}var w=e("q"),S=e("../VERSION"),I=e("sinch-ticketgen"),_={ErrorDomainNone:-1,ErrorDomainNetwork:0,ErrorDomainCapability:1,ErrorDomainSession:2,ErrorDomainApi:3,ErrorDomainOther:4,ErrorDomainSDK:5,ErrorDomainVerification:7},C={NoneNone:0,NetworkConnectionRefused:1e3,NetworkConnectionTimedOut:1001,NetworkServerError:1002,CapabilityUserNotFound:2e3,CapabilityCapabilityMissing:2001,CapabilityAuthenticationFailed:2002,SessionFailedToInitiateSession:3e3,SessionNoPendingSessionExists:3001,SessionTransferCantBeInitiated:3002,SessionActiveUserLimitReached:3003,ApiApiCallFailed:4e3,OtherInvalidOfflinePayloadTooBig:5e3,OtherInvalidOfflineInvitePayloadFailedToDecode:5001,OtherInvalidOfflineInviteUnknownType:5002,OtherOther:5003,SDKUnexpectedCall:6e3,SDKInternalError:6001,SDKInternalOther:6002,SDKMissingParameter:6003,SDKMissingCallback:6004,VerificationInvalidInput:7001,VerificationServiceError:7002,VerificationIncorrectCode:7003,VerificationFailedToInterceptCode:7004,VerificationUnexpectedInitiateError:7005},x=function(e,t){var n={method:e.method,headers:{"Content-Type":"application/json; charset=UTF-8",Accept:"application/json, text/plain, */*"}};"GET"!=e.method&&(n.data=t),n.url="";for(var i in e.urlParts){if(":"===e.urlParts[i][0]){var r=e.urlParts[i].slice(1);n.url+=encodeURIComponent((t||{})[r]).replace(/%2B/g,"+").replace(/%40/g,"@")}else n.url+=e.urlParts[i];i<e.urlParts.length-1&&(n.url+="/")}switch(e.auth){case"sign":n.headers=this.signSession(n);break;case"nosign":n.headers=this.signApp(n);break;case"ticket":n.headers=this.signTicket(n),delete n.data.authorization;break;case"signorticket":this._sessionId?n.headers=this.signSession(n):(n.headers=this.signTicket(n),delete n.data.authorization);break;default:throw new Error("Unsupported authentication type: "+e.auth)}if("GET"===e.method&&t&&Object.keys(t).length>0&&!e.hideQueryParams){n.url+="?";for(var s in t)n.url+=encodeURIComponent(s)+"="+encodeURIComponent(t[s])+"&"}return function(e){var t=w.defer(),n=new XMLHttpRequest;n.onload=function(){if(n.status>=200&&n.status<300){try{n.response=n.response||n.responseText,n.data=JSON.parse(n.response||"{}")}catch(e){console.log("Cant parse JSON"+n.response)}t.resolve(n.data)}else{try{n.response=n.response||n.responseText,n.data=JSON.parse(n.response||"{}")}catch(e){console.log("Cant parse JSON"+n.response)}t.reject(n)}},n.onerror=function(){t.reject(new Error("Unsupported operation "+n.status,n))},n.open(e.method,e.url,!0);for(var i in e.headers)n.setRequestHeader(i,e.headers[i]);return n.send(JSON.stringify(e.data)),t.promise}(n)},E=function(){return"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)})},k=k||{};k.base={getServerTime:{url:"timestamp/",method:"GET",auth:"nosign"},getInstance:{url:"instance",method:"POST",auth:"ticket"},renewInstance:{url:"instance",method:"POST",auth:"sign"},renewSecret:{url:"instances/id/:instanceId/authorization",method:"PUT",auth:"ticket"},getInstances:{url:"instances/id/",method:"GET",auth:"sign"}};(k=k||{}).calling={getConfiguration:{url:"configuration/user",method:"GET",auth:"sign"},placeCall:{url:"calls/:domain",method:"POST",auth:"sign"},callReporting:{url:"calls/:domain/id/:callId",method:"PUT",auth:"sign"},postMedia:{url:"media",method:"POST",auth:"sign"},pushCall:{url:"push",method:"POST",auth:"sign"}};(k=k||{}).messaging={getTransportById:{url:"transport",method:"GET",auth:"sign"},getTransportByParticipants:{url:"transport",method:"POST",auth:"sign"},messageReporting:{url:"report/im",method:"POST",auth:"sign"},pushMessage:{url:"push/messages",method:"POST",auth:"sign"}};(k=k||{}).user={authenticate:{url:"users/email/:email/authentication",method:"POST",auth:"nosign"},authenticateUsername:{url:"users/username/:username/authentication",method:"POST",auth:"nosign"},authenticateNumber:{url:"users/number/:number/authentication",method:"POST",auth:"nosign"},createUser:{url:"users",method:"POST",auth:"nosign"},changePassword:{url:"user/password",method:"PUT",auth:"sign"},updateUser:{url:"user/profile",method:"PATCH",auth:"sign"},getUserProfile:{url:"user/profile",method:"GET",auth:"sign"}};(k=k||{}).verification={verify:{url:"verifications",method:"POST",auth:"nosign"},confirmVerification:{url:"verifications/number/:number",method:"PUT",auth:"nosign"},confirmUserCallout:{url:"verifications",method:"POST",auth:"nosign"},confirmFlashCall:{url:"verifications/number/:number",method:"PUT",auth:"nosign"},queryVerificationById:{url:"verifications/callout/number/:number",method:"GET",hideQueryParams:!0,auth:"nosign"}},s.prototype.loadPAPIUrl=function(){this.PAPI=JSON.parse(JSON.stringify(k));for(var e in k)for(var t in k[e])this.PAPI[e][t].urlParts=(this._url[e]+this.PAPI[e][t].url).split("/"),this[t]=x.bind(this,this.PAPI[e][t])},s.prototype.loadTimeDelta=function(){var e=w.defer();return this.timeDelta?e.resolve():this.getServerTime().then(function(t){var n=new Date(t.timestamp),i=new Date;this.timeDelta=n-i,e.resolve()}.bind(this)).catch(function(t){console.error(t),e.fail(t)}),e.promise},s.prototype.config=function(e){this._appKey=e.appKey||this._appKey,this._sessionId=e.sessionId||this._sessionId,this._sessionSecret=e.sessionSecret||this._sessionSecret,localStorage["SinchSDK-"+this._appKey+"-"+this.user.userId]=this._sessionId},s.prototype.loadSessionId=function(){this._sessionId=localStorage["SinchSDK-"+this._appKey+"-"+this.user.userId]||""},s.prototype.log=function(e,t){t&&t.notify(e),this._logHandler(e)},s.prototype.logMxp=function(e){this._logMxpHandler(e)},s.prototype.setUrl=function(e){this._url.user=e.user||this._url.user,this._url.base=e.base||this._url.base,this._url.portal=e.portal||this._url.portal,this._url.reporting=e.reporting||this._url.reporting,this._url.reporting_v2=e.reporting_v2||this._url.reporting_v2,this._url.calling=e.calling||this._url.calling,this._url.messaging=e.messaging||this._url.messaging,this._url.verification=e.verification||this._url.verification,this.loadPAPIUrl()},s.prototype.terminate=function(){try{this.mxp&&this.mxp.close(),this.mxp.destroy(),this.mxp&&delete this.mxp,this._sessionId="",this._sessionSecret="",this.messageClient&&this.messageClient.destroy()}catch(e){}},s.prototype.stop=function(){console.error("Stop is deprecated, use terminate() instead!"),this.terminate()},s.prototype.adjustedTime=function(){var e=(new Date).getTime();return new Date(e+(this.timeDelta||0)).toISOString()},s.prototype.signSession=function(e){try{var t="";if(void 0!==e.data){var n="string"!=typeof e.data?JSON.stringify(e.data):e.data;t=z.MD5(n).toString(z.enc.Base64)}e.headers["Content-Type"]=(e.headers["Content-Type"]||"").replace("utf-8","UTF-8").replace("/json;chars","/json; chars"),e.headers["X-Timestamp"]=e.headers["X-Timestamp"]||this.adjustedTime();var i=e.method+"\n"+t+"\n"+(e.headers["Content-Type"]||"")+"\nx-timestamp:"+e.headers["X-Timestamp"]+"\n"+e.url.match(/^https?:\/\/[^\/]+([^#]*)/)[1];if(this._sessionId.length>0&&this._sessionSecret.length>0){var r=z.HmacSHA256(z.enc.Utf8.parse(i),z.enc.Base64.parse(this._sessionSecret)).toString(z.enc.Base64);e.headers.Authorization="instance "+this._sessionId+":"+r}else e.headers.Authorization="application "+this._appKey;return e.headers}catch(e){throw e}return null},s.prototype.signTicket=function(e,t){return t=t||e.data.authorization,e.headers=e.headers||{},e.headers.Authorization="user "+t,e.headers["X-Timestamp"]=this.adjustedTime(),e.headers},s.prototype.signApp=function(e){try{return e.headers["X-Timestamp"]=e.headers["X-Timestamp"]||this.adjustedTime(),e.headers.Authorization="application "+this._appKey,e.headers}catch(e){throw e}return null},s.prototype.getSession=function(){return{userId:this.user.userId,sessionId:this._sessionId,sessionSecret:this._sessionSecret,pushNotificationDisplayName:this.user.pushNotificationDisplayName}},s.prototype.newUser=function(e,t,n){var i=w.defer();return t=t||function(e){return console.info("User successfully created"),e},n=n||function(e){console.error(e)},this.user.create(e).then(t).then(i.resolve).fail(function(e){this.log(e),n(e),i.reject(e)}.bind(this)),i.promise},s.prototype.start=function(e,t,n){var i=w.defer();if(t=t||function(){this.log(new Notification(0,1,"SinchClient started"))}.bind(this),n=n||function(e){console.error(e)},this.started){var r=new Error("Sinch client already started");n(r),i.reject(r)}else e&&(this.user.pushNotificationDisplayName=e.pushNotificationDisplayName),this.started=!0,this.loadTimeDelta().then(function(e){return this.log(new Notification(0,5,"Get authentication token"),i),this.user.authenticate(e)}.bind(this,e),e).then(function(e){return this.loadSessionId(),e}.bind(this)).then(function(e){return this.log(new Notification(1,5,"Get instance using auth token"),i),e&&e.sessionId&&e.sessionSecret?this.user.resumeSession(e):this.user.initSessKeySecret()}.bind(this)).fail(function(e){if(40400===((e||{response:{}}).response||{}).errorCode)return this.log(new Notification(1,5,"Invalid instance. Will try again without any pre-set instance ID."),i),this._sessionId="",this.user.initSessKeySecret();throw e}.bind(this)).then(function(){return this.log(new Notification(2,5,"Get MXP configuration"),i),this.user.getMXPConf()}.bind(this)).then(function(){this.log(new Notification(3,5,"Create MXP object"),i),this.mxp=new b(this)}.bind(this)).then(function(){if(this._autoStartMxp&&(void 0!==this.messageClient||void 0!==this.callClient))return this.log(new Notification(4,5,"Will start active connection"),i),this.startActiveConnection();this.log(new Notification(4,5,"Will NOT start active connection. This will prevent IM and incoming data calls."),i)}.bind(this)).then(t).then(function(){this.log(new Notification(5,5,"Successfully started SinchClient"),i),i.resolve()}.bind(this)).fail(function(e){this.started=!1,this._sessionId="",this._sessionSecret="",this.log(e),n(e),i.reject(e)}.bind(this));return i.promise},s.prototype.getMessageClient=function(){if("messaging"in this.capabilities&&this.capabilities.messaging)return this.messageClient;throw new SinchError(_.ErrorDomainSDK,C.SDKInternalOther,"No messaging capability, not possible to retrieve messageClient")},s.prototype.getCallClient=function(){if("calling"in this.capabilities&&this.capabilities.calling)return this.callClient;throw new SinchError(_.ErrorDomainSDK,C.SDKInternalOther,"No calling capability, not possible to retrieve callClient")},s.prototype.createSmsVerification=function(e,t){return new y(this,e,t,"sms")},s.prototype.createCalloutVerification=function(e,t){return new u(this,e,t)},s.prototype.createFlashCallVerification=function(e,t){return new y(this,e,t,"flashcall")},s.prototype.createVerification=function(e,t,n){return new y(this,e,t,n.toLowerCase())},s.prototype.startActiveConnection=function(){if(this._onlineCapability&&this.started)return this.log(new Notification(4,5,"Manually starting active connection")),this.mxp.init();if(!this._onlineCapability)throw new SinchError(_.ErrorDomainSDK,C.SDKInternalOther,'No online capability, can not start active connection. Set configuration option "supportActiveConnection" to "true" when instantiating the SinchClient');this._autoStartMxp=!0},s.prototype.stopActiveConnection=function(){if(this._onlineCapability)return this.log(new Notification(4,5,"Manually closing active connection")),this.mxp.close();throw new SinchError(_.ErrorDomainSDK,C.SDKInternalOther,'No online capability, can not start active connection. Set configuration option "supportActiveConnection" to "true" when instantiating the SinchClient')},s.prototype.getVersion=function(){try{return S.version[1]}catch(e){return"dev"}},s.prototype.onnotification=function(e,t){};var D,M,O,B=B||{};D=window.RTCPeerConnection||window.mozRTCPeerConnection||window.webkitRTCPeerConnection||B.RTCPeerConnection,M=window.RTCSessionDescription||window.mozRTCSessionDescription||window.webkitRTCSessionDescription||B.RTCSessionDescription,O=window.RTCIceCandidate||window.mozRTCIceCandidate||B.RTCIceCandidate,o.prototype.addEventListener=function(e){this.eventListeners.push(e)},o.prototype.removeEventListener=function(e){this.eventListeners.splice(this.eventListeners.indexOf(e),1)},o.prototype.setStream=function(e){this.outgoingStream=e,this.outgoingStreamURL=window.URL.createObjectURL(e)},o.prototype.execListener=function(e,t){this.eventListeners.forEach(function(n){try{return n[e]&&n[e](this,t)}catch(t){var i=new SinchError(_.ErrorDomainSDK,C.SDKInternalOther,"Error executing listener: "+e,t);throw console.error(i),i}}.bind(this))},o.prototype.setEndCause=function(e){this.callEndCause===A.NONE&&(this.callEndCause=e)},o.prototype.setParticipants=function(e,t){this.callOutbound=e==this.sinch.user.userId,this.toId=t,this.fromId=e},o.prototype.progress=function(e){if(this.callState!=T.INITIATING)throw new SinchError(_.ErrorDomainOther,C.OtherOther,"Progress: Invalid call state for progressing",o);this.sinch.log(new Notification(0,1,"Call changing state to PROGRESSING")),this.timeProgressing=new Date,this.callState=T.PROGRESSING,e&&this.execListener("onCallProgressing"),this.autoAnswer&&this.answer(),this.autoHangup&&this.hangup()},o.prototype.establish=function(){if(this.callState==T.PROGRESSING){this.sinch.log(new Notification(0,1,"Call changing state to ESTABLISHED")),this.pc=this.pc||this.pcMap[this.activeInstance]||this.pcMap.virtual,delete this.pcMap.virtual;for(var e in this.pcMap)e!=this.activeInstance&&this.pcMap[e]!=this.pcMap[this.activeInstance]&&(this.pcMap[e]&&"closed"!=this.pcMap[e].signalingState&&this.pcMap[e].close(),delete this.pcMap[e]);"connection"!=this.callDomain&&(this.unmute(),this.incomingStream=this.pc.getRemoteStreams()[0],this.incomingStreamURL=window.URL.createObjectURL(this.incomingStream)),this.timeEstablished=new Date,this.callState=T.ESTABLISHED,this.execListener("onCallEstablished")}else console.log("Call state not in PROGRESSING, cant process second JOIN")},o.prototype.push=function(e){if(!this.sinch._supportManagedPush)return!1;if(this.callState!=T.INITIATING&&this.callState!=T.PROGRESSING)return!1;var t=[];for(H in this.instanceMap)this.instanceMap[H].capabilities&&this.instanceMap[H].capabilities.indexOf("push")>-1&&(!e&&this.instanceMap[H].capabilities.indexOf("online")<0||e&&this.instanceMap[H].capabilities.indexOf("online")>-1)&&t.push(H);if(t.length>0){var n=new function(e,t,n,i,r){this._version=e,this._type=t,this._sessionId=n,this._created=i,this._externalId=r,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(e){this._bytes.push(e)},this.encodeSessionId=function(e){var t=0;for(this._bytes.push(e==e.toLowerCase()?1:2);t<e.length;)"-"!=e.substring(t,t+1)?(this._bytes.push(parseInt(e.substr(t,2),16)),t+=2):++t},this.encodeTimestamp=function(e){this.encodeChar(255&e),this.encodeChar((65280&e)>>8),this.encodeChar((16711680&e)>>16),this.encodeChar((4278190080&e)>>24)},this.encodeString=function(e){for(var t=0;t<e.length;++t)this._bytes.push(e.charCodeAt(t))},this.getUserIdTypeAndLength=function(e,t){return 127&t|e<<7},this.base64Encode=function(){for(var e,t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".split(""),n=this._bytes,i="",r=0;r<n.length;r+=3)i+=t[n[r]>>2],i+=t[(3&n[r])<<4|n[r+1]>>4],void 0!==n[r+1]?i+=t[(15&n[r+1])<<2|n[r+2]>>6]:i+="=",void 0!==n[r+2]?i+=t[63&n[r+2]]:i+="=";for(e=i.slice(0,64),r=1;r<Math.ceil(i.length/64);r++)e+=i.slice(64*r,64*r+64)+(Math.ceil(i.length/64)==r+1?"":"\n");return e}}(2,1,this.callId,Date.now(),this.sinch.user.userId),i={};i.sinch=n.Encoded(),this.sinch.user.pushNotificationDisplayName&&(i.displayName=this.sinch.user.pushNotificationDisplayName);for(var r={sessionId:this.callId,template:"incoming_call",to:[],params:i},s=0;s<t.length;++s)r.to.push({instance:t[s]});this.sinch.pushCall({messages:[r]}),this._callPushed=!0,this.progress(!0)}return this._callPushed},o.prototype.createInstanceMap=function(e){if(!e)return null;for(var t={},n=0;n<e.length;++n)t[e[n].instanceId]={},t[e[n].instanceId].capabilities=e[n].capabilities;return t},o.prototype.mxpAck=function(e){if(this.sinch.log(new Notification(0,1,"Call ACK Received",e)),this.callState!=T.INITIATING&&this.callState!=T.PROGRESSING)throw new SinchError(_.ErrorDomainOther,C.OtherOther,"Invalid call state for processing Ack",o);this.clientMap[e.getSenderId()]=this.clientMap[e.getSenderId()]||e.getFrom(),this.instanceMap&&this.instanceMap[e.getInstanceId()]&&(this.instanceMap[e.getInstanceId()].acked=!0);for(var t=0;t<this.iceMapTx.length;t++){var n=this.iceMapTx[t];this.sinch.log(new Notification(0,1,"Firefox special: Transmitting buffered ICE candidates for the one Peer Connection we have.",n)),this.sinch.mxp.callTxICECandidate(this,n,e.fi).fail(function(e){throw new SinchError(_.ErrorDomainSDK,C.SDKInternalOther,"Error sending ICE candidate")})}"sdp"===e.decrypted.bt?this.processRTCAnswer(e).then(function(){"yes"===(e.decrypted.nvps||{}).earlymedia?(this.activeInstance=e.getSenderId(),this.progress(!1),this.establish(),this.earlymedia=!0):this.progress(!0),this.joinBuffer[e.getSenderId()]&&(this.sinch.log(new Notification(0,1,"Buffered JOIN was detected for this Ack, will immediatley process & remove.")),this.mxpJoin(this.joinBuffer[e.getSenderId()]),delete this.joinBuffer[e.getSenderId()])}.bind(this)):this.callState==T.INITIATING&&this.progress(!0)},o.prototype.intProcessAnswer=function(e,t){var n=w.defer();this.sinch.log(new Notification(2,2,"Will configure SDP Answer",e));return this.pcMap[t].setRemoteDescription(e,function(){this.sinch.log(new Notification(2,2,"Configured incoming SDP Answer",e)),n.resolve()}.bind(this),function(e){throw new SinchError(_.ErrorDomainSDK,C.SDKInternalOther,"Error setting remote SDP",e)}.bind(this)),n.promise},o.prototype.processRTCAnswer=function(e){var t=w.defer();if(this.callState!=T.ENDED){var n=e.decrypted.bd;this.sinch.log(new Notification(0,2,"Processing SDP Answer from B",n));var i=new M(JSON.parse(n));if(this.sinch.firefox)this.pcMap[e.getSenderId()]=this.offerGeneratorPC,this.sdpAnswerBuffer[e.getSenderId()]=i,t.resolve();else{this.pcMap[e.getSenderId()]=this.pcMap[e.getSenderId()]||this.initPC();var r=this.pcMap[e.getSenderId()];r.createOffer(function(n){r.setLocalDescription(this.outgoingOffer,function(){this.sinch.log(new Notification(1,2,"Configured cached outgoing SDP Offer",this.outgoingOffer)),this.intProcessAnswer(i,e.getSenderId()).then(function(){t.resolve()})}.bind(this),function(e){console.error("Error setting local Description, message: "+e)})}.bind(this),function(e){console.error("Error creating offer, message: "+e)},{offerToReceiveAudio:!0,offerToReceiveVideo:this.videoSupport})}}else t.resolve();return t.promise},o.prototype.mxpPeerEventSdp=function(e){if(this.callState==T.INITIATING||this.callState==T.PROGRESSING)this.disableIce=!0,this.processRTCAnswer(e);else if(this.callState==T.ESTABLISHED){var t=JSON.parse(e.decrypted.bd);if("offer"==t.type){this.sinch.log(new Notification(0,3,"Got renegotiation SDP Offer",t));n=new M(t);this.pc.setRemoteDescription(n,function(){this.sinch.log(new Notification(1,3,"Successfully configured SDP Offer.",t)),this.pc.createAnswer(function(t){this.pc.setLocalDescription(t,function(){this.sinch.log(new Notification(2,3,"Successfully created SDP Answer.",t)),this.sinch.mxp.callTxPeerEventSDP(this,t,e.getSenderId()).fail(function(e){throw new SinchError(_.ErrorDomainSDK,C.SDKInternalOther,"Error sending SDP Answer")})}.bind(this),function(e){console.error("Major error in setting local description",e)})}.bind(this),function(e){console.error("Major error in creating answer",e)})}.bind(this),function(e){throw setTimeout(function(){this.setEndCause(A.FAILURE),this.error=new SinchError(_.ErrorDomainSDK,C.SDKInternalOther,e),this.sinch.mxp.callCancel(this).fail(function(e){throw new SinchError(_.ErrorDomainSDK,C.SDKInternalOther,"Error sending call Cancel")}),this.callFailure()}.bind(this),2e3),new SinchError(_.ErrorDomainSDK,C.SDKInternalOther,"Error setting remote SDP")}.bind(this))}else if("answer"==t.type){this.sinch.log(new Notification(0,2,"Got renegotiation SDP Answer",t));var n=new M(t);this.pc.setRemoteDescription(n,function(){this.sinch.log(new Notification(1,2,"Configured incoming SDP Answer",t))}.bind(this),function(e){throw setTimeout(function(){this.setEndCause(A.FAILURE),this.error=new SinchError(_.ErrorDomainSDK,C.SDKInternalOther,e),this.sinch.mxpCancel(this).fail(function(e){throw new SinchError(_.ErrorDomainSDK,C.SDKInternalOther,"Error sending call Cancel")}),this.callFailure()}.bind(this),2e3),new SinchError(_.ErrorDomainSDK,C.SDKInternalOther,"Error setting remote SDP")})}}},o.prototype.mxpInjectIce=function(e){if(this.callState!=T.ENDED){this.sinch.log(new Notification(0,2,"Recieved ICE Candidate offer from B",e));var t=JSON.parse(e.decrypted.bd);t.candidate=t.cand||t.candidate,t.sdpMLineIndex=t.sdpMLI||t.sdpMLineIndex;var n=e.getSenderId();!this.sinch.firefox&&n in this.pcMap?(this.sinch.log(new Notification(0,2,"Injecting ICE candidate directly",t)),this.injectIce(n,t)):(this.sinch.log(new Notification(0,2,"Buffering ICE candidate until PeerConnection created",t)),this.iceMapRx[n]=this.iceMapRx[n]||[],this.iceMapRx[n].push(t))}},o.prototype.injectIce=function(e,t){var n=t.candidate.split(" ");if(-1!=n.indexOf("srflx")&&"udp"==n[2].toLowerCase()){var i={candidate:["candidate:"+(123+(this.pcMap[e].proxyIce||[]).length),n[1],n[2].toUpperCase(),Math.round(n[3]/10),this.proxyUrl.split("/")[3].split(":")[0],this.proxyUrl.split("/")[3].split(":")[1],"typ","relay","raddr",n[4],"rport",n[5],"generation",0].join(" "),sdpMLineIndex:"number"==typeof t.sdpMLI?t.sdpMLI:t.sdpMLineIndex||0,sdpMid:t.sdpMid};this.sinch.log(new Notification(0,1,"Generated extra candidate for Proxy Relay",i)),void 0===this.pcMap[e].proxyIce&&(this.pcMap[e].proxyIce=[]),this.pcMap[e].proxyIce.push(new O(i))}this.pcMap[e].addIceCandidate(new O(t),function(){},function(){})},o.prototype.mxpJoin=function(e){if(this.sinch.log(new Notification(0,1,"Call JOIN Received",e)),this.activeInstance&&this.activeInstance!=e.getSenderId())throw console.error("Can not process JOIN, call in session after previous JOIN"),new SinchError(_.ErrorDomainSession,C.SessionActiveUserLimitReached,"Can not process JOIN, call in session after previous JOIN");var t=e.getSenderId();this.callState==T.INITIATING?(this.sinch.log(new Notification(0,1,"JOIN received before ACK. Will cache JOIN to process after ACK.")),this.joinBuffer[t]=e):w.fcall(function(){var n=w.defer();if(this.sinch.firefox&&this.sdpAnswerBuffer[t]){var i=this.sdpAnswerBuffer[t];this.intProcessAnswer(i,e.getSenderId()).then(function(){for(;(this.iceMapRx[t]||[]).length;){var i=this.iceMapRx[t].pop();this.injectIce(e.getSenderId(),i),this.sinch.log(new Notification(0,1,"Injected ice from Ice Rx buffert",i))}setTimeout(function(){n.resolve()}.bind(this),200)}.bind(this))}else n.resolve();return n.promise}.bind(this)).then(function(){if(0==((this.pcMap[t]||{}).proxyIce||[]).length)if(console.error("Warning, no proxy configured (1). Will try to add candidate without srflx reference",this.pcMap[t]),this.proxyUrl){var n=this.proxyUrl.split("/")[3].split(":");this.pcMap[t].proxyIce=this.pcMap[t].proxyIce||[],this.pcMap[t].proxyIce.push(new O({sdpMid:"audio",sdpMLI:0,sdpMLineIndex:0,candidate:j.generateIceCandidate(n[0],n[1])}))}else console.error("Warning, no proxyUrl configured!");if(((this.pcMap[t]||{}).proxyIce||[]).forEach(function(e){this.sinch.log(new Notification(0,1,"Adding buffered proxy ICE candidate",e)),this.pcMap[t].addIceCandidate(e,function(){this.sinch.log(new Notification(0,1,"Successfully added proxy ICE candidate",e))}.bind(this),function(e){throw new SinchError(_.ErrorDomainSDK,C.SDKInternalOther,"Failed to add proxy ICE candidate when processing JOIN",e)})}.bind(this)),this.callState!=T.PROGRESSING&&!this.earlymedia)throw console.error("Can not process JOIN, call in unexpected state. Call state: "+this.getState()),new SinchError(_.ErrorDomainSDK,C.SDKInternalOther,"Can not process JOIN, call in unexpected state.");this.activeInstance=e.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(e){console.error("Unhandled error in call.mxpJoin.",e)})}.bind(this)).fail(function(e){console.error("Error processing JOIN",e)})},o.prototype.mxpJoined=function(e){if(this.sinch.log(new Notification(0,1,"Call JOINED Received",e)),this.callState==T.INITIATING||this.callState==T.PROGRESSING){if(JSON.parse(e.decrypted.bd).fi!=this.sinch._sessionId+":"+this.sinch._subInstanceId)this.setEndCause(A.OTHER_DEVICE_ANSWERED),this.mxpHangup();else if(this.callState==T.PROGRESSING){var t=e.getSenderId();if(this.sinch.firefox)for(;(this.iceMapRx[t]||[]).length;){var n=this.iceMapRx[t].pop();this.injectIce(e.getSenderId(),n),this.sinch.log(new Notification(0,1,"Injected ice from Ice Rx buffert",n))}if(0==((this.pcMap[t]||{}).proxyIce||[]).length)if(console.error("Warning, no proxy configured (2). Will try to add candidate without srflx reference",this.pcMap[t]),this.proxyUrl){var i=this.proxyUrl.split("/")[3].split(":");this.pcMap[t].proxyIce=this.pcMap[t].proxyIce||[],this.pcMap[t].proxyIce.push(new O({sdpMid:"audio",sdpMLI:0,sdpMLineIndex:0,candidate:j.generateIceCandidate(i[0],i[1])}))}else console.error("Warning, no proxyUrl configured!");((this.pcMap[t]||{}).proxyIce||[]).forEach(function(e){this.sinch.log(new Notification(0,1,"Adding buffered proxy ICE candidate",e)),this.pcMap[t].addIceCandidate(e,function(){this.sinch.log(new Notification(0,1,"Successfully added proxy ICE candidate",e))}.bind(this),function(e){throw new SinchError(_.ErrorDomainSDK,C.SDKInternalOther,"Failed to add proxy ICE candidate when processing JOINED",e)})}.bind(this)),this.establish()}}else console.log("Call state already ESTABLISHED (or ENDED), cant process second JOIN")},o.prototype.mxpHangup=function(e){if(this.callState!=T.ENDED){this.sinch.log(new Notification(0,1,"Call HANGUP Received",e)),this.callState==T.ESTABLISHED?this.setEndCause(A.HUNG_UP):this.setEndCause(A.CANCELED),this.timeEnded=new Date,this.callState=T.ENDED,this.execListener("onCallEnded"),this.pc&&"closed"!=this.pc.signalingState&&this.pc.close(),delete this.pc;for(var t in this.pcMap)delete this.pcMap[t]}},o.prototype.mxpDeny=function(e){if(this.callState!=T.ENDED){if(this.sinch.log(new Notification(0,1,"Call DENIED Received",e)),this.setEndCause(A.DENIED),"error/json"==e.decrypted.bt){this.error=new SinchError(_.ErrorDomainApi,C.ApiApiCallFailed,"");var t=JSON.parse(e.decrypted.bd);for(var n in t)this.error[n]=t[n];this.error.message=t.code+" "+t.reason,this.error.mxp=e.decrypted}this.callState==T.INITIATING?(this.autoHangup=!0,this.progress(!0)):this.hangup()}},o.prototype.mxpCancel=function(e){if(this.callState!=T.ENDED){this.sinch.log(new Notification(0,1,"Call CANCEL Received",e)),this.timeEnded=new Date,this.callState=T.ENDED;Date.now();this.setEndCause(A.CANCELED),this.execListener("onCallEnded"),this.pc&&"closed"!=this.pc.signalingState&&this.pc.close(),delete this.pc;for(var t in this.pcMap)delete this.pcMap[t]}},o.prototype.mxpFail=function(e){if(this.sinch.log(new Notification(0,1,"Call FAILURE Received",e)),"message"==e.decrypted.bt)this.error=new SinchError(_.ErrorDomainApi,C.ApiApiCallFailed,""),this.error.message=e.decrypted.bd,this.error.mxp=e.decrypted;else if("error/json"==e.decrypted.bt){this.error=new SinchError(_.ErrorDomainApi,C.ApiApiCallFailed,"");var t=JSON.parse(e.decrypted.bd);for(var n in t)this.error[n]=t[n];this.error.message=t.code+" "+t.reason,this.error.mxp=e.decrypted}this.callFailure()},o.prototype.callFailure=function(){this.timeEnded=new Date,this.callState=T.ENDED,this.setEndCause(A.FAILURE),this.execListener("onCallEnded"),this.pc&&"closed"!=this.pc.signalingState&&this.pc.close(),delete this.pc;for(var e in this.pcMap)delete this.pcMap[e]},o.prototype.addEventListenerPrototype=function(e){e.onOpen&&(this.onopen=e.onOpen),e.onClose&&(this.onclose=e.onClose),e.onMessage&&(this.onmessage=e.onMessage)},o.prototype.initPC=function(e){var t=new D(this.webRtcConfig,{optional:[{DtlsSrtpKeyAgreement:!0}]});return this.outgoingStream&&"connection"!=this.callDomain?(this.mute(),t.addStream(this.outgoingStream)):(this.sinch.log(new Notification(0,1,"WebRTC: Will add data channel before ICE negotiation")),this.dataChannels[this.sinch.user.userId]=t.createDataChannel(this.sinch.user.userId,{reliable:!1}),this.dataChannels[this.sinch.user.userId].onmessage=function(e){console.log("fallback",e)},this.dataChannels[this.sinch.user.userId].addEventListener=this.addEventListenerPrototype.bind(this.dataChannels[this.sinch.user.userId])),t.ontrack=function(e){}.bind(this),t.ondatachannel=function(e){this.sinch.log(new Notification(0,1,"WebRTC: Datachannel opened",e));try{this.dataChannels[e.channel.label]=e.channel,this.dataChannels[e.channel.label].addEventListener=this.addEventListenerPrototype.bind(this.dataChannels[e.channel.label]),this.execListener("onDataChannelAdded",this.dataChannels[e.channel.label])}catch(e){console.error("Error handling datachannel",e)}}.bind(this),t.oniceconnectionstatechange=function(e){this.sinch.log(new Notification(0,1,"WebRTC: Connection state changed",e)),this.renegotiate||!e.currentTarget||"failed"!=e.currentTarget.iceConnectionState&&"disconnected"!=e.currentTarget.iceConnectionState||(this.sinch.log(new SinchError(_.ErrorDomainNetwork,C.NetworkConnectionTimedOut,"Ice connection failed. Hanging up call!",e)),this.hangup())}.bind(this),t.onicecandidate=function(e){if(!this.renegotiate&&e.candidate){this.sinch.log(new Notification(0,2,"Preparing ICE candidate for B",e.candidate));var n=Object.keys(this.pcMap).filter(function(e){return this.pcMap[e]===t}.bind(this))[0],i={cand:e.candidate.candidate,candidate:e.candidate.candidate,sdpMLI:e.candidate.sdpMLineIndex,sdpMLineIndex:e.candidate.sdpMLineIndex,sdpMid:e.candidate.sdpMid||""};setTimeout(function(){n?this.disableIce?this.sinch.log(new Notification(1,2,"ICE Disabled, will not send any ICE candidates (will be sent in different way)",i)):(this.sinch.log(new Notification(1,2,"Instantly sending ICE candidate for B",i)),this.sinch.mxp.callTxICECandidate(this,i,n).fail(function(e){throw new SinchError(_.ErrorDomainSDK,C.SDKInternalOther,"Error sending ICE candidate")})):this.iceMapTx.push(i)}.bind(this),this.sinch.mxp.sessionBuffert[this.callId]?0:500)}}.bind(this),t.onnegotiationneeded=function(e){this.callState==T.ESTABLISHED&&(this.renegotiate=!0,this.sinch.log(new Notification(0,2,"Negotiation needed, will generate new offer",e)),t.createOffer(function(e){this.sinch.log(new Notification(1,2,"Negotiation needed, offer generated",e)),t.setLocalDescription(e,function(){this.sinch.log(new Notification(1,2,"Negotiation needed, sending offer to recipient",e)),this.sinch.mxp.callTxPeerEventSDP(this,e,this.activeInstance).fail(function(e){throw new SinchError(_.ErrorDomainSDK,C.SDKInternalOther,"Error sending SDP Offer")})}.bind(this))}.bind(this)))}.bind(this),t.onremovestream=function(e){this.sinch.log(new Notification(0,1,"WebRTC: Stream removed",e))}.bind(this),t.onsignalingstatechange=function(e){this.sinch.log(new Notification(0,1,"WebRTC: Signaling state change",e))}.bind(this),t.onidentityresult=function(e){this.sinch.log(new Notification(0,1,"WebRTC: onidentityresult event detected",e))},t.onidpassertionerror=function(e){this.sinch.log(new Notification(0,1,"WebRTC: onidpassertionerror event detected",e))},t.onidpvalidationerror=function(e){this.sinch.log(new Notification(0,1,"WebRTC: onidpvalidationerror event detected",e))},t.onpeeridentity=function(e){this.sinch.log(new Notification(0,1,"WebRTC: onpeeridentity event detected",e))},t},o.prototype.placeCall=function(e,t){var n=w.defer();this.callDomain=t,this.setParticipants(this.sinch.user.userId,e),setTimeout(function(){this.push(!0),this._callPushed||this.callState!=T.INITIATING||(this.sinch.log(new Notification(0,1,"Call PROGRESSING timeout. Will hangup call.",this)),this.setEndCause(A.TIMEOUT),this.hangup())}.bind(this),this.sinch._progressTimeout||P),setTimeout(function(){this.callState==T.PROGRESSING&&(this.sinch.log(new Notification(0,1,"Call ESTABLISHED timeout. Will hangup call.",this)),this.setEndCause(A.NO_ANSWER),this.hangup())}.bind(this),N);var i={cli:"",destination:{type:{pstn:"number",data:"username",conference:"username",connection:"username",sip:"username"}[t],endpoint:e},callId:this.callId,mediaChannels:["audio"],subinstanceId:this.sinch._subInstanceId,headers:{p2p:"yes"},domain:{pstn:"pstn",data:"data",conference:"conference",connection:"data",sip:"sip"}[t]};this.sinch._supportVideo&&i.mediaChannels.push("video"),this.customHeaders&&(i.headers.ph=JSON.stringify(this.customHeaders)),"connection"==t&&(i.headers.nomedia=!0);var r=this.initPC();return r.createOffer(function(t){this.outgoingOffer=t,i.sdp=t,this.sinch.placeCall(i).then(function(i){this.sinch.log(new Notification(0,1,"Successfully initiated call, waiting for MXP signalling.",i)),void 0!==i.SignalChannel&&null!==i.SignalChannel&&(this.clientMap.virtual={fs:i.SignalChannel,fu:e},this.instanceMap=this.createInstanceMap(i.instances),this.push(!1)&&(_callPushed=!0)),this.proxyUrl=i.Body.replace(/(\r\n|\n|\r)/gm,""),this.sinch.firefox&&(this.offerGeneratorPC=r,r.setLocalDescription(t,function(){this.sinch.log(new Notification(0,1,"Firefox special: Configuring the local description to gather ICE candidates.",t))}.bind(this),function(e){throw new SinchError(_.ErrorDomainSDK,C.SDKInternalOther,"Firefox special: Error configuring local description",e)})),this.sinch.mxp.configureMxpSession(this.callId,i.EncryptionKey,i.Body),n.resolve()}.bind(this)).fail(function(e){this.error=new SinchError(_.ErrorDomainSDK,C.SDKInternalOther,JSON.parse(e.response).message),this.callFailure(),n.reject(error)}.bind(this))}.bind(this),function(e){console.error("Failed to generate SDP Offer"),console.error(e)},{offerToReceiveAudio:!0,offerToReceiveVideo:this.videoSupport}),n.promise},o.prototype.ackIncomingCall=function(e){var t=w.defer();this.sinch.log(new Notification(0,1,"Incoming call",this)),setTimeout(function(){this.callState==T.INITIATING&&(this.sinch.log(new Notification(0,1,"Call PROGRESSING timeout. Will hangup call.",this)),this.setEndCause(A.TIMEOUT),this.hangup())}.bind(this),P),setTimeout(function(){this.callState==T.PROGRESSING&&(this.sinch.log(new Notification(0,1,"Call ESTABLISHED timeout. Will hangup call.",this)),this.setEndCause(A.NO_ANSWER),this.hangup())}.bind(this),N);var n=JSON.parse(e.decrypted.nvps.sdp);this.sinch.log(new Notification(0,1,"Received SDP offer from B",n));var i=new M(n),r=this.initPC();return this.pcMap[e.getSenderId()]=r,this.pc=r,r.setRemoteDescription(i,function(){for(this.sinch.log(new Notification(1,3,"Successfully configured SDP Offer.",n));(this.iceMapRx[this.activeInstance]||[]).length;){var t=this.iceMapRx[this.activeInstance].pop();this.injectIce(e.getSenderId(),t),this.sinch.log(new Notification(0,1,"Injected ice from Ice Rx buffert",t))}r.createAnswer(function(t){r.setLocalDescription(t,function(){if(this.sinch.log(new Notification(2,3,"Successfully created SDP Answer.",t)),this.progress(!1),this.sinch.firefox){var n={candidate:"candidate:123123 1 UDP 1 127.0.0.1 3000 typ host",sdpMLI:0,sdpMLineIndex:0,sdpMid:"audio"};this.sinch.log(new Notification(0,1,"Firefox special: Will setup fake candidate injection interval.",n)),this.ffInjectCounter=0,this.ffIceTimer=setInterval(function(){this.sinch.log(new Notification(0,1,"Firefox special: Injecting fake candidate number: "+this.ffInjectCounter,n)),this.ffInjectCounter+=1,this.ffInjectCounter>2&&(this.sinch.log(new Notification(0,1,"Firefox special: Done injecting fake candidates.",this)),clearInterval(this.ffIceTimer)),this.pc.addIceCandidate(new O(n),function(){},function(){})}.bind(this),15e3),this.pc.addIceCandidate(new O(n),function(){},function(){})}if("yes"==e.decrypted.nvps.p2p)this.sinch.log(new Notification(2,3,"Header detected, p2p, will proceed with direct peer connection!.",e)),this.sinch.mxp.sendSdpAnswer(this,t).fail(function(e){throw new SinchError(_.ErrorDomainSDK,C.SDKInternalOther,"Error sending SDP Answer")});else{this.disableIce=!0,this.sinch.log(new Notification(2,3,"p2p header not detected, will fall back on proxy, we might deal with an old client",e)),this.mediaObj={callid:this.callId,proxyid:e.decrypted.bd.split("/")[2],sdp:t},this.sinch.mxp.sendSdpAnswer(this);var i=e.decrypted.bd.split("/")[3].split(":");r.proxyIce=r.proxyIce||[],r.proxyIce.push(new O({sdpMid:"audio",sdpMLI:0,sdpMLineIndex:0,candidate:j.generateIceCandidate(i[0],i[1])}))}}.bind(this),function(e){console.error("Major error in setting local description",e)})}.bind(this),function(e){console.error("Major error in creating answer",e)})}.bind(this),function(e){throw setTimeout(function(){this.setEndCause(A.FAILURE),this.error=new SinchError(_.ErrorDomainSDK,C.SDKInternalOther,e),this.sinch.mxp.callCancel(this).fail(function(e){throw new SinchError(_.ErrorDomainSDK,C.SDKInternalOther,"Error sending call Cancel")}),this.callFailure()}.bind(this),2e3),new SinchError(_.ErrorDomainSDK,C.SDKInternalOther,"Error setting remote SDP")}.bind(this)),t.promise},o.prototype.answer=function(){if(this.sinch.log(new Notification(0,1,"Answer call initiated, to answer()",this)),this.callState==T.PROGRESSING)this.mediaObj?this.sinch.postMedia(this.mediaObj).then(function(e){var t="audio:ISAC/0.0.0.0/"+e.proxyid+"/"+e.ip+":"+e.port;this.sinch.mxp.joinIncomingCall(this,t).then(function(){this.sinch.log(new Notification(3,3,"Successfully sent updated proxy information in Ack to caller",t))}.bind(this)).fail(function(e){throw console.error(e),new SinchError(_.ErrorDomainSDK,C.SDKInternalOther,"Could not send Ack to Old with MEDIA answer")})}.bind(this)).fail(function(e){throw console.error(e),new SinchError(_.ErrorDomainSDK,C.SDKInternalOther,"Could not send Answer to v1/media")}):this.sinch.mxp.joinIncomingCall(this).fail(function(e){throw new SinchError(_.ErrorDomainSDK,C.SDKInternalOther,"Error sending JOIN (pickup phone).")});else if("undefined"==typeof outgoingStream)this.sinch.log(new Notification(0,1,"Outgoing stream undefined, perhaps early answer. Will set auto answer for future automatic answer.")),this.autoAnswer=!0;else{if(this.callState==T.ENDED||this.callState==T.ESTABLISHED)throw new SinchError(_.ErrorDomainSDK,C.SDKInternalOther,"Call in invalid state to answer.");this.sinch.log(new Notification(0,1,"Stream defined and state in initializing or progressing. Setting auto answer for later retry.")),this.autoAnswer=!0}},o.prototype.openDataChannel=function(e){return void 0===this.dataChannels[e]&&(this.dataChannels[e]=this.pcMap[this.activeInstance].createDataChannel(e,{reliable:!1}),this.dataChannels[e].addEventListener=this.addEventListenerPrototype.bind(this.dataChannels[e]),this.execListener("onDataChannelAdded",this.dataChannels[e])),this.dataChannels[e]},o.prototype.hangup=function(){if(this.hangupRetries=(this.hangupRetries||0)+1,this.callState==T.ESTABLISHED)this.sinch.mxp.callHangup(this).fail(function(e){throw new SinchError(_.ErrorDomainSDK,C.SDKInternalOther,"Error sending call Hangup")}),this.mxpHangup();else if(!this.callOutbound||this.callState!=T.PROGRESSING&&this.callState!=T.INITIATING)if(this.callOutbound||this.callState!=T.PROGRESSING&&this.callState!=T.INITIATING){if(this.callState==T.ENDED)throw new SinchError(_.ErrorDomainSDK,C.SDKInternalOther,"Call already ended");this.mxpHangup()}else this.callState==T.PROGRESSING?(this.sinch.mxp.callDeny(this).fail(function(e){throw new SinchError(_.ErrorDomainSDK,C.SDKInternalOther,"Error sending call Deny")}),this.setEndCause(A.DENIED),this.mxpHangup()):this.autoHangup=!0;else Object.keys(this.clientMap).length>0||this.hangupRetries>5?(this.sinch.mxp.callCancel(this).fail(function(e){throw new SinchError(_.ErrorDomainSDK,C.SDKInternalOther,"Error sending call Cancel")}),this.mxpHangup()):(this.sinch.log(new Notification(0,1,"Can not hang up call at this time. Will try again in 0.5 seconds (max five retries).")),setTimeout(this.hangup.bind(this),500))},o.prototype.getCallId=function(){return this.callId},o.prototype.getDetails=function(){return new a({endCause:this.callEndCause,endedTime:this.timeEnded,error:this.error,establishedTime:this.timeEstablished,startedTime:this.timeProgressing,duration:this.timeEstablished?(this.timeEnded-this.timeEstablished)/1e3:0})},o.prototype.getDirection=function(){return this.callOutbound?1:0},o.prototype.getRemoteUserId=function(){return this.getDirection()?this.toId:this.fromId},o.prototype.getState=function(){return Object.keys(T).filter(function(e){return T[e]===this.callState}.bind(this))[0]},o.prototype.getEndCause=function(){return Object.keys(A).filter(function(e){return A[e]===this.callEndCause}.bind(this))[0]},o.prototype.getHeaders=function(){return this.customHeaders},o.prototype.sendDTMF=function(e){return this.DTMFsender||(this.DTMFsender=this.pc.createDTMFSender(this.outgoingStream.getAudioTracks()[0])),this.DTMFsender&&this.DTMFsender.insertDTMF(e)},o.prototype.mute=function(){if(this.callState!=T.ESTABLISHED&&this.callState!=T.PROGRESSING&&this.callState!=T.INITIATING)throw new SinchError(_.ErrorDomainSDK,C.SDKInternalOther,"Call not in ESTABLISHED state.");this.sinch.log(new Notification(0,1,"Call was muted using mute()."));for(var e=this.outgoingStream.getAudioTracks(),t=0;t<e.length;t++)e[t].enabled=!1},o.prototype.unmute=function(){if(this.callState!=T.ESTABLISHED&&this.callState!=T.PROGRESSING&&this.callState!=T.INITIATING)throw new SinchError(_.ErrorDomainSDK,C.SDKInternalOther,"Call not in ESTABLISHED state.");this.sinch.log(new Notification(0,1,"Call was un-muted using unmute()."));for(var e=this.outgoingStream.getAudioTracks(),t=0;t<e.length;t++)e[t].enabled=!0},navigator.mediaDevices.getUserMedia=navigator.mediaDevices.getUserMedia||navigator.getUserMedia||navigator.mozGetUserMedia||navigator.webkitGetUserMedia,c.prototype.addEventListener=function(e){this.eventListeners.push(e)},c.prototype.removeEventListener=function(e){this.eventListeners.splice(this.eventListeners.indexOf(e),1)},c.prototype.execListener=function(e,t){var n=0;return this.eventListeners.forEach(function(i){return n++,i[e]&&i[e](t)}.bind(this)),n},c.prototype.initStream=function(e,t){var n=w.defer(),i=!(!this.sinch._supportVideo||t)&&{mandatory:{maxWidth:320,maxHeight:240}};return void 0!==e?(this.sinch.log(new Notification(0,1,"Will wire customStream into call",e)),n.resolve(e)):void 0===this.localMediaStream?(this.sinch.log(new Notification(0,1,"Will retrieve new Mic for stream")),navigator.mediaDevices.getUserMedia({video:i,audio:!0}).then(function(e){this.localMediaStream=e,n.resolve(this.localMediaStream)}).catch(function(e){console.error("Error retrieving media stream",e)})):(this.sinch.log(new Notification(0,1,"Will retrieve cached Mic for stream",this.localMediaStream)),n.resolve(this.localMediaStream)),n.promise},c.prototype.alreadyInCall=function(){if(this.sinch._multiCall)return!1;for(var e in this.callBuffert)if(this.callBuffert[e].callState==T.PROGRESSING||this.callBuffert[e].callState==T.ESTABLISHED)return!0},c.prototype.handleIncomingCall=function(e){this.sinch.log(new Notification(0,1,"Will handle incoming call",e));var t=new o(this.sinch,this.sinch._supportVideo,e.mxpSessionId);(e.decrypted.nvps||{}).nomedia?t.callDomain="connection":t.callDomain="data",t.setParticipants(e.decrypted.fu,this.sinch.user.userId),t.customHeaders=JSON.parse((e.decrypted.nvps||{}).ph||"{}"),this.sinch.mxp.configureMxpSession(t.callId,e.decrypted.nvps.key,e.decrypted.bd),t.clientMap[e.getSenderId()]=e.getFrom(),this.callBuffert[t.callId]=t,this.alreadyInCall()?(this.sinch.log(new Notification(0,1,"Already in a call, will hangup incoming call.",e)),this.sinch.mxp.subscribe("signalPubNub").then(function(){this.sinch.mxp.callDeny(t)}.bind(this))):this.execListener("onIncomingCall",t)?("connection"==t.callDomain?function(){var e=w.defer();return e.resolve(null),e.promise}():this.initStream(this.incomingCallCustomStream)).then(function(n){return this.sinch.mxp.subscribe("signalPubNub").then(function(){(e.decrypted.nvps||{}).nomedia||t.setStream(n),t.activeInstance=e.getSenderId(),t.proxyUrl=e.decrypted.bd.replace(/(\r\n|\n|\r)/gm,""),t.ackIncomingCall(e).catch(function(e){console.error("Error handling incoming call",e)})}.bind(this))}.bind(this)):this.sinch.log(new SinchError(_.ErrorDomainSDK,C.SDKMissingCallback,"Missing handler, onIncomingCall."))},c.prototype.callUser=function(e,t,n){this.sinch.log(new Notification(0,1,"CallUser method called",e));var i=new o(this.sinch,this.sinch._supportVideo);return i.customHeaders=t,this.initStream(n).then(function(t){return this.sinch.mxp.subscribe("signalPubNub").then(function(){if(i.callState!=T.INITIATING)throw new SinchError(_.ErrorDomainSDK,C.SDKInternalOther,"Error executing user call. Incorrect call state.");i.setStream(t),i.placeCall(e,"data"),this.callBuffert[i.callId]=i}.bind(this))}.bind(this)),i},c.prototype.callSip=function(e,t,n){this.sinch.log(new Notification(0,1,"CallSip method called",e));var i=new o(this.sinch);return i.customHeaders=t,this.initStream(n).then(function(t){return this.sinch.mxp.subscribe("signalPubNub").then(function(){if(i.callState!=T.INITIATING)throw new SinchError(_.ErrorDomainSDK,C.SDKInternalOther,"Error executing user call. Incorrect call state.");i.setStream(t),i.placeCall(e,"sip"),this.callBuffert[i.callId]=i}.bind(this))}.bind(this)),i},c.prototype.connect=function(e,t){this.sinch.log(new Notification(0,1,"connect method called",e));var n=new o(this.sinch);return n.customHeaders=t,this.sinch.mxp.subscribe("signalPubNub").then(function(){if(n.callState!=T.INITIATING)throw new SinchError(_.ErrorDomainSDK,C.SDKInternalOther,"Error executing connect. Incorrect call state.");n.placeCall(e,"connection"),this.callBuffert[n.callId]=n}.bind(this)),n},c.prototype.callPhoneNumber=function(e,t,n){this.sinch.log(new Notification(0,1,"CallPhoneNumber method called",e));var i=new o(this.sinch);return i.customHeaders=t,this.initStream(n,!0).then(function(t){return this.sinch.mxp.subscribe("signalPubNub").then(function(){if(i.callState!=T.INITIATING)throw new SinchError(_.ErrorDomainSDK,C.SDKInternalOther,"Error executing user call. Incorrect call state.");i.setStream(t),i.placeCall(e,"pstn"),this.callBuffert[i.callId]=i}.bind(this))}.bind(this)),i},c.prototype.callConference=function(e,t,n){if(this.sinch.log(new Notification(0,1,"CallConference method called",e)),!(e=""+e)||e.length>64)throw new SinchError(_.ErrorDomainSDK,C.SDKMissingParameter,"Invalid conferenceId. Must be alphanumeric string less than 64 characters in length.");var i=new o(this.sinch);return i.customHeaders=t,this.initStream(n,!0).then(function(t){return this.sinch.mxp.subscribe("signalPubNub").then(function(){if(i.callState!=T.INITIATING)throw new SinchError(_.ErrorDomainSDK,C.SDKInternalOther,"Error executing user call. Incorrect call state.");i.setStream(t),i.placeCall(e,"conference"),this.callBuffert[i.callId]=i}.bind(this))}.bind(this)),i},c.prototype.callGroup=function(e){if(this.sinch.log(new Notification(0,1,"callRoom method called, for group",e)),void 0!==this.groupChannel)throw new SinchError(_.ErrorDomainSDK,C.SDKInternalOther,"Can not call room, already in a room");if(!this.sinch._multiCall)throw new SinchError(_.ErrorDomainSDK,C.SDKInternalOther,"Can not call room, multiCall capability not specified");return this.groupChannel=e,new l(this.sinch,e)};var T={INITIATING:0,PROGRESSING:1,ESTABLISHED:2,ENDED:3,TRANSFERRING:4},A={NONE:0,TIMEOUT:1,CANCELED:6,DENIED:2,FAILURE:4,HUNG_UP:5,NO_ANSWER:3,OTHER_DEVICE_ANSWERED:7,TIMEOUT:1,TRANSFERRED:8},P=10500,N=45e3,j=function(){};j.generateIceCandidate=function(e,t){return"a=candidate:"+Math.random().toString(36).substring(5)+" 1 UDP 2130706431 "+e+" "+t+" typ relay\r\n"},u.prototype.initiate=function(e,t){var n=w.defer();if(this.flagVerified){var s=new SinchError(_.ErrorDomainVerification,C.VerificationUnexpectedInitiateError,"Verification already verified, can't perform another callout.");n.reject(s)}else{var o={identity:{type:"number",endpoint:this.number},custom:this.custom,method:"callout",metadata:{os:i(),platform:r(),sdk:"js/"+this.sinch.getVersion()}};this.sinch.log(new Notification(0,1,"Will initiate callout verification using object",o)),this.sinch.confirmUserCallout(o).then(function(i){var r=this;r.sinch.log(new Notification(0,1,"Successfully initiated callout verification with response",i));var s=0,o=function(){r.sinch.queryVerificationById({number:r.number}).then(function(a){switch(r.sinch.log(new Notification(0,1,"Poll result after "+s+"s",a)),a.status){case"SUCCESSFUL":r.sinch.log(new Notification(0,1,"Successfully verified number after "+s+"s")),e&&e(),n.resolve();break;case"PENDING":if(s+=i.callout.pollingInterval,i.callout.pollingInterval>0&&s<i.callout.stopPollingAfter)window.setTimeout(o,1e3*i.callout.pollingInterval);else{c=new SinchError(_.ErrorDomainVerification,C.VerificationIncorrectCode,"Verification Failed, Timeout");t&&t(c),n.reject(c)}break;case"FAIL":case"ERROR":r.sinch.log(new Notification(0,1,"Verification failed after "+s+"s"));var c=new SinchError(_.ErrorDomainVerification,C.VerificationIncorrectCode,"Verification Failed, "+a.reason);t&&t(c),n.reject(c);break;default:r.sinch.log(new Notification(0,1,"Server response not handled at "+s+"s",a))}}).fail(function(e){var i;i=e.status?new SinchError(_.ErrorDomainVerification,C.VerificationServiceError,"Could not poll verification status: "+e.statusText,e.responseText):e,this.sinch.log(i),t&&t(i),n.reject(i)})};window.setTimeout(o,1e3*i.callout.startPollingAfter)}.bind(this)).fail(function(e){var i;i=e.status?new SinchError(_.ErrorDomainVerification,C.VerificationServiceError,"Could not request verification: "+e.statusText,e.responseText):e,this.sinch.log(i),t&&t(i),n.reject(i)}.bind(this))}return n.promise},h.prototype.initiate=function(e,t){var n=w.defer();if(this.flagVerified){var s=new SinchError(_.ErrorDomainVerification,C.VerificationUnexpectedInitiateError,"Verification already verified, can't perform another callout.");n.reject(s)}else{var o={identity:{type:"number",endpoint:this.number},custom:this.custom,method:"flashcall",metadata:{os:i(),platform:r(),sdk:"js/"+this.sinch.getVersion()}};this.sinch.log(new Notification(0,1,"Will initiate flashcall verification using object: ",o)),this.sinch.confirmUserCallout(o).then(function(t){this.sinch.log(new Notification(0,1,"Successfully initiated callout verification with response",t)),e&&e(),n.resolve()}.bind(this)).fail(function(e){var i;i=e.status?new SinchError(_.ErrorDomainVerification,C.VerificationServiceError,"Could not request verification: "+e.statusText,e.responseText):e,this.sinch.log(i),t&&t(i),n.reject(i)}.bind(this))}return n.promise},h.prototype.verify=function(e,t,n){var i=w.defer();if(this.flagVerified)t&&t(this.cachedResponse),i.resolve(this.cachedResponse);else{var r={number:this.number,source:"manual",flashcall:{cli:e},method:"flashcall"};this.sinch.confirmUserSMS(r).then(function(e){this.flagVerified=!0,this.cachedResponse=e,t&&t(e),i.resolve(e)}.bind(this)).fail(function(e){var t;t=e.status?new SinchError(_.ErrorDomainVerification,C.VerificationIncorrectCode,"Could not verify code: "+e.statusText,e.responseText):e,n&&n(t),i.reject(t)}.bind(this))}return i.promise},l.prototype.addEventListener=function(e){this.eventListeners.push(e)},l.prototype.removeEventListener=function(e){this.eventListeners.splice(this.eventListeners.indexOf(e),1)},l.prototype.execListener=function(e,t){var n=0;return this.eventListeners.forEach(function(i){return n++,i[e]&&i[e](t)}.bind(this)),n},l.prototype.hangupGroup=function(){if(void 0===this.callClient.groupChannel)throw new SinchError(_.ErrorDomainSDK,C.SDKInternalOther,"Can not leave room, not in a room");for(var e in this.callBuffert)this.callBuffert[e].hangup();this.callClient.removeEventListener(this.groupListener),this.callClient.groupChannel=void 0},f.prototype.getMXPMessageObj=function(){var e=new v;return e.mxpSessionId=this.messageId,e.decrypted={bd:JSON.stringify({t:this.textBody})},this.headers&&(e.decrypted.nvps={ph:this.headers}),e.recipientIds=this.recipientIds,e},d.prototype.emptyLog=function(){this.logCounters={version:"2.0",sent:0,received:0,failed:0}},d.prototype.commitLog=function(){(this.logCounters.sent||this.logCounters.received||this.logCounters.failed)&&(this.sinch.log(new Notification(0,1,"Will post IM log to backend for statistics",this.logCounters)),this.sinch.messageReporting(this.logCounters).then(this.emptyLog.bind(this)))},d.prototype.destroy=function(){this.commitLog(),clearInterval(this.messageLogInterval)},d.prototype.handleMessage=function(e){e.recipientIds=e.transportObj.participants.reduce(function(e,t){return e.push(t.destination.identity),e}.bind(this),[]);var t,n=!1;return this.messageBuffert[e.mxpSessionId]?t=this.messageBuffert[e.mxpSessionId]:(t=new f(e,e.decrypted.fu!=this.sinch.user.userId),this.messageBuffert[t.messageId]=t,n=!0),!t.passedToHandler&&(this.eventListeners.forEach(function(e){return t.passedToHandler=!0,e.onIncomingMessage&&e.onIncomingMessage(t)}),n&&this.ackBuffert[t.messageId]&&(this.ackBuffert[t.messageId].forEach(function(e){this.ackMsg(e,t.messageId)}.bind(this)),delete this.ackBuffert[t.messageId]),t.direction||this.logCounters.received++,!0)},d.prototype.addEventListener=function(e){this.eventListeners.push(e)},d.prototype.removeEventListener=function(e){this.eventListeners.splice(this.eventListeners.indexOf(e),1)},d.prototype.send=function(e,t,n){var i=w.defer();if(this.sinch.log(new Notification(0,1,"Send message method called"),i),!(e instanceof f))throw new SinchError(_.ErrorDomainSDK,C.SDKMissingParameter,"Unsupported message parameters",e);return t=t||function(e){return e},n=n||function(e){console.error(e)},w.fcall(function(e){if(void 0===this.sinch.mxp){var t=new SinchError(_.ErrorDomainSDK,C.SDKUnexpectedCall,"Sinch is not ready yet");throw i.reject(t),t}if(e.sent)throw new SinchError(_.ErrorDomainSDK,C.SDKUnexpectedCall,"Message already sent");return e.sent=!0,e}.bind(this),e).then(this.sinch.mxp.sendMessage.bind(this.sinch.mxp)).then(t).then(function(){this.logCounters.sent++}.bind(this)).then(i.resolve).fail(function(e){this.sinch.log(e),n(e),this.logCounters.failed++,i.reject(e)}.bind(this)).progress(function(e){this.sinch.log(e),i.notify(e)}.bind(this)),i.promise},d.prototype.ackMsg=function(e,t){this.messageBuffert[t]&&-1===this.messageBuffert[t].delivered.indexOf(e)?(this.sinch.log(new MXPLog("Recieved ack from "+e+" for message",t)),this.messageBuffert[t].delivered.push(e),this.eventListeners.forEach(function(n){return n.onMessageDelivered&&n.onMessageDelivered(new p(e,t))}.bind(this))):(this.ackBuffert[t]||(this.ackBuffert[t]=[]),this.ackBuffert[t].push(e),this.sinch.log(new MXPLog("Got ack for message with non-existing messageId, storing in ackBuffert",t)))},d.prototype.newMessage=function(e,t,n){if("string"==typeof e&&(e=[e]),"string"!=typeof t)throw new SinchError(_.ErrorDomainSDK,C.SDKUnexpectedCall,"Message text must be a string (for cross device compatability). Please stringify any objects.");if(n&&"string"!=typeof n)throw new SinchError(_.ErrorDomainSDK,C.SDKUnexpectedCall,"Headers must be a string (for cross device compatability). Please stringify any objects.");return new f({recipientIds:e,textBody:t,senderId:this.sinch.user.userId,publicHeaders:n})},SinchError.prototype=Error.prototype,g.prototype.updateUser=function(e){var t=w.defer();return this.sinch.updateUser(e).then(function(e){this.userObj=e,t.resolve(e)}.bind(this)).fail(function(e){t.reject(e)}.bind(this)),t.promise},g.prototype.create=function(e){var t=w.defer(),n={password:e.password,identities:[]};return e.email&&(n.profile={contact:{email:e.email}},n.identities.push({type:"email",endpoint:e.email})),e.username&&n.identities.push({type:"username",endpoint:e.username}),e.number&&n.identities.push({type:"number",endpoint:e.number}),this.sinch.createUser(n).then(function(e){this.userObj=e,this.userId=e.user.identities.reduce(function(e,t){return"username"===t.type?t.endpoint:e+""},""),t.resolve(e)}.bind(this)).fail(function(e){t.reject(new SinchError(_.ErrorDomainApi,C.ApiApiCallFailed,e.data.errorCode+" "+e.data.message,e.data))}),t.promise},g.prototype.authenticate=function(e){if("object"!=typeof e)throw new SinchError(_.ErrorDomainSDK,C.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}',e);if(e.expiresIn=e.expiresIn||86400,e.sessionId&&e.sessionSecret)return e;var t=w.defer(),n="";if(this.sinch._appSecret)e=I(this.sinch._appKey,this.sinch._appSecret,e);else if("email"in e){if(n=this.sinch.authenticate,""==e.email)return t.reject(new SinchError(_.ErrorDomainSDK,C.SDKMissingParameter,"Email is empty",e)),t.promise}else if("username"in e){if(n=this.sinch.authenticateUsername,""==e.username)return t.reject(new SinchError(_.ErrorDomainSDK,C.SDKMissingParameter,"Username is empty",e)),t.promise}else if("number"in e&&(n=this.sinch.authenticateNumber,""==e.number))return t.reject(new SinchError(_.ErrorDomainSDK,C.SDKMissingParameter,"Number is empty",e)),t.promise;if(e.authorization||e.userTicket){if(e.userTicket&&!e.user){var i=e.userTicket.split(":"),r=JSON.parse(atob(i[0]));"username"===!r.identity.type&&t.reject(new SinchError(_.ErrorDomainSDK,C.SDKMissingParameter,"Username missing in userTicket JSON object.",e)),e.user={identities:[r.identity]}}this.userObj=e,this.userObj.authorization=e.authorization||e.userTicket,this.userId=e.user.identities.reduce(function(e,t){return"username"===t.type?t.endpoint:e+""},""),t.resolve()}else n?n(e).then(function(e){this.userObj=e,this.userId=e.user.identities.reduce(function(e,t){return"username"===t.type?t.endpoint:e+""},""),t.resolve()}.bind(this)).fail(function(e){t.reject(new SinchError(_.ErrorDomainApi,C.ApiApiCallFailed,e.data.errorCode+" "+e.data.message,e.data))}):t.reject(new SinchError(_.ErrorDomainSDK,C.SDKMissingParameter,"No valid identity or authentication ticket",e));return t.promise},g.prototype.initSessKeySecret=function(){var e=w.defer(),t={};t.version={os:i()||"unknown",platform:r()||"unknown",sdk:"js/"+this.sinch.getVersion()},t.services={calling:[]},this.sinch._onlineCapability&&t.services.calling.push("online"),this.sinch.capabilities.messaging&&t.services.calling.push("im"),this.sinch.capabilities.calling&&(t.services.calling.push("voip"),t.services.calling.push("p2p"),t.services.calling.push("srtp")),t.authorization=this.userObj.authorization;var n=""!==this.sinch._sessionId;return n&&(t.instanceId=this.sinch._sessionId),t.expiresIn=31536e3,this.sinch[n?"renewSecret":"getInstance"](t).then(function(t){this.sinch.config({sessionId:t.id,sessionSecret:t.secret}),e.resolve()}.bind(this)).fail(function(t){this.sinch._sessionId="",this.sinch._sessionSecret="",e.reject(new SinchError(_.ErrorDomainApi,C.ApiApiCallFailed,t.data.errorCode+" "+t.data.message,t.data))}.bind(this)),e.promise},g.prototype.resumeSession=function(e){var t=w.defer();return this.userId=e.userId,this.sinch.config(e),this.sinch.getUserProfile().then(function(e){this.userObj=e,t.resolve()}.bind(this)).fail(function(e){e instanceof SinchError?t.reject(e):t.reject(new SinchError(_.ErrorDomainApi,C.ApiApiCallFailed,e.data.errorCode+" "+e.data.message,e.data))}),t.promise},g.prototype.getMXPConf=function(){var e=w.defer();return this.sinch.getConfiguration().then(function(t){this.mxpConfig=t,e.resolve()}.bind(this)).fail(function(t){e.reject(new SinchError(_.ErrorDomainApi,C.ApiApiCallFailed,t.data.errorCode+" "+t.data.message,t.data))}),e.promise},y.prototype.request=function(e,t){var n=w.defer();if(this.flagVerified){var s=new SinchError(_.ErrorDomainVerification,C.VerificationUnexpectedInitiateError,"Verification already verified, can't request new code.");n.reject(s)}else{var o={identity:{type:"number",endpoint:this.number},custom:this.custom,method:this.method,metadata:{os:i(),platform:r(),sdk:"js/"+this.sinch.getVersion()}};this.sinch.verify(o).then(function(t){e&&e(),n.resolve()}.bind(this)).fail(function(e){var i;i=e.status?new SinchError(_.ErrorDomainVerification,C.VerificationServiceError,"Could not request verification: "+e.statusText,e.responseText):e,t&&t(i),n.reject(i)}.bind(this))}return n.promise},y.prototype.verify=function(e,t,n){var i=w.defer();if(this.flagVerified)t&&t(this.cachedResponse),i.resolve(this.cachedResponse);else{var r={number:this.number,source:"manual",sms:"sms"==this.method?{code:e}:null,flashcall:"flashcall"==this.method?{cli:e}:null,method:this.method||"sms"};this.sinch.confirmVerification(r).then(function(e){this.flagVerified=!0,this.cachedResponse=e,t&&t(e),i.resolve(e)}.bind(this)).fail(function(e){var t;t=e.status?new SinchError(_.ErrorDomainVerification,C.VerificationIncorrectCode,"Could not verify code: "+e.statusText,e.responseText):e,n&&n(t),i.reject(t)}.bind(this))}return i.promise},y.prototype.initiate=function(e,t){return this.request(e,t)},y.prototype.retry=function(e,t){return this.request(e,t)};var R=function(e){var t=e.key,n=e.decrypted;e.mxpSessionId;try{var i=z.enc.Utf8.parse(JSON.stringify(n));t=z.enc.Base64.parse(t);var r=z.lib.WordArray.random(16),s=z.AES.encrypt(i,t,{iv:r}),o=z.enc.Hex.parse(r.toString(z.enc.Hex)+s.ciphertext.toString(z.enc.Hex))}catch(t){throw t.message=e.message,new m(_.ErrorDomainOther,C.OtherOther,"MXPEncrypt error: "+t.message,t)}return e.encrypted=o.toString(z.enc.Base64),e},L=function(e){try{var t=e.key,n=e.message.split(" ")[5],i=z.enc.Base64.parse(n).toString(z.enc.Hex),r=z.enc.Hex.parse(i.substr(0,32)),s=z.enc.Hex.parse(i.substr(32)),o=z.lib.CipherParams.create({ciphertext:s,salt:null}),a=z.AES.decrypt(o,z.enc.Base64.parse(t),{iv:r}).toString(z.enc.Utf8),c=a.indexOf("{"),u=a.lastIndexOf("}")+1;a=a.substring(c,u),e.decrypted=JSON.parse(a)}catch(t){throw t.message=e.message,new m(_.ErrorDomainOther,C.OtherOther,"MXPDecrypt error: "+t.message,t)}return e};v.prototype.getSenderId=function(){if(void 0===this.decrypted.fi)throw new SinchError(_.ErrorDomainSDK,C.SDKInternalError,"getSenderId failed, no from instance defined",{});return this.decrypted.fsi?this.decrypted.fi+this.decrypted.fsi||"virtual":(this.decrypted.nvps||{}).fsi?this.decrypted.fi+this.decrypted.nvps.fsi||"virtual":this.decrypted.fi||"virtual"},v.prototype.getFrom=function(){return{fc:this.decrypted.fc,fd:this.decrypted.fd,fi:this.decrypted.fi,fsi:this.decrypted.fsi,fs:this.decrypted.fs,fu:this.decrypted.fu}},v.prototype.getInstanceId=function(){return this.decrypted.fi?this.decrypted.fi.split(":")[0]:null},b.prototype.init=function(){return this.subscribe("broadcastPubNub")},b.prototype.close=function(){var e=this.broadcastPubNub,t=this.signalPubNub;return setTimeout(function(){e&&e.offline(),t&&t.offline()}.bind(this),1e4),w.all([this.unsubscribe("broadcastPubNub"),this.unsubscribe("signalPubNub")])},b.prototype.destroy=function(){delete this.broadcastPubNub,delete this.signalPubNub},b.prototype.subscribe=function(e){var t=w.defer(),n={restore:!1,connect:function(e){t.resolve()}.bind(this),channel:Object.keys(this[e].sinchStack),callback:this._onmessagePubNub.bind(this),disconnect:this._ondisconnectPubNub.bind(this),error:this._onerrorPubNub.bind(this)},i=!0;for(var r in this[e].sinchStack)i&=0==this[e].sinchStack[r].length,this[e].sinchStack[r].push(!0);return i?this[e].subscribe(n):t.resolve(),t.promise},b.prototype.subscribeNotificationChannel=function(e){var t=w.defer();this.broadcastPubNub.sinchStack[e]=[];var n={restore:!1,connect:function(e){t.resolve()}.bind(this),channel:e,callback:function(t){this.sinch.onnotification(e,t)}.bind(this),disconnect:this._ondisconnectPubNub.bind(this),error:this._onerrorPubNub.bind(this)};return this.broadcastPubNub.subscribe(n),t.promise},b.prototype.unsubscribe=function(e){var t=!0;for(var n in this[e].sinchStack)this[e].sinchStack[n].pop(),t&=0==this[e].sinchStack[n].length;t&&this[e].unsubscribe({channel:Object.keys(this[e].sinchStack)})},b.prototype.signalStatus=function(){return this.signalPubNub.sinchStack[this.rtcProfile.signalChannel].length>0},b.prototype._onmessagePubNub=function(e){this.sinch.log(new MXPLog("Recieved message",e)),w.fcall(this.collectFrames.bind(this),e).then(this.identifyKey.bind(this)).then(L).then(this.handleMessage.bind(this)).fail(function(t){if(t instanceof m){var n=e.split(" ")[1];this.unencryptedFrames[n]=this.unencryptedFrames[n]||[],this.unencryptedFrames[n].push(t.response.message)}else this.handleError(t)}.bind(this))},b.prototype.configureMxpSession=function(e,t,n){this.sessionBuffert[e]={key:t,body:n},this.processUnencryptedForKey(e)},b.prototype.processUnencryptedForKey=function(e){for(var t in this.unencryptedFrames[e])this._onmessagePubNub(this.unencryptedFrames[e][t]),delete this.unencryptedFrames[e][t]},b.prototype._ondisconnectPubNub=function(e){this.sinch.log(new MXPLog("Was disconnected!",e))},b.prototype._onerrorPubNub=function(e){var t=new MXPError(_.ErrorDomainNetwork,C.NetworkConnectionRefused,"PubNub error",e);this.sinch.log(t)},b.prototype.collectFrames=function(e){var t=w.defer(),n=e.split(" "),i=n[1]+n[2];try{n[3]=parseInt(n[3]),n[4]=parseInt(n[4])}catch(e){console.error("Could not parse MXP indices. Malformatted MXP message.")}if(1===n[4])t.resolve(e);else if((this.messageBuffert[i]||(this.messageBuffert[i]={}))[n[3]]=n[5],Object.keys(this.messageBuffert[i]).length==n[4]){var r=n[0]+" "+n[1]+" "+n[2]+" 0 1 ";for(var s in this.messageBuffert[i])r+=this.messageBuffert[i][s];void 0!==n[6]&&(r+=" "+n[6]),this.sinch.log(new MXPLog("All frames collected and merged, full array",this.messageBuffert[i])),delete this.messageBuffert[i],t.resolve(r)}else t.reject(new MXPLog("All frames not yet gathered",this.messageBuffert[i]));return t.promise},b.prototype.identifyKey=function(e){this.sinch.log(new MXPLog("Will identify key",e));var t,n=w.defer(),i=e.trim().split(" ");return void 0!==(t=i[6])?(this.sinch.log(new MXPLog("Transport key identified",e)),this.getTransport(t).then(function(r){n.resolve(new v({mxpSessionId:i[1],message:e,transportId:t,transportObj:r,key:this.transportBuffert[t].key,keyType:"T"}))}.bind(this)).fail(function(e){n.reject(e)}.bind(this))):void 0!==(this.sessionBuffert[i[1]]||{}).key?(this.sinch.log(new MXPLog("Session key in buffert identified",e)),n.resolve(new v({mxpSessionId:i[1],message:e,key:this.sessionBuffert[i[1]].key,keyType:"S"}))):(this.sinch.log(new MXPLog("No key, fall back on instance key",e)),n.resolve(new v({mxpSessionId:i[1],message:e,key:this.rtcProfile.key,keyType:"I"}))),n.promise},b.prototype.handleMessage=function(e){this.sinch.log(new MXPLog("Will handle message",e));var t=w.defer(),n=e.decrypted.md+"_"+(e.decrypted.bt||"null");return this.sinch.logMxp(new function(e,t){this.handler=e,this.object=t}(n,e)),K[n]?K[n].call(this,e):t.reject(new MXPError(_.ErrorDomainOther,C.OtherOther,"Handler not implemented: "+n,{})),t.promise},b.prototype.handleError=function(e){this.sinch.log(e),e.stack&&console.error(e.stack)},b.prototype.getTransport=function(e){var t=w.defer();if(e.constructor==String){var n=e;void 0!==this.transportBuffert[n]?(this.sinch.log(new MXPLog("Got transport from Buffert",this.transportBuffert[n])),t.resolve(this.transportBuffert[n])):this.sinch.getTransportById({transportId:n}).then(function(e){this.sinch.log(new MXPLog("Got new transport",e)),this.transportBuffert[n]=e,t.resolve(this.transportBuffert[n])}.bind(this))}else{if(e instanceof v||e instanceof Array){var i=e instanceof v?e.recipientIds:e,r=(i=i.filter(function(e,t,n){return n.indexOf(e)===t})).indexOf(this.user.userId);r>-1&&i.splice(r,1);var s=[];i.forEach(function(e){if("string"==typeof e)s.push({identity:e});else if(e instanceof Object)for(var t in e)s.push({identity:e[t],type:t})}),i.push(this.user.userId),i=i.sort();var o=btoa(JSON.stringify(i));if(this.transportBuffert[o]){var a=this.transportBuffert[o];this.sinch.log(new MXPLog("Got cached transport for recipient(s)",a)),e instanceof v?(e.transportObj=a,e.transportId=e.transportObj.transportId,t.resolve(e)):t.resolve(a)}else this.sinch.getTransportByParticipants(s).then(function(n){n.participants.forEach(function(e){e.capabilityUnion=[],(e.instances||[]).forEach(function(t){e.capabilityUnion=e.capabilityUnion.concat(t.capabilities)}),e.capabilityUnion=e.capabilityUnion.filter(function(t,n){return e.capabilityUnion.indexOf(t)==n})});var r=[];if(n.participants.forEach(function(e){-1===e.capabilityUnion.indexOf("im")&&-1===e.capabilityUnion.indexOf("im.1")&&r.push(e.destination.identity)}),r.length>0)throw new SinchError(_.ErrorDomainCapability,C.CapabilityCapabilityMissing,"User missing capability",r);n.participants.unshift({channel:this.rtcProfile.transportChannel,destination:{identity:this.user.userId}});var s=n.participants.reduce(function(e,t){return e.push(t.destination.identity),e}.bind(this),[]),a=i.filter(function(e){return s.indexOf(e)<0});if(i.length!=n.participants.length)throw new MXPError(_.ErrorDomainCapability,C.CapabilityUserNotFound,"User does not exist",a);this.sinch.log(new MXPLog("Got new transport for recipient(s)",n)),this.transportBuffert[o]=n,e instanceof v?(e.transportObj=n,e.transportId=e.transportObj.transportId,t.resolve(e)):t.resolve(n)}.bind(this)).fail(function(e){t.reject(e)});return t.promise}t.reject(new MXPError(_.ErrorDomainOther,C.OtherOther,"Unknown transport ID",n))}return t.promise},b.prototype.sendMXP=function(e){var t=w.defer();return e.sub=e.sub||"broadcastPubNub",w.fcall(this.constructMXP.bind(this),e).then(this.identifyEnKey.bind(this)).then(R).then(this.splitFrames.bind(this)).then(this.getTxChannels.bind(this)).then(this.transmitFrames.bind(this)).then(function(e){t.resolve(e)}).fail(function(e){console.error(e.stack),console.error(e),t.reject(e)}).progress(function(e){t.notify(e)}),t.promise},b.prototype.constructMXP=function(e){return e.decrypted.fu=this.user.userId,e.decrypted.fi=this.sinch._sessionId+":"+this.sinch._subInstanceId,e.decrypted.fd=this.sinch._sessionId,e.decrypted.fc="",this.sinch.log(new MXPLog("Added meta data to MXP message",e)),e},b.prototype.identifyEnKey=function(e){return e.transportObj?(e.transportId=e.transportObj.transportId,e.key=e.transportObj.key,e.keyType="T",e.decrypted.fs=this.rtcProfile.transportChannel):(e.key=this.sessionBuffert[e.mxpSessionId].key,e.keyType="S",e.decrypted.fs=this.rtcProfile.signalChannel),this.sinch.log(new MXPLog("Identified Encoding Key",e)),e},b.prototype.splitFrames=function(e){e.encodedFrames=[];var t=1500;t-=e.mxpSessionId.length,t-=(e.transportId||"").length,t-=9,t-=6;do{e.encodedFrames.push(e.encrypted.slice(0,t)),e.encrypted=e.encrypted.substring(t)}while(e.encrypted.length>0);var n=Math.floor(2e9*Math.random());for(var i in e.encodedFrames)e.encodedFrames[i]="10 "+e.mxpSessionId+" "+(e.encodedFrames.length>1?n:"-")+" "+i+" "+e.encodedFrames.length+" "+e.encodedFrames[i],e.transportId&&(e.encodedFrames[i]+=" "+e.transportId);return this.sinch.log(new MXPLog("Split message into frames as needed",e)),e},b.prototype.getTxChannels=function(e){return e.txChannels=e.txChannels||[],e.transportObj&&e.transportObj.participants.forEach(function(t){e.txChannels.push(t.channel)}),this.sinch.log(new MXPLog("Identified Tx Channels",e)),e},b.prototype.transmitFrames=function(e){var t=w.defer();this.sinch.logMxp(new function(e,t){this.handler=e,this.object=t}(e.decrypted.md+"_"+(e.decrypted.bt||"null"),e));var n,i=[];return n=e.transportObj?e.transportObj.participants.length*e.encodedFrames.length:e.encodedFrames.length,i.length==n&&t.resolve(e),e.txChannels.forEach(function(r){e.encodedFrames.forEach(function(s){this.sinch.log(new MXPLog("Transmitting [channel, frame]",[r,s])),this[e.sub].publish({channel:r,message:s,callback:function(r){i.push(r),t.notify(new Notification(i.length,n,"MXP Message send progress (frame Tx)")),i.length==n&&setTimeout(function(){t.resolve(e)},1e3)},error:function(e){console.error("PubNub: Error sending frame",e),t.reject(new MXPError(_.ErrorDomainOther,C.OtherOther,"PubNub: Error sending frame",e))}})}.bind(this))}.bind(this)),t.promise},MXPError.prototype=Error.prototype;b.prototype.joinIncomingCall=function(e,t){var n=w.defer(),i=new v({mxpSessionId:e.callId},e);return i.decrypted.bd=t||null,i.decrypted.md=3,i.decrypted.bt=t?"media":"sdp",i.decrypted.bv=10,this.sendMXP(i).then(function(){n.resolve()}).fail(function(e){n.reject(e)}).progress(function(e){n.notify(e)}.bind(this)),n.promise},b.prototype.callJoined=function(e){var t=w.defer(),n=new v({mxpSessionId:e.callId},e);return n.decrypted.bd=JSON.stringify(e.clientMap[e.activeInstance]),n.decrypted.md=4,n.decrypted.bt="client",n.decrypted.bv=10,delete n.decrypted.nvps.to,this.sendMXP(n).then(function(){t.resolve()}).fail(function(e){t.reject(e)}).progress(function(e){t.notify(e)}.bind(this)),t.promise},b.prototype.sendSdpAnswer=function(e,t){var n=w.defer(),i=new v({mxpSessionId:e.callId},e);return i.decrypted.bd=t?JSON.stringify(t):null,i.decrypted.md=2,i.decrypted.bt=t?"sdp":null,i.decrypted.bv=10,this.sendMXP(i).then(function(){n.resolve()}).fail(function(e){n.reject(e)}).progress(function(e){n.notify(e)}.bind(this)),n.promise},b.prototype.callHangup=function(e){var t=w.defer(),n=new v({mxpSessionId:e.callId},e);return n.decrypted.md=5,n.decrypted.bv=10,this.sendMXP(n).then(function(){t.resolve()}).fail(function(e){t.reject(e)}).progress(function(e){t.notify(e)}.bind(this)),t.promise},b.prototype.callDeny=function(e){var t=w.defer(),n=new v({mxpSessionId:e.callId},e);return n.decrypted.md=6,n.decrypted.bv=10,this.sendMXP(n).then(function(){t.resolve()}).fail(function(e){t.reject(e)}).progress(function(e){t.notify(e)}.bind(this)),t.promise},b.prototype.callCancel=function(e){var t=w.defer(),n=new v({mxpSessionId:e.callId},e);return n.decrypted.md=7,n.decrypted.bv=10,this.sendMXP(n).then(function(){t.resolve()}).fail(function(e){t.reject(e)}).progress(function(e){t.notify(e)}.bind(this)),t.promise},b.prototype.callTxICECandidate=function(e,t,n){var i=w.defer(),r=new v({mxpSessionId:e.callId},e);return r.decrypted.bd=JSON.stringify(t),r.decrypted.md=10,r.decrypted.bt="sdp",r.decrypted.bv=10,n&&(r.decrypted.nvps=r.decrypted.nvps||{},r.decrypted.nvps.to=n||"undefined"),this.sendMXP(r).then(function(){i.resolve()}).fail(function(e){i.reject(e)}).progress(function(e){i.notify(e)}.bind(this)),i.promise},b.prototype.callTxPeerEventSDP=function(e,t,n){var i=w.defer(),r=new v({mxpSessionId:e.callId},e);return r.decrypted.bd=JSON.stringify(t),r.decrypted.md=10,r.decrypted.bt="sdp",r.decrypted.bv=10,r.decrypted.nvps=r.decrypted.nvps||{},r.decrypted.nvps.to=n||"undefined",this.sendMXP(r).then(function(){i.resolve()}).fail(function(e){i.reject(e)}).progress(function(e){i.notify(e)}.bind(this)),i.promise},b.prototype.msgToMe=function(e){return!e.decrypted.nvps||!e.decrypted.nvps.to||e.decrypted.nvps.to==this.sinch._sessionId+":"+this.sinch._subInstanceId},b.prototype.msgToMe2=function(e){return!e.decrypted.nvps||!e.decrypted.nvps.to||e.decrypted.nvps.to==this.sinch._sessionId};var U={"1_media":function(e){this.msgToMe2(e)?(function(){if(void 0===this.sinch.callClient){var e=new MXPError(_.ErrorDomainCapability,C.CapabilityCapabilityMissing,"Can not process call signal messages. Call capability not set.");this.sinch.log(e)}}.call(this),this.sinch.callClient&&this.sinch.callClient.handleIncomingCall(e)):this.sinch.log(new Notification(0,1,"Received INVITE message not meant for this instance, nvps.to header set to foreign instance id",e))},"2_media":function(e){this.sinch.callClient&&this.sinch.callClient.callBuffert[e.mxpSessionId]&&this.sinch.callClient.callBuffert[e.mxpSessionId].mxpAck(e)},"2_sdp":function(e){this.sinch.callClient&&this.sinch.callClient.callBuffert[e.mxpSessionId]&&this.sinch.callClient.callBuffert[e.mxpSessionId].mxpAck(e)},"3_media":function(e){this.sinch.callClient&&this.sinch.callClient.callBuffert[e.mxpSessionId]&&this.sinch.callClient.callBuffert[e.mxpSessionId].mxpJoin(e)},"3_sdp":function(e){this.sinch.callClient&&this.sinch.callClient.callBuffert[e.mxpSessionId]&&this.sinch.callClient.callBuffert[e.mxpSessionId].mxpJoin(e)},"4_client":function(e){this.sinch.callClient&&this.sinch.callClient.callBuffert[e.mxpSessionId]&&this.sinch.callClient.callBuffert[e.mxpSessionId].mxpJoined(e)},"5_null":function(e){this.msgToMe(e)?this.sinch.callClient&&this.sinch.callClient.callBuffert[e.mxpSessionId]&&this.sinch.callClient.callBuffert[e.mxpSessionId].mxpHangup(e):this.sinch.log(new Notification(0,1,"Received HUNG_UP message not meant for this instance, nvps.to header set to foreign instance id",e))},"6_null":function(e){this.msgToMe(e)?this.sinch.callClient&&this.sinch.callClient.callBuffert[e.mxpSessionId]&&this.sinch.callClient.callBuffert[e.mxpSessionId].mxpDeny(e):this.sinch.callClient&&this.sinch.log(new Notification(0,1,"Received DENIED message not meant for this instance, nvps.to header set to foreign instance id",e))},"6_error/json":function(e){this.msgToMe(e)?this.sinch.callClient&&this.sinch.callClient.callBuffert[e.mxpSessionId]&&this.sinch.callClient.callBuffert[e.mxpSessionId].mxpDeny(e):this.sinch.callClient&&this.sinch.log(new Notification(0,1,"Received DENIED message not meant for this instance, nvps.to header set to foreign instance id",e))},"7_null":function(e){this.msgToMe(e)?this.sinch.callClient&&this.sinch.callClient.callBuffert[e.mxpSessionId]&&this.sinch.callClient.callBuffert[e.mxpSessionId].mxpCancel(e):this.sinch.log(new Notification(0,1,"Received CANCEL message not meant for this instance, nvps.to header set to foreign instance id",e))},"7_client":function(e){this.msgToMe(e)?this.sinch.callClient&&this.sinch.callClient.callBuffert[e.mxpSessionId]&&this.sinch.callClient.callBuffert[e.mxpSessionId].mxpCancel(e):this.sinch.log(new Notification(0,1,"Received CANCEL message not meant for this instance, nvps.to header set to foreign instance id",e))},"9_message":function(e){this.sinch.callClient&&this.sinch.callClient.callBuffert[e.mxpSessionId]&&this.sinch.callClient.callBuffert[e.mxpSessionId].mxpFail(e)},"9_error/json":function(e){this.sinch.callClient&&this.sinch.callClient.callBuffert[e.mxpSessionId]&&this.sinch.callClient.callBuffert[e.mxpSessionId].mxpFail(e)},"10_sdp":function(e){if(this.msgToMe(e)){"type"in JSON.parse(e.decrypted.bd)?this.sinch.callClient&&this.sinch.callClient.callBuffert[e.mxpSessionId]&&this.sinch.callClient.callBuffert[e.mxpSessionId].mxpPeerEventSdp(e):this.sinch.callClient&&this.sinch.callClient.callBuffert[e.mxpSessionId]&&this.sinch.callClient.callBuffert[e.mxpSessionId].mxpInjectIce(e)}else this.sinch.log(new Notification(0,1,"Received SDP/CAND message not meant for this instance, nvps.to header set to foreign instance id",e))}},K=K||{};for(var H in U)K[H]=U[H];b.prototype.sendMessage=function(e){var t=e.getMXPMessageObj(),n=w.defer();return t.decrypted.md=1,t.decrypted.bt="msg",t.decrypted.bv=10,this.getTransport(t).then(this.sendMXP.bind(this)).then(function(e){K["1_msg"].call(this,e),this.sinch.log(new MXPLog("Message sent to all participants",e)),n.resolve(this.sinch.messageClient.messageBuffert[e.mxpSessionId])}.bind(this)).fail(function(e){n.reject(e)}).progress(function(e){n.notify(e)}.bind(this)),n.promise},b.prototype.sendMsgAck=function(e){var t=new v({mxpSessionId:e.mxpSessionId});t.decrypted.md=2,t.decrypted.bt=e.decrypted.bt,t.decrypted.bv=10,t.transportObj=e.transportObj;var n=[];t.transportObj.participants.forEach(function(t){t.channel==e.decrypted.fs&&n.push(t)}.bind(this)),t.transportObj.participants=n,Object.keys(t.transportObj.participants).length>0&&(this.sinch.log(new MXPLog("Will send Ack",t)),this.sendMXP(t).then(function(t){this.sinch.log(new MXPLog("Sent ack",[e.decrypted.fu,t.channel]))}.bind(this)).fail(function(e){console.error(e)}))};var F={none:function(e){console.log("Null handler for message object: ",e)},"1_msg":function(e){(function(){if(void 0===this.sinch.messageClient){var e=new MXPError(_.ErrorDomainCapability,C.CapabilityCapabilityMissing,"Can not process IM messages. Messaging capability not set.");this.sinch.log(e)}}).call(this);this.sinch.messageClient&&this.sinch.messageClient.handleMessage(e)&&e.decrypted.fu!=this.user.userId&&this.sendMsgAck(e)},"2_msg":function(e){this.sinch.messageClient&&this.sinch.messageClient.ackMsg(e.decrypted.fu,e.mxpSessionId)}},K=K||{};for(var H in F)K[H]=F[H];z=z||function(e,t){var n={},i=n.lib={},r=function(){},s=i.Base={extend:function(e){r.prototype=this;var t=new r;return e&&t.mixIn(e),t.hasOwnProperty("init")||(t.init=function(){t.$super.init.apply(this,arguments)}),t.init.prototype=t,t.$super=this,t},create:function(){var e=this.extend();return e.init.apply(e,arguments),e},init:function(){},mixIn:function(e){for(var t in e)e.hasOwnProperty(t)&&(this[t]=e[t]);e.hasOwnProperty("toString")&&(this.toString=e.toString)},clone:function(){return this.init.prototype.extend(this)}},o=i.WordArray=s.extend({init:function(e,t){e=this.words=e||[],this.sigBytes=void 0!=t?t:4*e.length},toString:function(e){return(e||c).stringify(this)},concat:function(e){var t=this.words,n=e.words,i=this.sigBytes;if(e=e.sigBytes,this.clamp(),i%4)for(var r=0;r<e;r++)t[i+r>>>2]|=(n[r>>>2]>>>24-r%4*8&255)<<24-(i+r)%4*8;else if(65535<n.length)for(r=0;r<e;r+=4)t[i+r>>>2]=n[r>>>2];else t.push.apply(t,n);return this.sigBytes+=e,this},clamp:function(){var t=this.words,n=this.sigBytes;t[n>>>2]&=4294967295<<32-n%4*8,t.length=e.ceil(n/4)},clone:function(){var e=s.clone.call(this);return e.words=this.words.slice(0),e},random:function(t){for(var n=[],i=0;i<t;i+=4)n.push(4294967296*e.random()|0);return new o.init(n,t)}}),a=n.enc={},c=a.Hex={stringify:function(e){var t=e.words;e=e.sigBytes;for(var n=[],i=0;i<e;i++){var r=t[i>>>2]>>>24-i%4*8&255;n.push((r>>>4).toString(16)),n.push((15&r).toString(16))}return n.join("")},parse:function(e){for(var t=e.length,n=[],i=0;i<t;i+=2)n[i>>>3]|=parseInt(e.substr(i,2),16)<<24-i%8*4;return new o.init(n,t/2)}},u=a.Latin1={stringify:function(e){var t=e.words;e=e.sigBytes;for(var n=[],i=0;i<e;i++)n.push(String.fromCharCode(t[i>>>2]>>>24-i%4*8&255));return n.join("")},parse:function(e){for(var t=e.length,n=[],i=0;i<t;i++)n[i>>>2]|=(255&e.charCodeAt(i))<<24-i%4*8;return new o.init(n,t)}},h=a.Utf8={stringify:function(e){try{return decodeURIComponent(escape(u.stringify(e)))}catch(e){throw Error("Malformed UTF-8 data")}},parse:function(e){return u.parse(unescape(encodeURIComponent(e)))}},l=i.BufferedBlockAlgorithm=s.extend({reset:function(){this._data=new o.init,this._nDataBytes=0},_append:function(e){"string"==typeof e&&(e=h.parse(e)),this._data.concat(e),this._nDataBytes+=e.sigBytes},_process:function(t){var n=this._data,i=n.words,r=n.sigBytes,s=this.blockSize,a=r/(4*s);if(t=(a=t?e.ceil(a):e.max((0|a)-this._minBufferSize,0))*s,r=e.min(4*t,r),t){for(var c=0;c<t;c+=s)this._doProcessBlock(i,c);c=i.splice(0,t),n.sigBytes-=r}return new o.init(c,r)},clone:function(){var e=s.clone.call(this);return e._data=this._data.clone(),e},_minBufferSize:0});i.Hasher=l.extend({cfg:s.extend(),init:function(e){this.cfg=this.cfg.extend(e),this.reset()},reset:function(){l.reset.call(this),this._doReset()},update:function(e){return this._append(e),this._process(),this},finalize:function(e){return e&&this._append(e),this._doFinalize()},blockSize:16,_createHelper:function(e){return function(t,n){return new e.init(n).finalize(t)}},_createHmacHelper:function(e){return function(t,n){return new f.HMAC.init(e,n).finalize(t)}}});var f=n.algo={};return n}(Math);!function(e){function t(e,t,n,i,r,s,o){return((e=e+(t&n|~t&i)+r+o)<<s|e>>>32-s)+t}function n(e,t,n,i,r,s,o){return((e=e+(t&i|n&~i)+r+o)<<s|e>>>32-s)+t}function i(e,t,n,i,r,s,o){return((e=e+(t^n^i)+r+o)<<s|e>>>32-s)+t}function r(e,t,n,i,r,s,o){return((e=e+(n^(t|~i))+r+o)<<s|e>>>32-s)+t}for(var s=z,o=(c=s.lib).WordArray,a=c.Hasher,c=s.algo,u=[],h=0;64>h;h++)u[h]=4294967296*e.abs(e.sin(h+1))|0;c=c.MD5=a.extend({_doReset:function(){this._hash=new o.init([1732584193,4023233417,2562383102,271733878])},_doProcessBlock:function(e,s){for(o=0;16>o;o++){c=e[a=s+o];e[a]=16711935&(c<<8|c>>>24)|4278255360&(c<<24|c>>>8)}var o=this._hash.words,a=e[s+0],c=e[s+1],h=e[s+2],l=e[s+3],f=e[s+4],p=e[s+5],d=e[s+6],g=e[s+7],y=e[s+8],m=e[s+9],v=e[s+10],b=e[s+11],w=e[s+12],S=e[s+13],I=e[s+14],_=e[s+15],C=o[0],x=o[1],E=o[2],k=o[3],x=r(x=r(x=r(x=r(x=i(x=i(x=i(x=i(x=n(x=n(x=n(x=n(x=t(x=t(x=t(x=t(x,E=t(E,k=t(k,C=t(C,x,E,k,a,7,u[0]),x,E,c,12,u[1]),C,x,h,17,u[2]),k,C,l,22,u[3]),E=t(E,k=t(k,C=t(C,x,E,k,f,7,u[4]),x,E,p,12,u[5]),C,x,d,17,u[6]),k,C,g,22,u[7]),E=t(E,k=t(k,C=t(C,x,E,k,y,7,u[8]),x,E,m,12,u[9]),C,x,v,17,u[10]),k,C,b,22,u[11]),E=t(E,k=t(k,C=t(C,x,E,k,w,7,u[12]),x,E,S,12,u[13]),C,x,I,17,u[14]),k,C,_,22,u[15]),E=n(E,k=n(k,C=n(C,x,E,k,c,5,u[16]),x,E,d,9,u[17]),C,x,b,14,u[18]),k,C,a,20,u[19]),E=n(E,k=n(k,C=n(C,x,E,k,p,5,u[20]),x,E,v,9,u[21]),C,x,_,14,u[22]),k,C,f,20,u[23]),E=n(E,k=n(k,C=n(C,x,E,k,m,5,u[24]),x,E,I,9,u[25]),C,x,l,14,u[26]),k,C,y,20,u[27]),E=n(E,k=n(k,C=n(C,x,E,k,S,5,u[28]),x,E,h,9,u[29]),C,x,g,14,u[30]),k,C,w,20,u[31]),E=i(E,k=i(k,C=i(C,x,E,k,p,4,u[32]),x,E,y,11,u[33]),C,x,b,16,u[34]),k,C,I,23,u[35]),E=i(E,k=i(k,C=i(C,x,E,k,c,4,u[36]),x,E,f,11,u[37]),C,x,g,16,u[38]),k,C,v,23,u[39]),E=i(E,k=i(k,C=i(C,x,E,k,S,4,u[40]),x,E,a,11,u[41]),C,x,l,16,u[42]),k,C,d,23,u[43]),E=i(E,k=i(k,C=i(C,x,E,k,m,4,u[44]),x,E,w,11,u[45]),C,x,_,16,u[46]),k,C,h,23,u[47]),E=r(E,k=r(k,C=r(C,x,E,k,a,6,u[48]),x,E,g,10,u[49]),C,x,I,15,u[50]),k,C,p,21,u[51]),E=r(E,k=r(k,C=r(C,x,E,k,w,6,u[52]),x,E,l,10,u[53]),C,x,v,15,u[54]),k,C,c,21,u[55]),E=r(E,k=r(k,C=r(C,x,E,k,y,6,u[56]),x,E,_,10,u[57]),C,x,d,15,u[58]),k,C,S,21,u[59]),E=r(E,k=r(k,C=r(C,x,E,k,f,6,u[60]),x,E,b,10,u[61]),C,x,h,15,u[62]),k,C,m,21,u[63]);o[0]=o[0]+C|0,o[1]=o[1]+x|0,o[2]=o[2]+E|0,o[3]=o[3]+k|0},_doFinalize:function(){var t=this._data,n=t.words,i=8*this._nDataBytes,r=8*t.sigBytes;n[r>>>5]|=128<<24-r%32;var s=e.floor(i/4294967296);for(n[15+(r+64>>>9<<4)]=16711935&(s<<8|s>>>24)|4278255360&(s<<24|s>>>8),n[14+(r+64>>>9<<4)]=16711935&(i<<8|i>>>24)|4278255360&(i<<24|i>>>8),t.sigBytes=4*(n.length+1),this._process(),n=(t=this._hash).words,i=0;4>i;i++)r=n[i],n[i]=16711935&(r<<8|r>>>24)|4278255360&(r<<24|r>>>8);return t},clone:function(){var e=a.clone.call(this);return e._hash=this._hash.clone(),e}}),s.MD5=a._createHelper(c),s.HmacMD5=a._createHmacHelper(c)}(Math);z=z||function(e,t){var n={},i=n.lib={},r=function(){},s=i.Base={extend:function(e){r.prototype=this;var t=new r;return e&&t.mixIn(e),t.hasOwnProperty("init")||(t.init=function(){t.$super.init.apply(this,arguments)}),t.init.prototype=t,t.$super=this,t},create:function(){var e=this.extend();return e.init.apply(e,arguments),e},init:function(){},mixIn:function(e){for(var t in e)e.hasOwnProperty(t)&&(this[t]=e[t]);e.hasOwnProperty("toString")&&(this.toString=e.toString)},clone:function(){return this.init.prototype.extend(this)}},o=i.WordArray=s.extend({init:function(e,t){e=this.words=e||[],this.sigBytes=void 0!=t?t:4*e.length},toString:function(e){return(e||c).stringify(this)},concat:function(e){var t=this.words,n=e.words,i=this.sigBytes;if(e=e.sigBytes,this.clamp(),i%4)for(var r=0;r<e;r++)t[i+r>>>2]|=(n[r>>>2]>>>24-r%4*8&255)<<24-(i+r)%4*8;else if(65535<n.length)for(r=0;r<e;r+=4)t[i+r>>>2]=n[r>>>2];else t.push.apply(t,n);return this.sigBytes+=e,this},clamp:function(){var t=this.words,n=this.sigBytes;t[n>>>2]&=4294967295<<32-n%4*8,t.length=e.ceil(n/4)},clone:function(){var e=s.clone.call(this);return e.words=this.words.slice(0),e},random:function(t){for(var n=[],i=0;i<t;i+=4)n.push(4294967296*e.random()|0);return new o.init(n,t)}}),a=n.enc={},c=a.Hex={stringify:function(e){var t=e.words;e=e.sigBytes;for(var n=[],i=0;i<e;i++){var r=t[i>>>2]>>>24-i%4*8&255;n.push((r>>>4).toString(16)),n.push((15&r).toString(16))}return n.join("")},parse:function(e){for(var t=e.length,n=[],i=0;i<t;i+=2)n[i>>>3]|=parseInt(e.substr(i,2),16)<<24-i%8*4;return new o.init(n,t/2)}},u=a.Latin1={stringify:function(e){var t=e.words;e=e.sigBytes;for(var n=[],i=0;i<e;i++)n.push(String.fromCharCode(t[i>>>2]>>>24-i%4*8&255));return n.join("")},parse:function(e){for(var t=e.length,n=[],i=0;i<t;i++)n[i>>>2]|=(255&e.charCodeAt(i))<<24-i%4*8;return new o.init(n,t)}},h=a.Utf8={stringify:function(e){try{return decodeURIComponent(escape(u.stringify(e)))}catch(e){throw Error("Malformed UTF-8 data")}},parse:function(e){return u.parse(unescape(encodeURIComponent(e)))}},l=i.BufferedBlockAlgorithm=s.extend({reset:function(){this._data=new o.init,this._nDataBytes=0},_append:function(e){"string"==typeof e&&(e=h.parse(e)),this._data.concat(e),this._nDataBytes+=e.sigBytes},_process:function(t){var n=this._data,i=n.words,r=n.sigBytes,s=this.blockSize,a=r/(4*s);if(t=(a=t?e.ceil(a):e.max((0|a)-this._minBufferSize,0))*s,r=e.min(4*t,r),t){for(var c=0;c<t;c+=s)this._doProcessBlock(i,c);c=i.splice(0,t),n.sigBytes-=r}return new o.init(c,r)},clone:function(){var e=s.clone.call(this);return e._data=this._data.clone(),e},_minBufferSize:0});i.Hasher=l.extend({cfg:s.extend(),init:function(e){this.cfg=this.cfg.extend(e),this.reset()},reset:function(){l.reset.call(this),this._doReset()},update:function(e){return this._append(e),this._process(),this},finalize:function(e){return e&&this._append(e),this._doFinalize()},blockSize:16,_createHelper:function(e){return function(t,n){return new e.init(n).finalize(t)}},_createHmacHelper:function(e){return function(t,n){return new f.HMAC.init(e,n).finalize(t)}}});var f=n.algo={};return n}(Math);!function(e){for(var t=z,n=(r=t.lib).WordArray,i=r.Hasher,r=t.algo,s=[],o=[],a=function(e){return 4294967296*(e-(0|e))|0},c=2,u=0;64>u;){var h;e:{h=c;for(var l=e.sqrt(h),f=2;f<=l;f++)if(!(h%f)){h=!1;break e}h=!0}h&&(8>u&&(s[u]=a(e.pow(c,.5))),o[u]=a(e.pow(c,1/3)),u++),c++}var p=[],r=r.SHA256=i.extend({_doReset:function(){this._hash=new n.init(s.slice(0))},_doProcessBlock:function(e,t){for(var n=this._hash.words,i=n[0],r=n[1],s=n[2],a=n[3],c=n[4],u=n[5],h=n[6],l=n[7],f=0;64>f;f++){if(16>f)p[f]=0|e[t+f];else{var d=p[f-15],g=p[f-2];p[f]=((d<<25|d>>>7)^(d<<14|d>>>18)^d>>>3)+p[f-7]+((g<<15|g>>>17)^(g<<13|g>>>19)^g>>>10)+p[f-16]}d=l+((c<<26|c>>>6)^(c<<21|c>>>11)^(c<<7|c>>>25))+(c&u^~c&h)+o[f]+p[f],g=((i<<30|i>>>2)^(i<<19|i>>>13)^(i<<10|i>>>22))+(i&r^i&s^r&s),l=h,h=u,u=c,c=a+d|0,a=s,s=r,r=i,i=d+g|0}n[0]=n[0]+i|0,n[1]=n[1]+r|0,n[2]=n[2]+s|0,n[3]=n[3]+a|0,n[4]=n[4]+c|0,n[5]=n[5]+u|0,n[6]=n[6]+h|0,n[7]=n[7]+l|0},_doFinalize:function(){var t=this._data,n=t.words,i=8*this._nDataBytes,r=8*t.sigBytes;return n[r>>>5]|=128<<24-r%32,n[14+(r+64>>>9<<4)]=e.floor(i/4294967296),n[15+(r+64>>>9<<4)]=i,t.sigBytes=4*n.length,this._process(),this._hash},clone:function(){var e=i.clone.call(this);return e._hash=this._hash.clone(),e}});t.SHA256=i._createHelper(r),t.HmacSHA256=i._createHmacHelper(r)}(Math),function(){var e=z,t=e.enc.Utf8;e.algo.HMAC=e.lib.Base.extend({init:function(e,n){e=this._hasher=new e.init,"string"==typeof n&&(n=t.parse(n));var i=e.blockSize,r=4*i;n.sigBytes>r&&(n=e.finalize(n)),n.clamp();for(var s=this._oKey=n.clone(),o=this._iKey=n.clone(),a=s.words,c=o.words,u=0;u<i;u++)a[u]^=1549556828,c[u]^=909522486;s.sigBytes=o.sigBytes=r,this.reset()},reset:function(){var e=this._hasher;e.reset(),e.update(this._iKey)},update:function(e){return this._hasher.update(e),this},finalize:function(e){var t=this._hasher;return e=t.finalize(e),t.reset(),t.finalize(this._oKey.clone().concat(e))}})}(),function(){var e=z,t=e.lib.WordArray;e.enc.Base64={stringify:function(e){var t=e.words,n=e.sigBytes,i=this._map;e.clamp(),e=[];for(var r=0;r<n;r+=3)for(var s=(t[r>>>2]>>>24-r%4*8&255)<<16|(t[r+1>>>2]>>>24-(r+1)%4*8&255)<<8|t[r+2>>>2]>>>24-(r+2)%4*8&255,o=0;4>o&&r+.75*o<n;o++)e.push(i.charAt(s>>>6*(3-o)&63));if(t=i.charAt(64))for(;e.length%4;)e.push(t);return e.join("")},parse:function(e){var n=e.length,i=this._map;(r=i.charAt(64))&&-1!=(r=e.indexOf(r))&&(n=r);for(var r=[],s=0,o=0;o<n;o++)if(o%4){var a=i.indexOf(e.charAt(o-1))<<o%4*2,c=i.indexOf(e.charAt(o))>>>6-o%4*2;r[s>>>2]|=(a|c)<<24-s%4*8,s++}return t.create(r,s)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="}}();var z=z||function(e,t){var n={},i=n.lib={},r=function(){},s=i.Base={extend:function(e){r.prototype=this;var t=new r;return e&&t.mixIn(e),t.hasOwnProperty("init")||(t.init=function(){t.$super.init.apply(this,arguments)}),t.init.prototype=t,t.$super=this,t},create:function(){var e=this.extend();return e.init.apply(e,arguments),e},init:function(){},mixIn:function(e){for(var t in e)e.hasOwnProperty(t)&&(this[t]=e[t]);e.hasOwnProperty("toString")&&(this.toString=e.toString)},clone:function(){return this.init.prototype.extend(this)}},o=i.WordArray=s.extend({init:function(e,t){e=this.words=e||[],this.sigBytes=void 0!=t?t:4*e.length},toString:function(e){return(e||c).stringify(this)},concat:function(e){var t=this.words,n=e.words,i=this.sigBytes;if(e=e.sigBytes,this.clamp(),i%4)for(var r=0;r<e;r++)t[i+r>>>2]|=(n[r>>>2]>>>24-r%4*8&255)<<24-(i+r)%4*8;else if(65535<n.length)for(r=0;r<e;r+=4)t[i+r>>>2]=n[r>>>2];else t.push.apply(t,n);return this.sigBytes+=e,this},clamp:function(){var t=this.words,n=this.sigBytes;t[n>>>2]&=4294967295<<32-n%4*8,t.length=e.ceil(n/4)},clone:function(){var e=s.clone.call(this);return e.words=this.words.slice(0),e},random:function(t){for(var n=[],i=0;i<t;i+=4)n.push(4294967296*e.random()|0);return new o.init(n,t)}}),a=n.enc={},c=a.Hex={stringify:function(e){var t=e.words;e=e.sigBytes;for(var n=[],i=0;i<e;i++){var r=t[i>>>2]>>>24-i%4*8&255;n.push((r>>>4).toString(16)),n.push((15&r).toString(16))}return n.join("")},parse:function(e){for(var t=e.length,n=[],i=0;i<t;i+=2)n[i>>>3]|=parseInt(e.substr(i,2),16)<<24-i%8*4;return new o.init(n,t/2)}},u=a.Latin1={stringify:function(e){var t=e.words;e=e.sigBytes;for(var n=[],i=0;i<e;i++)n.push(String.fromCharCode(t[i>>>2]>>>24-i%4*8&255));return n.join("")},parse:function(e){for(var t=e.length,n=[],i=0;i<t;i++)n[i>>>2]|=(255&e.charCodeAt(i))<<24-i%4*8;return new o.init(n,t)}},h=a.Utf8={stringify:function(e){try{return decodeURIComponent(escape(u.stringify(e)))}catch(e){throw Error("Malformed UTF-8 data")}},parse:function(e){return u.parse(unescape(encodeURIComponent(e)))}},l=i.BufferedBlockAlgorithm=s.extend({reset:function(){this._data=new o.init,this._nDataBytes=0},_append:function(e){"string"==typeof e&&(e=h.parse(e)),this._data.concat(e),this._nDataBytes+=e.sigBytes},_process:function(t){var n=this._data,i=n.words,r=n.sigBytes,s=this.blockSize,a=r/(4*s);if(t=(a=t?e.ceil(a):e.max((0|a)-this._minBufferSize,0))*s,r=e.min(4*t,r),t){for(var c=0;c<t;c+=s)this._doProcessBlock(i,c);c=i.splice(0,t),n.sigBytes-=r}return new o.init(c,r)},clone:function(){var e=s.clone.call(this);return e._data=this._data.clone(),e},_minBufferSize:0});i.Hasher=l.extend({cfg:s.extend(),init:function(e){this.cfg=this.cfg.extend(e),this.reset()},reset:function(){l.reset.call(this),this._doReset()},update:function(e){return this._append(e),this._process(),this},finalize:function(e){return e&&this._append(e),this._doFinalize()},blockSize:16,_createHelper:function(e){return function(t,n){return new e.init(n).finalize(t)}},_createHmacHelper:function(e){return function(t,n){return new f.HMAC.init(e,n).finalize(t)}}});var f=n.algo={};return n}(Math);!function(){var e=z,t=e.lib.WordArray;e.enc.Base64={stringify:function(e){var t=e.words,n=e.sigBytes,i=this._map;e.clamp(),e=[];for(var r=0;r<n;r+=3)for(var s=(t[r>>>2]>>>24-r%4*8&255)<<16|(t[r+1>>>2]>>>24-(r+1)%4*8&255)<<8|t[r+2>>>2]>>>24-(r+2)%4*8&255,o=0;4>o&&r+.75*o<n;o++)e.push(i.charAt(s>>>6*(3-o)&63));if(t=i.charAt(64))for(;e.length%4;)e.push(t);return e.join("")},parse:function(e){var n=e.length,i=this._map;(r=i.charAt(64))&&-1!=(r=e.indexOf(r))&&(n=r);for(var r=[],s=0,o=0;o<n;o++)if(o%4){var a=i.indexOf(e.charAt(o-1))<<o%4*2,c=i.indexOf(e.charAt(o))>>>6-o%4*2;r[s>>>2]|=(a|c)<<24-s%4*8,s++}return t.create(r,s)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="}}(),function(e){function t(e,t,n,i,r,s,o){return((e=e+(t&n|~t&i)+r+o)<<s|e>>>32-s)+t}function n(e,t,n,i,r,s,o){return((e=e+(t&i|n&~i)+r+o)<<s|e>>>32-s)+t}function i(e,t,n,i,r,s,o){return((e=e+(t^n^i)+r+o)<<s|e>>>32-s)+t}function r(e,t,n,i,r,s,o){return((e=e+(n^(t|~i))+r+o)<<s|e>>>32-s)+t}for(var s=z,o=(c=s.lib).WordArray,a=c.Hasher,c=s.algo,u=[],h=0;64>h;h++)u[h]=4294967296*e.abs(e.sin(h+1))|0;c=c.MD5=a.extend({_doReset:function(){this._hash=new o.init([1732584193,4023233417,2562383102,271733878])},_doProcessBlock:function(e,s){for(o=0;16>o;o++){c=e[a=s+o];e[a]=16711935&(c<<8|c>>>24)|4278255360&(c<<24|c>>>8)}var o=this._hash.words,a=e[s+0],c=e[s+1],h=e[s+2],l=e[s+3],f=e[s+4],p=e[s+5],d=e[s+6],g=e[s+7],y=e[s+8],m=e[s+9],v=e[s+10],b=e[s+11],w=e[s+12],S=e[s+13],I=e[s+14],_=e[s+15],C=o[0],x=o[1],E=o[2],k=o[3],x=r(x=r(x=r(x=r(x=i(x=i(x=i(x=i(x=n(x=n(x=n(x=n(x=t(x=t(x=t(x=t(x,E=t(E,k=t(k,C=t(C,x,E,k,a,7,u[0]),x,E,c,12,u[1]),C,x,h,17,u[2]),k,C,l,22,u[3]),E=t(E,k=t(k,C=t(C,x,E,k,f,7,u[4]),x,E,p,12,u[5]),C,x,d,17,u[6]),k,C,g,22,u[7]),E=t(E,k=t(k,C=t(C,x,E,k,y,7,u[8]),x,E,m,12,u[9]),C,x,v,17,u[10]),k,C,b,22,u[11]),E=t(E,k=t(k,C=t(C,x,E,k,w,7,u[12]),x,E,S,12,u[13]),C,x,I,17,u[14]),k,C,_,22,u[15]),E=n(E,k=n(k,C=n(C,x,E,k,c,5,u[16]),x,E,d,9,u[17]),C,x,b,14,u[18]),k,C,a,20,u[19]),E=n(E,k=n(k,C=n(C,x,E,k,p,5,u[20]),x,E,v,9,u[21]),C,x,_,14,u[22]),k,C,f,20,u[23]),E=n(E,k=n(k,C=n(C,x,E,k,m,5,u[24]),x,E,I,9,u[25]),C,x,l,14,u[26]),k,C,y,20,u[27]),E=n(E,k=n(k,C=n(C,x,E,k,S,5,u[28]),x,E,h,9,u[29]),C,x,g,14,u[30]),k,C,w,20,u[31]),E=i(E,k=i(k,C=i(C,x,E,k,p,4,u[32]),x,E,y,11,u[33]),C,x,b,16,u[34]),k,C,I,23,u[35]),E=i(E,k=i(k,C=i(C,x,E,k,c,4,u[36]),x,E,f,11,u[37]),C,x,g,16,u[38]),k,C,v,23,u[39]),E=i(E,k=i(k,C=i(C,x,E,k,S,4,u[40]),x,E,a,11,u[41]),C,x,l,16,u[42]),k,C,d,23,u[43]),E=i(E,k=i(k,C=i(C,x,E,k,m,4,u[44]),x,E,w,11,u[45]),C,x,_,16,u[46]),k,C,h,23,u[47]),E=r(E,k=r(k,C=r(C,x,E,k,a,6,u[48]),x,E,g,10,u[49]),C,x,I,15,u[50]),k,C,p,21,u[51]),E=r(E,k=r(k,C=r(C,x,E,k,w,6,u[52]),x,E,l,10,u[53]),C,x,v,15,u[54]),k,C,c,21,u[55]),E=r(E,k=r(k,C=r(C,x,E,k,y,6,u[56]),x,E,_,10,u[57]),C,x,d,15,u[58]),k,C,S,21,u[59]),E=r(E,k=r(k,C=r(C,x,E,k,f,6,u[60]),x,E,b,10,u[61]),C,x,h,15,u[62]),k,C,m,21,u[63]);o[0]=o[0]+C|0,o[1]=o[1]+x|0,o[2]=o[2]+E|0,o[3]=o[3]+k|0},_doFinalize:function(){var t=this._data,n=t.words,i=8*this._nDataBytes,r=8*t.sigBytes;n[r>>>5]|=128<<24-r%32;var s=e.floor(i/4294967296);for(n[15+(r+64>>>9<<4)]=16711935&(s<<8|s>>>24)|4278255360&(s<<24|s>>>8),n[14+(r+64>>>9<<4)]=16711935&(i<<8|i>>>24)|4278255360&(i<<24|i>>>8),t.sigBytes=4*(n.length+1),this._process(),n=(t=this._hash).words,i=0;4>i;i++)r=n[i],n[i]=16711935&(r<<8|r>>>24)|4278255360&(r<<24|r>>>8);return t},clone:function(){var e=a.clone.call(this);return e._hash=this._hash.clone(),e}}),s.MD5=a._createHelper(c),s.HmacMD5=a._createHmacHelper(c)}(Math),function(){var e=z,t=e.lib,n=t.Base,i=t.WordArray,r=(t=e.algo).EvpKDF=n.extend({cfg:n.extend({keySize:4,hasher:t.MD5,iterations:1}),init:function(e){this.cfg=this.cfg.extend(e)},compute:function(e,t){for(var n=(a=this.cfg).hasher.create(),r=i.create(),s=r.words,o=a.keySize,a=a.iterations;s.length<o;){c&&n.update(c);var c=n.update(e).finalize(t);n.reset();for(var u=1;u<a;u++)c=n.finalize(c),n.reset();r.concat(c)}return r.sigBytes=4*o,r}});e.EvpKDF=function(e,t,n){return r.create(n).compute(e,t)}}(),z.lib.Cipher||function(e){var t=(p=z).lib,n=t.Base,i=t.WordArray,r=t.BufferedBlockAlgorithm,s=p.enc.Base64,o=p.algo.EvpKDF,a=t.Cipher=r.extend({cfg:n.extend(),createEncryptor:function(e,t){return this.create(this._ENC_XFORM_MODE,e,t)},createDecryptor:function(e,t){return this.create(this._DEC_XFORM_MODE,e,t)},init:function(e,t,n){this.cfg=this.cfg.extend(n),this._xformMode=e,this._key=t,this.reset()},reset:function(){r.reset.call(this),this._doReset()},process:function(e){return this._append(e),this._process()},finalize:function(e){return e&&this._append(e),this._doFinalize()},keySize:4,ivSize:4,_ENC_XFORM_MODE:1,_DEC_XFORM_MODE:2,_createHelper:function(e){return{encrypt:function(t,n,i){return("string"==typeof n?d:f).encrypt(e,t,n,i)},decrypt:function(t,n,i){return("string"==typeof n?d:f).decrypt(e,t,n,i)}}}});t.StreamCipher=a.extend({_doFinalize:function(){return this._process(!0)},blockSize:1});var c=p.mode={},u=function(e,t,n){var i=this._iv;i?this._iv=void 0:i=this._prevBlock;for(var r=0;r<n;r++)e[t+r]^=i[r]},h=(t.BlockCipherMode=n.extend({createEncryptor:function(e,t){return this.Encryptor.create(e,t)},createDecryptor:function(e,t){return this.Decryptor.create(e,t)},init:function(e,t){this._cipher=e,this._iv=t}})).extend();h.Encryptor=h.extend({processBlock:function(e,t){var n=this._cipher,i=n.blockSize;u.call(this,e,t,i),n.encryptBlock(e,t),this._prevBlock=e.slice(t,t+i)}}),h.Decryptor=h.extend({processBlock:function(e,t){var n=this._cipher,i=n.blockSize,r=e.slice(t,t+i);n.decryptBlock(e,t),u.call(this,e,t,i),this._prevBlock=r}}),c=c.CBC=h,h=(p.pad={}).Pkcs7={pad:function(e,t){for(var n=4*t,r=(n=n-e.sigBytes%n)<<24|n<<16|n<<8|n,s=[],o=0;o<n;o+=4)s.push(r);n=i.create(s,n),e.concat(n)},unpad:function(e){e.sigBytes-=255&e.words[e.sigBytes-1>>>2]}},t.BlockCipher=a.extend({cfg:a.cfg.extend({mode:c,padding:h}),reset:function(){a.reset.call(this);var e=(t=this.cfg).iv,t=t.mode;if(this._xformMode==this._ENC_XFORM_MODE)var n=t.createEncryptor;else n=t.createDecryptor,this._minBufferSize=1;this._mode=n.call(t,this,e&&e.words)},_doProcessBlock:function(e,t){this._mode.processBlock(e,t)},_doFinalize:function(){var e=this.cfg.padding;if(this._xformMode==this._ENC_XFORM_MODE){e.pad(this._data,this.blockSize);var t=this._process(!0)}else t=this._process(!0),e.unpad(t);return t},blockSize:4});var l=t.CipherParams=n.extend({init:function(e){this.mixIn(e)},toString:function(e){return(e||this.formatter).stringify(this)}}),c=(p.format={}).OpenSSL={stringify:function(e){var t=e.ciphertext;return((e=e.salt)?i.create([1398893684,1701076831]).concat(e).concat(t):t).toString(s)},parse:function(e){var t=(e=s.parse(e)).words;if(1398893684==t[0]&&1701076831==t[1]){var n=i.create(t.slice(2,4));t.splice(0,4),e.sigBytes-=16}return l.create({ciphertext:e,salt:n})}},f=t.SerializableCipher=n.extend({cfg:n.extend({format:c}),encrypt:function(e,t,n,i){i=this.cfg.extend(i);var r=e.createEncryptor(n,i);return t=r.finalize(t),r=r.cfg,l.create({ciphertext:t,key:n,iv:r.iv,algorithm:e,mode:r.mode,padding:r.padding,blockSize:e.blockSize,formatter:i.format})},decrypt:function(e,t,n,i){return i=this.cfg.extend(i),t=this._parse(t,i.format),e.createDecryptor(n,i).finalize(t.ciphertext)},_parse:function(e,t){return"string"==typeof e?t.parse(e,this):e}}),p=(p.kdf={}).OpenSSL={execute:function(e,t,n,r){return r||(r=i.random(8)),e=o.create({keySize:t+n}).compute(e,r),n=i.create(e.words.slice(t),4*n),e.sigBytes=4*t,l.create({key:e,iv:n,salt:r})}},d=t.PasswordBasedCipher=f.extend({cfg:f.cfg.extend({kdf:p}),encrypt:function(e,t,n,i){return i=this.cfg.extend(i),n=i.kdf.execute(n,e.keySize,e.ivSize),i.iv=n.iv,(e=f.encrypt.call(this,e,t,n.key,i)).mixIn(n),e},decrypt:function(e,t,n,i){return i=this.cfg.extend(i),t=this._parse(t,i.format),n=i.kdf.execute(n,e.keySize,e.ivSize,t.salt),i.iv=n.iv,f.decrypt.call(this,e,t,n.key,i)}})}(),function(){for(var e=z,t=e.lib.BlockCipher,n=e.algo,i=[],r=[],s=[],o=[],a=[],c=[],u=[],h=[],l=[],f=[],p=[],d=0;256>d;d++)p[d]=128>d?d<<1:d<<1^283;for(var g=0,y=0,d=0;256>d;d++){var m=(m=y^y<<1^y<<2^y<<3^y<<4)>>>8^255&m^99;i[g]=m,r[m]=g;var v=p[g],b=p[v],w=p[b],S=257*p[m]^16843008*m;s[g]=S<<24|S>>>8,o[g]=S<<16|S>>>16,a[g]=S<<8|S>>>24,c[g]=S,S=16843009*w^65537*b^257*v^16843008*g,u[m]=S<<24|S>>>8,h[m]=S<<16|S>>>16,l[m]=S<<8|S>>>24,f[m]=S,g?(g=v^p[p[p[w^v]]],y^=p[p[y]]):g=y=1}var I=[0,1,2,4,8,16,32,64,128,27,54],n=n.AES=t.extend({_doReset:function(){for(var e=(n=this._key).words,t=n.sigBytes/4,n=4*((this._nRounds=t+6)+1),r=this._keySchedule=[],s=0;s<n;s++)if(s<t)r[s]=e[s];else{var o=r[s-1];s%t?6<t&&4==s%t&&(o=i[o>>>24]<<24|i[o>>>16&255]<<16|i[o>>>8&255]<<8|i[255&o]):(o=o<<8|o>>>24,o=i[o>>>24]<<24|i[o>>>16&255]<<16|i[o>>>8&255]<<8|i[255&o],o^=I[s/t|0]<<24),r[s]=r[s-t]^o}for(e=this._invKeySchedule=[],t=0;t<n;t++)s=n-t,o=t%4?r[s]:r[s-4],e[t]=4>t||4>=s?o:u[i[o>>>24]]^h[i[o>>>16&255]]^l[i[o>>>8&255]]^f[i[255&o]]},encryptBlock:function(e,t){this._doCryptBlock(e,t,this._keySchedule,s,o,a,c,i)},decryptBlock:function(e,t){var n=e[t+1];e[t+1]=e[t+3],e[t+3]=n,this._doCryptBlock(e,t,this._invKeySchedule,u,h,l,f,r),n=e[t+1],e[t+1]=e[t+3],e[t+3]=n},_doCryptBlock:function(e,t,n,i,r,s,o,a){for(var c=this._nRounds,u=e[t]^n[0],h=e[t+1]^n[1],l=e[t+2]^n[2],f=e[t+3]^n[3],p=4,d=1;d<c;d++)var g=i[u>>>24]^r[h>>>16&255]^s[l>>>8&255]^o[255&f]^n[p++],y=i[h>>>24]^r[l>>>16&255]^s[f>>>8&255]^o[255&u]^n[p++],m=i[l>>>24]^r[f>>>16&255]^s[u>>>8&255]^o[255&h]^n[p++],f=i[f>>>24]^r[u>>>16&255]^s[h>>>8&255]^o[255&l]^n[p++],u=g,h=y,l=m;g=(a[u>>>24]<<24|a[h>>>16&255]<<16|a[l>>>8&255]<<8|a[255&f])^n[p++],y=(a[h>>>24]<<24|a[l>>>16&255]<<16|a[f>>>8&255]<<8|a[255&u])^n[p++],m=(a[l>>>24]<<24|a[f>>>16&255]<<16|a[u>>>8&255]<<8|a[255&h])^n[p++],f=(a[f>>>24]<<24|a[u>>>16&255]<<16|a[h>>>8&255]<<8|a[255&l])^n[p++],e[t]=g,e[t+1]=y,e[t+2]=m,e[t+3]=f},keySize:8});e.AES=t._createHelper(n)}(),t.exports=s,t.exports.MessageClient=d,t.exports.Message=f,t.exports.Call=o,t.exports.CallClient=c,t.exports.Verification=y,t.exports.CallDetails=a,t.exports.MessageDeliveryInfo=p,t.exports.PAPIDefs=k},{"../VERSION":1,q:13,"sinch-ticketgen":14}]},{},[16])(16)});