samvyo-rn-sdk
Version:
Samvyo React Native SDK for building Enterprise-grade real-time voice/video communication applications.
1 lines • 83.2 kB
JavaScript
"use strict";var e=require("events"),t=require("mediasoup-client"),o=require("react-native"),r=require("react-native-webrtc"),s=require("react-native-permissions");function a(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function i(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(o){if("default"!==o){var r=Object.getOwnPropertyDescriptor(e,o);Object.defineProperty(t,o,r.get?r:{enumerable:!0,get:function(){return e[o]}})}})),t.default=e,Object.freeze(t)}var n=a(e),c=i(t);function d(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var l,u,h={};var p,m,g,f,v={};function _(){if(g)return m;g=1;const e=function(){if(u)return l;u=1;const{EventEmitter:e}=n.default;return l=class extends e{constructor(){super(),this.setMaxListeners(1/0)}safeEmit(e,...t){try{this.emit(e,...t)}catch(t){console.error("safeEmit() | event listener threw an error [event:%s]:",e,t)}}async safeEmitAsPromise(e,...t){return new Promise(((o,r)=>{this.safeEmit(e,...t,o,r)}))}}}(),{sleep:t}=(p||(p=1,v.generateRandomNumber=function(){return Math.round(1e7*Math.random())},v.sleep=async e=>new Promise((t=>setTimeout((()=>t()),e)))),v);return m=class extends e{constructor(e,t){super(),this._closed=!1,this._url=e,this._ws=null,this._socketShouldReconnect=t,this._isConnected=!1,this._lastTimerId=null,this._roomJoined=!1,console.log("Request received to instantiate websocket transport! with url :%s",e),this.createAndUpdateSocket({connectionType:null})}get connectionStatus(){return this._isConnected}createAndUpdateSocket=async({connectionType:e=null})=>{console.log("Room close status:%s",this._closed);let o,r=this;if(this._closed)return void console.log("Websocket already closed!");if(!this._url)return void console.log("url not available!");o=null===e?`${this._url}&connectionType=landing`:`${this._url}&connectionType=${e}`,console.log("the url is:%s",o),this._ws=new WebSocket(o),console.log("new websocket connection is",this._ws);let s=0;for(console.log("websocketHelper createAndUpdateSocket created a new websocket"),console.log("websocketHelper createAndUpdateSocket:%s",this._ws.readyState);1!==this._ws.readyState&&this._socketShouldReconnect;)if(3===this._ws.readyState&&(console.log("websocketHelper createAndUpdateSocket"),await t(2e3),this._ws=new WebSocket(o),console.log("websocketHelper createAndUpdateSocket newly created websocket state:%s",this._ws.readyState)),await t(500),s++,s>250){logger.error("No of retries limit to connect with server exhausted!");break}1===this._ws.readyState&&console.log(`updated the websocket with ready state -${this._ws.readyState}`),this.safeEmit("connected"),console.log(`updating the websocket to redux store with ready state -${this._ws.readyState}`),this._ws.onopen=()=>{this._closed||(console.log("Websocket open"),this.safeEmit("open"))},this._isConnected=!0,this._ws.onmessage=e=>{if(this._closed)return;let t=JSON.parse(e.data);switch(t.id){case"ping":{this._lastTimerId&&clearTimeout(this._lastTimerId);let e=this;this._lastTimerId=setTimeout((function(){e._isConnected=!1,this._roomJoined?e.close(4104,"In call connections close as server is unreachable for last 5 seconds!"):e.close(4103,"Landing page socket close by client as server not reachable for a couple of seconds!"),e._socketShouldReconnect&&(e._closed=!1,e.createAndUpdateSocket({connectionType:"inCall"}))}),22e3);const t={id:"pong"};this._ws.send(JSON.stringify(t));break}case"invalidToken":console.log("Session token invalid!"),this._socketShouldReconnect=!1,this.safeEmit("invalidToken",t);break;case"alreadyActive":this.safeEmit("alreadyActive",t);break;case"passwordDisabled":this.safeEmit("passwordDisabled",t);break;case"notify":this.safeEmit("notify",t.data);break;case"remotePeerJoin":this.safeEmit("roomStartedP2p",t);break;case"userError":this.safeEmit("userError",t);break;case"validationAlert":this.safeEmit("validationError",t);break;case"joinStatusOnLanding":this.safeEmit("defaultJoinStatus",t);break;default:this.safeEmit("message",t)}},this._ws.onclose=e=>{r._closed||(console.log('WebSocket "close" event [wasClean:%s, code:%s, reason:"%s"]',e.wasClean,e.code,e.reason),4503===e.code||4504===e.code?(logger.error("Socket closed with reason",e.reason),r._closed=!0):4500!==e.code&&(console.log("trying to reconnect:%s",e.code),r._closed=!1,this._roomJoined?(console.log("Trying to join after a network reset while in a meeting"),r.createAndUpdateSocket({connectionType:"inCall"})):(console.log("Trying to join after a network reset while on the landing page"),r.createAndUpdateSocket({connectionType:null})),clearTimeout(r._lastTimerId)),this._url=null,console.log("The websocket closed status is:%s",r._closed),r.safeEmit("close",{code:e.code,reason:e.reason}))}};close(e,t){if(!this._closed){console.log("close()"),this._closed=!0,this.safeEmit("close",{code:e,reason:t});try{this._ws.onopen=null,this._ws.onclose=null,this._ws.onerror=null,this._ws.onmessage=null,clearTimeout(this._lastTimerId),e&&t?this._ws.close(e,t):this._ws.close()}catch(e){logger.error("close() | error closing the WebSocket: %o",e)}}}async send(e){if(this._closed)logger.error("Transport closed or not yet ready. Try again later!");else try{this._ws.send(JSON.stringify(e))}catch(e){throw console.log("send() failed:%o",e),e}}}}var y=function(){if(f)return h;f=1;const e=_();return h.WebSocketTransport=e,h}();class b{constructor(){this.queue=new Map}push(e,t){console.log("SocketQueue push",e,t),this.queue.set(e,t),console.log("SocketQueue push",Array.from(this.queue.keys()))}get(e){return this.queue.get(e)}remove(e){this.queue.delete(e)}}const P=async e=>new Promise((t=>setTimeout((()=>t()),e)));var S,I,w={},T={},k={};function C(){if(S)return k;S=1,Object.defineProperty(k,"__esModule",{value:!0}),k.bytesToString=k.stringToBytes=k.NIL=k.X500=k.OID=k.URL=k.DNS=k.hexToByte=k.byteToHex=void 0;let e=[],t={};for(var o=0;o<256;o++)e[o]=(o+256).toString(16).substr(1),t[e[o]]=o;k.byteToHex=e,k.hexToByte=t,k.DNS="6ba7b810-9dad-11d1-80b4-00c04fd430c8",k.URL="6ba7b811-9dad-11d1-80b4-00c04fd430c8",k.OID="6ba7b812-9dad-11d1-80b4-00c04fd430c8",k.X500="6ba7b814-9dad-11d1-80b4-00c04fd430c8",k.NIL="00000000-0000-0000-0000-000000000000";k.stringToBytes=e=>{e=unescape(encodeURIComponent(e));const t=new Uint8Array(e.length);for(let o=0;o<e.length;++o)t[o]=e.charCodeAt(o);return t};return k.bytesToString=e=>{const t=new Uint8Array(e,0,e.byteLength);return String.fromCharCode.apply(null,Array.from(t))},k}function R(){if(I)return T;I=1,Object.defineProperty(T,"__esModule",{value:!0}),T.parse=void 0;const e=C();return T.parse=(t,o,r)=>{let s=o&&r||0,a=0;for(o=o||[],t.toLowerCase().replace(/[0-9a-f]{2}/g,(t=>(a<16&&o&&(o[s+a++]=e.hexToByte[t]),"")));a<16;)o[s+a++]=0;return o},T}var M,E={};function A(){if(M)return E;M=1,Object.defineProperty(E,"__esModule",{value:!0}),E.unparse=void 0;const e=C();return E.unparse=(t,o)=>{let r=o||0,s=e.byteToHex;return s[t[r++]]+s[t[r++]]+s[t[r++]]+s[t[r++]]+"-"+s[t[r++]]+s[t[r++]]+"-"+s[t[r++]]+s[t[r++]]+"-"+s[t[r++]]+s[t[r++]]+"-"+s[t[r++]]+s[t[r++]]+s[t[r++]]+s[t[r++]]+s[t[r++]]+s[t[r++]]},E}var D,N,L={},O={};function q(){if(N)return L;N=1;var e=L&&L.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(L,"__esModule",{value:!0}),L.validate=void 0;const t=e((D||(D=1,Object.defineProperty(O,"__esModule",{value:!0}),O.default=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i),O));return L.validate=e=>"string"==typeof e&&t.default.test(e),L}var B,x={};var U,$={},V={};function j(){if(U)return V;U=1,Object.defineProperty(V,"__esModule",{value:!0}),V.stringify=void 0;const e=q(),t=[];for(let e=0;e<256;++e)t.push((e+256).toString(16).substr(1));return V.stringify=(o,r=0)=>{const s=(t[o[r+0]]+t[o[r+1]]+t[o[r+2]]+t[o[r+3]]+"-"+t[o[r+4]]+t[o[r+5]]+"-"+t[o[r+6]]+t[o[r+7]]+"-"+t[o[r+8]]+t[o[r+9]]+"-"+t[o[r+10]]+t[o[r+11]]+t[o[r+12]]+t[o[r+13]]+t[o[r+14]]+t[o[r+15]]).toLowerCase();if(!(0,e.validate)(s))throw TypeError("Stringified UUID is invalid");return s},V}var W,G,F={};function H(){if(W)return F;W=1,Object.defineProperty(F,"__esModule",{value:!0}),F.rng=void 0;return F.rng=()=>{let e=new Array(16);for(let t=0;t<16;t++)e[t]=255&256*Math.random()+0;return e},F}var J,K={},Q={};function z(){if(J)return Q;J=1,Object.defineProperty(Q,"__esModule",{value:!0}),Q.v35=void 0;const e=j(),t=R(),o=C();return Q.v35=(r,s,a)=>(r,i,n,c=0)=>{if("string"==typeof r&&(r=(0,o.stringToBytes)(r)),"string"==typeof i&&(i=(0,t.parse)(i)),i&&16!==i.length)throw TypeError("Namespace must be array-like (16 iterable integer values, 0-255)");let d=new Uint8Array(16+r.length);if(d.set(i),d.set(r,i.length),d=(0,o.stringToBytes)(a((0,o.bytesToString)(d))),d[6]=15&d[6]|s,d[8]=63&d[8]|128,n)for(let e=0;e<16;++e)n[c+e]=d[e];return n||(0,e.stringify)(d)},Q}var X,Y,Z={};function ee(){if(Y)return K;Y=1;var e=K&&K.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(K,"__esModule",{value:!0}),K.v3=void 0;const t=z(),o=e((X||(X=1,function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.any_hmac_md5=e.b64_hmac_md5=e.hex_hmac_md5=e.any_md5=e.b64_md5=e.hex_md5=void 0;let t=0,o="";e.hex_md5=e=>a(r(c(e))),e.default=e.hex_md5,e.b64_md5=e=>i(r(c(e))),e.any_md5=(e,t)=>n(r(c(e)),t),e.hex_hmac_md5=(e,t)=>a(s(c(e),c(t))),e.b64_hmac_md5=(e,t)=>i(s(c(e),c(t))),e.any_hmac_md5=(e,t,o)=>n(s(c(e),c(t)),o);const r=e=>l(u(d(e),8*e.length)),s=(e,t)=>{var o=d(e);o.length>16&&(o=u(o,8*e.length));let r=Array(16),s=Array(16);for(var a=0;a<16;a++)r[a]=909522486^o[a],s[a]=1549556828^o[a];var i=u(r.concat(d(t)),512+8*t.length);return l(u(s.concat(i),640))},a=e=>{for(var o,r=t?"0123456789ABCDEF":"0123456789abcdef",s="",a=0;a<e.length;a++)o=e.charCodeAt(a),s+=r.charAt(o>>>4&15)+r.charAt(15&o);return s},i=e=>{for(var t="",r=e.length,s=0;s<r;s+=3)for(var a=e.charCodeAt(s)<<16|(s+1<r?e.charCodeAt(s+1)<<8:0)|(s+2<r?e.charCodeAt(s+2):0),i=0;i<4;i++)8*s+6*i>8*e.length?t+=o:t+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(a>>>6*(3-i)&63);return t},n=(e,t)=>{var o,r,s,a,i,n=t.length,c=Array(Math.ceil(e.length/2));for(o=0;o<c.length;o++)c[o]=e.charCodeAt(2*o)<<8|e.charCodeAt(2*o+1);var d=Math.ceil(8*e.length/(Math.log(t.length)/Math.log(2))),l=Array(d);for(r=0;r<d;r++){for(i=[],a=0,o=0;o<c.length;o++)a=(a<<16)+c[o],a-=(s=Math.floor(a/n))*n,(i.length>0||s>0)&&(i[i.length]=s);l[r]=a,c=i}var u="";for(o=l.length-1;o>=0;o--)u+=t.charAt(l[o]);return u},c=e=>{for(var t,o,r="",s=-1;++s<e.length;)t=e.charCodeAt(s),o=s+1<e.length?e.charCodeAt(s+1):0,t>=55296&&t<=56319&&o>=56320&&o<=57343&&(t=65536+((1023&t)<<10)+(1023&o),s++),t<=127?r+=String.fromCharCode(t):t<=2047?r+=String.fromCharCode(192|t>>>6&31,128|63&t):t<=65535?r+=String.fromCharCode(224|t>>>12&15,128|t>>>6&63,128|63&t):t<=2097151&&(r+=String.fromCharCode(240|t>>>18&7,128|t>>>12&63,128|t>>>6&63,128|63&t));return r},d=e=>{let t=Array(e.length>>2);for(var o=0;o<t.length;o++)t[o]=0;for(o=0;o<8*e.length;o+=8)t[o>>5]|=(255&e.charCodeAt(o/8))<<o%32;return t},l=e=>{for(var t="",o=0;o<32*e.length;o+=8)t+=String.fromCharCode(e[o>>5]>>>o%32&255);return t},u=(e,t)=>{e[t>>5]|=128<<t%32,e[14+(t+64>>>9<<4)]=t;for(var o=1732584193,r=-271733879,s=-1732584194,a=271733878,i=0;i<e.length;i+=16){var n=o,c=r,d=s,l=a;o=p(o,r,s,a,e[i+0],7,-680876936),a=p(a,o,r,s,e[i+1],12,-389564586),s=p(s,a,o,r,e[i+2],17,606105819),r=p(r,s,a,o,e[i+3],22,-1044525330),o=p(o,r,s,a,e[i+4],7,-176418897),a=p(a,o,r,s,e[i+5],12,1200080426),s=p(s,a,o,r,e[i+6],17,-1473231341),r=p(r,s,a,o,e[i+7],22,-45705983),o=p(o,r,s,a,e[i+8],7,1770035416),a=p(a,o,r,s,e[i+9],12,-1958414417),s=p(s,a,o,r,e[i+10],17,-42063),r=p(r,s,a,o,e[i+11],22,-1990404162),o=p(o,r,s,a,e[i+12],7,1804603682),a=p(a,o,r,s,e[i+13],12,-40341101),s=p(s,a,o,r,e[i+14],17,-1502002290),r=p(r,s,a,o,e[i+15],22,1236535329),o=m(o,r,s,a,e[i+1],5,-165796510),a=m(a,o,r,s,e[i+6],9,-1069501632),s=m(s,a,o,r,e[i+11],14,643717713),r=m(r,s,a,o,e[i+0],20,-373897302),o=m(o,r,s,a,e[i+5],5,-701558691),a=m(a,o,r,s,e[i+10],9,38016083),s=m(s,a,o,r,e[i+15],14,-660478335),r=m(r,s,a,o,e[i+4],20,-405537848),o=m(o,r,s,a,e[i+9],5,568446438),a=m(a,o,r,s,e[i+14],9,-1019803690),s=m(s,a,o,r,e[i+3],14,-187363961),r=m(r,s,a,o,e[i+8],20,1163531501),o=m(o,r,s,a,e[i+13],5,-1444681467),a=m(a,o,r,s,e[i+2],9,-51403784),s=m(s,a,o,r,e[i+7],14,1735328473),r=m(r,s,a,o,e[i+12],20,-1926607734),o=g(o,r,s,a,e[i+5],4,-378558),a=g(a,o,r,s,e[i+8],11,-2022574463),s=g(s,a,o,r,e[i+11],16,1839030562),r=g(r,s,a,o,e[i+14],23,-35309556),o=g(o,r,s,a,e[i+1],4,-1530992060),a=g(a,o,r,s,e[i+4],11,1272893353),s=g(s,a,o,r,e[i+7],16,-155497632),r=g(r,s,a,o,e[i+10],23,-1094730640),o=g(o,r,s,a,e[i+13],4,681279174),a=g(a,o,r,s,e[i+0],11,-358537222),s=g(s,a,o,r,e[i+3],16,-722521979),r=g(r,s,a,o,e[i+6],23,76029189),o=g(o,r,s,a,e[i+9],4,-640364487),a=g(a,o,r,s,e[i+12],11,-421815835),s=g(s,a,o,r,e[i+15],16,530742520),r=g(r,s,a,o,e[i+2],23,-995338651),o=f(o,r,s,a,e[i+0],6,-198630844),a=f(a,o,r,s,e[i+7],10,1126891415),s=f(s,a,o,r,e[i+14],15,-1416354905),r=f(r,s,a,o,e[i+5],21,-57434055),o=f(o,r,s,a,e[i+12],6,1700485571),a=f(a,o,r,s,e[i+3],10,-1894986606),s=f(s,a,o,r,e[i+10],15,-1051523),r=f(r,s,a,o,e[i+1],21,-2054922799),o=f(o,r,s,a,e[i+8],6,1873313359),a=f(a,o,r,s,e[i+15],10,-30611744),s=f(s,a,o,r,e[i+6],15,-1560198380),r=f(r,s,a,o,e[i+13],21,1309151649),o=f(o,r,s,a,e[i+4],6,-145523070),a=f(a,o,r,s,e[i+11],10,-1120210379),s=f(s,a,o,r,e[i+2],15,718787259),r=f(r,s,a,o,e[i+9],21,-343485551),o=v(o,n),r=v(r,c),s=v(s,d),a=v(a,l)}return[o,r,s,a]},h=(e,t,o,r,s,a)=>v(_(v(v(t,e),v(r,a)),s),o),p=(e,t,o,r,s,a,i)=>h(t&o|~t&r,e,t,s,a,i),m=(e,t,o,r,s,a,i)=>h(t&r|o&~r,e,t,s,a,i),g=(e,t,o,r,s,a,i)=>h(t^o^r,e,t,s,a,i),f=(e,t,o,r,s,a,i)=>h(o^(t|~r),e,t,s,a,i),v=(e,t)=>{var o=(65535&e)+(65535&t);return(e>>16)+(t>>16)+(o>>16)<<16|65535&o},_=(e,t)=>e<<t|e>>>32-t}(Z)),Z));return K.v3=(0,t.v35)("v3",48,o.default),K}var te,oe={};var re,se,ae,ie={},ne={};function ce(){if(se)return ie;se=1;var e=ie&&ie.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(ie,"__esModule",{value:!0}),ie.v5=void 0;const t=z(),o=e((re||(re=1,function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.any_hmac_sha1=e.b64_hmac_sha1=e.hex_hmac_sha1=e.any_sha1=e.b64_sha1=e.hex_sha1=void 0;let t=0,o="";e.hex_sha1=e=>a(r(c(e))),e.default=e.hex_sha1,e.b64_sha1=e=>i(r(c(e))),e.any_sha1=(e,t)=>n(r(c(e)),t),e.hex_hmac_sha1=(e,t)=>a(s(c(e),c(t))),e.b64_hmac_sha1=(e,t)=>i(s(c(e),c(t))),e.any_hmac_sha1=(e,t,o)=>n(s(c(e),c(t)),o);const r=e=>l(u(d(e),8*e.length)),s=(e,t)=>{let o=d(e);o.length>16&&(o=u(o,8*e.length));let r=Array(16),s=Array(16);for(var a=0;a<16;a++)r[a]=909522486^o[a],s[a]=1549556828^o[a];var i=u(r.concat(d(t)),512+8*t.length);return l(u(s.concat(i),672))},a=e=>{for(var o,r=t?"0123456789ABCDEF":"0123456789abcdef",s="",a=0;a<e.length;a++)o=e.charCodeAt(a),s+=r.charAt(o>>>4&15)+r.charAt(15&o);return s},i=e=>{for(var t="",r=e.length,s=0;s<r;s+=3)for(var a=e.charCodeAt(s)<<16|(s+1<r?e.charCodeAt(s+1)<<8:0)|(s+2<r?e.charCodeAt(s+2):0),i=0;i<4;i++)8*s+6*i>8*e.length?t+=o:t+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(a>>>6*(3-i)&63);return t},n=(e,t)=>{var o,r,s,a,i=t.length,n=[],c=Array(Math.ceil(e.length/2));for(o=0;o<c.length;o++)c[o]=e.charCodeAt(2*o)<<8|e.charCodeAt(2*o+1);for(;c.length>0;){for(a=[],s=0,o=0;o<c.length;o++)s=(s<<16)+c[o],s-=(r=Math.floor(s/i))*i,(a.length>0||r>0)&&(a[a.length]=r);n[n.length]=s,c=a}var d="";for(o=n.length-1;o>=0;o--)d+=t.charAt(n[o]);var l=Math.ceil(8*e.length/(Math.log(t.length)/Math.log(2)));for(o=d.length;o<l;o++)d=t[0]+d;return d},c=e=>{for(var t,o,r="",s=-1;++s<e.length;)t=e.charCodeAt(s),o=s+1<e.length?e.charCodeAt(s+1):0,t>=55296&&t<=56319&&o>=56320&&o<=57343&&(t=65536+((1023&t)<<10)+(1023&o),s++),t<=127?r+=String.fromCharCode(t):t<=2047?r+=String.fromCharCode(192|t>>>6&31,128|63&t):t<=65535?r+=String.fromCharCode(224|t>>>12&15,128|t>>>6&63,128|63&t):t<=2097151&&(r+=String.fromCharCode(240|t>>>18&7,128|t>>>12&63,128|t>>>6&63,128|63&t));return r},d=e=>{for(var t=Array(e.length>>2),o=0;o<t.length;o++)t[o]=0;for(o=0;o<8*e.length;o+=8)t[o>>5]|=(255&e.charCodeAt(o/8))<<24-o%32;return t},l=e=>{for(var t="",o=0;o<32*e.length;o+=8)t+=String.fromCharCode(e[o>>5]>>>24-o%32&255);return t},u=(e,t)=>{e[t>>5]|=128<<24-t%32,e[15+(t+64>>9<<4)]=t;for(var o=Array(80),r=1732584193,s=-271733879,a=-1732584194,i=271733878,n=-1009589776,c=0;c<e.length;c+=16){for(var d=r,l=s,u=a,f=i,v=n,_=0;_<80;_++){o[_]=_<16?e[c+_]:g(o[_-3]^o[_-8]^o[_-14]^o[_-16],1);let t=m(m(g(r,5),h(_,s,a,i)),m(m(n,o[_]),p(_)));n=i,i=a,a=g(s,30),s=r,r=t}r=m(r,d),s=m(s,l),a=m(a,u),i=m(i,f),n=m(n,v)}return[r,s,a,i,n]},h=(e,t,o,r)=>e<20?t&o|~t&r:e<40?t^o^r:e<60?t&o|t&r|o&r:t^o^r,p=e=>e<20?1518500249:e<40?1859775393:e<60?-1894007588:-899497514,m=(e,t)=>{var o=(65535&e)+(65535&t);return(e>>16)+(t>>16)+(o>>16)<<16|65535&o},g=(e,t)=>e<<t|e>>>32-t}(ne)),ne));return ie.v5=(0,t.v35)("v5",80,o.default),ie}var de=function(){if(ae)return w;ae=1,Object.defineProperty(w,"__esModule",{value:!0});const e=R(),t=A(),o=q(),r=function(){if(B)return x;B=1,Object.defineProperty(x,"__esModule",{value:!0}),x.version=void 0;const e=q();return x.version=t=>{if(!(0,e.validate)(t))throw TypeError("Invalid UUID");return parseInt(t.substr(14,1),16)},x}(),s=function(){if(G)return $;G=1,Object.defineProperty($,"__esModule",{value:!0}),$.v1=void 0;const e=j(),t=H();let o,r,s=0,a=0;return $.v1=(i,n,c=0)=>{let d=n&&c||0;const l=n||new Uint8Array(16);let u=i&&i.node?i.node:o,h=i&&i.clockseq?i.clockseq:r;if(null==u||null==h){const e=i&&i.random?i.random:i&&i.rng?i.rng():(0,t.rng)();null==u&&(u=o=[1|e[0],e[1],e[2],e[3],e[4],e[5]]),null==h&&(h=r=16383&(e[6]<<8|e[7]))}let p=i&&i.msecs?i.msecs:Date.now(),m=i&&i.nsecs?i.nsecs:a+1;const g=p-s+(m-a)/1e4;if(g<0&&i&&!i.clockseq&&(h=h+1&16383),(g<0||p>s)&&i&&!i.nsecs&&(m=0),m>=1e4)throw new Error("uuid.v1(): Can't create more than 10M uuids/sec");s=p,a=m,r=h,p+=122192928e5;const f=(1e4*(268435455&p)+m)%4294967296;l[d++]=f>>>24&255,l[d++]=f>>>16&255,l[d++]=f>>>8&255,l[d++]=255&f;const v=p/4294967296*1e4&268435455;l[d++]=v>>>8&255,l[d++]=255&v,l[d++]=v>>>24&15|16,l[d++]=v>>>16&255,l[d++]=h>>>8|128,l[d++]=255&h;for(let e=0;e<6;++e)l[d+e]=u[e];return n||(0,e.stringify)(l)},$}(),a=ee(),i=function(){if(te)return oe;te=1,Object.defineProperty(oe,"__esModule",{value:!0}),oe.v4=function(o,r,s){let a=r&&s||0,i=(0,t.rng)();if(!o||o instanceof String||(o.random&&(i=o.random),o.rng&&(i=o.rng())),i[6]=15&i[6]|64,i[8]=63&i[8]|128,r)for(var n=0;n<16;n++)r[a+n]=i[n];return r||(0,e.unparse)(i)};const e=A(),t=H();return oe}(),n=ce(),c=C();return w.default={parse:e.parse,unparse:t.unparse,validate:o.validate,version:r.version,v1:s.v1,v3:a.v3,v4:i.v4,v5:n.v5,NIL:c.NIL,DNS:c.DNS,URL:c.URL,OID:c.OID,X500:c.X500},w}(),le=d(de);const ue=async()=>{try{const e={audioDevices:[],videoDevices:[],audioDevicesOutput:[]};return(await r.mediaDevices.enumerateDevices()).forEach(((t,o)=>{if("audioinput"===t.kind){let r=t.label||`Mic ${Number(o)+1}`;e.audioDevices.push({label:r,deviceId:t.deviceId})}if("videoinput"===t.kind){let r=t.label||`Camera ${Number(o)+1}`;e.videoDevices.push({label:r,deviceId:t.deviceId,facing:t.facing})}if("audiooutput"===t.kind){let r=t.label||`Speaker ${Number(o)+1}`;e.audioDevicesOutput.push({label:r,deviceId:t.deviceId})}})),{success:!0,deviceList:e}}catch(e){return console.error("Error fetching devices:",e),{success:!1,reason:{text:e.message||"Failed to load devices"}}}},he=async e=>{if(!await(async()=>{if("ios"===o.Platform.OS)try{return await s.check(s.PERMISSIONS.IOS.MICROPHONE)!==s.RESULTS.GRANTED&&await s.request(s.PERMISSIONS.IOS.MICROPHONE)!==s.RESULTS.GRANTED?(console.warn("Permission Required","Microphone permission is required for video conferencing"),!1):await s.check(s.PERMISSIONS.IOS.CAMERA)===s.RESULTS.GRANTED||await s.request(s.PERMISSIONS.IOS.CAMERA)===s.RESULTS.GRANTED||(console.warn("Permission Required","Camera permission is required for video conferencing"),!1)}catch(e){return console.error("Error requesting permissions:",e),!1}else{if("android"!==o.Platform.OS)return console.log("Unknown platform",o.Platform.OS),!1;try{console.log("Requesting camera permission");const e=await o.PermissionsAndroid.request(o.PermissionsAndroid.PERMISSIONS.CAMERA,{title:"Camera Permission",message:"App needs access to your camera for video calls",buttonNeutral:"Ask Me Later",buttonNegative:"Cancel",buttonPositive:"OK"});console.log("Requesting microphone permission");const t=await o.PermissionsAndroid.request(o.PermissionsAndroid.PERMISSIONS.RECORD_AUDIO,{title:"Microphone Permission",message:"App needs access to your microphone for calls",buttonNeutral:"Ask Me Later",buttonNegative:"Cancel",buttonPositive:"OK"});return console.log("Permission results",{camera:e,audio:t}),e===o.PermissionsAndroid.RESULTS.GRANTED&&t===o.PermissionsAndroid.RESULTS.GRANTED?(console.log("All permissions granted"),!0):(console.log("Permissions denied",{camera:e,audio:t}),console.error("Permissions Denied","Camera and Audio permissions are required to start the call."),!1)}catch(e){return console.log("Permission request error",e),!1}}})())return console.error("Permissions not granted"),null;try{const t=await r.mediaDevices.getUserMedia(e);return console.log("Stream obtained successfully:",t),t}catch(e){return console.error("Error getting user media:",e),null}},pe=new Set(["240p","360p","480p","720p","1080p","1440p","2160p"]);function me(e){return!!Array.isArray(e)&&e.every((e=>pe.has(e)))}class ge extends Error{}function fe(e){let t=e.replace(/-/g,"+").replace(/_/g,"/");switch(t.length%4){case 0:break;case 2:t+="==";break;case 3:t+="=";break;default:throw new Error("base64 string is not of the correct length")}try{return function(e){return decodeURIComponent(atob(e).replace(/(.)/g,((e,t)=>{let o=t.charCodeAt(0).toString(16).toUpperCase();return o.length<2&&(o="0"+o),"%"+o})))}(t)}catch(e){return atob(t)}}ge.prototype.name="InvalidTokenError";process.env.NODE_ENV;const ve={P2P:"p2p",CONFERENCING:"conferencing",EVENT:"event"},_e="record",ye="rtmpStreamAndRecord",be=["mp4"];function Pe(e,t){try{const o=e.split("/").pop().split(".").pop().toLowerCase();return console.log("Extracted extension:",o),console.log("Expected type:",t.toLowerCase()),o===t.toLowerCase()}catch(e){return console.error("URL parsing error:",e),!1}}r.registerGlobals();const Se={small:{width:160,height:120,frameRate:15},qvga:{width:320,height:240,frameRate:15},vga:{width:640,height:480,frameRate:30},hd:{width:1280,height:720,frameRate:30},fhd:{width:1920,height:1080,frameRate:30}};let Ie;class we extends e.EventEmitter{static async listDevices(){if(Ie)return console.log("Device list already exists:%O",Ie),{success:!0,deviceList:Ie};const e=await ue();return e.success?(Ie=e.deviceList,{success:!0,deviceList:e.deviceList}):{success:!1,reason:e.reason}}static async init({sessionToken:e,roomId:t,peerId:o}={}){if(!e)throw new Error("Session token is required to join the room.");try{console.log("session token",e);const r=function(e,t){if("string"!=typeof e)throw new ge("Invalid token specified: must be a string");t||(t={});const o=!0===t.header?0:1,r=e.split(".")[o];if("string"!=typeof r)throw new ge(`Invalid token specified: missing part #${o+1}`);let s;try{s=fe(r)}catch(e){throw new ge(`Invalid token specified: invalid base64 for part #${o+1} (${e.message})`)}try{return JSON.parse(s)}catch(e){throw new ge(`Invalid token specified: invalid json for part #${o+1} (${e.message})`)}}(e);console.log("Directly decoded token:",r);const{data:s,signallingServerUrl:a}=r;if(!s||!a)throw new Error("Missing required token data");return o||(o=le.v4()),t||(t=Math.floor(1e10*Math.random())),new we({peerId:o,roomId:t,outputData:{sessionToken:e,innerSessionToken:s,signallingServerUrl:a}})}catch(e){throw console.log("Failed to initialise room:",e.message),e}}constructor({peerId:e,roomId:t,outputData:r}){super(),this._closed=!1,this._roomStatus="initialised",this._roomDisplayName=null,this._running=!1,this._cignal=null,this._socket=null,this._sendTransport=null,this._recvTransport=null,this._device=new c.Device({handlerName:"ReactNativeUnifiedPlan"}),this._webCamProducer=null,this._micProducer=null,this._shareProducer=null,this._shareAudioProducer=null,this._producers=new Map,this._consumers=new Map,this._peers=new Map,this._data={...r,inputParams:{peerId:e,roomId:t,roomType:"conferencing"}},this._micStream=null,this._webCamStream=null,this._webcam={device:null,resolution:"hd"},this._mic={device:null},this._deviceList=Ie||null,this._externalVideoStream=null,this._forceVP8=!1,this._forceH264=!1,this._forceVP9=!1,this._enableWebcamLayers=!0,this._numSimulcastStreams=3,this._enableSharingLayers=!0,this._client={os:{name:o.Platform.OS},browser:{name:"ReactNative",version:o.Platform.Version}},this._routerRtpCapabilities=null,this._recordingStartedByMe={},this._cignalConnected=!1,this._reconnectionInitiated=!1,this._restartIceInProgressSendTransport=!1,this._restartIceInProgressRecvTransport=!1,this._activeSpeaker=null,this._queue=new b,this.initLocal({})}get closed(){return this._closed}get data(){return this._data}set data(e){throw new Error("Setting the whole data object is not possible!")}get peers(){return this._peers}set peers(e){throw new Error("Setting the whole peers object is not possible!")}get transports(){return{produce:this._sendTransport,consume:this._recvTransport}}set transports(e){throw new Error("Setting of transport is not possible!")}get videoStream(){return this._webCamStream}get audioStream(){return this._micStream}get clientAgent(){return this._client}get activeParameters(){return this._data.inputParams}get deviceList(){return this._deviceList?this._deviceList:{videoDevices:[],audioDevices:[],audioOutputDevices:[]}}set deviceList(e){throw new Error("Setting of deviceList is not possible!")}get currentlyActiveSpeaker(){return this._activeSpeaker}set currentlyActiveSpeaker(e){throw new Error("Setting of currentActivespeaker is not possible!")}get roomDisplayName(){return this._roomDisplayName}set roomDisplayName(e){throw new Error("Setting of roomDisplayName is not possible!")}async listDevicesInternal(){let e=await ue();if(console.log("Media devices changed!:%O",e),e.audioDevices&&e.audioDevices.length>0&&(this._deviceList.audioDevices=e.audioDevices),e.videoDevices&&e.videoDevices.length>0&&(this._deviceList.videoDevices=e.videoDevices),e.audioDevices&&e.audioDevices.length>0&&(this._deviceList.audioOutputDevices=e.audioDevicesOutput),Ie=this._deviceList,this.emit("deviceListUpdated"),!this._deviceList){const e=await ue();if(e.success)return this._deviceList=e.deviceList,void(Ie=this._deviceList)}}async initLocal(){const e={flag:"react-native",version:o.Platform.Version,os:o.Platform.OS};console.log("The device is:%O",e),await this.listDevicesInternal(),await this._initSocket()}async _initSocket(){let e=this;const t=this.data.signallingServerUrl.replace(/^(http|https):\/\//,""),o=`wss://${t}/?sessionToken=${this.data.sessionToken}&roomId=${this.data.inputParams.roomId}&peerId=${this.data.inputParams.peerId}&roomType=${this.data.inputParams.roomType}`;console.log(`Going to create a new socket! with address: ${t}`),this._socket=new y.WebSocketTransport(o,!0),this._listenToSocket(),this._socket.on("notify",(({type:e,title:t,message:o})=>{this.emit("notification",{eventType:e,eventText:`${t}: ${o}`,roomId:this.data.inputParams.roomId,peerId:this.data.inputParams.peerId})})),this._socket.on("roomStartedP2p",(e=>{console.log("P2P room successfully started"),this._running=!0})),this._socket.on("userError",(t=>{console.log("User Error happened with message:%O",t),e.emit("notification",{eventType:t.title,eventText:`${t.text}`})})),this._socket.on("validationAlert",(e=>{console.log("Validation alert happened")})),this._socket.on("alreadyActive",(({title:e,text:t})=>{this.emit("notification",{eventType:"alreadyActive",eventText:"This peer already has an active connection",roomId:this.data.inputParams.roomId,peerId:this.data.inputParams.peerId})})),this._socket.on("passwordDisabled",(()=>{console.log("password disabled by moderator!"),this.emit("notification",{eventType:"passwordDisabled",eventText:"Password for this room has been disabled by moderator",roomId:this.data.inputParams.roomId})})),this._socket.on("close",(({code:e,reason:t})=>{if(console.log(`socket closed with code ${e}`),4500!==e&&4100!==e){let o=t||"Connection to server closed unexpectedly! Trying to reconnect.";console.log(`socket close code is${e} with reason ${o}`)}else console.log("Socket is now closed!"),this.close()})),this._socket.on("connected",(async()=>{console.log("Socket connected"),e.pc&&e._sendTransport&&e._recvTransport?roomType===ve.P2P&&e.pc?(console.log("Socket seems to be reconnected in mid call! RestartIce needed for p2p call."),"failed"!==e.pc.iceConnectionState&&"disconnected"!==e.pc.iceConnectionState||e.restartICE()):(console.log("Ice restarts for mediasoup transports for a joined peer"),e._sendTransport&&["Failed","disconnected"].includes(e._sendTransport.connectionState)?(console.log("Restart ice for sendtransport"),e.restartIce(e._sendTransport.id,"send")):console.log("Send transport not available!"),e._recvTransport&&["Failed","disconnected"].includes(e._recvTransport.connectionState)?(console.log("Restart ice for recvtransport"),e.restartIce(e._recvTransport.id,"recv")):console.log("Recv transport not available!")):(console.log("Connection getting connected for first time"),this.emit("initSuccess"))})),this._socket.on("defaultJoinStatus",(async e=>{console.log(" Socket defaultjoinstatus:%O",e)}))}_sendMessage(e){this._socket?this._socket.send({usageType:"sdk",...e}):console.log("Tried to send message but socket is not initialized.")}_listenToSocket(){this._socket.on("message",(e=>{try{switch("currentlyActiveSpeaker"===e.id||"allStats"===e.id||console.log("message in Room is:%O",e),e.id){case"chatMessage":this.processChatMessage(e);break;case"existingParticipants":this.onExistingParticipants(e);break;case"newPeerJoin":this.onNewPeer(e);break;case"recordingError":this.handleRecordingErrors(e);break;case"moderatorAuthentication":this.authenticateUser(e);break;case"authenticationRequested":this.authenticationRequested(e);break;case"toggleMyMic":this.toggleMyMic(e);break;case"toggleMyCamera":this.toggleMyCamera(e);break;case"logMeOut":this.logMeOutNew(e);break;case"userAlreadyAuthenticated":this.hideUserAuthenticationDialog(e);break;case"peerLeft":this.peerLeft(e);break;case"recordingStarted":this.setRecordingStatusStarted(e);break;case"recordingStopped":this.setRecordingStatusEnded(e);break;case"startDefaultRecording":this.startRecording();break;case"mediaToggled":this.mediaToggled(e);break;case"processingStarted":this.handleProcessingStart(e);break;case"processingCompleted":this.handleProcessingCompletion(e);break;case"processingError":this.handleProcessingError(e);break;case"createTransportResponse":this.handleCreateTransportRequest(e);break;case"connectTransportResponse":this.handleConnectTransportRequest(e);break;case"connectRecvTransportResponse":this.handleConnectRecvTransportRequest(e);break;case"sendTrackResponse":this.handleSendTrackRequest(e);break;case"recvTrackResponse":this.handleRecvTrackRequest(e);break;case"roomClosedByModerator":this.leaveRoomCommon(),this.roomClosed();break;case"currentlyActiveSpeaker":this.setCurrentlyActiveSpeaker(e);break;case"restartIceResponse":this.restartIceResponse(e);break;case"consumerClosed":this.closeConsumer(e);break;case"handRaise":this.handleHandRaise(e);break;case"upgradeParticipant":this.handleUpgradeParticipant(e);break;case"downgradeParticipant":this.handleDowngradeParticipant(e);break;case"switchMicOff":this.handleSwitchMicOff(e);break;case"screenShareLimitReached":this.handleScreenShareLimitReached(e);break;case"upgradeLimitReached":this.handleUpgradeLimitReached(e);break;case"modUpgradeReq":this.handleModUpgradeReq(e);break;case"lockUnlockRoom":this.handleLockUnlockRoom(e);break;case"peersWaiting":this.handlePeersWaiting(e);break;case"remotePeerJoin":this.handleRemotePeerJoin(e);break;case"offer":console.log("inside offer"),this.handleOffer(e);break;case"answer":console.log("inside answer"),this.handleAnswer(e);break;case"candidate":console.log("inside handle candidate"),this.handleCandidate(e.candidate);break;case"p2pRoomClosed":console.log("inside p2p room close"),this.leaveRoomNewP2p("leaveAndCloseRoom");break;case"p2pUserLeft":console.log("inside p2p user left"),this.userLeftRoom(e);break;case"iceRestart":this.handleIceRestart(e);break;case"iceRestarted":this.handleIceRestartResponse(e);break;case"screenShareP2p":this.handleScreenShareP2p(e);break;default:console.log("Unrecognized message:%o",e)}}catch(e){console.log("listentomessage:%O",e)}}))}joinRoom=async({peerName:e=null,produce:t=!0,produceAudio:o=!0,produceVideo:r=!0,consume:s=!0,videoResolution:a="hd",forceVp8:i=!1,forceVp9:n=!1,forceH264:c=!1,h264Profile:d="high",forcePCMU:l=!1,forcePCMA:u=!1,forceFPS:h=25,enableWebcamLayers:p=!0,numSimulcastStreams:m=3,autoGainControl:g=!0,echoCancellation:f=!0,noiseSuppression:v=!0,sampleRate:_=44e3,channelCount:y=1,videoBitRates:b=[700,250,75],share:P=!1,shareAudio:S=!1,enableSharingLayers:I=!0,shareBitRates:w=[2500,1250,500],audioDeviceId:T=null,videoDeviceId:k=null,peerType:C="participant",roomType:R=ve.CONFERENCING,authenticationRequired:M=!1,password:E=null,roomDisplayName:A=null}={})=>{console.log("Going to join room"),["hd","vga","qvga"].includes(a)||(console.log("Invalid video resolution value. setting it to default value of 'hd' "),a="hd"),"boolean"!=typeof t&&(console.log("Produe should either be true or false"),t=Boolean(t)),"boolean"!=typeof o&&(console.log("ProduceAudio should either be true or false"),o=Boolean(o)),"boolean"!=typeof r&&(console.log("ProduceVideo should either be true or false"),r=Boolean(r)),"boolean"!=typeof s&&(console.log("Consume should either be true or false"),s=Boolean(s)),"boolean"!=typeof i&&(console.log("forceVp8 should either be true or false"),i=Boolean(i)),"boolean"!=typeof n&&(console.log("forceVp9 should either be true or false"),n=Boolean(n)),"boolean"!=typeof c&&(console.log("forceH264 should either be true or false"),c=Boolean(c)),["high","low"].includes(d.toLowerCase())||(console.log("h264Profile should either be 'high' or 'low'"),d="high"),(!Number.isInteger(h)||Number.isInteger(h)&&(h>65||h<5))&&(console.log("forceFPS should be a number between 5 to 65, default value is 25 fps."),h=25),"boolean"!=typeof p&&(console.log("enableWebcamLayers should either be true or false"),p=Boolean(p)),(!Number.isInteger(m)||Number.isInteger(m)&&(m>3||m<1))&&(console.log("numSimulcastStreams should be a number between 1 to 3, default value is 3."),m=3),Array.isArray(b)&&b.length>=1&&b.length<=3&&b.every((e=>Number.isInteger(e)&&e>=75&&e<=800))?console.log("videoBitRates values are correct"):(console.log("videobitrates values should be an integer array with maximum 3 elements and minimum 1 element. The values in the array are '[700,250,75]'"),b=[700,250,75]),"boolean"!=typeof l&&(console.log("forcePCMU should either be true or false"),l=Boolean(l)),"boolean"!=typeof u&&(console.log("forcePCMA should either be true or false"),u=Boolean(u)),"boolean"!=typeof g&&(console.log("autoGainControl should either be true or false"),g=Boolean(g)),"boolean"!=typeof f&&(console.log("echoCancellation should either be true or false"),f=Boolean(f)),"boolean"!=typeof v&&(console.log("noiseSuppression should either be true or false"),v=Boolean(v)),(!Number.isInteger(_)||Number.isInteger(_)&&(_>64e3||_<8e3))&&(console.log("sampleRate should be a number between 8000 to 64000, default value is 44000 Khz."),_=44e3),(!Number.isInteger(y)||Number.isInteger(y)&&(y>2||y<1))&&(console.log("sampleRate should be a number between 1 to 2, default value is 1, which is a mono audio."),y=1),"boolean"!=typeof P&&(console.log("share should either be true or false"),P=Boolean(P)),"boolean"!=typeof S&&(console.log("shareAudio should either be true or false"),S=Boolean(S)),"boolean"!=typeof I&&(console.log("enableSharingLayers should either be true or false"),I=Boolean(I)),Array.isArray(w)&&w.length>=1&&w.length<=3&&w.every((e=>Number.isInteger(e)&&e>=500&&e<=2500))?console.log("shareBitRates values are correct"):(console.log("sharebitrates values should be an integer array with maximum 3 elements and minimum 1 element. The values in the array are '[2500,1250,500]'"),w=[2500,1250,500]),["moderator","participant","attendee"].includes(C)?console.log("peerType is valid:%s",C):(C="participant",console.log("peerType is invalid:%s. By default set to: participant",C)),this._videoResolution=a,this._forceVP8=Boolean(i),this._forceH264=Boolean(c),this._forceVP9=Boolean(n),this._enableWebcamLayers=Boolean(p),this._numSimulcastStreams=m,this._enableSharingLayers=Boolean(I);try{e||(e=randomName()),this.data.inputParams={...this.data.inputParams,peerName:e,produce:t,produceAudio:o,produceVideo:r,consume:s,videoResolution:a,forceVp8:i,forceVp9:n,forceH264:c,h264Profile:d,forceFPS:h,forcePCMU:l,forcePCMA:u,enableWebcamLayers:p,numSimulcastStreams:m,autoGainControl:g,echoCancellation:f,noiseSuppression:v,sampleRate:_,channelCount:y,videoBitRates:b,share:P,shareAudio:S,enableSharingLayers:I,shareBitRates:w,audioDeviceId:T,videoDeviceId:k,peerType:C,roomType:R,authenticationRequired:M,password:E,roomDisplayName:A},console.log("input params are:%O",this.data.inputParams);const D={id:"joinRoom",type:"r",peerId:this.data.inputParams.peerId,participantType:"attendee"===C?"viewer":C,roomType:R,roomDisplayName:A||`room-${1e5+Math.round(9e5*Math.random())}`,browser:this._client,name:this.data.inputParams.peerName,room:this.data.inputParams.roomId,authenticationRequired:M,isRoomPassword:!!E,roomPassword:E||null,usageType:"sdk"};this._sendMessage(D)}catch(e){return console.log("Failed to join room:",e.message),{success:!1,reason:e.message}}};authenticateUser=e=>{console.log("Moderator authentication requested",e),this.emit("moderatorAuthentication",{moderatorName:e.moderatorName,requesterName:e.requesterName,requesterPeerId:e.requesterPeerId,text:e.title})};authenticationRequested=e=>{console.log("Moderator authentication requested:%O",e),this.emit("authenticationRequested",{requesterName:e.requesterName,requesterPeerId:this.data.inputParams.peerId,text:e.title})};allowRoomJoin=e=>{if(!e)return console.log("peerId can't be undefined!"),{success:!1,reason:"PeerId can't be undefined"};console.log("Allow user to join room:%O",e);let t={id:"userAuthenticated",peerId:e,roomName:this.data.inputParams.roomId,moderator:this.data.inputParams.peerId};this._sendMessage(t)};denyRoomJoin=e=>{if(!e)return console.log("peerId can't be undefined!"),{success:!1,reason:"PeerId can't be undefined"};console.log("Deny user to join room:%O",e);let t={id:"userDenied",peerId:e,roomName:this.data.inputParams.roomId,moderator:this.data.inputParams.peerId};this._sendMessage(t)};hideUserAuthenticationDialog=e=>{console.log("authentication already done message",e),this.emit("moderatorAuthStatus",{requesterId:e.requesterId,moderatorActed:e.peerId})};onNewPeer(e){const{peerId:t,displayName:o,participantType:r}=e;this._peers.set(t,{displayName:o,participantType:r,consumers:[]}),this.emit("newPeer",{peerId:t,peerName:o,type:this.data.inputParams.peerId===t?"local":"remote",peerRole:r})}async onExistingParticipants(e){if(console.log("Onexisting participant message:%O",e),this._routerRtpCapabilities=e.routerRtpCapabilities,this._roomStatus="connected",this._roomDisplayName=e.roomDisplayName,this._running=!0,this._socket._roomJoined=!0,this.emit("newPeer",{peerId:this.data.inputParams.peerId,peerName:this.data.inputParams.peerName,type:"local",peerRole:this.data.inputParams.peerType}),this.data.inputParams.produce?await this._createSendTransport():console.log("Produce is false!"),this.data.inputParams.consume){await this._createRecvTransport();let t=this;e.peers&&e.peers.length>0&&e.peers.forEach((e=>{t.emit("newPeer",{peerId:e.peerId,peerName:e.name,type:"remote",peerRole:e.participantType})}))}else console.log("Consume is false!")}setCurrentlyActiveSpeaker(e){const{peerId:t,volume:o}=e.activeSpeaker;this._activeSpeaker=e.activeSpeaker,this.emit("activeSpeaker",{peerId:t,volume:o})}_createSendTransport=async()=>{console.log("Room _createSendTransport");try{this._device.loaded||(console.log("Room _createSendTransport","Going to load device with routerrtpcapabilities"),await this._device.load({routerRtpCapabilities:this._routerRtpCapabilities}));let e="send";this._sendTransport||this._sendMessage({id:"createTransport",peerId:this.data.inputParams.peerId,roomName:this.data.inputParams.roomId,direction:e})}catch(e){console.log("Room _createSendTransport",e)}};_createRecvTransport=async()=>{this._device.loaded||(console.log("loading device for creating recv transport"),await this._device.load({routerRtpCapabilities:this._routerRtpCapabilities}));this._recvTransport||(console.log("receive transport created"),this._sendMessage({id:"createTransport",peerId:this.data.inputParams.peerId,roomName:this.data.inputParams.roomId,direction:"recv"}))};handleCreateTransportRequest=async e=>{console.log("Room handleCreateTransportRequest():%O",e);let t,{transportOptions:o,direction:r}=e;try{if("recv"===r)t=await this._device.createRecvTransport(o),console.log("Room",`handleCreateTransportRequest() recv transport created ${t.id}`),this._recvTransport=t,this.handleRecvTransportListeners();else{if("send"!==r)throw new Error(`bad transport 'direction': ${r}`);t=await this._device.createSendTransport(o),console.log("Room",`handleCreateTransportRequest() send transport created [id:%s]${t.id}`),this._sendTransport=t,this.handleSendTransportListeners(),this.produceMedia()}}catch(e){console.error("handleCreateTransportRequest() failed to create transport [error:%o]",e)}};handleSendTransportListeners=()=>{this._sendTransport.on("connect",this.handleTransportConnectEvent),this._sendTransport.on("produce",this.handleTransportProduceEvent);let e=this;this._sendTransport.on("connectionstatechange",(async t=>{if(console.log(`ConferenceRoom sendTransport connectionState ${t} & socketconnection state ${this._socket._ws.readyState}`),"failed"===t||"disconnected"===t)if(1===this._socket._ws.readyState)e.restartIce(this._sendTransport.id,"send");else{for(;1!==this._socket._ws.readyState;)console.log(`socket not yet ready with state- ${this._socket._ws.readyState}`),await P(1500);"connected"===this._roomStatus&&this.restartIce(this._sendTransport.id,"send")}console.log("ConferenceRoom",`send transport connection state change [state:%s]${t}`)}))};handleTransportConnectEvent=({dtlsParameters:e},t,o)=>{try{const o=e=>{console.log("connect-transport action"),t(),this._queue.remove("connectTransport")};console.log("sending connect-transport action"),this._queue.push("connectTransport",o),console.log("queue after pushing",Array.from(this._queue.queue.keys()));let r={id:"connectTransport",peerId:this.data.inputParams.peerId,roomName:this.data.inputParams.roomId,transportId:this._sendTransport.id,dtlsParameters:e,direction:"send"};this._sendMessage(r)}catch(e){console.log("handleTransportConnectEvent() failed [error:%o]",e),o(e)}};handleTransportProduceEvent=({kind:e,rtpParameters:t,appData:o},r,s)=>{try{console.log("Inside handleTransportProduceEvent");const s=e=>{console.log("handleTransportProduceEvent callback [data:%o]",e),r({id:e.producerId}),this._queue.remove("produce")};console.log("Before pushing produce action"),this._queue.push("produce",s),console.log("queue after pushing",Array.from(this._queue.queue.keys()));let a="cam-audio"===o.mediaTag&&void 0!==this.data.inputParams.audioStatus&&!this.data.inputParams.audioStatus;console.log(`handleTransportProduceEvent() | pause status->${a}`);let i={id:"sendTrack",transportId:this._sendTransport.id,peerId:this.data.inputParams.peerId,roomName:this.data.inputParams.roomId,kind:e,rtpParameters:t,paused:a,appData:o,clientOs:this._client.os.name,browser:this._client.browser};this._sendMessage(i)}catch(e){console.log("handleTransportProduceEvent() failed [error:%o]",e),s(e)}};produceMedia=async()=>{this.data.inputParams.produce?(this.data.inputParams.produceAudio?this.enableMic({deviceId:this.data.inputParams.audioDeviceId?this.data.inputParams.audioDeviceId:null}):console.log("No need to produce audio!"),this._device.canProduce("video")&&(this.data.inputParams.produceVideo?this.enableCam({deviceId:this.data.inputParams.videoDeviceId?this.data.inputParams.videoDeviceId:null}):console.log("No need to produce video!"),this.data.inputParams.share&&this.enableShare({shareAudio:this.data.inputParams.shareAudio,enableSharingLayers:this._enableSharingLayers,shareBitRates:this.data.inputParams.shareBitRates}))):console.log("produce is false!")};handleRecvTransportListeners=async()=>{this._recvTransport.on("connect",this.handleRecvTransportConnectEvent);let e=this;this._recvTransport.on("connectionstatechange",(async t=>{if(console.log(`ConferenceRoom recvTransport connectionState ${t} & socketconnection state ${this._socket._ws.readyState}`),"failed"===t||"disconnected"===t)if(1===this._socket._ws.readyState)e.restartIce(this._recvTransport.id,"recv");else{for(;1!==this._socket._ws.readyState;)console.log(`socket not yet ready with state- ${this._socket._ws.readyState}`),await P(1e3);"connected"===this._roomStatus&&e.restartIce(this._recvTransport.id,"recv")}console.log("ConferenceRoom",`Recv transport connection state change [state:%s]${t}`)}));let t={id:"transportsAvailable",peerId:this.data.inputParams.peerId,roomName:this.data.inputParams.roomId,rtpCapabilities:this._device.rtpCapabilities};this._sendMessage(t)};handleRecvTransportConnectEvent=({dtlsParameters:e},t,o)=>{try{const o=e=>{console.log("ConferenceRoom","connect-recv-transport action"),t(),this._queue.remove("connectRecvTransport")};this._queue.push("connectRecvTransport",o);let r={id:"connectTransport",peerId:this.data.inputParams.peerId,roomName:this.data.inputParams.roomId,transportId:this._recvTransport.id,dtlsParameters:e,direction:"recv"};this._sendMessage(r)}catch(e){console.log("handleTransportConnectEvent() failed [error:%o]",e),o(e)}};handleRecvTrackRequest=async e=>{if(console.log("Room handleRecvTrackRequest",e),!this.data.inputParams.consume)return void console.log("I do not want to consume");let{senderPeerId:t,mediaTag:o,sender:r,audioStatus:s,videoStatus:a,senderParticipantType:i,type:n,producerPaused:d,...l}=e;console.log("New consumer created",l),l.id=l.consumerId,delete l.consumerId,console.log("ConferenceRoom",`senderPeerId is ->${t}`);let u=await this._recvTransport.consume({...l,streamId:`${t}-${"screen-video"===o||"screen-audio"===o?"share":"mic-webcam"}`,appData:{peerId:t,mediaTag:o}});for(;this._recvTransport&&"connected"!==this._recvTransport.connectionState;)console.log(`recv transport connstate${this._recvTransport.connectionState}`),await P(100);this._consumers.set(u.id,u),u.on("transportclose",(()=>{this._consumers.delete(u.id)}));const{spatialLayers:h,temporalLayers:p}=c.parseScalabilityMode(u.rtpParameters.encodings[0].scalabilityMode),m=this._peers.get(this.data.inputParams.peerId);console.log(`Consumer created for sender peerId ${t} for kind ${u.kind} for receiver peerId ${this.data.inputParams.peerId}`),console.log("The old peer data is :%O",m),m?(m["screen-video"===o||"screen-audio"===o?`ss${u.kind}`:u.kind]={consumerId:u.id,type:n,locallyPaused:!1,remotelyPaused:d,rtpParameters:u.rtpParameters,spatialLayers:h,temporalLayers:p,preferredSpatialLayer:h-1,preferredTemporalLayer:p-1,priority:1,codec:u.rtpParameters.codecs[0].mimeType.split("/")[1],track:u.track,share:"screen-video"===o||"screen-audio"===o},console.log("The new peer data is :%O",m),this._peers.set(this.data.inputParams.peerId,m)):(console.log("Peer not found!"),this._peers.set(this.data.inputParams.peerId,{["screen-video"===o||"screen-audio"===o?`ss${u.kind}`:u.kind]:{consumerId:u.id,type:n,locallyPaused:!1,remotelyPaused:d,rtpParameters:u.rtpParameters,spatialLayers:h,temporalLayers:p,preferredSpatialLayer:h-1,preferredTemporalLayer:p-1,priority:1,codec:u.rtpParameters.codecs[0].mimeType.split("/")[1],track:u.track,share:"screen-video"===o||"screen-audio"===o}})),await this.resumeConsumer(u),console.log("Going to emit mic start / videostart"),"audio"===u.kind?"screen-audio"===o?this.emit("ssAudioStart",{peerId:t,audioTrack:u.track,type:"remote"}):this.emit("micStart",{peerId:t,audioTrack:u.track,type:"remote"}):"video"===u.kind&&("screen-video"===o?this.emit("ssVideoStart",{peerId:t,videoTrack:u.track,type:"remote"}):this.emit("videoStart",{peerId:t,videoTrack:u.track,type:"remote"}))};resumeConsumer=async e=>{if(e){console.log("resume consumer",e.appData.peerId,e.appData.mediaTag);try{let t={id:"resumeConsumer",peerId:this.data.inputParams.peerId,roomName:this.data.inputParams.roomId,consumerId:e.id};this._sendMessage(t),await e.resume()}catch(e){console.error(e)}}};handleConnectTransportRequest=async e=>{console.log("handleTransportConnectRequest()");try{const t=this._queue.get("connectTransport");console.log("queue is:%O",Array.from(this._queue.queue.keys())),t&&await t(e)}catch(e){console.error("handleTransportConnectRequest() failed [error:%o]",e)}};handleConnectRecvTransportRequest=async e=>{console.log("handleTransportConnectRecvRequest()");try{const t=this._queue.get("connectRecvTransport");if(!t)throw new Error("recv transport-connect action was not found");await t(e)}catch(e){console.error("handleRecvTransportConnectRequest() failed [error:%o]",e)}};handleSendTrackRequest=async e=>{console.log("ConferenceRoom","handleProduceRequest()");try{const t=this._queue.get("produce");if(!t)throw new Error("produce action was not found");await t(e)}catch(e){console.log("handleProduceRequest() failed [error:%o]",e)}};mediaToggled=e=>{switch(console.log("Media Toggled message:%O",e),