@cloudflare/realtimekit 0.5.0-staging.106 → 0.5.0-staging.108

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/browser.js CHANGED
@@ -19,4 +19,4 @@ slogScale: ${r}, isVoice: ${n}, minEnergy: ${a(this,Nn)},
19
19
  maxEnergy: ${a(this,Mr)}`),r===-1/0||i<1e-6?{energy:0,isVoice:!1}:((!a(this,Nn)||r<a(this,Nn))&&v(this,Nn,r),(!a(this,Mr)||r>a(this,Mr))&&v(this,Mr,r),{energy:(r-a(this,Nn))/(a(this,Mr)-a(this,Nn))*10||0,isVoice:n})},Gd=new WeakSet,xh=function(t){return t<5},Vh=new WeakSet,Dv=function(t=a(this,Cs)){var e;if(!a(this,xi)||!t){Q.hasFeature(ne.ENABLE_AUDIO_ACTIVITY_DEBUG_LOGS)&&u.debug(`AudioActivityReporter: No producerId or energy to report: ${a(this,xi)}`);return}const i={producerId:a(this,xi),energy:Math.round(t),silent:j(e=qd,Gd,xh).call(e,t)};v(this,So,i.silent),this.reportRequest(i)},Uh=new WeakSet,Ov=function(t){const e=Math.log10(t);return Math.round(e)},f(Fh,Gd),f(Fh,Uh);const LD=(t=!1)=>{const e=new window.AudioContext,i=e.createOscillator();i.type="triangle",i.frequency.setValueAtTime(20,e.currentTime);const n=e.createGain();n.gain.setValueAtTime(0,e.currentTime),i.connect(n);const r=e.createMediaStreamDestination();n.connect(r),i.start();const s=r.stream.getAudioTracks()[0];return s.enabled=t,s},xD=(t=!1)=>{var e,i;const n=new MediaStream().getVideoTracks()[0],r=document.createElement("canvas");r.height=(e=n==null?void 0:n.getSettings().height)!=null?e:720,r.width=(i=n==null?void 0:n.getSettings().width)!=null?i:1280;const s=r.getContext("2d");s.fillStyle="black",s.fillRect(0,0,r.width,r.height),setInterval(()=>{s.fillStyle="black",s.fillRect(0,0,r.width,r.height)},1e3);const o=r.captureStream().getVideoTracks()[0];return o.enabled=t,o};var VD=Object.defineProperty,UD=Object.getOwnPropertyDescriptor,ue=(t,e,i,n)=>{for(var r=n>1?void 0:n?UD(e,i):e,s=t.length-1,o;s>=0;s--)(o=t[s])&&(r=(n?o(e,i,r):o(r))||r);return n&&r&&VD(e,i,r),r};const Vi=["video/VP9","video/VP8"];var Jd,$d,Pt,$,Eo,Ar,Vt,Ps,Rs,Dr,Kd,Ln,To,Ms,As,Ut,Kt,Or,Ds,gt,Rt,Os,ko,Bh,Nv,Wh,Lv,jh,xv;class le{constructor(e,i,n){f(this,Or),f(this,gt),f(this,Os),f(this,Bh),f(this,Wh),f(this,jh),m(this,"context"),m(this,"authToken"),m(this,"e2ee"),f(this,Jd,void 0),f(this,$d,void 0),f(this,Pt,void 0),f(this,$,void 0),f(this,Eo,void 0),f(this,Ar,void 0),f(this,Vt,void 0),f(this,Ps,void 0),f(this,Rs,void 0),f(this,Dr,void 0),f(this,Kd,void 0),f(this,Ln,void 0),f(this,To,void 0),f(this,Ms,void 0),f(this,As,void 0),f(this,Ut,void 0),f(this,Kt,void 0),m(this,"partialJoinRoomPromise");var r,s;this.context=e;const{socket:o}=n;this.mediaJoined=!1,v(this,Ms,new Map([["video/VP9",new Set],["video/VP8",new Set]])),v(this,As,new Map([["video/VP9",new Set],["video/VP8",new Set]])),v(this,Ar,i),v(this,Pt,o),v(this,Ps,!1),v(this,$,new DD(e,o,i)),v(this,Vt,a(this,$).events),v(this,Ln,new Set),v(this,Ut,new Map),v(this,Rs,!1),v(this,Dr,new Sd),i===et.CF&&!navigator.isReactNative&&v(this,Kt,new Fh(a(this,$).socketHandler.audioActivity.bind(a(this,$).socketHandler))),this.e2ee=(s=(r=e.getValue("modules").e2ee)==null?void 0:r.enabled)!=null?s:!1,this.handleSocketEvents(),this.handleCallstatsEvents(),v(this,Kd,Ic(()=>h(this,null,function*(){if(!a(this,Or,Ds).mediaJoinAttempted)return;const{roomJoined:c}=yield this.joinRoom(a(this,$d),a(this,Jd),{},!0,!0);c&&(P.emit(R.RESET_PRODUCER_STATE),P.emit(R.ROOM_NODE_RECONNECTED))}),5e3,{leading:!0,maxWait:1e3}))}get peerId(){return this.context.getValue("peerId")}get mediaJoined(){return a(this,Or,Ds).mediaJoined}set mediaJoined(e){a(this,Or,Ds).mediaJoined=e}reset(e=!0){a(this,$).closeAllProducers(),a(this,$).closeAllConsumers(),a(this,Ut).clear(),a(this,Ln).clear(),e&&(this.partialJoinRoomPromise=void 0,a(this,Dr).stop(),a(this,$).stopAllTransports(),a(this,$).reset(),v(this,Dr,new Sd))}joinRoom(e,i){return h(this,arguments,function*(n,r,s={},o=!1,c=!1){a(this,Or,Ds).mediaJoinAttempted=!0,v(this,Ps,!0),this.reset(o);const d=at().ipInfo;if(d!=null&&d.loc&&!a(this,To)){const p=d.loc.split(",");v(this,To,{latitude:parseFloat(p[0]),longitude:parseFloat(p[1])})}let l;try{return l=yield a(this,Dr).push(()=>this._joinRoom(n,r,s,c,a(this,To)),"joinRoom"),l}catch(p){l={roomJoined:!1}}return l.roomJoined||P.emit(R.ROOM_NODE_FAILED),l})}_partialJoinRoom(e,i,n=!1,r=void 0){return h(this,null,function*(){var s;const{ipInfo:o}=at();let c=r;if(o!=null&&o.loc&&!r){const[p,g]=o.loc.split(",").map(parseFloat);c={latitude:p,longitude:g}}const d=(s=Q.getValue(ne.FORCE_VIDEO_CODEC))==null?void 0:s.toString(),l=yD(d);v(this,Eo,l),yield th((p,g)=>h(this,null,function*(){if(!a(this,Pt).isConnected){g(new Error("socket is not connected"));return}p>0&&u.warn(`retrying sending join room request, count: ${p}`);try{yield a(this,$).socketHandler.joinRoom(i,e,l,n,c)}catch(y){throw u.error("failed to send join room request, error:",{error:y}),y}}),{delayTime:1e3,strategy:"exponential",maxRetryCount:Q.hasFeature(ne.ENABLE_HIVE_INFINITE_RETRIES)?1/0:3}),yield a(this,$).setupTransports({send:!0,recv:!0}),a(this,Ar)!==et.HIVE&&Q.hasFeature(ne.PRECREATE_PRODUCERS)&&(this.shareWebcam(xD()),this.shareMic(LD()))})}partialJoinRoom(e,i,n=!1,r=void 0){return h(this,null,function*(){return this.partialJoinRoomPromise=a(this,Dr).push(()=>this._partialJoinRoom(e,i,n,r)),this.partialJoinRoomPromise})}_joinRoom(e,i){return h(this,arguments,function*(n,r,s={},o=!1,c=null){v(this,$d,n);try{this.partialJoinRoomPromise?yield this.partialJoinRoomPromise:yield this._partialJoinRoom(n,r,o,c)}catch(d){u.error("error in partial join room",{error:d})}finally{this.partialJoinRoomPromise=void 0}try{return navigator.product!=="ReactNative"&&setTimeout(()=>h(this,null,function*(){const d={userId:this.context.getValue("userId"),peerId:this.peerId,roomUUID:r,roomViewType:"groupCall",deviceInfo:q(x({},_e.getDeviceInfo()),{userAgent:navigator.userAgent,memory:navigator.deviceMemory,cpus:navigator.hardwareConcurrency}),sdkName:this.context.getValue("sdkName"),sdkVersion:this.context.getValue("sdkVersion"),metaData:{},permissions:{}};J.roomJoined(d)})),{roomJoined:yield this.completeJoinRoom()}}catch(d){return u.error("error on sending join room request",{error:d}),{roomJoined:!1}}})}completeJoinRoom(){return h(this,null,function*(){try{this.mediaJoined=!0;const{roomState:e}=yield a(this,$).socketHandler.notifySelfJoinComplete();return v(this,Jd,e.roomUuid),v(this,Rs,!0),v(this,Ps,!1),!0}catch(e){return u.error("error on completing join room:",{error:e}),this.mediaJoined=!1,!1}})}leaveRoom(){return h(this,null,function*(){a(this,$).stopAllTransports(),v(this,Rs,!1),a(this,Or,Ds).mediaJoinAttempted=!1;const e={closeRoom:!1};a(this,Pt).sendMessagePromise(a(this,Vt).leaveRoom,Dw.toBinary(e)).then(i=>{var n;(n=fI.fromBinary(i.payload))!=null&&n.closed||u.warn("weird state on peer closed and should not happen")}).catch(i=>{u.error("error on sending leave room request",{error:i})}),J.callEnded(),S.destruct()})}getConsumers(){return a(this,$).consumers}activatePeers(e){return h(this,null,function*(){return this.createConsumers(e)})}deactivatePeers(e,i="default"){return h(this,null,function*(){const n=new Set;e.forEach(s=>{s.screenShare&&s.kind==="video"&&n.add(s.producingPeerId)});const r=i==="default"?e.filter(s=>!n.has(s.producingPeerId)).filter(s=>s.kind!=="audio"):e;yield Promise.all(r.map(s=>{const o=a(this,$).producerIdToConsumerIdMap.get(s.producerId);if(!o){u.warn(`consumer not found in deactivate producers: ${s.producerId}`);return}return a(this,$).closeConsumer(o)}))})}createConsumers(e){return h(this,null,function*(){return e.length===0?Promise.resolve():a(this,$).createConsumers(e)})}closeConsumers(e){return h(this,null,function*(){if(!e.length)return;const i=e.reduce((n,r)=>{const s=a(this,$).producerIdToConsumerIdMap.get(r.producerId);return s?(n.push(s),n):(u.warn(`consumer not found in deactivate producers: ${r.producerId}`),n)},[]);yield a(this,$).closeConsumers(i)})}_shareWebcam(e,i){return h(this,null,function*(){const n=i==="video/VP9"?Te.WEBCAM:Te.WEBCAM_BACKUP,r=j(this,gt,Rt).call(this,n);if(r){const p=yield r;if(a(this,$).producers.has(p)){const g=a(this,$).producers.get(p);if(!g.closed&&!navigator.isReactNative)return yield g.replaceTrack({track:e}),yield this.resumeWebcam(n),e;yield this.disableWebcam(i)}return this._shareWebcam(e,i)}const s=j(this,jh,xv).call(this,e,i),o=Rc(this.context,"disableSimulcast"),c=a(this,Ar)===et.CF?ne.ENABLE_CF_SIMULCAST:ne.ENABLE_HIVE_SIMULCAST;!o&&Q.hasFeature(c)?(u.info(`Simulcast enabled for SFU: ${a(this,Ar)}`),s.encodings=p1(e)):u.info(`Simulcast disabled for webcam producer, SFU: ${a(this,Ar)}`),Q.hasFeature(ne.TRACK_HINT)&&(s.track.contentHint=Q.getValue(ne.TRACK_HINT));const d=()=>{u.info("Disabling video due to the producer closure"),a(this,Ut).delete(n)},l=a(this,$).createProducer(s,d);return j(this,Os,ko).call(this,n,l.then(p=>p.id)),l.then(p=>p.track)})}shareWebcam(e){return h(this,null,function*(){if(e===void 0)return null;if(Q.hasFeature(ne.FORCE_VIDEO_CODEC)){const i=Q.getValue(ne.FORCE_VIDEO_CODEC).toString();if(i)return u.debug(`Calling _shareWebcam with forced video codec: ${i}`),this._shareWebcam(e,i)}return yield Promise.all(Vi.map(i=>{var n,r;return((r=(n=a(this,Eo).sender)==null?void 0:n.video)==null?void 0:r.codecs.findIndex(s=>s.mimeType===i))>=0&&a(this,As).get(i).size>0?(u.debug(`Calling _shareWebcam with video codec: ${i}`),this._shareWebcam(e,i)):e})),e})}shareScreen(e){return h(this,null,function*(){const{video:i,audio:n}=e;if(i===void 0)return;const r={track:i,codecOptions:[{name:"VP8"}],appData:{screenShare:!0,e2ee:this.e2ee,supportsRemoteControl:_e.isElectron()},stopTracks:!1},s=()=>{u.info("Disabling screenShare due to the producer closure"),a(this,Ut).delete(Te.SCREENSHARE_VIDEO),a(this,Ut).delete(Te.SCREENSHARE_AUDIO)},o=a(this,$).createProducer(r,s);j(this,Os,ko).call(this,Te.SCREENSHARE_VIDEO,o.then(d=>d.id));let c;if(n){const d={track:n,codecOptions:[{name:"opus"}],appData:{screenShare:!0,e2ee:this.e2ee,supportsRemoteControl:_e.isElectron()},stopTracks:!1,zeroRtpOnPause:!0},l=()=>{};c=a(this,$).createProducer(d,l),j(this,Os,ko).call(this,Te.SCREENSHARE_AUDIO,c.then(p=>p.id))}yield Promise.all([o,c||Promise.resolve()]),J.screenShareStart()})}shareMic(e){return h(this,null,function*(){try{if(e===void 0)throw new xt("track undefined");const i=j(this,gt,Rt).call(this,Te.MIC);if(i){const o=yield i;if(a(this,$).producers.has(o)){const c=a(this,$).producers.get(o);if(!c.closed&&!navigator.isReactNative){yield c.replaceTrack({track:e}),yield this.resumeMic(),a(this,Kt)&&(a(this,Kt).audioTrack=e,a(this,Kt).producerId=o,a(this,Kt).start());return}yield a(this,$).closeProducer(o,{stopTrack:!1})}yield this.shareMic(e);return}const n=j(this,Wh,Lv).call(this,e),r=()=>{a(this,Ut).delete(Te.MIC)},s=a(this,$).createProducer(n,r);j(this,Os,ko).call(this,Te.MIC,s.then(o=>o.id)),yield s.then(o=>{a(this,Kt)&&(a(this,Kt).audioTrack=o.track,a(this,Kt).producerId=o.id,a(this,Kt).start())})}catch(i){throw new w(i)}})}pauseMic(){return h(this,null,function*(){var e;const i=yield j(this,gt,Rt).call(this,Te.MIC),n=a(this,$).producers.get(i);if(!n){u.error("pauseMic::could_not_find_mic_producer");return}if(n.paused){u.info("pauseMic::mic_producer_already_paused");return}n.pause(),(e=a(this,Kt))==null||e.stop();const r={producerId:n.id,pause:!0};a(this,Pt).sendMessage(a(this,Vt).toggleProducer,Oc.toBinary(r))})}pauseWebcam(){return h(this,null,function*(){const e=yield j(this,gt,Rt).call(this,Te.WEBCAM),i=yield j(this,gt,Rt).call(this,Te.WEBCAM_BACKUP),n=a(this,$).producers.get(e),r=a(this,$).producers.get(i);if(!n&&!r){u.error("pauseWebcam::could_not_find_webcam_producer");return}const s=o=>{const c={producerId:o.id,pause:!0};a(this,Pt).sendMessage(a(this,Vt).toggleProducer,Oc.toBinary(c))};n&&(n.pause(),s(n)),r&&(r.pause(),s(r))})}resumeMic(){return h(this,null,function*(){const e=yield j(this,gt,Rt).call(this,Te.MIC),i=a(this,$).producers.get(e);if(!i){u.error("resumeMic::could_not_find_mic_producer");return}if(!i.pause){u.info("resumeMic::mic_producer_already_resumed");return}i.resume(),i.appData.e2ee&&P.emit(R.E2EE_ACTIVE_PRODUCER,i);const n={producerId:i.id,pause:!1};a(this,Pt).sendMessage(a(this,Vt).toggleProducer,Oc.toBinary(n))})}resumeWebcam(){return h(this,arguments,function*(e=Te.WEBCAM){const i=yield j(this,gt,Rt).call(this,e),n=a(this,$).producers.get(i);if(!n){u.error("resumeWebcam::could_not_find_webcam_producer");return}if(!n.paused){u.info("resumeWebcam::webcam_producer_already_resumed");return}n.resume(),n.appData.e2ee&&P.emit(R.E2EE_ACTIVE_PRODUCER,n);const r={producerId:n.id,pause:!1};a(this,Pt).sendMessage(a(this,Vt).toggleProducer,Oc.toBinary(r))})}disableWebcam(e){return h(this,null,function*(){const i=e==="video/VP9"?Te.WEBCAM:Te.WEBCAM_BACKUP,n=yield j(this,gt,Rt).call(this,i);j(this,Bh,Nv).call(this,i),n&&(yield a(this,$).closeProducer(n))})}disableMic(){return h(this,null,function*(){var e;const i=yield j(this,gt,Rt).call(this,Te.MIC);i&&(yield a(this,$).closeProducer(i)),(e=a(this,Kt))==null||e.stop(),a(this,Ut).delete(Te.MIC)})}disableScreenShare(){return h(this,null,function*(){u.info("screen_sharing_stopped"),J.screenShareStop();const e=yield j(this,gt,Rt).call(this,Te.SCREENSHARE_VIDEO),i=yield j(this,gt,Rt).call(this,Te.SCREENSHARE_AUDIO);e&&(yield a(this,$).closeProducer(e)),i&&(yield a(this,$).closeProducer(i)),a(this,Ln).clear(),a(this,Ut).delete(Te.SCREENSHARE_VIDEO),a(this,Ut).delete(Te.SCREENSHARE_AUDIO)})}muteSelf(){return h(this,null,function*(){this.pauseMic()})}unmuteSelf(){return h(this,null,function*(){})}resetVideoProducers(e,i){return h(this,null,function*(){if(e){const n=yield j(this,gt,Rt).call(this,Te.WEBCAM),r=yield j(this,gt,Rt).call(this,Te.WEBCAM_BACKUP);yield a(this,$).closeProducer(n,{stopTrack:!1}),yield a(this,$).closeProducer(r,{stopTrack:!1}),this.shareWebcam(e)}if(i){const n=yield j(this,gt,Rt).call(this,Te.SCREENSHARE_VIDEO);yield a(this,$).closeProducer(n,{stopTrack:!1}),this.shareScreen({video:i})}})}changeDisplayName(e,i){return h(this,null,function*(){const n={displayName:e,participantId:i!=null?i:this.peerId};if(!(yield a(this,$).socketHandler.changeDisplayName(n)))throw new Error("failed to change display name!")})}kick(e){const i={peerIds:[e]};a(this,$).socketHandler.kickPeer(i)}kickAll(){a(this,$).socketHandler.kickAll()}muteAll(e){return h(this,null,function*(){if(!(yield a(this,$).socketHandler.hostControlForAll("audio")))throw new Error("failed to mute all participant")})}muteAllVideo(){return h(this,null,function*(){if(!(yield a(this,$).socketHandler.hostControlForAll("video")))throw new Error("failed to mute all video participant")})}disableAudio(e){return h(this,null,function*(){if(!(yield a(this,$).socketHandler.hostControlForPeer(e,"audio")))throw new Error("failed to mute given participant")})}disableVideo(e){return h(this,null,function*(){if(!(yield a(this,$).socketHandler.hostControlForPeer(e,"video")))throw new Error("failed to mute video of given participant")})}pinPeer(e){return h(this,null,function*(){const i={participantId:e!=null?e:""};try{yield a(this,Pt).sendMessagePromise(a(this,Vt).globalPinPeer,jw.toBinary(i))}catch(n){u.error("Error in pinning peer:",{error:n})}})}validateScreenShare(e){return this.peerId===e.peerId&&a(this,$).producers.get(e.producerId)&&a(this,Ln).add(e.consumerPeerId),a(this,Ln).size}switchConsumersToLayer(e,i){return h(this,null,function*(){a(this,$).switchConsumersToLayer(e,i)})}handleSocketEvents(){return h(this,null,function*(){a(this,Pt).on(a(this,Vt).peerProducerCreateBroadcast,({payload:e})=>{var i,n;if(this.mediaJoined)try{const{participantId:r,producerState:s}=JI.fromBinary(e);if(r===this.peerId)return;if(s!=null&&s.mimeType||(s.mimeType=s.kind===Ai.AUDIO?"audio/opus":"video/VP8"),s.kind===Ai.VIDEO&&!s.screenShare&&((n=(i=a(this,Eo).receiver)==null?void 0:i.video)==null?void 0:n.codecs.findIndex(o=>o.mimeType===Vi[0]))>=0&&a(this,Ms).get(Vi[0]).has(r)&&s.mimeType!==Vi[0]){u.warn(`Ignoring producer: ${s.producerId}`);return}u.info(`producer created broadcast: ${r}, producer state: ${s}`),P.emit(R.NEW_PRODUCER,{peerId:r,producer:q(x({},s),{kind:s.kind===Ai.AUDIO?"audio":"video",producingPeerId:r})})}catch(r){u.error("error in peer-producer-create-broadcast",{error:r})}}),a(this,Pt).on(a(this,Vt).peerProducerToggleBroadcast,({payload:e})=>{if(this.mediaJoined)try{const{participantId:i,initiatorParticipantId:n,producerState:{kind:r,pause:s,producerId:o}}=Hg.fromBinary(e),c=r===Ai.AUDIO?"audio":"video";if(u.info(`producer toggle broadcast: ${i}, producerId: ${o}, kind:${c}, paused:${s} payload: ${JSON.stringify(Hg.fromBinary(e))}`),i===this.peerId&&n!==this.peerId&&s&&P.emit(c==="audio"?R.MUTE_SELF:R.MUTE_SELF_VIDEO),i===this.peerId)return;P.emit(R.PRODUCER_TOGGLE,{peerId:i,producerId:o,paused:s,kind:c}),Array.from(this.getConsumers().values()).filter(d=>d.producerId===o).forEach(d=>{d.paused!==s&&(u.debug(`consumer state mismatched for ${d.id}. updating consumer pause state ${d.paused} to ${s}`),s?(d.pause(),P.emit(R.CONSUMER_PAUSED,{id:d.id})):(d.resume(),P.emit(R.CONSUMER_RESUMED,{id:d.id})))})}catch(i){u.error("error in producer toggle broadcast handler",{error:i})}}),a(this,Pt).on(a(this,Vt).peerLeaveBroadcast,({payload:e})=>{if(this.mediaJoined)try{const{participantId:i}=nu.fromBinary(e);if(i===this.peerId)return;u.info(`peer left broadcast:${i}`),a(this,Ln).delete(i),a(this,$).consumers.forEach(n=>{n.peerId===i&&n.close()}),P.emit(R.PEER_CLOSED,{id:i})}catch(i){u.error("error in peer left broadcast",{error:i})}}),a(this,Pt).on(a(this,Vt).peerProducerCloseBroadcast,({payload:e})=>{if(this.mediaJoined)try{const{participantId:i,producerState:{producerId:n}}=zI.fromBinary(e);if(i===this.peerId)return;u.info(`producer closed broadcast:${i}`),P.emit(R.PRODUCER_CLOSED,{peerId:i,producerId:n});const r=a(this,$).producerIdToConsumerIdMap.get(n);if(!r){u.warn(`no consumer found for producer:${n}`);return}u.info(`closing consumer ${r}, producer id: ${n}`),a(this,$).closeConsumer(r).then(()=>{u.info(`closed consumer: ${r}`),a(this,$).producerIdToConsumerIdMap.delete(n),P.emit(R.CONSUMER_CLOSED,{id:r})}).catch(s=>{u.error("error closing consumer",{error:s})})}catch(i){u.error("error on producer close broadcast",{error:i})}}),a(this,Pt).on(a(this,Vt).mediaRoomTerminationBroadcastResponse,()=>{!this.mediaJoined&&!a(this,Ps)&&!a(this,Rs)||(u.warn("media hub termination broadcast received, rejoining room"),P.emit(R.ROOM_NODE_DISCONNECTED),a(this,Kd).call(this))})})}handleCallstatsEvents(){J.onConsumerScore(e=>{e.forEach((i,n)=>{const r=a(this,$).consumers.get(n);r&&P.emit(R.CONSUMER_SCORE_UPDATE,{id:n,kind:r.kind,peerId:r.peerId,score:i.score,scoreStats:i})})}),J.onProducerScore(e=>{e.forEach((i,n)=>{const r=Array.from(a(this,$).producers.values()).find(s=>s.id===n);r&&P.emit(R.PRODUCER_SCORE_UPDATE,{id:n,kind:r.kind,appData:r.appData,score:i.score,scoreStats:i})})})}handlePeerCapabilities(e,i){var n,r,s,o;for(let c=0;c<=Vi.length;c+=1){const d=Vi[c];if(((r=(n=i==null?void 0:i.receiver)==null?void 0:n.video)==null?void 0:r.codecs.findIndex(l=>l.mimeType===d))>=0||c===Vi.length-1){a(this,As).get(d).add(e);break}}for(let c=0;c<=Vi.length;c+=1){const d=Vi[c];if(((o=(s=i==null?void 0:i.sender)==null?void 0:s.video)==null?void 0:o.codecs.findIndex(l=>l.mimeType===d))>=0||c===Vi.length-1){a(this,Ms).get(d).add(e);break}}}handlePeerLeaving(e){Q.hasFeature(ne.FORCE_VIDEO_CODEC)||(a(this,Ms).forEach(i=>i.delete(e)),a(this,As).forEach((i,n)=>{i.delete(e),i.size===0&&this.disableWebcam(n)}))}}Jd=new WeakMap,$d=new WeakMap,Pt=new WeakMap,$=new WeakMap,Eo=new WeakMap,Ar=new WeakMap,Vt=new WeakMap,Ps=new WeakMap,Rs=new WeakMap,Dr=new WeakMap,Kd=new WeakMap,Ln=new WeakMap,To=new WeakMap,Ms=new WeakMap,As=new WeakMap,Ut=new WeakMap,Kt=new WeakMap,Or=new WeakSet,Ds=function(){return this.context.getValue("connectionHandler")},gt=new WeakSet,Rt=function(t){return a(this,Ut).get(t)},Os=new WeakSet,ko=function(t,e){return a(this,Ut).set(t,e)},Bh=new WeakSet,Nv=function(t){return a(this,Ut).delete(t)},Wh=new WeakSet,Lv=function(t){return{track:t,encodings:[{priority:"high"}],codecOptions:[{name:"opus"}],appData:{e2ee:this.e2ee},stopTracks:!1,zeroRtpOnPause:!0}},jh=new WeakSet,xv=function(t,e){return{track:t,codecOptions:[{name:e?e.split("/")[1]:"VP8"}],appData:{screenShare:!1,e2ee:this.e2ee},stopTracks:!1}},ue([S.trace("MediaNodeClient.reset",{country:S.location.country})],le.prototype,"reset",1),ue([S.trace("MediaNodeClient.joinRoom")],le.prototype,"joinRoom",1),ue([S.trace("MediaNodeClient.completeJoinRoom")],le.prototype,"completeJoinRoom",1),ue([S.trace("MediaNodeClient.leaveRoom")],le.prototype,"leaveRoom",1),ue([S.trace("MediaNodeClient.activatePeers")],le.prototype,"activatePeers",1),ue([S.trace("MediaNodeClient.deactivatePeers")],le.prototype,"deactivatePeers",1),ue([S.trace("MediaNodeClient.createConsumers")],le.prototype,"createConsumers",1),ue([S.trace("MediaNodeClient.closeConsumers")],le.prototype,"closeConsumers",1),ue([S.trace("MediaNodeClient._shareWebcam")],le.prototype,"_shareWebcam",1),ue([S.trace("MediaNodeClient.shareWebcam")],le.prototype,"shareWebcam",1),ue([S.trace("MediaNodeClient.shareScreen")],le.prototype,"shareScreen",1),ue([S.trace("MediaNodeClient.shareMic")],le.prototype,"shareMic",1),ue([S.trace("MediaNodeClient.pauseMic")],le.prototype,"pauseMic",1),ue([S.trace("MediaNodeClient.pauseWebcam")],le.prototype,"pauseWebcam",1),ue([S.trace("MediaNodeClient.resumeMic")],le.prototype,"resumeMic",1),ue([S.trace("MediaNodeClient.resumeWebcam")],le.prototype,"resumeWebcam",1),ue([S.trace("MediaNodeClient.disableWebcam")],le.prototype,"disableWebcam",1),ue([S.trace("HiveClient.disableMic")],le.prototype,"disableMic",1),ue([S.trace("HiveClient.disableScreenShare")],le.prototype,"disableScreenShare",1),ue([S.trace("MediaNodeClient.muteSelf")],le.prototype,"muteSelf",1),ue([S.trace("MediaNodeClient.resetVideoProducers")],le.prototype,"resetVideoProducers",1),ue([S.trace("MediaNodeClient.changeDisplayName")],le.prototype,"changeDisplayName",1),ue([S.trace("MediaNodeClient.kickPeer")],le.prototype,"kick",1),ue([S.trace("MediaNodeClient.kickAllPeers")],le.prototype,"kickAll",1),ue([S.trace("MediaNodeClient.muteAll")],le.prototype,"muteAll",1),ue([S.trace("MediaNodeClient.muteAllVideo")],le.prototype,"muteAllVideo",1),ue([S.trace("MediaNodeClient.disableAudio")],le.prototype,"disableAudio",1),ue([S.trace("MediaNodeClient.disableVideo")],le.prototype,"disableVideo",1),ue([S.trace("MediaNodeClient.pinPeer")],le.prototype,"pinPeer",1),ue([S.trace("MediaNodeClient.validateScreenShare")],le.prototype,"validateScreenShare",1);function Vv(t,e,i){const n=t.getValue("roomNodeClient");if(n){if(n)return n;throw new Error("Room node client already set up.")}const r=new le(t,e,i);return t.setValue("roomNodeClient",r),r}function Uv(t){const e=t.getValue("roomNodeClient");try{e==null||e.leaveRoom()}catch(i){u.error("roomNodeClient::cleanupRoomNodeClient")}t.setValue("roomNodeClient",void 0)}var FD=Object.defineProperty,BD=Object.getOwnPropertyDescriptor,Nr=(t,e,i,n)=>{for(var r=n>1?void 0:n?BD(e,i):e,s=t.length-1,o;s>=0;s--)(o=t[s])&&(r=(n?o(e,i,r):o(r))||r);return n&&r&&FD(e,i,r),r},Lr,Ui,Mt,ni,Ti,Fv;const Bv=(Fv=class{constructor(t,e,i,n){f(this,ni),m(this,"self"),m(this,"authToken"),f(this,Lr,void 0),m(this,"viewType"),f(this,Ui,void 0),f(this,Mt,void 0);const{socket:r}=i,s=t.getValue("authToken");this.self=e,v(this,Mt,t),this.viewType=n,this.authToken=s,v(this,Lr,r),v(this,Ui,i),e.config.viewType!==yt.Chat&&this.setupEvents()}get peerId(){return a(this,Mt).getValue("peerId")}get mediaJoined(){return a(this,Mt).getValue("connectionHandler").mediaJoined}static init(t,e,i,n,r){return h(this,null,function*(){const s=at(),o=t.getValue("peerId"),c=!!t.getValue("cachedUserDetails"),d=yield it.__init__(t,i,n,r,r.name,c);if(navigator.product!=="ReactNative"){const l=!Q.hasFeature(ne.PRECALL_BANDWIDTH_TEST);setTimeout(()=>h(this,null,function*(){const p=yield d.getAllDevices();u.info("populated_full_device_list",{devices:JSON.stringify(p)}),J.devices("AUDIO",p==null?void 0:p.filter(g=>g.kind==="audioinput")),J.devices("VIDEO",p==null?void 0:p.filter(g=>g.kind==="videoinput")),J.devices("SPEAKER",p==null?void 0:p.filter(g=>g.kind==="audiooutput")),u.info("Callstats:: initializing");try{yield J.initialize({peerId:o,engineName:_e.getDeviceInfo().engineName,env:t.getValue("env"),iceServers:yield s.getICEServers(),apiBase:t.getValue("apiBase"),flags:Q.getAllFlags(),logger:u,apiHostnames:Ig(t),skipConnectivityChecks:l}),u.info("Callstats:: initialized")}catch(g){u.error("Callstats:: initialization failed",{error:g})}}),0)}else u.info("Callstats:: Skipped initialization due to navigator product being ReactNative.");return new Bv(t,d,e,r.viewType)})}shareMediaTracks(){return h(this,null,function*(){var t;const{audioTrack:e,videoTrack:i,permissions:n,audioEnabled:r,videoEnabled:s,screenShareEnabled:o,screenShareTracks:c}=this.self;if(n.canProduceAudio&&r)try{yield a(this,ni,Ti).shareMic(e)}catch(d){this.self.disableAudio()}if(n.canProduceVideo&&s)try{const d=yield a(this,ni,Ti).shareWebcam(i);d&&d.id!==i.id&&Q.hasFeature(ne.EXP_RESHARE)&&(yield a(this,ni,Ti).shareWebcam(d))}catch(d){this.self.disableVideo()}if(n.canProduceScreenshare&&o)try{yield(t=a(this,ni,Ti))==null?void 0:t.shareScreen({video:c.video,audio:c.audio})}catch(d){this.self.disableScreenShare()}})}kickHandler(t){return h(this,null,function*(){let e="kicked";(t==null?void 0:t.kickType)==="kickAll"&&(e="ended"),this.leaveRoom(e)})}waitlistedHandler(){u.info("SelController.waitlisted"),this.self.waitlistStatus="waiting",this.self.roomState="waitlisted",this.self.emit("waitlisted")}waitlistAcceptHandler(){if(u.info("SelController.waitlistAccepted"),this.self.waitlistStatus==="accepted"){u.warn("SelfController.WAITLIST_ACCEPTED.UserAlreadyAccepted");return}this.self.waitlistStatus="accepted",this.joinRoom()}waitlistRejectedHandler(){if(u.info("SelfController.waitlistRejected"),this.self.waitlistStatus==="rejected"){u.warn("SelfController.WAITLIST_REJECTED.UserAlreadyRejected");return}this.self.waitlistStatus="rejected",this.leaveRoom("rejected")}resetSelf(t){return h(this,null,function*(){J.callEnded(),a(this,ni,Ti).reset(),t&&(yield this.joinRoom(t))})}setupEvents(){P.on(R.RESET_PRODUCER_STATE,()=>h(this,null,function*(){this.mediaJoined&&this.shareMediaTracks()})),P.on(R.ROOM_NODE_RECONNECTED,()=>{this.self.roomState="joined",this.self.emit("roomJoined",{reconnected:!0})}),P.on(R.ROOM_NODE_DISCONNECTED,()=>{this.self.roomState!=="disconnected"&&(this.self.roomState="disconnected",this.self.emit("roomLeft",{state:"disconnected"}))}),P.on(R.ROOM_NODE_FAILED,()=>{this.self.roomState="failed",this.self.emit("roomLeft",{state:"failed"})}),P.on(R.SOCKET_SERVICE_RECONNECTED,({wasJoinAttempted:t})=>{t===!1&&(this.self.roomState="init"),this.resetSelf(t)}),P.on(R.SOCKET_SERVICE_DISCONNECTED,({joinAttempted:t})=>{if(this.self.roomState==="disconnected")return;let{peerId:e}=this;t&&Q.hasFeature(ne.REFRESH_ID_ON_DISCONNECTION)&&(e=Br()),a(this,Lr).updateURL(e),S.resetPeerId(e),at().setHeader("dyte-tracing-id",e),Zn.remapContext(e,a(this,Mt)),this.self.roomState="disconnected",this.self.emit("roomLeft",{state:"disconnected"})}),P.on(R.SOCKET_SERVICE_FAILED,()=>{this.self.roomState="failed",this.self.emit("roomLeft",{state:"failed"})}),a(this,Ui).on(B.waitingRoomRequestAccepted,()=>{this.waitlistAcceptHandler()}),a(this,Ui).on(Fc.updateUserPreset,t=>{t.updatePeersPresets.forEach(e=>{e.userIds===this.self.userId&&P.emit(R.UPDATE_PERMISSIONS,e.patch)})}),a(this,Ui).on(B.waitingRoomRequestDenied,()=>{this.waitlistRejectedHandler()}),a(this,Ui).on(B.kick,()=>{this.kickHandler({kickType:"kick"})}),a(this,Ui).on(B.kickAll,()=>{this.kickHandler({kickType:"kickAll"})}),P.onAsync(R.JOIN_MEDIA_ROOM,this.joinMediaRoom.bind(this)),P.on(R.PRODUCER_SCORE_UPDATE,({score:t,kind:e,appData:i,scoreStats:n})=>{var r;const s=(r=i==null?void 0:i.screenShare)!=null?r:!1;this.self.emit("mediaScoreUpdate",{kind:e,isScreenshare:s,score:t,participantId:this.self.id,scoreStats:n})}),P.on(R.MUTE_SELF,()=>h(this,null,function*(){this.self.audioEnabled&&(yield this.self.disableAudio(),J.audioOff())})),P.on(R.MUTE_SELF_VIDEO,()=>h(this,null,function*(){this.self.videoEnabled&&(yield this.self.disableVideo(),J.videoOff())})),P.onAsync(R.LEAVE_MEDIA_ROOM,this.leaveMediaRoom.bind(this)),P.on(R.PIP_HANGUP,this.leaveRoom.bind(this))}joinRoom(t=!1){return h(this,null,function*(){try{const{peer:e}=yield a(this,Ui).joinRoom(this.self);a(this,Ui).socket.flush();const i=Du(e.stageType);if(a(this,Mt).setValue("stageStatus",i,!1),e.waitlisted){this.waitlistedHandler();return}yield this.joinMediaRoom(t),a(this,Mt).notify("stageStatus")}catch(e){throw u.error("Error in joinRoom",{error:e}),e}})}leaveRoom(t="left"){return h(this,null,function*(){var e,i;if(t==="rejected"){try{(e=a(this,Lr))==null||e.disconnect()}catch(n){u.error("SelfController::leaveRoom::socketDisconnect")}this.self.roomState=t,this.self.emit("roomLeft",{state:t});return}this.self.setIsPinned(!1),a(this,Mt).setValue("stageStatus","OFF_STAGE",!1),yield this.leaveMediaRoom(t),a(this,Mt).notify("stageStatus");try{(i=a(this,Lr))==null||i.disconnect()}catch(n){u.error("SelfController::leaveRoom::socketDisconnect")}Uv(a(this,Mt)),vd.cleanup(),this.self.roomState=t,this.self.emit("roomLeft",{state:t})})}joinMediaRoom(t=!1){return h(this,null,function*(){var e,i;const{peerId:n,viewType:r,meetingId:s,stageStatus:o,roomNodeOptions:c}=a(this,Mt).getAllValues(),{sfu:d}=c;try{if(r===yt.Livestream){if(o!=="ON_STAGE"){this.self.roomState="joined",this.self.emit("roomJoined",{reconnected:t});return}Vv(a(this,Mt),d,{socket:a(this,Lr),peerId:n})}const{roomJoined:l}=(i=yield(e=a(this,ni,Ti))==null?void 0:e.joinRoom(this.self.name,s,{audio:this.self.audioEnabled,video:this.self.videoEnabled,screen:this.self.screenShareEnabled},t,t))!=null?i:{};if(!l)return;o==="ON_STAGE"&&(yield this.shareMediaTracks()),this.self.roomState="joined",this.self.emit("roomJoined",{reconnected:t})}catch(l){throw u.error("Error:SelfController.mediaRoomJoin",{error:l}),new w("Error: could not join media room","0002")}})}leaveMediaRoom(t){return h(this,null,function*(){const e=a(this,Mt).getValue("viewType");t!=="connected-meeting"&&(yield this.cleanupSelf()),!(t==="stageLeft"&&e===yt.Webinar)&&a(this,ni,Ti)&&(a(this,ni,Ti).mediaJoined&&t!=="disconnected"&&(yield a(this,ni,Ti).leaveRoom()),!(t==="stageLeft"&&e===yt.Livestream)&&(a(this,ni,Ti).mediaJoined=!1))})}cleanupSelf(){return h(this,null,function*(){yield this.self.disableAudio(),yield this.self.disableVideo(),yield this.self.disableScreenShare(),this.self.cleanUpTracks(),this.self.destructMediaHandler(),navigator.isReactNative||this.self.removeDocumentEventListeners()})}},Lr=new WeakMap,Ui=new WeakMap,Mt=new WeakMap,ni=new WeakSet,Ti=function(){return a(this,Mt).getValue("roomNodeClient")},Fv);let xn=Bv;Nr([S.trace("SelfController.resetSelf")],xn.prototype,"resetSelf",1),Nr([S.trace("SelfController.setupEvents")],xn.prototype,"setupEvents",1),Nr([S.trace("SelfController.joinRoom")],xn.prototype,"joinRoom",1),Nr([S.trace("SelfController.leaveRoom")],xn.prototype,"leaveRoom",1),Nr([S.trace("SelfController.joinMediaRoom")],xn.prototype,"joinMediaRoom",1),Nr([S.trace("SelfController.leaveMediaRoom")],xn.prototype,"leaveMediaRoom",1),Nr([S.trace("SelfController.init")],xn,"init",1);var zd;class WD{constructor(e){f(this,zd,void 0),v(this,zd,e)}on(e,i){let n;e===B.roomPeerCount?n=Jg.fromBinary.bind(Jg):n=lf.fromBinary.bind(lf),a(this,zd).on(e,({payload:r})=>{const s=n(r);return i(s)})}}zd=new WeakMap;var Yd;class jD{constructor(e){f(this,Yd,void 0),v(this,Yd,e)}on(e,i){let n,r;switch(e){case B.transcript:{n=ru.fromBinary.bind(ru),r=ru.create();break}default:{u.debug("AISocketHandler switch case hit default, event not accounted for.");break}}a(this,Yd).on(e,({payload:s})=>{let o=r;try{o=n(s)}catch(c){u.error("chatSocketHandler::on::binary_decode_error",{error:c})}return i(o)})}}Yd=new WeakMap;var HD=Object.defineProperty,GD=Object.getOwnPropertyDescriptor,Hh=(t,e,i,n)=>{for(var r=n>1?void 0:n?GD(e,i):e,s=t.length-1,o;s>=0;s--)(o=t[s])&&(r=(n?o(e,i,r):o(r))||r);return n&&r&&HD(e,i,r),r},Vn;class Qd{constructor(e){f(this,Vn,void 0),v(this,Vn,e)}getPolls(){return a(this,Vn).sendMessagePromise(Ki.getPolls)}createPoll(e,i,n=!1,r=!1){const s={anonymous:n,hideVotes:r,question:e,options:i};return a(this,Vn).sendMessage(Ki.createPoll,VM.toBinary(s))}votePoll(e,i){const n={index:i,pollId:e};return a(this,Vn).sendMessage(Ki.votePoll,FM.toBinary(n))}on(e,i){let n,r;switch(e){case Ki.updatePoll:case Ki.createPoll:case Ki.votePoll:{n=vu.fromBinary.bind(vu),r=vu.create();break}}a(this,Vn).on(e,({payload:s})=>{let o=r;try{o=n(s)}catch(c){u.error("pollSocketHandler::on::binary_decode_error",{error:c})}return i(o)})}removeListeners(e){a(this,Vn).removeListeners(e)}}Vn=new WeakMap,Hh([S.trace("PollSocketHandler.getPolls")],Qd.prototype,"getPolls",1),Hh([S.trace("PollSocketHandler.createPoll")],Qd.prototype,"createPoll",1),Hh([S.trace("PollSocketHandler.votePoll")],Qd.prototype,"votePoll",1);var zt;class qD{constructor(e){f(this,zt,void 0),v(this,zt,e)}getStageRequests(){return h(this,null,function*(){const{payload:e}=yield a(this,zt).sendMessagePromise(B.getStageRequests);return e?fu.fromBinary(e):{stageRequests:[]}})}requestAccess(){a(this,zt).sendMessage(B.requestStageAccess)}cancelRequestAccess(){a(this,zt).sendMessage(B.cancelStageRequest)}grantAccess(e){return h(this,null,function*(){const i={userIds:e};a(this,zt).sendMessage(B.grantStageAccess,CM.toBinary(i))})}denyAccess(e){return h(this,null,function*(){const i={userIds:e};a(this,zt).sendMessage(B.denyStageAccess,RM.toBinary(i))})}joinStage(){return a(this,zt).sendMessagePromise(B.joinStage,void 0,void 0,B.peerStageStatusUpdate)}leaveStage(e){const i={userIds:[e]};return a(this,zt).sendMessagePromise(B.leaveStage,hf.toBinary(i),void 0,B.peerStageStatusUpdate)}kick(e){const i={userIds:e};return a(this,zt).sendMessagePromise(B.leaveStage,hf.toBinary(i))}on(e,i){let n;switch(e){case B.grantStageAccess:case B.denyStageAccess:{n=void 0;break}case B.getStagePeers:{n=uf.fromBinary.bind(uf);break}case B.getStageRequests:case B.requestStageAccess:case B.cancelStageRequest:{n=fu.fromBinary.bind(fu);break}case B.peerStageStatusUpdate:{n=qg.fromBinary.bind(qg);break}}a(this,zt).on(e,({payload:r,id:s})=>{if(!r||!n)return i(void 0,s);const o=n(r);return i(o,s)})}getPeerInfo(e){return h(this,null,function*(){const i=yield a(this,zt).sendMessagePromise(B.getPeerInfo,zg.toBinary({peerId:e}));return zr.fromBinary(i.payload)})}}zt=new WeakMap;var nt;class JD{constructor(e){f(this,nt,void 0),v(this,nt,e)}addPlugin(e,i){a(this,nt).sendMessage(z.addPlugin,GR.toBinary({pluginId:e,staggered:i}))}removePlugin(e){a(this,nt).sendMessage(z.removePlugin,JR.toBinary({pluginId:e,staggered:!1}))}getActivePlugins(){return h(this,null,function*(){const{payload:e}=yield a(this,nt).sendMessagePromise(z.getPlugins);return e?gM.fromBinary(e):{plugins:[]}})}customPluginEventToRoom(e,i,n){const r={pluginId:e,pluginData:new TextEncoder().encode(JSON.stringify(i))};a(this,nt).sendMessage(z.customPluginEventToRoom,iM.toBinary(r),n)}customPluginEventToPeers(e,i,n,r){const s={pluginId:e,peerIds:i,pluginData:new TextEncoder().encode(JSON.stringify(n))};a(this,nt).sendMessage(z.customPluginEventToPeers,rM.toBinary(s),r)}enablePluginForRoom(e,i){a(this,nt).sendMessage(z.enablePluginForRoom,KR.toBinary({pluginId:e}),i)}enablePluginForPeers(e,i,n){a(this,nt).sendMessage(z.enablePluginForPeers,XR.toBinary({pluginId:e,peerIds:i}),n)}disablePluginForRoom(e,i){a(this,nt).sendMessage(z.disablePluginForRoom,YR.toBinary({pluginId:e}),i)}disablePluginForPeers(e,i,n){a(this,nt).sendMessage(z.disablePluginForPeers,eM.toBinary({pluginId:e,peerIds:i}),n)}storeInsertKeys(e,i,n,r){const s={pluginId:e,storeName:i,insertKeys:n.map(o=>({storeKey:o.key,payload:new TextEncoder().encode(JSON.stringify(o.payload))}))};a(this,nt).sendMessage(z.storeInsertKeys,af.toBinary(s),r)}storeGetKeys(e,i,n,r){const s={pluginId:e,storeName:i,getKeys:n.map(o=>({storeKey:o.key}))};a(this,nt).sendMessage(z.storeGetKeys,cM.toBinary(s),r)}storeDeleteKeys(e,i,n,r){const s={pluginId:e,storeName:i,deleteKeys:n.map(o=>({storeKey:o.key}))};a(this,nt).sendMessage(z.storeDeleteKeys,lM.toBinary(s),r)}storeDelete(e,i,n){a(this,nt).sendMessage(z.storeDelete,hM.toBinary({pluginId:e,storeName:i}),n)}getPluginDataOld(e,i){u.info("getPluginDataOld",{plugin:{id:e,storeName:i}})}storePluginDataOld(e,i,n){const r={pluginId:e,storeName:i,insertKeys:[{storeKey:n.key,payload:new TextEncoder().encode(JSON.stringify(n))}]};a(this,nt).sendMessage(z.storeInsertKeys,af.toBinary(r))}on(e,i){let n;switch(e){case z.addPlugin:case z.enablePluginForPeers:case z.enablePluginForRoom:{n=gu.fromBinary.bind(gu);break}case z.removePlugin:case z.disablePluginForPeers:case z.disablePluginForRoom:{n=of.fromBinary.bind(of);break}case z.customPluginEventToPeers:case z.customPluginEventToRoom:{n=df.fromBinary.bind(df);break}case z.storeInsertKeys:case z.storeGetKeys:case z.storeDeleteKeys:case z.storeDelete:{n=cf.fromBinary.bind(cf);break}}a(this,nt).on(e,({payload:r,id:s})=>{const o=n(r);return i(o,s)})}}nt=new WeakMap;var $D=Object.defineProperty,KD=(t,e,i)=>e in t?$D(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,zD=(t,e,i)=>(KD(t,typeof e!="symbol"?e+"":e,i),i),Gh=(t,e,i)=>{if(!e.has(t))throw TypeError("Cannot "+i)},L=(t,e,i)=>(Gh(t,e,"read from private field"),i?i.call(t):e.get(t)),we=(t,e,i)=>{if(e.has(t))throw TypeError("Cannot add the same private member more than once");e instanceof WeakSet?e.add(t):e.set(t,i)},pe=(t,e,i,n)=>(Gh(t,e,"write to private field"),n?n.call(t,i):e.set(t,i),i),Pe=(t,e,i)=>(Gh(t,e,"access private method"),i),Xd={},YD={get exports(){return Xd},set exports(t){Xd=t}},Ns=typeof Reflect=="object"?Reflect:null,Wv=Ns&&typeof Ns.apply=="function"?Ns.apply:function(t,e,i){return Function.prototype.apply.call(t,e,i)},Zd;Ns&&typeof Ns.ownKeys=="function"?Zd=Ns.ownKeys:Object.getOwnPropertySymbols?Zd=function(t){return Object.getOwnPropertyNames(t).concat(Object.getOwnPropertySymbols(t))}:Zd=function(t){return Object.getOwnPropertyNames(t)};function QD(t){console&&console.warn&&console.warn(t)}var jv=Number.isNaN||function(t){return t!==t};function ge(){ge.init.call(this)}YD.exports=ge,Xd.once=tO,ge.EventEmitter=ge,ge.prototype._events=void 0,ge.prototype._eventsCount=0,ge.prototype._maxListeners=void 0;var Hv=10;function el(t){if(typeof t!="function")throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof t)}Object.defineProperty(ge,"defaultMaxListeners",{enumerable:!0,get:function(){return Hv},set:function(t){if(typeof t!="number"||t<0||jv(t))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+t+".");Hv=t}}),ge.init=function(){(this._events===void 0||this._events===Object.getPrototypeOf(this)._events)&&(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},ge.prototype.setMaxListeners=function(t){if(typeof t!="number"||t<0||jv(t))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+t+".");return this._maxListeners=t,this};function Gv(t){return t._maxListeners===void 0?ge.defaultMaxListeners:t._maxListeners}ge.prototype.getMaxListeners=function(){return Gv(this)},ge.prototype.emit=function(t){for(var e=[],i=1;i<arguments.length;i++)e.push(arguments[i]);var n=t==="error",r=this._events;if(r!==void 0)n=n&&r.error===void 0;else if(!n)return!1;if(n){var s;if(e.length>0&&(s=e[0]),s instanceof Error)throw s;var o=new Error("Unhandled error."+(s?" ("+s.message+")":""));throw o.context=s,o}var c=r[t];if(c===void 0)return!1;if(typeof c=="function")Wv(c,this,e);else for(var d=c.length,l=zv(c,d),i=0;i<d;++i)Wv(l[i],this,e);return!0};function qv(t,e,i,n){var r,s,o;if(el(i),s=t._events,s===void 0?(s=t._events=Object.create(null),t._eventsCount=0):(s.newListener!==void 0&&(t.emit("newListener",e,i.listener?i.listener:i),s=t._events),o=s[e]),o===void 0)o=s[e]=i,++t._eventsCount;else if(typeof o=="function"?o=s[e]=n?[i,o]:[o,i]:n?o.unshift(i):o.push(i),r=Gv(t),r>0&&o.length>r&&!o.warned){o.warned=!0;var c=new Error("Possible EventEmitter memory leak detected. "+o.length+" "+String(e)+" listeners added. Use emitter.setMaxListeners() to increase limit");c.name="MaxListenersExceededWarning",c.emitter=t,c.type=e,c.count=o.length,QD(c)}return t}ge.prototype.addListener=function(t,e){return qv(this,t,e,!1)},ge.prototype.on=ge.prototype.addListener,ge.prototype.prependListener=function(t,e){return qv(this,t,e,!0)};function XD(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,arguments.length===0?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function Jv(t,e,i){var n={fired:!1,wrapFn:void 0,target:t,type:e,listener:i},r=XD.bind(n);return r.listener=i,n.wrapFn=r,r}ge.prototype.once=function(t,e){return el(e),this.on(t,Jv(this,t,e)),this},ge.prototype.prependOnceListener=function(t,e){return el(e),this.prependListener(t,Jv(this,t,e)),this},ge.prototype.removeListener=function(t,e){var i,n,r,s,o;if(el(e),n=this._events,n===void 0)return this;if(i=n[t],i===void 0)return this;if(i===e||i.listener===e)--this._eventsCount===0?this._events=Object.create(null):(delete n[t],n.removeListener&&this.emit("removeListener",t,i.listener||e));else if(typeof i!="function"){for(r=-1,s=i.length-1;s>=0;s--)if(i[s]===e||i[s].listener===e){o=i[s].listener,r=s;break}if(r<0)return this;r===0?i.shift():ZD(i,r),i.length===1&&(n[t]=i[0]),n.removeListener!==void 0&&this.emit("removeListener",t,o||e)}return this},ge.prototype.off=ge.prototype.removeListener,ge.prototype.removeAllListeners=function(t){var e,i,n;if(i=this._events,i===void 0)return this;if(i.removeListener===void 0)return arguments.length===0?(this._events=Object.create(null),this._eventsCount=0):i[t]!==void 0&&(--this._eventsCount===0?this._events=Object.create(null):delete i[t]),this;if(arguments.length===0){var r=Object.keys(i),s;for(n=0;n<r.length;++n)s=r[n],s!=="removeListener"&&this.removeAllListeners(s);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if(e=i[t],typeof e=="function")this.removeListener(t,e);else if(e!==void 0)for(n=e.length-1;n>=0;n--)this.removeListener(t,e[n]);return this};function $v(t,e,i){var n=t._events;if(n===void 0)return[];var r=n[e];return r===void 0?[]:typeof r=="function"?i?[r.listener||r]:[r]:i?eO(r):zv(r,r.length)}ge.prototype.listeners=function(t){return $v(this,t,!0)},ge.prototype.rawListeners=function(t){return $v(this,t,!1)},ge.listenerCount=function(t,e){return typeof t.listenerCount=="function"?t.listenerCount(e):Kv.call(t,e)},ge.prototype.listenerCount=Kv;function Kv(t){var e=this._events;if(e!==void 0){var i=e[t];if(typeof i=="function")return 1;if(i!==void 0)return i.length}return 0}ge.prototype.eventNames=function(){return this._eventsCount>0?Zd(this._events):[]};function zv(t,e){for(var i=new Array(e),n=0;n<e;++n)i[n]=t[n];return i}function ZD(t,e){for(;e+1<t.length;e++)t[e]=t[e+1];t.pop()}function eO(t){for(var e=new Array(t.length),i=0;i<e.length;++i)e[i]=t[i].listener||t[i];return e}function tO(t,e){return new Promise(function(i,n){function r(o){t.removeListener(e,s),n(o)}function s(){typeof t.removeListener=="function"&&t.removeListener("error",r),i([].slice.call(arguments))}Yv(t,e,s,{once:!0}),e!=="error"&&iO(t,r,{once:!0})})}function iO(t,e,i){typeof t.on=="function"&&Yv(t,"error",e,i)}function Yv(t,e,i,n){if(typeof t.on=="function")n.once?t.once(e,i):t.on(e,i);else if(typeof t.addEventListener=="function")t.addEventListener(e,function r(s){n.once&&t.removeEventListener(e,r),i(s)});else throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+typeof t)}class nO extends E{constructor(){super("message.v1.SocketMessage",[{no:1,name:"event",kind:"scalar",T:13},{no:2,name:"id",kind:"scalar",opt:!0,T:9},{no:3,name:"payload",kind:"scalar",opt:!0,T:12},{no:4,name:"metadata",kind:"scalar",opt:!0,T:12}])}}const Qv=new nO;class Xv{static encode(e){return Qv.toBinary(e)}static decode(e){return Qv.fromBinary(new Uint8Array(e))}}function rO(t,e){return Math.floor(Math.random()*(e-t+1)+t)}var Un;class sO{constructor(e={}){zD(this,"opts"),we(this,Un,void 0),this.opts={initialTimeout:e.initialTimeout||1e3,maxTimeout:e.maxTimeout||1e4,factor:e.factor||2},pe(this,Un,0)}wait(){return h(this,null,function*(){pe(this,Un,L(this,Un)+1);const e=rO(0,Math.min(this.opts.maxTimeout,this.opts.initialTimeout*hS(2,L(this,Un))));yield new Promise(i=>{setTimeout(i,e)})})}getAttempts(){return L(this,Un)}reset(){pe(this,Un,0)}}Un=new WeakMap;const Fn={debug:0,info:1,warn:2,error:3};var xr,Vr;class aO{constructor(e){we(this,xr,void 0),we(this,Vr,void 0),pe(this,xr,console),pe(this,Vr,e)}debug(...e){Fn[L(this,Vr)]>Fn.debug||L(this,xr).debug("[Sockrates]:",...e)}info(...e){Fn[L(this,Vr)]>Fn.info||L(this,xr).info("[Sockrates]:",...e)}warn(...e){Fn[L(this,Vr)]>Fn.warn||L(this,xr).warn("[Sockrates]:",...e)}error(...e){Fn[L(this,Vr)]>Fn.error||L(this,xr).error("[Sockrates]:",...e)}}xr=new WeakMap,Vr=new WeakMap;var Zv=(t=>(t[t.CONNECTING=0]="CONNECTING",t[t.OPEN=1]="OPEN",t[t.CLOSING=2]="CLOSING",t[t.CLOSED=3]="CLOSED",t))(Zv||{});const oO="2",cO="3";var Le,Ls,Re,je,Bn,rt,sn,Wn,ki,xs,an,qh,ey,bo,tl,Jh,ty,$h,iy,il,Kh,zh,ny,_o,nl,wo,rl,sl,Yh,Vs,Io,Co,al;class dO{constructor(e,i){var n;we(this,qh),we(this,bo),we(this,Jh),we(this,$h),we(this,il),we(this,zh),we(this,_o),we(this,wo),we(this,sl),we(this,Vs),we(this,Co),we(this,Le,void 0),we(this,Ls,void 0),we(this,Re,void 0),we(this,je,void 0),we(this,Bn,void 0),we(this,rt,void 0),we(this,sn,void 0),we(this,Wn,void 0),we(this,ki,void 0),we(this,xs,void 0),we(this,an,void 0);var r,s,o,c,d,l,p,g,y;pe(this,Ls,e),pe(this,Bn,[]),pe(this,rt,new Xd),pe(this,sn,!0),pe(this,ki,!1),pe(this,Re,i!=null?i:{}),(r=L(this,Re)).autoReconnect!=null||(r.autoReconnect=!0),(s=L(this,Re)).retryConnectionInterval!=null||(s.retryConnectionInterval=1e3),(o=L(this,Re)).pingTimeout!=null||(o.pingTimeout=3e4),(c=L(this,Re)).connectionTimeout!=null||(c.connectionTimeout=5e3),(d=L(this,Re)).debug!=null||(d.debug=!0),(l=L(this,Re)).maxReconnectionAttempts!=null||(l.maxReconnectionAttempts=10),(p=L(this,Re)).disconnectOnPingTimeout!=null||(p.disconnectOnPingTimeout=!0),(g=L(this,Re)).queueOnDisconnect!=null||(g.queueOnDisconnect=!1),(y=L(this,Re)).flushOnReconnect!=null||(y.flushOnReconnect=!1),pe(this,Wn,{code:void 0,reason:void 0}),pe(this,je,(n=L(this,Re).logger)!=null?n:new aO(L(this,Re).debug?"debug":"info")),pe(this,an,new sO)}get readyState(){var e;return(e=L(this,Le))==null?void 0:e.readyState}get url(){return L(this,Ls)}updateURL(e){pe(this,Ls,e),Pe(this,zh,ny).call(this)}get config(){return L(this,Re)}get sendQueue(){return L(this,Bn)}flush(){if(!L(this,Re).queueOnDisconnect)return!1;const e=[];return L(this,Bn).forEach(i=>{this.send(i.event,i.id,i.payload,i.metadata)||e.push(i)}),pe(this,Bn,e),L(this,Bn)}connect(e=!1){return h(this,null,function*(){if(!e&&[0,1].includes(this.readyState)){L(this,je).debug("Websocket was already connecting or connected.");return}if(L(this,sn)!==!1)return new Promise((i,n)=>{Pe(this,Vs,Io).call(this),Pe(this,Co,al).call(this);try{pe(this,Le,new WebSocket(Pe(this,qh,ey).call(this,L(this,Ls)))),L(this,Le).binaryType="arraybuffer",L(this,je).debug("Connecting");const r=setTimeout(()=>{L(this,je).debug("Connection timeout. Closing socket"),pe(this,sn,!0),Pe(this,Co,al).call(this),L(this,Le).close(3001,"Connection Timeout"),L(this,Re).autoReconnect&&!L(this,ki)&&(L(this,rt).emit("reconnecting"),Pe(this,_o,nl).call(this)),n(new Error("Connection timed out!"))},L(this,Re).connectionTimeout);L(this,Le).onopen=()=>{L(this,je).debug(`Ready State: ${Zv[L(this,Le).readyState]}`),r&&clearTimeout(r),Pe(this,sl,Yh).call(this),pe(this,Wn,{code:void 0,reason:void 0}),L(this,rt).emit("connected"),L(this,Re).flushOnReconnect&&this.flush(),i()},L(this,Le).onclose=s=>{try{r&&clearTimeout(r);const{code:o,reason:c}=s;n(c),L(this,je).debug("Socket closed. Close event:",{event:s}),L(this,je).debug(`Connection closed code: ${o}`),L(this,je).debug(`Connection closed reason: ${c}`),L(this,ki)||Pe(this,il,Kh).call(this,o,c)}catch(o){Pe(this,bo,tl).call(this,o)}},L(this,Le).onerror=s=>{Pe(this,bo,tl).call(this,s)},L(this,Le).onmessage=s=>Pe(this,Jh,ty).call(this,s)}catch(r){Pe(this,bo,tl).call(this,r,n)}})})}send(e,i,n,r){const s={event:e,id:i,payload:n,metadata:r};if(L(this,Re).queueOnDisconnect&&(!L(this,Le)||L(this,Le).readyState!==1))return L(this,je).debug("Queuing message since socket is not connected!",s),L(this,Bn).push(s),!1;const o=Xv.encode(s);return Pe(this,wo,rl).call(this,o)}emit(e,i,n,r){return this.send(e,i,n,r)}sendRaw(e){return Pe(this,wo,rl).call(this,e)}receive(e,i){return L(this,rt).on(e.toString(),i)}on(e,i){if(typeof e=="string"&&(e==="connected"||e==="disconnected"||e==="errored"||e==="reconnected"||e==="reconnecting"||e==="reconnectAttempt"||e==="reconnectFailure"||e==="failed")){L(this,rt).on(e,i);return}this.receive(e,i)}removeAllListeners(){L(this,rt).removeAllListeners()}removeReceiver(e,i){this.removeListener(e,i)}removeListener(e,i){L(this,rt).removeListener(e.toString(),i)}removeReceivers(e){this.removeListeners(e)}removeListeners(e){L(this,rt).listeners(e.toString()).map(i=>this.removeListener(e,i))}disconnect(){pe(this,sn,!1),Pe(this,Vs,Io).call(this),this.removeAllListeners(),pe(this,Wn,{code:1e3,reason:"Sockrates disconnect method called"}),L(this,Le).close(1e3,"Sockrates disconnect method called.")}}Le=new WeakMap,Ls=new WeakMap,Re=new WeakMap,je=new WeakMap,Bn=new WeakMap,rt=new WeakMap,sn=new WeakMap,Wn=new WeakMap,ki=new WeakMap,xs=new WeakMap,an=new WeakMap,qh=new WeakSet,ey=function(t){if(t.startsWith("ws://")||t.startsWith("wss://"))return t;if(t.startsWith("https://"))return`wss://${t.substring(8)}`;if(t.startsWith("http://"))return`ws://${t.substring(7)}`;throw new Error("Invalid URL. URL must start with http(s):// or ws(s)://.")},bo=new WeakSet,tl=function(t,e){L(this,je).error("Error:",{error:t}),L(this,rt).emit("errored",{error:t}),e==null||e(t)},Jh=new WeakSet,ty=function(t){if(Pe(this,sl,Yh).call(this),t.data===oO){L(this,je).debug("Received ping from server"),Pe(this,wo,rl).call(this,cO);return}const e=Xv.decode(t.data),{id:i,payload:n}=e;L(this,je).debug("Received message",{event:e.event,messageID:i}),L(this,rt).emit(e.event.toString(),{id:i,payload:n})},$h=new WeakSet,iy=function(){return L(this,Le).readyState===1},il=new WeakSet,Kh=function(t,e){pe(this,Wn,{reason:e,code:t}),L(this,rt).emit("disconnected",{code:t,reason:e})},zh=new WeakSet,ny=function(){const{reason:t,code:e}=L(this,Wn);e&&e!==1e3&&L(this,sn)&&L(this,Re).autoReconnect&&!L(this,ki)&&(L(this,je).debug(`Triggering reconnection due to ${t}.`),L(this,rt).emit("reconnecting"),Pe(this,_o,nl).call(this))},_o=new WeakSet,nl=function(t=!0){return h(this,null,function*(){if(t&&L(this,ki)){L(this,je).debug("Reconnect called when already in a reconnect loop. Ignoring.");return}if(L(this,ki)||L(this,an).reset(),L(this,Re).maxReconnectionAttempts!==null&&L(this,an).getAttempts()>=L(this,Re).maxReconnectionAttempts){L(this,rt).emit("failed"),pe(this,ki,!1);return}pe(this,ki,!0),Pe(this,Co,al).call(this),Pe(this,Vs,Io).call(this);try{if(yield L(this,an).wait(),L(this,sn)===!1)return;if(L(this,je).debug(`Reconnection attempt ${L(this,an).getAttempts()}`),L(this,rt).emit("reconnectAttempt",{attempt:L(this,an).getAttempts()}),yield this.connect(),!Pe(this,$h,iy).call(this))throw Error("Reconnect Failed");pe(this,ki,!1),pe(this,Wn,{code:void 0,reason:void 0}),L(this,rt).emit("reconnected")}catch(e){L(this,je).debug("Failed to reconnect."),L(this,rt).emit("reconnectFailure",{attempt:L(this,an).getAttempts()}),Pe(this,_o,nl).call(this,!1)}})},wo=new WeakSet,rl=function(t){try{return L(this,Le).send(t),!0}catch(e){return L(this,je).error(e.message),!1}},sl=new WeakSet,Yh=function(){this.config.disconnectOnPingTimeout&&(L(this,je).debug("Resetting ping timeout"),Pe(this,Vs,Io).call(this),pe(this,xs,setTimeout(()=>{var t;L(this,je).debug("Disconnecting the socket due to ping timeout"),pe(this,sn,!0);const e=3002,i="Ping timeout";(t=L(this,Le))==null||t.close(e,i),Pe(this,il,Kh).call(this,e,i)},L(this,Re).pingTimeout)))},Vs=new WeakSet,Io=function(){L(this,xs)&&(clearTimeout(L(this,xs)),pe(this,xs,void 0))},Co=new WeakSet,al=function(){L(this,Le)&&(L(this,Le).onopen=void 0,L(this,Le).onerror=void 0,L(this,Le).onmessage=void 0,L(this,Le).onclose=void 0)};var lO=Object.defineProperty,uO=Object.getOwnPropertyDescriptor,ol=(t,e,i,n)=>{for(var r=n>1?void 0:n?uO(e,i):e,s=t.length-1,o;s>=0;s--)(o=t[s])&&(r=(n?o(e,i,r):o(r))||r);return n&&r&&lO(e,i,r),r};const ry=65535,hO=3e3;var Ur,xe,Ve,He,bi,jn,cl,Qh,dl,Xh,sy;const ay=(sy=class{constructor(t,{peerId:e,meetingId:i,authToken:n,capabilities:r}){f(this,Ve),f(this,cl),f(this,dl),f(this,Ur,void 0),f(this,xe,void 0),m(this,"roomName"),m(this,"authToken"),m(this,"capabilities"),f(this,bi,void 0),f(this,jn,void 0);var s;if(!e||!i||!n)throw new w("peerId, meetingId, or authToken can not be empty","0404");v(this,bi,void 0),v(this,jn,t),this.capabilities=r,this.roomName=i,this.authToken=n,v(this,Ur,j(this,cl,Qh).call(this,e)),v(this,xe,new dO(a(this,Ur),{autoReconnect:!0,disconnectOnPingTimeout:(s=r.includes("PING"))!=null?s:!1,queueOnDisconnect:!0,flushOnReconnect:!1,logger:u})),this.handleSocketConnectionEvents()}get joinAttempted(){return a(this,Ve,He).socketJoinAttempted}set joinAttempted(t){a(this,Ve,He).socketJoinAttempted=t}get peerId(){return a(this,jn).getValue("peerId")}updateURL(t){t!==this.peerId&&(v(this,Ur,j(this,cl,Qh).call(this,t)),u.debug("SocketService:: Connection URL updated.")),a(this,xe).updateURL(a(this,Ur))}static getSocketEdgeDomain(t){return $r({servicePrefix:"socket-edge",baseURI:t})}get url(){return a(this,Ur)}connect(){return h(this,null,function*(){a(this,Ve,He).socketJoinAttempted=!0,yield a(this,xe).connect(),a(this,Ve,He).socketJoinAttempted=!0,a(this,Ve,He).socketState={state:"connected",reconnected:!1,reconnectionAttempt:void 0}})}disconnect(){return h(this,null,function*(){a(this,Ve,He).socketJoinAttempted=!1,a(this,xe).disconnect(),a(this,Ve,He).socketJoinAttempted=!0,a(this,Ve,He).socketState={state:"disconnected",reconnected:!1,reconnectionAttempt:void 0}})}get isConnected(){try{return a(this,xe).readyState===1}catch(t){return!1}}sendMessage(t,e,i){const n={};return S.injectContext(n),a(this,xe).send(t,i!=null?i:j(this,dl,Xh).call(this),e,new TextEncoder().encode(JSON.stringify(n)))}sendMessagePromise(t,e,i,n){const r=parseInt({}.SOCKET_SERVICE_MESSAGE_REQUEST_TIMEOUT,10)||2e4;return this.sendMessagePromiseWithTimeout({event:t,timeout:r,protobuf:e,messageId:i,resp:n})}sendMessagePromiseWithTimeout({event:t,timeout:e,protobuf:i,messageId:n,resp:r}){const s=r!=null?r:t;return new Promise((o,c)=>{const d=(T,b)=>{a(this,xe).removeListener(s,T),a(this,xe).removeListener(ry,b),a(this,xe).removeListener(Xt.errorResponse,b),a(this,xe).removeListener(li.errorResponse,b)},l=n!=null?n:j(this,dl,Xh).call(this),p={};S.injectContext(p);const g=({id:T,payload:b})=>{if(l===T){let N;try{const M=aI.fromBinary(b);N=new Error(M.errorMessage)}catch(M){N=new Error("failed to parse error message",{cause:M});try{const F=oC.fromBinary(b);N=new Error(F.message)}catch(F){N=new Error("failed to parse error message",{cause:F})}}c(N),d(y,g)}},y=({id:T,payload:b})=>{l===T&&(o({id:T,payload:b}),d(y,g))};a(this,xe).on(s,y),a(this,xe).on(ry,g),a(this,xe).on(Xt.errorResponse,g),a(this,xe).on(li.errorResponse,g),setTimeout(()=>{d(y,g),c(new Error(`request timeout for callback eventId:${t}`))},e),a(this,xe).send(t,l,i,new TextEncoder().encode(JSON.stringify(p)))})}on(t,e){a(this,xe).on(t,e)}onStateEvent(t,e){a(this,xe).on(t,e)}removeListener(t,e){a(this,xe).removeListener(t,e)}removeListeners(t){a(this,xe).removeListeners(t)}flush(){return a(this,xe).flush()}handleSocketConnectionEvents(){this.onStateEvent("connected",()=>h(this,null,function*(){u.info("SocketService::Connected to socket-edge"),a(this,bi)&&(clearTimeout(a(this,bi)),v(this,bi,void 0)),a(this,Ve,He).updateSocketConnectionState("connected")})),this.onStateEvent("disconnected",({code:t,reason:e})=>{var i;u.info("SocketService::Disconnected from socket-edge",{error:{code:t,reason:e},country:S.location.country});const{recv:n,send:r}=(i=a(this,Ve,He).mediaState)!=null?i:{};n!=null&&n.state&&(n==null?void 0:n.state)!==wn.CONNECTED||r!=null&&r.state&&(r==null?void 0:r.state)!==wn.CONNECTED?P.emit(R.SOCKET_SERVICE_DISCONNECTED,{joinAttempted:a(this,Ve,He).joinAttempted}):v(this,bi,setTimeout(()=>{P.emit(R.SOCKET_SERVICE_DISCONNECTED,{joinAttempted:a(this,Ve,He).joinAttempted}),v(this,bi,void 0)},hO)),a(this,Ve,He).updateSocketConnectionState("disconnected")}),this.onStateEvent("reconnecting",()=>h(this,null,function*(){u.info("SocketService::Reconnecting to socket-edge",{country:S.location.country}),a(this,Ve,He).updateSocketConnectionState("reconnecting")})),this.onStateEvent("reconnectAttempt",t=>h(this,[t],function*({attempt:e}){u.info("SocketService::Attempting to reconnect to socket-edge",{socket:{retryAttempt:e}}),a(this,Ve,He).updateSocketConnectionState("reconnectAttempt",e)})),this.onStateEvent("reconnectFailure",({attempt:t})=>{u.info("SocketService::Reconnect attempt to socket-edge failed",{socket:{retryAttempt:t}}),a(this,Ve,He).updateSocketConnectionState("reconnectFailure",t)}),this.onStateEvent("reconnected",()=>h(this,null,function*(){u.info("SocketService::Reconnected to socket-edge",{connectionState:{joinAttempted:a(this,Ve,He).mediaJoinAttempted}}),a(this,bi)&&(clearTimeout(a(this,bi)),v(this,bi,void 0)),P.emit(R.SOCKET_SERVICE_RECONNECTED,{wasJoinAttempted:a(this,Ve,He).mediaJoinAttempted}),a(this,Ve,He).updateSocketConnectionState("reconnected")})),this.onStateEvent("failed",()=>h(this,null,function*(){u.info("SocketService::Failed to connect to socket-edge",{country:S.location.country}),P.emit(R.SOCKET_SERVICE_FAILED),a(this,Ve,He).updateSocketConnectionState("failed")}))}},Ur=new WeakMap,xe=new WeakMap,Ve=new WeakSet,He=function(){return a(this,jn).getValue("connectionHandler")},bi=new WeakMap,jn=new WeakMap,cl=new WeakSet,Qh=function(t){let e=ay.getSocketEdgeDomain(a(this,jn).getValue("baseURI"));typeof Rc(a(this,jn),"socket_server_base")=="string"&&(e=Rc(a(this,jn),"socket_server_base"));const i=`wss://${e}`,n=new URL(`${i}/ws`),r=this.peerId,s=q(x({roomID:this.roomName,peerID:t,authToken:this.authToken,useMediaV2:!0},r!==t&&{oldPeerID:r}),{ping:this.capabilities.includes("PING"),capabilities:this.capabilities.map(o=>Nc[o]).join(" "),joinWithDetails:!0,useCfWorker:!0});return Object.entries(s).forEach(([o,c])=>{n.searchParams.append(o,c.toString())}),n.href},dl=new WeakSet,Xh=function(){return`${this.peerId}-${(Math.random()+1).toString(36).substring(7)}`},sy);let Po=ay;ol([S.trace("SocketService.connect")],Po.prototype,"connect",1),ol([S.trace("SocketService.disconnect")],Po.prototype,"disconnect",1),ol([S.trace("SocketService.sendMessagePromise")],Po.prototype,"sendMessagePromise",1),ol([S.trace("SocketService.sendMessagePromiseWithTimeout")],Po.prototype,"sendMessagePromiseWithTimeout",1);const Fr=class{static handleConnectedRoomsDumpRaw({payload:t}){var e;const i=NC.fromBinary(t),n=i.meetings.map(r=>{var s;return{id:r.id,title:r.title,participants:(s=r.participants)!=null?s:[]}});return{parentMeeting:{id:i.parentMeeting.id,title:i.parentMeeting.title,participants:(e=i.parentMeeting.participants)!=null?e:[]},meetings:n}}static handleTransferPeerRaw({payload:t}){const e=aP.fromBinary(t);return{authToken:e.authToken,meetingId:e.meetingId}}static handleMovedPeerRaw({payload:t}){const e=Xg.fromBinary(t);return{meetingId:e.meetingId,customParticipantId:e.customParticipantId}}static handleConnectedRoomsUpdatedRaw({payload:t}){return Qg.fromBinary(t).payloads.map(e=>({id:e.id,title:e.title}))}static handleConnectedRoomsDeletedRaw({payload:t}){return YC.fromBinary(t).payloads}static getConnectedRoomsDump(){return h(this,null,function*(){const t=yield Fr.socketService.sendMessagePromise(B.getConnectedRoomsDump);return Fr.handleConnectedRoomsDumpRaw(t)})}static createConnectedRooms(t){return h(this,null,function*(){const{payload:e}=yield Fr.socketService.sendMessagePromise(B.createConnectedRooms,UC.toBinary({payloads:t}));return Qg.fromBinary(e).payloads.map(i=>({id:i.id,title:i.title}))})}static updateConnectedRooms(t){return h(this,null,function*(){})}static disableConnectedRooms(t){return h(this,null,function*(){const e=t.map(n=>({id:n})),i=yield Fr.socketService.sendMessagePromise(B.deleteConnectedRooms,KC.toBinary({payloads:e}));return Fr.handleConnectedRoomsDeletedRaw(i)})}static movePeersBetweenRooms(t){return h(this,null,function*(){try{const e=yield Fr.socketService.sendMessagePromise(B.movePeers,iP.toBinary({sourceMeetingId:t.sourceMeetingId,destinationMeetingId:t.destinationMeetingId,participants:t.participants}));return new TextDecoder().decode(e.payload).includes("error")?{success:!1,error:"failed to move participants"}:{success:!0}}catch(e){return{success:!1,error:e}}})}};let Ae=Fr;m(Ae,"socketService"),m(Ae,"currentMeetingId");var pO=Object.defineProperty,mO=Object.getOwnPropertyDescriptor,ll=(t,e,i,n)=>{for(var r=n>1?void 0:n?mO(e,i):e,s=t.length-1,o;s>=0;s--)(o=t[s])&&(r=(n?o(e,i,r):o(r))||r);return n&&r&&pO(e,i,r),r};const Us=class{constructor(t,e){m(this,"apiBase"),m(this,"selfController"),m(this,"pollController"),m(this,"chatController"),m(this,"metaController"),m(this,"storesManager"),m(this,"stageController"),m(this,"pluginController"),m(this,"internalsController"),m(this,"recordingController"),m(this,"livestreamController"),m(this,"participantController"),this.apiBase=t,this.storesManager=e.storesManager,this.metaController=e.metaController,this.selfController=e.selfController,this.chatController=e.chatController,this.pollController=e.pollController,this.stageController=e.stageController,this.pluginController=e.pluginController,this.recordingController=e.recordingController,this.internalsController=e.internalsController,this.participantController=e.participantController,this.livestreamController=e.livestreamController}static init(t){return h(this,null,function*(){var e,i;const{peerId:n,apiBase:r,authToken:s,meetingId:o,organizationId:c,cachedUserDetails:d}=t.getAllValues();if(P.reset(),vd.cleanup(),Uv(t),_e.isSupported()===!1)throw new w("Browser not supported","0010",!0);const l=yA(t,{authToken:s,baseURL:r,cachedUserDetails:d});l.setRoomName(o),l.setRoomUUID(o),l.setOrganizationId(c),l.setHeader("dyte-tracing-id",n),t.setValue("apiClient",l);const p=new e1;t.setValue("connectionHandler",p);const g=Us.createSocketService(t),y=g.connect(),T=l.getUserDetails(),b=l.getPlugins();let N=et.HIVE,M,F="";try{yield Us.setupFlagsmith(t)}catch(re){u.error("Failed to setup flagsmith",{error:re})}try{yield y}catch(re){u.error("[Controller]: Failed to connect to socket server:",{error:re})}try{({sfu:N,meetingTitle:F}=yield l.getRoomNodeData()),M=yield T,u.info(`SFU ${N} is being used.`),t.setValue("presetName",M.preset.name),t.setValue("roomNodeOptions",{sfu:N})}catch(re){u.error("Failed to get room metadata",{error:re})}const H=U1.init(M.preset,!t.getValue("modules").theme),K=Us.setupControllers(g,t,M,b,F,H);HA(H)&&((e=Us.createRoomNodeClient(t,g).partialJoinRoom(M.participant.name,o,void 0))==null||e.catch(re=>{u.error("[Controller]: Failed to queue partial media room promise:",{error:re})})),S.location.country=(i=l.ipInfo)==null?void 0:i.country;const{controllers:I}=yield K;return q_(),new Us(r,I)})}static setupFlagsmith(t){return h(this,null,function*(){var e;const{peerId:i,baseURI:n,overrides:r,meetingId:s,organizationId:o}=t.getAllValues(),c=H_(s),d=q(x({entity:Zl.PEER,clientId:o,isAnonUser:!o,sdkVersion:t.getValue("sdkVersion"),presetName:t.getValue("presetName"),meetingHash:c,roomName:s},_e.getDeviceInfo()),{isReactNative:navigator.isReactNative});try{const l=(e=r==null?void 0:r.whitelabelled_flags_endpoint)==null||e?$r({servicePrefix:"flags",baseURI:n}):"edge.api.flagsmith.com";yield Q.identify(`${Zl.PEER}_${i}`,JSON.parse(JSON.stringify(d)),!1,5e3,l,u),u.info("flagsmith::allFlags",{flags:JSON.stringify(Q.getAllFlags())},!0)}catch(l){u.error("Failed to fetch flagsmith flags")}})}static setupControllers(t,e,i,n,r,s){return h(this,null,function*(){var o,c,d;const l=e.getValue("modules"),{preset:p,participant:g}=i,y=e.getValue("defaults"),{sfu:T}=e.getValue("roomNodeOptions"),{viewType:b,mediaConstraints:{audio:N}}=s;e.setValue("viewType",b),e.setValue("defaults",x({mediaConfiguration:{audio:{enableHighBitrate:(o=N.enableHighBitrate)!=null?o:!1,enableStereo:(c=N.enableStereo)!=null?c:!1}}},y));const M=sD.init(e,b,p.permissions);e.setValue("maxPreferredStreams",_e.isMobile()?s.maxVideoStreams.mobile:s.maxVideoStreams.desktop);let F,H,K,I,re,ae,De,Oe;const ft=new jD(t);Ae.socketService=t;const Yt=new Qd(t),A=new Zt(t),k=new qD(t),_=vd.create(t,e),W=new JD(t),Ie=new WD(t),Ye=new rr(t),U=yield xn.init(e,_,g,M,s),C=yield Of.init(e,U.self,_,ft,r);if(l.participant&&(Oe=new Zi(e,U.self,_,T)),(d=l.e2ee)!=null&&d.enabled&&l.e2ee.manager.init(u,P),l.chat&&(H=yield zi.init(e,A,Ye,U.self,Oe.participants)),l.internals&&(re=yield xu.init()),l.livestream&&s.viewType===yt.Livestream&&Q.hasFeature(ne.LIVESTREAM)&&(De=new Qf(U.self,Ie)),s.viewType!==yt.Chat){if(l.poll&&(F=yield Cf.init(e,U.self,Yt)),l.recording&&(ae=new Wf(e,U.self,_)),l.stage&&(K=new Nf(e,k,_,U.self,Oe.participants)),l.plugin){if(!Oe)throw new w("The plugin module cannot be initialized without the `participant` module","0102");const on=yield n;I=yield ya.init(e,on,W,A,H==null?void 0:H.chat,U.self,Oe.participants,r)}if(l.pip){const on=yield K_._init(e,U.self);e.setValue("pip",on)}}const Qe={storesManager:new J1(e,W),pollController:F,selfController:U,metaController:C,chatController:H,stageController:K,pluginController:I,recordingController:ae,internalsController:re,livestreamController:De,participantController:Oe};return{theme:s,permissions:M,controllers:Qe}})}static createRoomNodeClient(t,e){const{peerId:i,roomNodeOptions:n}=t.getAllValues(),{sfu:r}=n;return Vv(t,r,{socket:e,peerId:i})}static createSocketService(t){const{peerId:e,meetingId:i,authToken:n}=t.getAllValues(),r=["PING"];return new Po(t,{peerId:e,meetingId:i,authToken:n,capabilities:r})}};let Ro=Us;ll([S.trace("Controller.init")],Ro,"init",1),ll([S.trace("setupFlagsmith")],Ro,"setupFlagsmith",1),ll([S.trace("Controller.createRoomNodeClient")],Ro,"createRoomNodeClient",1),ll([S.trace("Controller.createSocketService")],Ro,"createSocketService",1);var gO=Object.defineProperty,fO=Object.getOwnPropertyDescriptor,vO=(t,e,i,n)=>{for(var r=n>1?void 0:n?fO(e,i):e,s=t.length-1,o;s>=0;s--)(o=t[s])&&(r=(n?o(e,i,r):o(r))||r);return n&&r&&gO(e,i,r),r},ul,Zh;class oy extends Ft{constructor(e,i){super(),f(this,ul,void 0),m(this,"meetings",[]),m(this,"parentMeeting",null),f(this,Zh,void 0),v(this,Zh,e),v(this,ul,i.self)}get supportsConnectedMeetings(){return a(this,ul).id!==""}get isActive(){return this.meetings.length!==0}get currentMeetingId(){return Ae.currentMeetingId}validateConnectedMeetingsAction(){if(!this.supportsConnectedMeetings)throw new Error(`You are not allowed to perform this action.
20
20
  Please connect with Dyte team to move you to V2 APIs & to enable connected meetings.`)}getConnectedMeetings(){return h(this,null,function*(){return this.validateConnectedMeetingsAction(),yield Ae.getConnectedRoomsDump()})}createMeetings(e){return h(this,null,function*(){return this.validateConnectedMeetingsAction(),(yield Ae.createConnectedRooms(e)).map(i=>({id:i.id,title:i.title}))})}updateMeetings(e){return h(this,null,function*(){this.validateConnectedMeetingsAction(),yield Ae.updateConnectedRooms(e.map(i=>({meetingId:i.id,title:i.title})))})}deleteMeetings(e){return h(this,null,function*(){this.validateConnectedMeetingsAction();const i=this.meetings.map(n=>e.includes(n.id)&&n.participants.length!==0?this.moveParticipants(n.id,this.parentMeeting.id,n.participants.map(r=>r.id)):Promise.resolve());return yield Promise.all(i),yield Ae.disableConnectedRooms(e)})}moveParticipants(e,i,n){return h(this,null,function*(){this.validateConnectedMeetingsAction();const r=yield Ae.movePeersBetweenRooms({sourceMeetingId:e,destinationMeetingId:i,participants:n.map(s=>({id:s}))});return r.success&&this.moveSuccessHandler(e,i,n),r})}moveParticipantsWithCustomPreset(e,i,n){return h(this,null,function*(){this.validateConnectedMeetingsAction();const r=yield Ae.movePeersBetweenRooms({sourceMeetingId:e,destinationMeetingId:i,participants:n});return r.success&&this.moveSuccessHandler(e,i,n.map(s=>s.id)),r})}moveSuccessHandler(e,i,n){const r=new Map;[...this.parentMeeting.participants,...this.meetings.flatMap(s=>s.participants)].forEach(s=>r.set(s.id,s)),i===this.parentMeeting.id&&(this.parentMeeting.participants=this.parentMeeting.participants.concat(n.map(s=>r.get(s)))),e===this.parentMeeting.id&&(this.parentMeeting.participants=this.parentMeeting.participants.filter(s=>!n.includes(s.id))),this.meetings=this.meetings.map(s=>{if(i===s.id){const o=s.participants.concat(n.map(c=>r.get(c)));return q(x({},s),{participants:o})}if(e===s.id){const o=s.participants.filter(c=>!n.includes(c.id));return q(x({},s),{participants:o})}return s})}}ul=new WeakMap,Zh=new WeakMap,vO([Dt({maxInvocations:60,period:60})],oy.prototype,"getConnectedMeetings",1);var yO=Object.defineProperty,SO=Object.getOwnPropertyDescriptor,ep=(t,e,i,n)=>{for(var r=n>1?void 0:n?SO(e,i):e,s=t.length-1,o;s>=0;s--)(o=t[s])&&(r=(n?o(e,i,r):o(r))||r);return n&&r&&yO(e,i,r),r},Mo,_i,tp,ip;const Hn=(tp=class{constructor(t,e,i){m(this,"connectedMeetings"),f(this,Mo,void 0),f(this,_i,void 0),f(this,ip,void 0),v(this,ip,t),v(this,Mo,i),this.connectedMeetings=new oy(t,e),this.setCurrentMeeting(e)}static init(t,e,i){return Hn.instance||(Hn.instance=new Hn(t,e,i)),Hn.instance.connectedMeetings.supportsConnectedMeetings&&(Hn.instance.setupEvents(),e.self.once("roomJoined",()=>Hn.instance.getConnectedMeetings())),Hn.instance}setCurrentMeeting(t){v(this,_i,t),Ae.currentMeetingId=t.meta.meetingId}getConnectedMeetings(){this.connectedMeetings.getConnectedMeetings()}setupEvents(){Ae.socketService&&(Ae.socketService.on(B.getConnectedRoomsDump,this.handleConnectedRoomsDump.bind(this)),Ae.socketService.on(B.transferPeer,this.handleTransferPeer.bind(this)),Ae.socketService.on(B.movedPeer,this.handleMovedPeer.bind(this)),Ae.socketService.on(B.connectedRoomsUpdated,this.handleConnectedRoomsUpdated.bind(this)),Ae.socketService.on(B.connectedRoomsDeleted,this.handleConnectedRoomsDeleted.bind(this)))}handleTransferPeer(t){const e=Ae.handleTransferPeerRaw(t);return this.switchMeeting(e)}switchMeeting(t){return h(this,arguments,function*({authToken:e,meetingId:i}){var n,r,s,o;if(!this.connectedMeetings.supportsConnectedMeetings)throw new Error(`You are not allowed to perform this action.
21
21
  Please connect with Dyte team to move you to V2 APIs & to enable connected meetings.`);u.info("ConnectedMeetingsController::switchMeeting:: asking ui-kit to show switching breakout UI"),this.connectedMeetings.emit("changingMeeting",i);const c={video:a(this,_i).self.videoEnabled,audio:a(this,_i).self.audioEnabled};try{a(this,_i).self.cleanupEvents(),yield a(this,_i).leave("connected-meeting")}catch(l){u.error(`ConnectedMeetingsController:: switchMeeting:: issues in leaving previous meeting. Meeting Id: ${(r=(n=a(this,_i))==null?void 0:n.meta)==null?void 0:r.meetingId}`,{error:l})}Ae.socketService=void 0,u.info(`ConnectedMeetingsController::switchMeeting:: initializing new meeting. Meeting Id: ${i}`);const d=yield uy.init(q(x({},a(this,Mo)),{cachedUserDetails:null,defaults:q(x(x({},a(this,Mo).defaults),c),{mediaHandler:a(this,_i).self}),authToken:e}));u.info(`ConnectedMeetingsController::switchMeeting:: initialized new meeting. Meeting Id: ${(s=d==null?void 0:d.meta)==null?void 0:s.meetingId}`);try{const{hidden:l}=a(this,_i).self;d.self.setName(a(this,_i).self.name),yield d.join(),l&&d.self.hide()}catch(l){u.error("ConnectedMeetingsController.joinRoom",{error:l})}return u.info(`ConnectedMeetingsController::switchMeeting:: asking ui-kit to show in-meeting ui of newly joined meeting id: ${(o=d==null?void 0:d.meta)==null?void 0:o.meetingId}`),this.connectedMeetings.emit("meetingChanged",d),this.setCurrentMeeting(d),d})}handleConnectedRoomsDump(t){const e=Ae.handleConnectedRoomsDumpRaw(t);this.connectedMeetings.meetings=e.meetings.map(i=>({id:i.id,title:i.title,participants:i.participants||[]})),this.connectedMeetings.parentMeeting={id:e.parentMeeting.id,title:e.parentMeeting.title,participants:e.parentMeeting.participants},this.emitStateUpdate()}handleMovedPeer(t){return Ae.handleMovedPeerRaw(t)}handleConnectedRoomsUpdated(t){const e=Ae.handleConnectedRoomsUpdatedRaw(t),i=new Map;this.connectedMeetings.meetings.forEach(n=>{i.set(n.id,n)}),e.forEach(n=>{i.has(n.id)?i.get(n.id).title=n.title:i.set(n.id,q(x({},n),{participants:[]}))}),this.connectedMeetings.meetings=Array.from(i.values()),this.emitStateUpdate()}handleConnectedRoomsDeleted(t){const e=Ae.handleConnectedRoomsDeletedRaw(t).map(i=>i.id);this.connectedMeetings.meetings=this.connectedMeetings.meetings.filter(i=>!e.includes(i.id)),this.emitStateUpdate()}emitStateUpdate(){this.connectedMeetings.emit("stateUpdate",{meetings:this.connectedMeetings.meetings,parentMeeting:this.connectedMeetings.parentMeeting})}},Mo=new WeakMap,_i=new WeakMap,ip=new WeakMap,m(tp,"instance"),tp);let hl=Hn;ep([S.trace("ConnectedMeetingsController.getConnectedMeetings")],hl.prototype,"getConnectedMeetings",1),ep([S.trace("ConnectedMeetingsController.setupEvents")],hl.prototype,"setupEvents",1),ep([S.trace("ConnectedMeetingsController.switchMeeting")],hl.prototype,"switchMeeting",1);class EO{constructor(){m(this,"battery"),m(this,"init",()=>h(this,null,function*(){try{"getBattery"in navigator&&(this.battery=yield navigator.getBattery(),this.battery.addEventListener("chargingchange",this.updateChargeInfo),this.battery.addEventListener("levelchange",this.updateLevelInfo),this.updateLevelInfo(),this.updateChargeInfo())}catch(e){u.error("Error getting battery",e)}})),m(this,"updateChargeInfo",()=>{var e;u.log(`Battery charging? ${(e=this.battery)!=null&&e.charging?"Yes":"No"}`)}),m(this,"updateLevelInfo",()=>{if(!this.battery){u.log("Battery level: Not known");return}u.log(`Battery level: ${this.battery.level*100}%`)}),m(this,"cleanup",()=>{var e,i;"getBattery"in navigator&&((e=this.battery)==null||e.removeEventListener("chargingchange",this.updateChargeInfo),(i=this.battery)==null||i.removeEventListener("levelchange",this.updateLevelInfo))})}}const cy=new EO;function TO(t,e){t.startsWith("eyJ")||console.error("Invalid auth token provided. Ensure you are passing a %cparticipant `authToken`%c \u2014 not an Org API Key or an incorrectly formatted token.\nYou get the participant token from the Add Participant API: https://docs.dyte.io/api#/operations/add_participant","font-weight: bold","font-weight: normal");try{const{meetingId:i,orgId:n,participantId:r}=JSON.parse(atob(t.split(".")[1]));if(!i)throw Error(`Received V1 auth token ${t}`);let s="dyte.io";e&&(s=e);const o=`https://api.${s}`;return{meetingId:i,orgId:n,participantId:r,baseURI:s,apiBase:o}}catch(i){throw u.error("constants::decodeAuthToken",{error:i,debuggingHint:`Unable to decode auth token: ${t}`},!0),new w("Invalid auth token","0004")}}var kO=Object.defineProperty,bO=Object.getOwnPropertyDescriptor,pl=(t,e,i,n)=>{for(var r=n>1?void 0:n?bO(e,i):e,s=t.length-1,o;s>=0;s--)(o=t[s])&&(r=(n?o(e,i,r):o(r))||r);return n&&r&&kO(e,i,r),r},ct,ml,gl,np,dy,ly;let Gn=(ly=class{constructor(t,e){f(this,np),f(this,ct,void 0),f(this,ml,void 0),f(this,gl,void 0),v(this,gl,t),v(this,ct,e)}static init(t){return h(this,null,function*(){var e,i,n,r,s,o,c;B_(),_e.init();const d=(i=(e=t==null?void 0:t.cachedUserDetails)==null?void 0:e.peerId)!=null?i:Br();cy.init();const{authToken:l,baseURI:p}=t,g=TO(l,p),{meetingId:y}=g,T=sc(g,["meetingId"]);window.__zone_symbol__DISABLE_WRAPPING_UNCAUGHT_PROMISE_REJECTION=!0;const b=Gn.setupContext(d,t,y,T);S.meetingMetadata.roomName=y,S.meetingMetadata.userId=T.participantId,S.meetingMetadata.organizationId=T.orgId,S.init(b,(r=(n=t.modules)==null?void 0:n.tracing)!=null?r:!0),u.info("DyteClient::init::options",{dyteClientInitOptions:q(x({},t),{authToken:`${(s=t.authToken)==null?void 0:s.slice(0,10)}...
22
- ${(o=t.authToken)==null?void 0:o.slice(-10)}`})});const N=yield Ro.init(b),M=new Gn(b,N);return j(c=M,np,dy).call(c,t),M})}static setupContext(t,e,i,n){var r;const s=Zn.createContext(t,e),o=x(x({},N_),e==null?void 0:e.modules);return s.setValue("peerId",t),s.setValue("modules",o),s.setValue("sdkName","web-core"),s.setValue("meetingId",i),s.setValue("apiBase",n.apiBase),s.setValue("baseURI",n.baseURI),s.setValue("userId",n.participantId),s.setValue("organizationId",n.orgId),s.setValue("authToken",e.authToken),s.setValue("overrides",(r=e.overrides)!=null?r:{}),s.setValue("env",L_({baseURI:n.baseURI})),s.setValue("defaults",e.defaults||{audio:!0,video:!0}),s.setValue("onError",e.onError||(()=>{})),s.setValue("cachedUserDetails",hi(e.cachedUserDetails)),s.setValue("sdkVersion","2.5.0-staging.106"),s}join(){return h(this,null,function*(){const{selfController:t}=a(this,ct);return t.self.roomJoined?null:t.joinRoom()})}leave(t){return h(this,null,function*(){cy.cleanup();const{selfController:e}=a(this,ct);return e.leaveRoom(t)})}get participants(){var t;return(t=a(this,ct).participantController)==null?void 0:t.participants}get self(){var t;return(t=a(this,ct).selfController)==null?void 0:t.self}get meta(){var t;return(t=a(this,ct).metaController)==null?void 0:t.meta}get ai(){var t;return(t=a(this,ct).metaController)==null?void 0:t.ai}get plugins(){var t;return(t=a(this,ct).pluginController)==null?void 0:t.plugins}get chat(){var t;return(t=a(this,ct).chatController)==null?void 0:t.chat}get polls(){var t;return(t=a(this,ct).pollController)==null?void 0:t.polls}get connectedMeetings(){var t;return(t=a(this,ml))==null?void 0:t.connectedMeetings}get recording(){var t;return(t=a(this,ct).recordingController)==null?void 0:t.recording}get livestream(){var t;return(t=a(this,ct).livestreamController)==null?void 0:t.livestream}get stage(){var t;return(t=a(this,ct).stageController)==null?void 0:t.stage}get stores(){return a(this,ct).storesManager}get __internals__(){var t;return(t=a(this,ct).internalsController)==null?void 0:t.internals}joinRoom(){return h(this,null,function*(){return this.join()})}leaveRoom(t){return h(this,null,function*(){return this.leave(t)})}},ct=new WeakMap,ml=new WeakMap,gl=new WeakMap,np=new WeakSet,dy=function(t){v(this,ml,hl.init(a(this,gl),this,t))},ly);pl([ut("0002"),In.executeWithLock({methodName:"meeting.join",lockName:"DyteClient.join",timeout:3e3})],Gn.prototype,"join",1),pl([ut("0003")],Gn.prototype,"leave",1),pl([ut("0001"),In.executeWithLock({methodName:"DyteClient.init",lockName:"DyteClient.init",timeout:3e3})],Gn,"init",1),Gn=pl([ut("0000")],Gn);const uy=Gn;return uy}();
22
+ ${(o=t.authToken)==null?void 0:o.slice(-10)}`})});const N=yield Ro.init(b),M=new Gn(b,N);return j(c=M,np,dy).call(c,t),M})}static setupContext(t,e,i,n){var r;const s=Zn.createContext(t,e),o=x(x({},N_),e==null?void 0:e.modules);return s.setValue("peerId",t),s.setValue("modules",o),s.setValue("sdkName","web-core"),s.setValue("meetingId",i),s.setValue("apiBase",n.apiBase),s.setValue("baseURI",n.baseURI),s.setValue("userId",n.participantId),s.setValue("organizationId",n.orgId),s.setValue("authToken",e.authToken),s.setValue("overrides",(r=e.overrides)!=null?r:{}),s.setValue("env",L_({baseURI:n.baseURI})),s.setValue("defaults",e.defaults||{audio:!0,video:!0}),s.setValue("onError",e.onError||(()=>{})),s.setValue("cachedUserDetails",hi(e.cachedUserDetails)),s.setValue("sdkVersion","2.5.0-staging.108"),s}join(){return h(this,null,function*(){const{selfController:t}=a(this,ct);return t.self.roomJoined?null:t.joinRoom()})}leave(t){return h(this,null,function*(){cy.cleanup();const{selfController:e}=a(this,ct);return e.leaveRoom(t)})}get participants(){var t;return(t=a(this,ct).participantController)==null?void 0:t.participants}get self(){var t;return(t=a(this,ct).selfController)==null?void 0:t.self}get meta(){var t;return(t=a(this,ct).metaController)==null?void 0:t.meta}get ai(){var t;return(t=a(this,ct).metaController)==null?void 0:t.ai}get plugins(){var t;return(t=a(this,ct).pluginController)==null?void 0:t.plugins}get chat(){var t;return(t=a(this,ct).chatController)==null?void 0:t.chat}get polls(){var t;return(t=a(this,ct).pollController)==null?void 0:t.polls}get connectedMeetings(){var t;return(t=a(this,ml))==null?void 0:t.connectedMeetings}get recording(){var t;return(t=a(this,ct).recordingController)==null?void 0:t.recording}get livestream(){var t;return(t=a(this,ct).livestreamController)==null?void 0:t.livestream}get stage(){var t;return(t=a(this,ct).stageController)==null?void 0:t.stage}get stores(){return a(this,ct).storesManager}get __internals__(){var t;return(t=a(this,ct).internalsController)==null?void 0:t.internals}joinRoom(){return h(this,null,function*(){return this.join()})}leaveRoom(t){return h(this,null,function*(){return this.leave(t)})}},ct=new WeakMap,ml=new WeakMap,gl=new WeakMap,np=new WeakSet,dy=function(t){v(this,ml,hl.init(a(this,gl),this,t))},ly);pl([ut("0002"),In.executeWithLock({methodName:"meeting.join",lockName:"DyteClient.join",timeout:3e3})],Gn.prototype,"join",1),pl([ut("0003")],Gn.prototype,"leave",1),pl([ut("0001"),In.executeWithLock({methodName:"DyteClient.init",lockName:"DyteClient.init",timeout:3e3})],Gn,"init",1),Gn=pl([ut("0000")],Gn);const uy=Gn;return uy}();
package/dist/index.cjs.js CHANGED
@@ -20,4 +20,4 @@ ${t}`}const xs={maxInvocations:5,period:1};function Vt(t,e){return function(i,n,
20
20
  maxEnergy: ${a(this,dr)}`),r===-1/0||i<1e-6?{energy:0,isVoice:!1}:((!a(this,_n)||r<a(this,_n))&&v(this,_n,r),(!a(this,dr)||r>a(this,dr))&&v(this,dr,r),{energy:(r-a(this,_n))/(a(this,dr)-a(this,_n))*10||0,isVoice:n})},ed=new WeakSet,lh=function(t){return t<5},uh=new WeakSet,Gv=function(t=a(this,Is)){var e;if(!a(this,Ni)||!t){Q.hasFeature(re.ENABLE_AUDIO_ACTIVITY_DEBUG_LOGS)&&u.debug(`AudioActivityReporter: No producerId or energy to report: ${a(this,Ni)}`);return}const i={producerId:a(this,Ni),energy:Math.round(t),silent:j(e=Fd,ed,lh).call(e,t)};v(this,Io,i.silent),this.reportRequest(i)},Yl=new WeakSet,ag=function(t){const e=Math.log10(t);return Math.round(e)},f(hh,ed),f(hh,Yl);const BD=(t=!1)=>{const e=new window.AudioContext,i=e.createOscillator();i.type="triangle",i.frequency.setValueAtTime(20,e.currentTime);const n=e.createGain();n.gain.setValueAtTime(0,e.currentTime),i.connect(n);const r=e.createMediaStreamDestination();n.connect(r),i.start();const s=r.stream.getAudioTracks()[0];return s.enabled=t,s},WD=(t=!1)=>{var e,i;const n=new MediaStream().getVideoTracks()[0],r=document.createElement("canvas");r.height=(e=n==null?void 0:n.getSettings().height)!=null?e:720,r.width=(i=n==null?void 0:n.getSettings().width)!=null?i:1280;const s=r.getContext("2d");s.fillStyle="black",s.fillRect(0,0,r.width,r.height),setInterval(()=>{s.fillStyle="black",s.fillRect(0,0,r.width,r.height)},1e3);const o=r.captureStream().getVideoTracks()[0];return o.enabled=t,o};var jD=Object.defineProperty,HD=Object.getOwnPropertyDescriptor,ue=(t,e,i,n)=>{for(var r=n>1?void 0:n?HD(e,i):e,s=t.length-1,o;s>=0;s--)(o=t[s])&&(r=(n?o(e,i,r):o(r))||r);return n&&r&&jD(e,i,r),r};const wi=["video/VP9","video/VP8"];var td,id,kt,$,ao,lr,Nt,ds,ls,ur,nd,wn,oo,us,hs,Lt,Ht,hr,ps,ht,bt,ms,co,ph,qv,mh,Jv,gh,$v;class le{constructor(e,i,n){f(this,hr),f(this,ht),f(this,ms),f(this,ph),f(this,mh),f(this,gh),m(this,"context"),m(this,"authToken"),m(this,"e2ee"),f(this,td,void 0),f(this,id,void 0),f(this,kt,void 0),f(this,$,void 0),f(this,ao,void 0),f(this,lr,void 0),f(this,Nt,void 0),f(this,ds,void 0),f(this,ls,void 0),f(this,ur,void 0),f(this,nd,void 0),f(this,wn,void 0),f(this,oo,void 0),f(this,us,void 0),f(this,hs,void 0),f(this,Lt,void 0),f(this,Ht,void 0),m(this,"partialJoinRoomPromise");var r,s;this.context=e;const{socket:o}=n;this.mediaJoined=!1,v(this,us,new Map([["video/VP9",new Set],["video/VP8",new Set]])),v(this,hs,new Map([["video/VP9",new Set],["video/VP8",new Set]])),v(this,lr,i),v(this,kt,o),v(this,ds,!1),v(this,$,new VD(e,o,i)),v(this,Nt,a(this,$).events),v(this,wn,new Set),v(this,Lt,new Map),v(this,ls,!1),v(this,ur,new Ad),i===it.CF&&!navigator.isReactNative&&v(this,Ht,new hh(a(this,$).socketHandler.audioActivity.bind(a(this,$).socketHandler))),this.e2ee=(s=(r=e.getValue("modules").e2ee)==null?void 0:r.enabled)!=null?s:!1,this.handleSocketEvents(),this.handleCallstatsEvents(),v(this,nd,bd(()=>h(this,null,function*(){if(!a(this,hr,ps).mediaJoinAttempted)return;const{roomJoined:c}=yield this.joinRoom(a(this,id),a(this,td),{},!0,!0);c&&(P.emit(R.RESET_PRODUCER_STATE),P.emit(R.ROOM_NODE_RECONNECTED))}),5e3,{leading:!0,maxWait:1e3}))}get peerId(){return this.context.getValue("peerId")}get mediaJoined(){return a(this,hr,ps).mediaJoined}set mediaJoined(e){a(this,hr,ps).mediaJoined=e}reset(e=!0){a(this,$).closeAllProducers(),a(this,$).closeAllConsumers(),a(this,Lt).clear(),a(this,wn).clear(),e&&(this.partialJoinRoomPromise=void 0,a(this,ur).stop(),a(this,$).stopAllTransports(),a(this,$).reset(),v(this,ur,new Ad))}joinRoom(e,i){return h(this,arguments,function*(n,r,s={},o=!1,c=!1){a(this,hr,ps).mediaJoinAttempted=!0,v(this,ds,!0),this.reset(o);const d=ct().ipInfo;if(d!=null&&d.loc&&!a(this,oo)){const p=d.loc.split(",");v(this,oo,{latitude:parseFloat(p[0]),longitude:parseFloat(p[1])})}let l;try{return l=yield a(this,ur).push(()=>this._joinRoom(n,r,s,c,a(this,oo)),"joinRoom"),l}catch{l={roomJoined:!1}}return l.roomJoined||P.emit(R.ROOM_NODE_FAILED),l})}_partialJoinRoom(e,i,n=!1,r=void 0){return h(this,null,function*(){var s;const{ipInfo:o}=ct();let c=r;if(o!=null&&o.loc&&!r){const[p,g]=o.loc.split(",").map(parseFloat);c={latitude:p,longitude:g}}const d=(s=Q.getValue(re.FORCE_VIDEO_CODEC))==null?void 0:s.toString(),l=bD(d);v(this,ao,l),yield Qh((p,g)=>h(this,null,function*(){if(!a(this,kt).isConnected){g(new Error("socket is not connected"));return}p>0&&u.warn(`retrying sending join room request, count: ${p}`);try{yield a(this,$).socketHandler.joinRoom(i,e,l,n,c)}catch(y){throw u.error("failed to send join room request, error:",{error:y}),y}}),{delayTime:1e3,strategy:"exponential",maxRetryCount:Q.hasFeature(re.ENABLE_HIVE_INFINITE_RETRIES)?1/0:3}),yield a(this,$).setupTransports({send:!0,recv:!0}),a(this,lr)!==it.HIVE&&Q.hasFeature(re.PRECREATE_PRODUCERS)&&(this.shareWebcam(WD()),this.shareMic(BD()))})}partialJoinRoom(e,i,n=!1,r=void 0){return h(this,null,function*(){return this.partialJoinRoomPromise=a(this,ur).push(()=>this._partialJoinRoom(e,i,n,r)),this.partialJoinRoomPromise})}_joinRoom(e,i){return h(this,arguments,function*(n,r,s={},o=!1,c=null){v(this,id,n);try{this.partialJoinRoomPromise?yield this.partialJoinRoomPromise:yield this._partialJoinRoom(n,r,o,c)}catch(d){u.error("error in partial join room",{error:d})}finally{this.partialJoinRoomPromise=void 0}try{return navigator.product!=="ReactNative"&&setTimeout(()=>h(this,null,function*(){const d={userId:this.context.getValue("userId"),peerId:this.peerId,roomUUID:r,roomViewType:"groupCall",deviceInfo:q(x({},Ie.getDeviceInfo()),{userAgent:navigator.userAgent,memory:navigator.deviceMemory,cpus:navigator.hardwareConcurrency}),sdkName:this.context.getValue("sdkName"),sdkVersion:this.context.getValue("sdkVersion"),metaData:{},permissions:{}};K.roomJoined(d)})),{roomJoined:yield this.completeJoinRoom()}}catch(d){return u.error("error on sending join room request",{error:d}),{roomJoined:!1}}})}completeJoinRoom(){return h(this,null,function*(){try{this.mediaJoined=!0;const{roomState:e}=yield a(this,$).socketHandler.notifySelfJoinComplete();return v(this,td,e.roomUuid),v(this,ls,!0),v(this,ds,!1),!0}catch(e){return u.error("error on completing join room:",{error:e}),this.mediaJoined=!1,!1}})}leaveRoom(){return h(this,null,function*(){a(this,$).stopAllTransports(),v(this,ls,!1),a(this,hr,ps).mediaJoinAttempted=!1;const e={closeRoom:!1};a(this,kt).sendMessagePromise(a(this,Nt).leaveRoom,Uw.toBinary(e)).then(i=>{var n;(n=kI.fromBinary(i.payload))!=null&&n.closed||u.warn("weird state on peer closed and should not happen")}).catch(i=>{u.error("error on sending leave room request",{error:i})}),K.callEnded(),S.destruct()})}getConsumers(){return a(this,$).consumers}activatePeers(e){return h(this,null,function*(){return this.createConsumers(e)})}deactivatePeers(e,i="default"){return h(this,null,function*(){const n=new Set;e.forEach(s=>{s.screenShare&&s.kind==="video"&&n.add(s.producingPeerId)});const r=i==="default"?e.filter(s=>!n.has(s.producingPeerId)).filter(s=>s.kind!=="audio"):e;yield Promise.all(r.map(s=>{const o=a(this,$).producerIdToConsumerIdMap.get(s.producerId);if(!o){u.warn(`consumer not found in deactivate producers: ${s.producerId}`);return}return a(this,$).closeConsumer(o)}))})}createConsumers(e){return h(this,null,function*(){return e.length===0?Promise.resolve():a(this,$).createConsumers(e)})}closeConsumers(e){return h(this,null,function*(){if(!e.length)return;const i=e.reduce((n,r)=>{const s=a(this,$).producerIdToConsumerIdMap.get(r.producerId);return s?(n.push(s),n):(u.warn(`consumer not found in deactivate producers: ${r.producerId}`),n)},[]);yield a(this,$).closeConsumers(i)})}_shareWebcam(e,i){return h(this,null,function*(){const n=i==="video/VP9"?Ee.WEBCAM:Ee.WEBCAM_BACKUP,r=j(this,ht,bt).call(this,n);if(r){const p=yield r;if(a(this,$).producers.has(p)){const g=a(this,$).producers.get(p);if(!g.closed&&!navigator.isReactNative)return yield g.replaceTrack({track:e}),yield this.resumeWebcam(n),e;yield this.disableWebcam(i)}return this._shareWebcam(e,i)}const s=j(this,gh,$v).call(this,e,i),o=wd(this.context,"disableSimulcast"),c=a(this,lr)===it.CF?re.ENABLE_CF_SIMULCAST:re.ENABLE_HIVE_SIMULCAST;!o&&Q.hasFeature(c)?(u.info(`Simulcast enabled for SFU: ${a(this,lr)}`),s.encodings=S1(e)):u.info(`Simulcast disabled for webcam producer, SFU: ${a(this,lr)}`),Q.hasFeature(re.TRACK_HINT)&&(s.track.contentHint=Q.getValue(re.TRACK_HINT));const d=()=>{u.info("Disabling video due to the producer closure"),a(this,Lt).delete(n)},l=a(this,$).createProducer(s,d);return j(this,ms,co).call(this,n,l.then(p=>p.id)),l.then(p=>p.track)})}shareWebcam(e){return h(this,null,function*(){if(e===void 0)return null;if(Q.hasFeature(re.FORCE_VIDEO_CODEC)){const i=Q.getValue(re.FORCE_VIDEO_CODEC).toString();if(i)return u.debug(`Calling _shareWebcam with forced video codec: ${i}`),this._shareWebcam(e,i)}return yield Promise.all(wi.map(i=>{var n,r;return((r=(n=a(this,ao).sender)==null?void 0:n.video)==null?void 0:r.codecs.findIndex(s=>s.mimeType===i))>=0&&a(this,hs).get(i).size>0?(u.debug(`Calling _shareWebcam with video codec: ${i}`),this._shareWebcam(e,i)):e})),e})}shareScreen(e){return h(this,null,function*(){const{video:i,audio:n}=e;if(i===void 0)return;const r={track:i,codecOptions:[{name:"VP8"}],appData:{screenShare:!0,e2ee:this.e2ee,supportsRemoteControl:Ie.isElectron()},stopTracks:!1},s=()=>{u.info("Disabling screenShare due to the producer closure"),a(this,Lt).delete(Ee.SCREENSHARE_VIDEO),a(this,Lt).delete(Ee.SCREENSHARE_AUDIO)},o=a(this,$).createProducer(r,s);j(this,ms,co).call(this,Ee.SCREENSHARE_VIDEO,o.then(d=>d.id));let c;if(n){const d={track:n,codecOptions:[{name:"opus"}],appData:{screenShare:!0,e2ee:this.e2ee,supportsRemoteControl:Ie.isElectron()},stopTracks:!1,zeroRtpOnPause:!0},l=()=>{};c=a(this,$).createProducer(d,l),j(this,ms,co).call(this,Ee.SCREENSHARE_AUDIO,c.then(p=>p.id))}yield Promise.all([o,c||Promise.resolve()]),K.screenShareStart()})}shareMic(e){return h(this,null,function*(){try{if(e===void 0)throw new xt("track undefined");const i=j(this,ht,bt).call(this,Ee.MIC);if(i){const o=yield i;if(a(this,$).producers.has(o)){const c=a(this,$).producers.get(o);if(!c.closed&&!navigator.isReactNative){yield c.replaceTrack({track:e}),yield this.resumeMic(),a(this,Ht)&&(a(this,Ht).audioTrack=e,a(this,Ht).producerId=o,a(this,Ht).start());return}yield a(this,$).closeProducer(o,{stopTrack:!1})}yield this.shareMic(e);return}const n=j(this,mh,Jv).call(this,e),r=()=>{a(this,Lt).delete(Ee.MIC)},s=a(this,$).createProducer(n,r);j(this,ms,co).call(this,Ee.MIC,s.then(o=>o.id)),yield s.then(o=>{a(this,Ht)&&(a(this,Ht).audioTrack=o.track,a(this,Ht).producerId=o.id,a(this,Ht).start())})}catch(i){throw new w(i)}})}pauseMic(){return h(this,null,function*(){var e;const i=yield j(this,ht,bt).call(this,Ee.MIC),n=a(this,$).producers.get(i);if(!n){u.error("pauseMic::could_not_find_mic_producer");return}if(n.paused){u.info("pauseMic::mic_producer_already_paused");return}n.pause(),(e=a(this,Ht))==null||e.stop();const r={producerId:n.id,pause:!0};a(this,kt).sendMessage(a(this,Nt).toggleProducer,ec.toBinary(r))})}pauseWebcam(){return h(this,null,function*(){const e=yield j(this,ht,bt).call(this,Ee.WEBCAM),i=yield j(this,ht,bt).call(this,Ee.WEBCAM_BACKUP),n=a(this,$).producers.get(e),r=a(this,$).producers.get(i);if(!n&&!r){u.error("pauseWebcam::could_not_find_webcam_producer");return}const s=o=>{const c={producerId:o.id,pause:!0};a(this,kt).sendMessage(a(this,Nt).toggleProducer,ec.toBinary(c))};n&&(n.pause(),s(n)),r&&(r.pause(),s(r))})}resumeMic(){return h(this,null,function*(){const e=yield j(this,ht,bt).call(this,Ee.MIC),i=a(this,$).producers.get(e);if(!i){u.error("resumeMic::could_not_find_mic_producer");return}if(!i.pause){u.info("resumeMic::mic_producer_already_resumed");return}i.resume(),i.appData.e2ee&&P.emit(R.E2EE_ACTIVE_PRODUCER,i);const n={producerId:i.id,pause:!1};a(this,kt).sendMessage(a(this,Nt).toggleProducer,ec.toBinary(n))})}resumeWebcam(){return h(this,arguments,function*(e=Ee.WEBCAM){const i=yield j(this,ht,bt).call(this,e),n=a(this,$).producers.get(i);if(!n){u.error("resumeWebcam::could_not_find_webcam_producer");return}if(!n.paused){u.info("resumeWebcam::webcam_producer_already_resumed");return}n.resume(),n.appData.e2ee&&P.emit(R.E2EE_ACTIVE_PRODUCER,n);const r={producerId:n.id,pause:!1};a(this,kt).sendMessage(a(this,Nt).toggleProducer,ec.toBinary(r))})}disableWebcam(e){return h(this,null,function*(){const i=e==="video/VP9"?Ee.WEBCAM:Ee.WEBCAM_BACKUP,n=yield j(this,ht,bt).call(this,i);j(this,ph,qv).call(this,i),n&&(yield a(this,$).closeProducer(n))})}disableMic(){return h(this,null,function*(){var e;const i=yield j(this,ht,bt).call(this,Ee.MIC);i&&(yield a(this,$).closeProducer(i)),(e=a(this,Ht))==null||e.stop(),a(this,Lt).delete(Ee.MIC)})}disableScreenShare(){return h(this,null,function*(){u.info("screen_sharing_stopped"),K.screenShareStop();const e=yield j(this,ht,bt).call(this,Ee.SCREENSHARE_VIDEO),i=yield j(this,ht,bt).call(this,Ee.SCREENSHARE_AUDIO);e&&(yield a(this,$).closeProducer(e)),i&&(yield a(this,$).closeProducer(i)),a(this,wn).clear(),a(this,Lt).delete(Ee.SCREENSHARE_VIDEO),a(this,Lt).delete(Ee.SCREENSHARE_AUDIO)})}muteSelf(){return h(this,null,function*(){this.pauseMic()})}unmuteSelf(){return h(this,null,function*(){})}resetVideoProducers(e,i){return h(this,null,function*(){if(e){const n=yield j(this,ht,bt).call(this,Ee.WEBCAM),r=yield j(this,ht,bt).call(this,Ee.WEBCAM_BACKUP);yield a(this,$).closeProducer(n,{stopTrack:!1}),yield a(this,$).closeProducer(r,{stopTrack:!1}),this.shareWebcam(e)}if(i){const n=yield j(this,ht,bt).call(this,Ee.SCREENSHARE_VIDEO);yield a(this,$).closeProducer(n,{stopTrack:!1}),this.shareScreen({video:i})}})}changeDisplayName(e,i){return h(this,null,function*(){const n={displayName:e,participantId:i!=null?i:this.peerId};if(!(yield a(this,$).socketHandler.changeDisplayName(n)))throw new Error("failed to change display name!")})}kick(e){const i={peerIds:[e]};a(this,$).socketHandler.kickPeer(i)}kickAll(){a(this,$).socketHandler.kickAll()}muteAll(e){return h(this,null,function*(){if(!(yield a(this,$).socketHandler.hostControlForAll("audio")))throw new Error("failed to mute all participant")})}muteAllVideo(){return h(this,null,function*(){if(!(yield a(this,$).socketHandler.hostControlForAll("video")))throw new Error("failed to mute all video participant")})}disableAudio(e){return h(this,null,function*(){if(!(yield a(this,$).socketHandler.hostControlForPeer(e,"audio")))throw new Error("failed to mute given participant")})}disableVideo(e){return h(this,null,function*(){if(!(yield a(this,$).socketHandler.hostControlForPeer(e,"video")))throw new Error("failed to mute video of given participant")})}pinPeer(e){return h(this,null,function*(){const i={participantId:e!=null?e:""};try{yield a(this,kt).sendMessagePromise(a(this,Nt).globalPinPeer,Kw.toBinary(i))}catch(n){u.error("Error in pinning peer:",{error:n})}})}validateScreenShare(e){return this.peerId===e.peerId&&a(this,$).producers.get(e.producerId)&&a(this,wn).add(e.consumerPeerId),a(this,wn).size}switchConsumersToLayer(e,i){return h(this,null,function*(){a(this,$).switchConsumersToLayer(e,i)})}handleSocketEvents(){return h(this,null,function*(){a(this,kt).on(a(this,Nt).peerProducerCreateBroadcast,({payload:e})=>{var i,n;if(this.mediaJoined)try{const{participantId:r,producerState:s}=XI.fromBinary(e);if(r===this.peerId)return;if(s!=null&&s.mimeType||(s.mimeType=s.kind===Li.AUDIO?"audio/opus":"video/VP8"),s.kind===Li.VIDEO&&!s.screenShare&&((n=(i=a(this,ao).receiver)==null?void 0:i.video)==null?void 0:n.codecs.findIndex(o=>o.mimeType===wi[0]))>=0&&a(this,us).get(wi[0]).has(r)&&s.mimeType!==wi[0]){u.warn(`Ignoring producer: ${s.producerId}`);return}u.info(`producer created broadcast: ${r}, producer state: ${s}`),P.emit(R.NEW_PRODUCER,{peerId:r,producer:q(x({},s),{kind:s.kind===Li.AUDIO?"audio":"video",producingPeerId:r})})}catch(r){u.error("error in peer-producer-create-broadcast",{error:r})}}),a(this,kt).on(a(this,Nt).peerProducerToggleBroadcast,({payload:e})=>{if(this.mediaJoined)try{const{participantId:i,initiatorParticipantId:n,producerState:{kind:r,pause:s,producerId:o}}=cm.fromBinary(e),c=r===Li.AUDIO?"audio":"video";if(u.info(`producer toggle broadcast: ${i}, producerId: ${o}, kind:${c}, paused:${s} payload: ${JSON.stringify(cm.fromBinary(e))}`),i===this.peerId&&n!==this.peerId&&s&&P.emit(c==="audio"?R.MUTE_SELF:R.MUTE_SELF_VIDEO),i===this.peerId)return;P.emit(R.PRODUCER_TOGGLE,{peerId:i,producerId:o,paused:s,kind:c}),Array.from(this.getConsumers().values()).filter(d=>d.producerId===o).forEach(d=>{d.paused!==s&&(u.debug(`consumer state mismatched for ${d.id}. updating consumer pause state ${d.paused} to ${s}`),s?(d.pause(),P.emit(R.CONSUMER_PAUSED,{id:d.id})):(d.resume(),P.emit(R.CONSUMER_RESUMED,{id:d.id})))})}catch(i){u.error("error in producer toggle broadcast handler",{error:i})}}),a(this,kt).on(a(this,Nt).peerLeaveBroadcast,({payload:e})=>{if(this.mediaJoined)try{const{participantId:i}=yu.fromBinary(e);if(i===this.peerId)return;u.info(`peer left broadcast:${i}`),a(this,wn).delete(i),a(this,$).consumers.forEach(n=>{n.peerId===i&&n.close()}),P.emit(R.PEER_CLOSED,{id:i})}catch(i){u.error("error in peer left broadcast",{error:i})}}),a(this,kt).on(a(this,Nt).peerProducerCloseBroadcast,({payload:e})=>{if(this.mediaJoined)try{const{participantId:i,producerState:{producerId:n}}=tC.fromBinary(e);if(i===this.peerId)return;u.info(`producer closed broadcast:${i}`),P.emit(R.PRODUCER_CLOSED,{peerId:i,producerId:n});const r=a(this,$).producerIdToConsumerIdMap.get(n);if(!r){u.warn(`no consumer found for producer:${n}`);return}u.info(`closing consumer ${r}, producer id: ${n}`),a(this,$).closeConsumer(r).then(()=>{u.info(`closed consumer: ${r}`),a(this,$).producerIdToConsumerIdMap.delete(n),P.emit(R.CONSUMER_CLOSED,{id:r})}).catch(s=>{u.error("error closing consumer",{error:s})})}catch(i){u.error("error on producer close broadcast",{error:i})}}),a(this,kt).on(a(this,Nt).mediaRoomTerminationBroadcastResponse,()=>{!this.mediaJoined&&!a(this,ds)&&!a(this,ls)||(u.warn("media hub termination broadcast received, rejoining room"),P.emit(R.ROOM_NODE_DISCONNECTED),a(this,nd).call(this))})})}handleCallstatsEvents(){K.onConsumerScore(e=>{e.forEach((i,n)=>{const r=a(this,$).consumers.get(n);r&&P.emit(R.CONSUMER_SCORE_UPDATE,{id:n,kind:r.kind,peerId:r.peerId,score:i.score,scoreStats:i})})}),K.onProducerScore(e=>{e.forEach((i,n)=>{const r=Array.from(a(this,$).producers.values()).find(s=>s.id===n);r&&P.emit(R.PRODUCER_SCORE_UPDATE,{id:n,kind:r.kind,appData:r.appData,score:i.score,scoreStats:i})})})}handlePeerCapabilities(e,i){var n,r,s,o;for(let c=0;c<=wi.length;c+=1){const d=wi[c];if(((r=(n=i==null?void 0:i.receiver)==null?void 0:n.video)==null?void 0:r.codecs.findIndex(l=>l.mimeType===d))>=0||c===wi.length-1){a(this,hs).get(d).add(e);break}}for(let c=0;c<=wi.length;c+=1){const d=wi[c];if(((o=(s=i==null?void 0:i.sender)==null?void 0:s.video)==null?void 0:o.codecs.findIndex(l=>l.mimeType===d))>=0||c===wi.length-1){a(this,us).get(d).add(e);break}}}handlePeerLeaving(e){Q.hasFeature(re.FORCE_VIDEO_CODEC)||(a(this,us).forEach(i=>i.delete(e)),a(this,hs).forEach((i,n)=>{i.delete(e),i.size===0&&this.disableWebcam(n)}))}}td=new WeakMap,id=new WeakMap,kt=new WeakMap,$=new WeakMap,ao=new WeakMap,lr=new WeakMap,Nt=new WeakMap,ds=new WeakMap,ls=new WeakMap,ur=new WeakMap,nd=new WeakMap,wn=new WeakMap,oo=new WeakMap,us=new WeakMap,hs=new WeakMap,Lt=new WeakMap,Ht=new WeakMap,hr=new WeakSet,ps=function(){return this.context.getValue("connectionHandler")},ht=new WeakSet,bt=function(t){return a(this,Lt).get(t)},ms=new WeakSet,co=function(t,e){return a(this,Lt).set(t,e)},ph=new WeakSet,qv=function(t){return a(this,Lt).delete(t)},mh=new WeakSet,Jv=function(t){return{track:t,encodings:[{priority:"high"}],codecOptions:[{name:"opus"}],appData:{e2ee:this.e2ee},stopTracks:!1,zeroRtpOnPause:!0}},gh=new WeakSet,$v=function(t,e){return{track:t,codecOptions:[{name:e?e.split("/")[1]:"VP8"}],appData:{screenShare:!1,e2ee:this.e2ee},stopTracks:!1}};ue([S.trace("MediaNodeClient.reset",{country:S.location.country})],le.prototype,"reset",1);ue([S.trace("MediaNodeClient.joinRoom")],le.prototype,"joinRoom",1);ue([S.trace("MediaNodeClient.completeJoinRoom")],le.prototype,"completeJoinRoom",1);ue([S.trace("MediaNodeClient.leaveRoom")],le.prototype,"leaveRoom",1);ue([S.trace("MediaNodeClient.activatePeers")],le.prototype,"activatePeers",1);ue([S.trace("MediaNodeClient.deactivatePeers")],le.prototype,"deactivatePeers",1);ue([S.trace("MediaNodeClient.createConsumers")],le.prototype,"createConsumers",1);ue([S.trace("MediaNodeClient.closeConsumers")],le.prototype,"closeConsumers",1);ue([S.trace("MediaNodeClient._shareWebcam")],le.prototype,"_shareWebcam",1);ue([S.trace("MediaNodeClient.shareWebcam")],le.prototype,"shareWebcam",1);ue([S.trace("MediaNodeClient.shareScreen")],le.prototype,"shareScreen",1);ue([S.trace("MediaNodeClient.shareMic")],le.prototype,"shareMic",1);ue([S.trace("MediaNodeClient.pauseMic")],le.prototype,"pauseMic",1);ue([S.trace("MediaNodeClient.pauseWebcam")],le.prototype,"pauseWebcam",1);ue([S.trace("MediaNodeClient.resumeMic")],le.prototype,"resumeMic",1);ue([S.trace("MediaNodeClient.resumeWebcam")],le.prototype,"resumeWebcam",1);ue([S.trace("MediaNodeClient.disableWebcam")],le.prototype,"disableWebcam",1);ue([S.trace("HiveClient.disableMic")],le.prototype,"disableMic",1);ue([S.trace("HiveClient.disableScreenShare")],le.prototype,"disableScreenShare",1);ue([S.trace("MediaNodeClient.muteSelf")],le.prototype,"muteSelf",1);ue([S.trace("MediaNodeClient.resetVideoProducers")],le.prototype,"resetVideoProducers",1);ue([S.trace("MediaNodeClient.changeDisplayName")],le.prototype,"changeDisplayName",1);ue([S.trace("MediaNodeClient.kickPeer")],le.prototype,"kick",1);ue([S.trace("MediaNodeClient.kickAllPeers")],le.prototype,"kickAll",1);ue([S.trace("MediaNodeClient.muteAll")],le.prototype,"muteAll",1);ue([S.trace("MediaNodeClient.muteAllVideo")],le.prototype,"muteAllVideo",1);ue([S.trace("MediaNodeClient.disableAudio")],le.prototype,"disableAudio",1);ue([S.trace("MediaNodeClient.disableVideo")],le.prototype,"disableVideo",1);ue([S.trace("MediaNodeClient.pinPeer")],le.prototype,"pinPeer",1);ue([S.trace("MediaNodeClient.validateScreenShare")],le.prototype,"validateScreenShare",1);function Kv(t,e,i){const n=t.getValue("roomNodeClient");if(n){if(n)return n;throw new Error("Room node client already set up.")}const r=new le(t,e,i);return t.setValue("roomNodeClient",r),r}function zv(t){const e=t.getValue("roomNodeClient");try{e==null||e.leaveRoom()}catch{u.error("roomNodeClient::cleanupRoomNodeClient")}t.setValue("roomNodeClient",void 0)}var GD=Object.defineProperty,qD=Object.getOwnPropertyDescriptor,Fr=(t,e,i,n)=>{for(var r=n>1?void 0:n?qD(e,i):e,s=t.length-1,o;s>=0;s--)(o=t[s])&&(r=(n?o(e,i,r):o(r))||r);return n&&r&&GD(e,i,r),r},Yn,Ii,yt,Xt,oi,og;const Yv=(og=class{constructor(t,e,i,n){f(this,Xt),m(this,"self"),m(this,"authToken"),f(this,Yn,void 0),m(this,"viewType"),f(this,Ii,void 0),f(this,yt,void 0);const{socket:r}=i,s=t.getValue("authToken");this.self=e,v(this,yt,t),this.viewType=n,this.authToken=s,v(this,Yn,r),v(this,Ii,i),e.config.viewType!==Pt.Chat&&this.setupEvents()}get peerId(){return a(this,yt).getValue("peerId")}get mediaJoined(){return a(this,yt).getValue("connectionHandler").mediaJoined}static init(t,e,i,n,r){return h(this,null,function*(){const s=ct(),o=t.getValue("peerId"),c=!!t.getValue("cachedUserDetails"),d=yield rt.__init__(t,i,n,r,r.name,c);if(navigator.product!=="ReactNative"){const l=!Q.hasFeature(re.PRECALL_BANDWIDTH_TEST);setTimeout(()=>h(this,null,function*(){const p=yield d.getAllDevices();u.info("populated_full_device_list",{devices:JSON.stringify(p)}),K.devices("AUDIO",p==null?void 0:p.filter(g=>g.kind==="audioinput")),K.devices("VIDEO",p==null?void 0:p.filter(g=>g.kind==="videoinput")),K.devices("SPEAKER",p==null?void 0:p.filter(g=>g.kind==="audiooutput")),u.info("Callstats:: initializing");try{yield K.initialize({peerId:o,engineName:Ie.getDeviceInfo().engineName,env:t.getValue("env"),iceServers:yield s.getICEServers(),apiBase:t.getValue("apiBase"),flags:Q.getAllFlags(),logger:u,apiHostnames:Gf(t),skipConnectivityChecks:l}),u.info("Callstats:: initialized")}catch(g){u.error("Callstats:: initialization failed",{error:g})}}),0)}else u.info("Callstats:: Skipped initialization due to navigator product being ReactNative.");return new Yv(t,d,e,r.viewType)})}shareMediaTracks(){return h(this,null,function*(){var t;const{audioTrack:e,videoTrack:i,permissions:n,audioEnabled:r,videoEnabled:s,screenShareEnabled:o,screenShareTracks:c}=this.self;if(n.canProduceAudio&&r)try{yield a(this,Xt,oi).shareMic(e)}catch{this.self.disableAudio()}if(n.canProduceVideo&&s)try{const d=yield a(this,Xt,oi).shareWebcam(i);d&&d.id!==i.id&&Q.hasFeature(re.EXP_RESHARE)&&(yield a(this,Xt,oi).shareWebcam(d))}catch{this.self.disableVideo()}if(n.canProduceScreenshare&&o)try{yield(t=a(this,Xt,oi))==null?void 0:t.shareScreen({video:c.video,audio:c.audio})}catch{this.self.disableScreenShare()}})}kickHandler(t){return h(this,null,function*(){let e="kicked";(t==null?void 0:t.kickType)==="kickAll"&&(e="ended"),this.leaveRoom(e)})}waitlistedHandler(){u.info("SelController.waitlisted"),this.self.waitlistStatus="waiting",this.self.roomState="waitlisted",this.self.emit("waitlisted")}waitlistAcceptHandler(){if(u.info("SelController.waitlistAccepted"),this.self.waitlistStatus==="accepted"){u.warn("SelfController.WAITLIST_ACCEPTED.UserAlreadyAccepted");return}this.self.waitlistStatus="accepted",this.joinRoom()}waitlistRejectedHandler(){if(u.info("SelfController.waitlistRejected"),this.self.waitlistStatus==="rejected"){u.warn("SelfController.WAITLIST_REJECTED.UserAlreadyRejected");return}this.self.waitlistStatus="rejected",this.leaveRoom("rejected")}resetSelf(t){return h(this,null,function*(){K.callEnded(),a(this,Xt,oi).reset(),t&&(yield this.joinRoom(t))})}setupEvents(){P.on(R.RESET_PRODUCER_STATE,()=>h(this,null,function*(){this.mediaJoined&&this.shareMediaTracks()})),P.on(R.ROOM_NODE_RECONNECTED,()=>{this.self.roomState="joined",this.self.emit("roomJoined",{reconnected:!0})}),P.on(R.ROOM_NODE_DISCONNECTED,()=>{this.self.roomState!=="disconnected"&&(this.self.roomState="disconnected",this.self.emit("roomLeft",{state:"disconnected"}))}),P.on(R.ROOM_NODE_FAILED,()=>{this.self.roomState="failed",this.self.emit("roomLeft",{state:"failed"})}),P.on(R.SOCKET_SERVICE_RECONNECTED,({wasJoinAttempted:t})=>{t===!1&&(this.self.roomState="init"),this.resetSelf(t)}),P.on(R.SOCKET_SERVICE_DISCONNECTED,({joinAttempted:t})=>{if(this.self.roomState==="disconnected")return;let{peerId:e}=this;t&&Q.hasFeature(re.REFRESH_ID_ON_DISCONNECTION)&&(e=Os()),a(this,Yn).updateURL(e),S.resetPeerId(e),ct().setHeader("dyte-tracing-id",e),wr.remapContext(e,a(this,yt)),this.self.roomState="disconnected",this.self.emit("roomLeft",{state:"disconnected"})}),P.on(R.SOCKET_SERVICE_FAILED,()=>{this.self.roomState="failed",this.self.emit("roomLeft",{state:"failed"})}),a(this,Ii).on(B.waitingRoomRequestAccepted,()=>{this.waitlistAcceptHandler()}),a(this,Ii).on(Ac.updateUserPreset,t=>{t.updatePeersPresets.forEach(e=>{e.userIds===this.self.userId&&P.emit(R.UPDATE_PERMISSIONS,e.patch)})}),a(this,Ii).on(B.waitingRoomRequestDenied,()=>{this.waitlistRejectedHandler()}),a(this,Ii).on(B.kick,()=>{this.kickHandler({kickType:"kick"})}),a(this,Ii).on(B.kickAll,()=>{this.kickHandler({kickType:"kickAll"})}),P.onAsync(R.JOIN_MEDIA_ROOM,this.joinMediaRoom.bind(this)),P.on(R.PRODUCER_SCORE_UPDATE,({score:t,kind:e,appData:i,scoreStats:n})=>{var r;const s=(r=i==null?void 0:i.screenShare)!=null?r:!1;this.self.emit("mediaScoreUpdate",{kind:e,isScreenshare:s,score:t,participantId:this.self.id,scoreStats:n})}),P.on(R.MUTE_SELF,()=>h(this,null,function*(){this.self.audioEnabled&&(yield this.self.disableAudio(),K.audioOff())})),P.on(R.MUTE_SELF_VIDEO,()=>h(this,null,function*(){this.self.videoEnabled&&(yield this.self.disableVideo(),K.videoOff())})),P.onAsync(R.LEAVE_MEDIA_ROOM,this.leaveMediaRoom.bind(this)),P.on(R.PIP_HANGUP,this.leaveRoom.bind(this))}joinRoom(t=!1){return h(this,null,function*(){try{const{peer:e}=yield a(this,Ii).joinRoom(this.self);a(this,Ii).socket.flush();const i=Gh(e.stageType);if(a(this,yt).setValue("stageStatus",i,!1),e.waitlisted){this.waitlistedHandler();return}yield this.joinMediaRoom(t),a(this,yt).notify("stageStatus")}catch(e){throw u.error("Error in joinRoom",{error:e}),e}})}leaveRoom(t="left"){return h(this,null,function*(){var e,i;if(t==="rejected"){try{(e=a(this,Yn))==null||e.disconnect()}catch{u.error("SelfController::leaveRoom::socketDisconnect")}this.self.roomState=t,this.self.emit("roomLeft",{state:t});return}this.self.setIsPinned(!1),a(this,yt).setValue("stageStatus","OFF_STAGE",!1),yield this.leaveMediaRoom(t),a(this,yt).notify("stageStatus");try{(i=a(this,Yn))==null||i.disconnect()}catch{u.error("SelfController::leaveRoom::socketDisconnect")}zv(a(this,yt)),Md.cleanup(),this.self.roomState=t,this.self.emit("roomLeft",{state:t})})}joinMediaRoom(t=!1){return h(this,null,function*(){var e,i;const{peerId:n,viewType:r,meetingId:s,stageStatus:o,roomNodeOptions:c}=a(this,yt).getAllValues(),{sfu:d}=c;try{if(r===Pt.Livestream){if(o!=="ON_STAGE"){this.self.roomState="joined",this.self.emit("roomJoined",{reconnected:t});return}Kv(a(this,yt),d,{socket:a(this,Yn),peerId:n})}const{roomJoined:l}=(i=yield(e=a(this,Xt,oi))==null?void 0:e.joinRoom(this.self.name,s,{audio:this.self.audioEnabled,video:this.self.videoEnabled,screen:this.self.screenShareEnabled},t,t))!=null?i:{};if(!l)return;o==="ON_STAGE"&&(yield this.shareMediaTracks()),this.self.roomState="joined",this.self.emit("roomJoined",{reconnected:t})}catch(l){throw u.error("Error:SelfController.mediaRoomJoin",{error:l}),new w("Error: could not join media room","0002")}})}leaveMediaRoom(t){return h(this,null,function*(){const e=a(this,yt).getValue("viewType");t!=="connected-meeting"&&(yield this.cleanupSelf()),!(t==="stageLeft"&&e===Pt.Webinar)&&a(this,Xt,oi)&&(a(this,Xt,oi).mediaJoined&&t!=="disconnected"&&(yield a(this,Xt,oi).leaveRoom()),!(t==="stageLeft"&&e===Pt.Livestream)&&(a(this,Xt,oi).mediaJoined=!1))})}cleanupSelf(){return h(this,null,function*(){yield this.self.disableAudio(),yield this.self.disableVideo(),yield this.self.disableScreenShare(),this.self.cleanUpTracks(),this.self.destructMediaHandler(),navigator.isReactNative||this.self.removeDocumentEventListeners()})}},Yn=new WeakMap,Ii=new WeakMap,yt=new WeakMap,Xt=new WeakSet,oi=function(){return a(this,yt).getValue("roomNodeClient")},og);let Gn=Yv;Fr([S.trace("SelfController.resetSelf")],Gn.prototype,"resetSelf",1);Fr([S.trace("SelfController.setupEvents")],Gn.prototype,"setupEvents",1);Fr([S.trace("SelfController.joinRoom")],Gn.prototype,"joinRoom",1);Fr([S.trace("SelfController.leaveRoom")],Gn.prototype,"leaveRoom",1);Fr([S.trace("SelfController.joinMediaRoom")],Gn.prototype,"joinMediaRoom",1);Fr([S.trace("SelfController.leaveMediaRoom")],Gn.prototype,"leaveMediaRoom",1);Fr([S.trace("SelfController.init")],Gn,"init",1);var rd;class JD{constructor(e){f(this,rd,void 0),v(this,rd,e)}on(e,i){let n;e===B.roomPeerCount?n=um.fromBinary.bind(um):n=km.fromBinary.bind(km),a(this,rd).on(e,({payload:r})=>{const s=n(r);return i(s)})}}rd=new WeakMap;var sd;class $D{constructor(e){f(this,sd,void 0),v(this,sd,e)}on(e,i){let n,r;switch(e){case B.transcript:{n=wl.fromBinary.bind(wl),r=wl.create();break}default:{u.debug("AISocketHandler switch case hit default, event not accounted for.");break}}a(this,sd).on(e,({payload:s})=>{let o=r;try{o=n(s)}catch(c){u.error("chatSocketHandler::on::binary_decode_error",{error:c})}return i(o)})}}sd=new WeakMap;var KD=Object.defineProperty,zD=Object.getOwnPropertyDescriptor,ip=(t,e,i,n)=>{for(var r=n>1?void 0:n?zD(e,i):e,s=t.length-1,o;s>=0;s--)(o=t[s])&&(r=(n?o(e,i,r):o(r))||r);return n&&r&&KD(e,i,r),r},In;class ll{constructor(e){f(this,In,void 0),v(this,In,e)}getPolls(){return a(this,In).sendMessagePromise(Ji.getPolls)}createPoll(e,i,n=!1,r=!1){const s={anonymous:n,hideVotes:r,question:e,options:i};return a(this,In).sendMessage(Ji.createPoll,HM.toBinary(s))}votePoll(e,i){const n={index:i,pollId:e};return a(this,In).sendMessage(Ji.votePoll,qM.toBinary(n))}on(e,i){let n,r;switch(e){case Ji.updatePoll:case Ji.createPoll:case Ji.votePoll:{n=Al.fromBinary.bind(Al),r=Al.create();break}}a(this,In).on(e,({payload:s})=>{let o=r;try{o=n(s)}catch(c){u.error("pollSocketHandler::on::binary_decode_error",{error:c})}return i(o)})}removeListeners(e){a(this,In).removeListeners(e)}}In=new WeakMap;ip([S.trace("PollSocketHandler.getPolls")],ll.prototype,"getPolls",1);ip([S.trace("PollSocketHandler.createPoll")],ll.prototype,"createPoll",1);ip([S.trace("PollSocketHandler.votePoll")],ll.prototype,"votePoll",1);var Gt;class YD{constructor(e){f(this,Gt,void 0),v(this,Gt,e)}getStageRequests(){return h(this,null,function*(){const{payload:e}=yield a(this,Gt).sendMessagePromise(B.getStageRequests);return e?Ml.fromBinary(e):{stageRequests:[]}})}requestAccess(){a(this,Gt).sendMessage(B.requestStageAccess)}cancelRequestAccess(){a(this,Gt).sendMessage(B.cancelStageRequest)}grantAccess(e){return h(this,null,function*(){const i={userIds:e};a(this,Gt).sendMessage(B.grantStageAccess,OM.toBinary(i))})}denyAccess(e){return h(this,null,function*(){const i={userIds:e};a(this,Gt).sendMessage(B.denyStageAccess,LM.toBinary(i))})}joinStage(){return a(this,Gt).sendMessagePromise(B.joinStage,void 0,void 0,B.peerStageStatusUpdate)}leaveStage(e){const i={userIds:[e]};return a(this,Gt).sendMessagePromise(B.leaveStage,_m.toBinary(i),void 0,B.peerStageStatusUpdate)}kick(e){const i={userIds:e};return a(this,Gt).sendMessagePromise(B.leaveStage,_m.toBinary(i))}on(e,i){let n;switch(e){case B.grantStageAccess:case B.denyStageAccess:{n=void 0;break}case B.getStagePeers:{n=bm.fromBinary.bind(bm);break}case B.getStageRequests:case B.requestStageAccess:case B.cancelStageRequest:{n=Ml.fromBinary.bind(Ml);break}case B.peerStageStatusUpdate:{n=lm.fromBinary.bind(lm);break}}a(this,Gt).on(e,({payload:r,id:s})=>{if(!r||!n)return i(void 0,s);const o=n(r);return i(o,s)})}getPeerInfo(e){return h(this,null,function*(){const i=yield a(this,Gt).sendMessagePromise(B.getPeerInfo,ev.toBinary({peerId:e}));return Zr.fromBinary(i.payload)})}}Gt=new WeakMap;var et;class QD{constructor(e){f(this,et,void 0),v(this,et,e)}addPlugin(e,i){a(this,et).sendMessage(z.addPlugin,YR.toBinary({pluginId:e,staggered:i}))}removePlugin(e){a(this,et).sendMessage(z.removePlugin,XR.toBinary({pluginId:e,staggered:!1}))}getActivePlugins(){return h(this,null,function*(){const{payload:e}=yield a(this,et).sendMessagePromise(z.getPlugins);return e?TM.fromBinary(e):{plugins:[]}})}customPluginEventToRoom(e,i,n){const r={pluginId:e,pluginData:new TextEncoder().encode(JSON.stringify(i))};a(this,et).sendMessage(z.customPluginEventToRoom,cM.toBinary(r),n)}customPluginEventToPeers(e,i,n,r){const s={pluginId:e,peerIds:i,pluginData:new TextEncoder().encode(JSON.stringify(n))};a(this,et).sendMessage(z.customPluginEventToPeers,lM.toBinary(s),r)}enablePluginForRoom(e,i){a(this,et).sendMessage(z.enablePluginForRoom,eM.toBinary({pluginId:e}),i)}enablePluginForPeers(e,i,n){a(this,et).sendMessage(z.enablePluginForPeers,rM.toBinary({pluginId:e,peerIds:i}),n)}disablePluginForRoom(e,i){a(this,et).sendMessage(z.disablePluginForRoom,iM.toBinary({pluginId:e}),i)}disablePluginForPeers(e,i,n){a(this,et).sendMessage(z.disablePluginForPeers,aM.toBinary({pluginId:e,peerIds:i}),n)}storeInsertKeys(e,i,n,r){const s={pluginId:e,storeName:i,insertKeys:n.map(o=>({storeKey:o.key,payload:new TextEncoder().encode(JSON.stringify(o.payload))}))};a(this,et).sendMessage(z.storeInsertKeys,ym.toBinary(s),r)}storeGetKeys(e,i,n,r){const s={pluginId:e,storeName:i,getKeys:n.map(o=>({storeKey:o.key}))};a(this,et).sendMessage(z.storeGetKeys,mM.toBinary(s),r)}storeDeleteKeys(e,i,n,r){const s={pluginId:e,storeName:i,deleteKeys:n.map(o=>({storeKey:o.key}))};a(this,et).sendMessage(z.storeDeleteKeys,fM.toBinary(s),r)}storeDelete(e,i,n){a(this,et).sendMessage(z.storeDelete,yM.toBinary({pluginId:e,storeName:i}),n)}getPluginDataOld(e,i){u.info("getPluginDataOld",{plugin:{id:e,storeName:i}})}storePluginDataOld(e,i,n){const r={pluginId:e,storeName:i,insertKeys:[{storeKey:n.key,payload:new TextEncoder().encode(JSON.stringify(n))}]};a(this,et).sendMessage(z.storeInsertKeys,ym.toBinary(r))}on(e,i){let n;switch(e){case z.addPlugin:case z.enablePluginForPeers:case z.enablePluginForRoom:{n=ku.fromBinary.bind(ku);break}case z.removePlugin:case z.disablePluginForPeers:case z.disablePluginForRoom:{n=Sm.fromBinary.bind(Sm);break}case z.customPluginEventToPeers:case z.customPluginEventToRoom:{n=Tm.fromBinary.bind(Tm);break}case z.storeInsertKeys:case z.storeGetKeys:case z.storeDeleteKeys:case z.storeDelete:{n=Em.fromBinary.bind(Em);break}}a(this,et).on(e,({payload:r,id:s})=>{const o=n(r);return i(o,s)})}}et=new WeakMap;var XD=Object.defineProperty,ZD=(t,e,i)=>e in t?XD(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,eO=(t,e,i)=>(ZD(t,typeof e!="symbol"?e+"":e,i),i),np=(t,e,i)=>{if(!e.has(t))throw TypeError("Cannot "+i)},L=(t,e,i)=>(np(t,e,"read from private field"),i?i.call(t):e.get(t)),_e=(t,e,i)=>{if(e.has(t))throw TypeError("Cannot add the same private member more than once");e instanceof WeakSet?e.add(t):e.set(t,i)},pe=(t,e,i,n)=>(np(t,e,"write to private field"),n?n.call(t,i):e.set(t,i),i),Re=(t,e,i)=>(np(t,e,"access private method"),i),Bd={},tO={get exports(){return Bd},set exports(t){Bd=t}},Cs=typeof Reflect=="object"?Reflect:null,cg=Cs&&typeof Cs.apply=="function"?Cs.apply:function(t,e,i){return Function.prototype.apply.call(t,e,i)},ad;Cs&&typeof Cs.ownKeys=="function"?ad=Cs.ownKeys:Object.getOwnPropertySymbols?ad=function(t){return Object.getOwnPropertyNames(t).concat(Object.getOwnPropertySymbols(t))}:ad=function(t){return Object.getOwnPropertyNames(t)};function iO(t){console&&console.warn&&console.warn(t)}var Qv=Number.isNaN||function(t){return t!==t};function ge(){ge.init.call(this)}tO.exports=ge;Bd.once=aO;ge.EventEmitter=ge;ge.prototype._events=void 0;ge.prototype._eventsCount=0;ge.prototype._maxListeners=void 0;var dg=10;function ul(t){if(typeof t!="function")throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof t)}Object.defineProperty(ge,"defaultMaxListeners",{enumerable:!0,get:function(){return dg},set:function(t){if(typeof t!="number"||t<0||Qv(t))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+t+".");dg=t}});ge.init=function(){(this._events===void 0||this._events===Object.getPrototypeOf(this)._events)&&(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0};ge.prototype.setMaxListeners=function(t){if(typeof t!="number"||t<0||Qv(t))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+t+".");return this._maxListeners=t,this};function Xv(t){return t._maxListeners===void 0?ge.defaultMaxListeners:t._maxListeners}ge.prototype.getMaxListeners=function(){return Xv(this)};ge.prototype.emit=function(t){for(var e=[],i=1;i<arguments.length;i++)e.push(arguments[i]);var n=t==="error",r=this._events;if(r!==void 0)n=n&&r.error===void 0;else if(!n)return!1;if(n){var s;if(e.length>0&&(s=e[0]),s instanceof Error)throw s;var o=new Error("Unhandled error."+(s?" ("+s.message+")":""));throw o.context=s,o}var c=r[t];if(c===void 0)return!1;if(typeof c=="function")cg(c,this,e);else for(var d=c.length,l=ny(c,d),i=0;i<d;++i)cg(l[i],this,e);return!0};function Zv(t,e,i,n){var r,s,o;if(ul(i),s=t._events,s===void 0?(s=t._events=Object.create(null),t._eventsCount=0):(s.newListener!==void 0&&(t.emit("newListener",e,i.listener?i.listener:i),s=t._events),o=s[e]),o===void 0)o=s[e]=i,++t._eventsCount;else if(typeof o=="function"?o=s[e]=n?[i,o]:[o,i]:n?o.unshift(i):o.push(i),r=Xv(t),r>0&&o.length>r&&!o.warned){o.warned=!0;var c=new Error("Possible EventEmitter memory leak detected. "+o.length+" "+String(e)+" listeners added. Use emitter.setMaxListeners() to increase limit");c.name="MaxListenersExceededWarning",c.emitter=t,c.type=e,c.count=o.length,iO(c)}return t}ge.prototype.addListener=function(t,e){return Zv(this,t,e,!1)};ge.prototype.on=ge.prototype.addListener;ge.prototype.prependListener=function(t,e){return Zv(this,t,e,!0)};function nO(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,arguments.length===0?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function ey(t,e,i){var n={fired:!1,wrapFn:void 0,target:t,type:e,listener:i},r=nO.bind(n);return r.listener=i,n.wrapFn=r,r}ge.prototype.once=function(t,e){return ul(e),this.on(t,ey(this,t,e)),this};ge.prototype.prependOnceListener=function(t,e){return ul(e),this.prependListener(t,ey(this,t,e)),this};ge.prototype.removeListener=function(t,e){var i,n,r,s,o;if(ul(e),n=this._events,n===void 0)return this;if(i=n[t],i===void 0)return this;if(i===e||i.listener===e)--this._eventsCount===0?this._events=Object.create(null):(delete n[t],n.removeListener&&this.emit("removeListener",t,i.listener||e));else if(typeof i!="function"){for(r=-1,s=i.length-1;s>=0;s--)if(i[s]===e||i[s].listener===e){o=i[s].listener,r=s;break}if(r<0)return this;r===0?i.shift():rO(i,r),i.length===1&&(n[t]=i[0]),n.removeListener!==void 0&&this.emit("removeListener",t,o||e)}return this};ge.prototype.off=ge.prototype.removeListener;ge.prototype.removeAllListeners=function(t){var e,i,n;if(i=this._events,i===void 0)return this;if(i.removeListener===void 0)return arguments.length===0?(this._events=Object.create(null),this._eventsCount=0):i[t]!==void 0&&(--this._eventsCount===0?this._events=Object.create(null):delete i[t]),this;if(arguments.length===0){var r=Object.keys(i),s;for(n=0;n<r.length;++n)s=r[n],s!=="removeListener"&&this.removeAllListeners(s);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if(e=i[t],typeof e=="function")this.removeListener(t,e);else if(e!==void 0)for(n=e.length-1;n>=0;n--)this.removeListener(t,e[n]);return this};function ty(t,e,i){var n=t._events;if(n===void 0)return[];var r=n[e];return r===void 0?[]:typeof r=="function"?i?[r.listener||r]:[r]:i?sO(r):ny(r,r.length)}ge.prototype.listeners=function(t){return ty(this,t,!0)};ge.prototype.rawListeners=function(t){return ty(this,t,!1)};ge.listenerCount=function(t,e){return typeof t.listenerCount=="function"?t.listenerCount(e):iy.call(t,e)};ge.prototype.listenerCount=iy;function iy(t){var e=this._events;if(e!==void 0){var i=e[t];if(typeof i=="function")return 1;if(i!==void 0)return i.length}return 0}ge.prototype.eventNames=function(){return this._eventsCount>0?ad(this._events):[]};function ny(t,e){for(var i=new Array(e),n=0;n<e;++n)i[n]=t[n];return i}function rO(t,e){for(;e+1<t.length;e++)t[e]=t[e+1];t.pop()}function sO(t){for(var e=new Array(t.length),i=0;i<e.length;++i)e[i]=t[i].listener||t[i];return e}function aO(t,e){return new Promise(function(i,n){function r(o){t.removeListener(e,s),n(o)}function s(){typeof t.removeListener=="function"&&t.removeListener("error",r),i([].slice.call(arguments))}ry(t,e,s,{once:!0}),e!=="error"&&oO(t,r,{once:!0})})}function oO(t,e,i){typeof t.on=="function"&&ry(t,"error",e,i)}function ry(t,e,i,n){if(typeof t.on=="function")n.once?t.once(e,i):t.on(e,i);else if(typeof t.addEventListener=="function")t.addEventListener(e,function r(s){n.once&&t.removeEventListener(e,r),i(s)});else throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+typeof t)}class cO extends E{constructor(){super("message.v1.SocketMessage",[{no:1,name:"event",kind:"scalar",T:13},{no:2,name:"id",kind:"scalar",opt:!0,T:9},{no:3,name:"payload",kind:"scalar",opt:!0,T:12},{no:4,name:"metadata",kind:"scalar",opt:!0,T:12}])}}const lg=new cO;class sy{static encode(e){return lg.toBinary(e)}static decode(e){return lg.fromBinary(new Uint8Array(e))}}function dO(t,e){return Math.floor(Math.random()*(e-t+1)+t)}var Cn;class lO{constructor(e={}){eO(this,"opts"),_e(this,Cn,void 0),this.opts={initialTimeout:e.initialTimeout||1e3,maxTimeout:e.maxTimeout||1e4,factor:e.factor||2},pe(this,Cn,0)}wait(){return h(this,null,function*(){pe(this,Cn,L(this,Cn)+1);const e=dO(0,Math.min(this.opts.maxTimeout,this.opts.initialTimeout*vS(2,L(this,Cn))));yield new Promise(i=>{setTimeout(i,e)})})}getAttempts(){return L(this,Cn)}reset(){pe(this,Cn,0)}}Cn=new WeakMap;const hn={debug:0,info:1,warn:2,error:3};var pr,mr;class uO{constructor(e){_e(this,pr,void 0),_e(this,mr,void 0),pe(this,pr,console),pe(this,mr,e)}debug(...e){hn[L(this,mr)]>hn.debug||L(this,pr).debug("[Sockrates]:",...e)}info(...e){hn[L(this,mr)]>hn.info||L(this,pr).info("[Sockrates]:",...e)}warn(...e){hn[L(this,mr)]>hn.warn||L(this,pr).warn("[Sockrates]:",...e)}error(...e){hn[L(this,mr)]>hn.error||L(this,pr).error("[Sockrates]:",...e)}}pr=new WeakMap,mr=new WeakMap;var ay=(t=>(t[t.CONNECTING=0]="CONNECTING",t[t.OPEN=1]="OPEN",t[t.CLOSING=2]="CLOSING",t[t.CLOSED=3]="CLOSED",t))(ay||{});const hO="2",pO="3";var Ve,gs,Pe,je,Pn,tt,Qi,Ln,fi,fs,qi,fh,oy,lo,od,vh,cy,yh,ug,Wd,Sh,Eh,dy,Co,cd,Po,jd,Hd,Th,Ps,Ro,Mo,Gd;class mO{constructor(e,i){var n;_e(this,fh),_e(this,lo),_e(this,vh),_e(this,yh),_e(this,Wd),_e(this,Eh),_e(this,Co),_e(this,Po),_e(this,Hd),_e(this,Ps),_e(this,Mo),_e(this,Ve,void 0),_e(this,gs,void 0),_e(this,Pe,void 0),_e(this,je,void 0),_e(this,Pn,void 0),_e(this,tt,void 0),_e(this,Qi,void 0),_e(this,Ln,void 0),_e(this,fi,void 0),_e(this,fs,void 0),_e(this,qi,void 0);var r,s,o,c,d,l,p,g,y;pe(this,gs,e),pe(this,Pn,[]),pe(this,tt,new Bd),pe(this,Qi,!0),pe(this,fi,!1),pe(this,Pe,i!=null?i:{}),(r=L(this,Pe)).autoReconnect!=null||(r.autoReconnect=!0),(s=L(this,Pe)).retryConnectionInterval!=null||(s.retryConnectionInterval=1e3),(o=L(this,Pe)).pingTimeout!=null||(o.pingTimeout=3e4),(c=L(this,Pe)).connectionTimeout!=null||(c.connectionTimeout=5e3),(d=L(this,Pe)).debug!=null||(d.debug=!0),(l=L(this,Pe)).maxReconnectionAttempts!=null||(l.maxReconnectionAttempts=10),(p=L(this,Pe)).disconnectOnPingTimeout!=null||(p.disconnectOnPingTimeout=!0),(g=L(this,Pe)).queueOnDisconnect!=null||(g.queueOnDisconnect=!1),(y=L(this,Pe)).flushOnReconnect!=null||(y.flushOnReconnect=!1),pe(this,Ln,{code:void 0,reason:void 0}),pe(this,je,(n=L(this,Pe).logger)!=null?n:new uO(L(this,Pe).debug?"debug":"info")),pe(this,qi,new lO)}get readyState(){var e;return(e=L(this,Ve))==null?void 0:e.readyState}get url(){return L(this,gs)}updateURL(e){pe(this,gs,e),Re(this,Eh,dy).call(this)}get config(){return L(this,Pe)}get sendQueue(){return L(this,Pn)}flush(){if(!L(this,Pe).queueOnDisconnect)return!1;const e=[];return L(this,Pn).forEach(i=>{this.send(i.event,i.id,i.payload,i.metadata)||e.push(i)}),pe(this,Pn,e),L(this,Pn)}connect(e=!1){return h(this,null,function*(){if(!e&&[0,1].includes(this.readyState)){L(this,je).debug("Websocket was already connecting or connected.");return}if(L(this,Qi)!==!1)return new Promise((i,n)=>{Re(this,Ps,Ro).call(this),Re(this,Mo,Gd).call(this);try{pe(this,Ve,new WebSocket(Re(this,fh,oy).call(this,L(this,gs)))),L(this,Ve).binaryType="arraybuffer",L(this,je).debug("Connecting");const r=setTimeout(()=>{L(this,je).debug("Connection timeout. Closing socket"),pe(this,Qi,!0),Re(this,Mo,Gd).call(this),L(this,Ve).close(3001,"Connection Timeout"),L(this,Pe).autoReconnect&&!L(this,fi)&&(L(this,tt).emit("reconnecting"),Re(this,Co,cd).call(this)),n(new Error("Connection timed out!"))},L(this,Pe).connectionTimeout);L(this,Ve).onopen=()=>{L(this,je).debug(`Ready State: ${ay[L(this,Ve).readyState]}`),r&&clearTimeout(r),Re(this,Hd,Th).call(this),pe(this,Ln,{code:void 0,reason:void 0}),L(this,tt).emit("connected"),L(this,Pe).flushOnReconnect&&this.flush(),i()},L(this,Ve).onclose=s=>{try{r&&clearTimeout(r);const{code:o,reason:c}=s;n(c),L(this,je).debug("Socket closed. Close event:",{event:s}),L(this,je).debug(`Connection closed code: ${o}`),L(this,je).debug(`Connection closed reason: ${c}`),L(this,fi)||Re(this,Wd,Sh).call(this,o,c)}catch(o){Re(this,lo,od).call(this,o)}},L(this,Ve).onerror=s=>{Re(this,lo,od).call(this,s)},L(this,Ve).onmessage=s=>Re(this,vh,cy).call(this,s)}catch(r){Re(this,lo,od).call(this,r,n)}})})}send(e,i,n,r){const s={event:e,id:i,payload:n,metadata:r};if(L(this,Pe).queueOnDisconnect&&(!L(this,Ve)||L(this,Ve).readyState!==1))return L(this,je).debug("Queuing message since socket is not connected!",s),L(this,Pn).push(s),!1;const o=sy.encode(s);return Re(this,Po,jd).call(this,o)}emit(e,i,n,r){return this.send(e,i,n,r)}sendRaw(e){return Re(this,Po,jd).call(this,e)}receive(e,i){return L(this,tt).on(e.toString(),i)}on(e,i){if(typeof e=="string"&&(e==="connected"||e==="disconnected"||e==="errored"||e==="reconnected"||e==="reconnecting"||e==="reconnectAttempt"||e==="reconnectFailure"||e==="failed")){L(this,tt).on(e,i);return}this.receive(e,i)}removeAllListeners(){L(this,tt).removeAllListeners()}removeReceiver(e,i){this.removeListener(e,i)}removeListener(e,i){L(this,tt).removeListener(e.toString(),i)}removeReceivers(e){this.removeListeners(e)}removeListeners(e){L(this,tt).listeners(e.toString()).map(i=>this.removeListener(e,i))}disconnect(){pe(this,Qi,!1),Re(this,Ps,Ro).call(this),this.removeAllListeners(),pe(this,Ln,{code:1e3,reason:"Sockrates disconnect method called"}),L(this,Ve).close(1e3,"Sockrates disconnect method called.")}}Ve=new WeakMap,gs=new WeakMap,Pe=new WeakMap,je=new WeakMap,Pn=new WeakMap,tt=new WeakMap,Qi=new WeakMap,Ln=new WeakMap,fi=new WeakMap,fs=new WeakMap,qi=new WeakMap,fh=new WeakSet,oy=function(t){if(t.startsWith("ws://")||t.startsWith("wss://"))return t;if(t.startsWith("https://"))return`wss://${t.substring(8)}`;if(t.startsWith("http://"))return`ws://${t.substring(7)}`;throw new Error("Invalid URL. URL must start with http(s):// or ws(s)://.")},lo=new WeakSet,od=function(t,e){L(this,je).error("Error:",{error:t}),L(this,tt).emit("errored",{error:t}),e==null||e(t)},vh=new WeakSet,cy=function(t){if(Re(this,Hd,Th).call(this),t.data===hO){L(this,je).debug("Received ping from server"),Re(this,Po,jd).call(this,pO);return}const e=sy.decode(t.data),{id:i,payload:n}=e;L(this,je).debug("Received message",{event:e.event,messageID:i}),L(this,tt).emit(e.event.toString(),{id:i,payload:n})},yh=new WeakSet,ug=function(){return L(this,Ve).readyState===1},Wd=new WeakSet,Sh=function(t,e){pe(this,Ln,{reason:e,code:t}),L(this,tt).emit("disconnected",{code:t,reason:e})},Eh=new WeakSet,dy=function(){const{reason:t,code:e}=L(this,Ln);e&&e!==1e3&&L(this,Qi)&&L(this,Pe).autoReconnect&&!L(this,fi)&&(L(this,je).debug(`Triggering reconnection due to ${t}.`),L(this,tt).emit("reconnecting"),Re(this,Co,cd).call(this))},Co=new WeakSet,cd=function(t=!0){return h(this,null,function*(){if(t&&L(this,fi)){L(this,je).debug("Reconnect called when already in a reconnect loop. Ignoring.");return}if(L(this,fi)||L(this,qi).reset(),L(this,Pe).maxReconnectionAttempts!==null&&L(this,qi).getAttempts()>=L(this,Pe).maxReconnectionAttempts){L(this,tt).emit("failed"),pe(this,fi,!1);return}pe(this,fi,!0),Re(this,Mo,Gd).call(this),Re(this,Ps,Ro).call(this);try{if(yield L(this,qi).wait(),L(this,Qi)===!1)return;if(L(this,je).debug(`Reconnection attempt ${L(this,qi).getAttempts()}`),L(this,tt).emit("reconnectAttempt",{attempt:L(this,qi).getAttempts()}),yield this.connect(),!Re(this,yh,ug).call(this))throw Error("Reconnect Failed");pe(this,fi,!1),pe(this,Ln,{code:void 0,reason:void 0}),L(this,tt).emit("reconnected")}catch{L(this,je).debug("Failed to reconnect."),L(this,tt).emit("reconnectFailure",{attempt:L(this,qi).getAttempts()}),Re(this,Co,cd).call(this,!1)}})},Po=new WeakSet,jd=function(t){try{return L(this,Ve).send(t),!0}catch(e){return L(this,je).error(e.message),!1}},Hd=new WeakSet,Th=function(){this.config.disconnectOnPingTimeout&&(L(this,je).debug("Resetting ping timeout"),Re(this,Ps,Ro).call(this),pe(this,fs,setTimeout(()=>{var t;L(this,je).debug("Disconnecting the socket due to ping timeout"),pe(this,Qi,!0);const e=3002,i="Ping timeout";(t=L(this,Ve))==null||t.close(e,i),Re(this,Wd,Sh).call(this,e,i)},L(this,Pe).pingTimeout)))},Ps=new WeakSet,Ro=function(){L(this,fs)&&(clearTimeout(L(this,fs)),pe(this,fs,void 0))},Mo=new WeakSet,Gd=function(){L(this,Ve)&&(L(this,Ve).onopen=void 0,L(this,Ve).onerror=void 0,L(this,Ve).onmessage=void 0,L(this,Ve).onclose=void 0)};var gO=Object.defineProperty,fO=Object.getOwnPropertyDescriptor,hl=(t,e,i,n)=>{for(var r=n>1?void 0:n?fO(e,i):e,s=t.length-1,o;s>=0;s--)(o=t[s])&&(r=(n?o(e,i,r):o(r))||r);return n&&r&&gO(e,i,r),r};const hg=65535,vO=3e3;var Qn,Ne,Le,Ue,ci,pn,Tc,Ql,kc,Xl,pg;const ly=(pg=class{constructor(t,{peerId:e,meetingId:i,authToken:n,capabilities:r}){f(this,Le),f(this,Tc),f(this,kc),f(this,Qn,void 0),f(this,Ne,void 0),m(this,"roomName"),m(this,"authToken"),m(this,"capabilities"),f(this,ci,void 0),f(this,pn,void 0);var s;if(!e||!i||!n)throw new w("peerId, meetingId, or authToken can not be empty","0404");v(this,ci,void 0),v(this,pn,t),this.capabilities=r,this.roomName=i,this.authToken=n,v(this,Qn,j(this,Tc,Ql).call(this,e)),v(this,Ne,new mO(a(this,Qn),{autoReconnect:!0,disconnectOnPingTimeout:(s=r.includes("PING"))!=null?s:!1,queueOnDisconnect:!0,flushOnReconnect:!1,logger:u})),this.handleSocketConnectionEvents()}get joinAttempted(){return a(this,Le,Ue).socketJoinAttempted}set joinAttempted(t){a(this,Le,Ue).socketJoinAttempted=t}get peerId(){return a(this,pn).getValue("peerId")}updateURL(t){t!==this.peerId&&(v(this,Qn,j(this,Tc,Ql).call(this,t)),u.debug("SocketService:: Connection URL updated.")),a(this,Ne).updateURL(a(this,Qn))}static getSocketEdgeDomain(t){return _s({servicePrefix:"socket-edge",baseURI:t})}get url(){return a(this,Qn)}connect(){return h(this,null,function*(){a(this,Le,Ue).socketJoinAttempted=!0,yield a(this,Ne).connect(),a(this,Le,Ue).socketJoinAttempted=!0,a(this,Le,Ue).socketState={state:"connected",reconnected:!1,reconnectionAttempt:void 0}})}disconnect(){return h(this,null,function*(){a(this,Le,Ue).socketJoinAttempted=!1,a(this,Ne).disconnect(),a(this,Le,Ue).socketJoinAttempted=!0,a(this,Le,Ue).socketState={state:"disconnected",reconnected:!1,reconnectionAttempt:void 0}})}get isConnected(){try{return a(this,Ne).readyState===1}catch{return!1}}sendMessage(t,e,i){const n={};return S.injectContext(n),a(this,Ne).send(t,i!=null?i:j(this,kc,Xl).call(this),e,new TextEncoder().encode(JSON.stringify(n)))}sendMessagePromise(t,e,i,n){const r=parseInt({}.SOCKET_SERVICE_MESSAGE_REQUEST_TIMEOUT,10)||2e4;return this.sendMessagePromiseWithTimeout({event:t,timeout:r,protobuf:e,messageId:i,resp:n})}sendMessagePromiseWithTimeout({event:t,timeout:e,protobuf:i,messageId:n,resp:r}){const s=r!=null?r:t;return new Promise((o,c)=>{const d=(T,b)=>{a(this,Ne).removeListener(s,T),a(this,Ne).removeListener(hg,b),a(this,Ne).removeListener(ti.errorResponse,b),a(this,Ne).removeListener(vi.errorResponse,b)},l=n!=null?n:j(this,kc,Xl).call(this),p={};S.injectContext(p);const g=({id:T,payload:b})=>{if(l===T){let O;try{const M=hI.fromBinary(b);O=new Error(M.errorMessage)}catch(M){O=new Error("failed to parse error message",{cause:M});try{const F=pC.fromBinary(b);O=new Error(F.message)}catch(F){O=new Error("failed to parse error message",{cause:F})}}c(O),d(y,g)}},y=({id:T,payload:b})=>{l===T&&(o({id:T,payload:b}),d(y,g))};a(this,Ne).on(s,y),a(this,Ne).on(hg,g),a(this,Ne).on(ti.errorResponse,g),a(this,Ne).on(vi.errorResponse,g),setTimeout(()=>{d(y,g),c(new Error(`request timeout for callback eventId:${t}`))},e),a(this,Ne).send(t,l,i,new TextEncoder().encode(JSON.stringify(p)))})}on(t,e){a(this,Ne).on(t,e)}onStateEvent(t,e){a(this,Ne).on(t,e)}removeListener(t,e){a(this,Ne).removeListener(t,e)}removeListeners(t){a(this,Ne).removeListeners(t)}flush(){return a(this,Ne).flush()}handleSocketConnectionEvents(){this.onStateEvent("connected",()=>h(this,null,function*(){u.info("SocketService::Connected to socket-edge"),a(this,ci)&&(clearTimeout(a(this,ci)),v(this,ci,void 0)),a(this,Le,Ue).updateSocketConnectionState("connected")})),this.onStateEvent("disconnected",({code:t,reason:e})=>{var i;u.info("SocketService::Disconnected from socket-edge",{error:{code:t,reason:e},country:S.location.country});const{recv:n,send:r}=(i=a(this,Le,Ue).mediaState)!=null?i:{};n!=null&&n.state&&(n==null?void 0:n.state)!==Bn.CONNECTED||r!=null&&r.state&&(r==null?void 0:r.state)!==Bn.CONNECTED?P.emit(R.SOCKET_SERVICE_DISCONNECTED,{joinAttempted:a(this,Le,Ue).joinAttempted}):v(this,ci,setTimeout(()=>{P.emit(R.SOCKET_SERVICE_DISCONNECTED,{joinAttempted:a(this,Le,Ue).joinAttempted}),v(this,ci,void 0)},vO)),a(this,Le,Ue).updateSocketConnectionState("disconnected")}),this.onStateEvent("reconnecting",()=>h(this,null,function*(){u.info("SocketService::Reconnecting to socket-edge",{country:S.location.country}),a(this,Le,Ue).updateSocketConnectionState("reconnecting")})),this.onStateEvent("reconnectAttempt",t=>h(this,[t],function*({attempt:e}){u.info("SocketService::Attempting to reconnect to socket-edge",{socket:{retryAttempt:e}}),a(this,Le,Ue).updateSocketConnectionState("reconnectAttempt",e)})),this.onStateEvent("reconnectFailure",({attempt:t})=>{u.info("SocketService::Reconnect attempt to socket-edge failed",{socket:{retryAttempt:t}}),a(this,Le,Ue).updateSocketConnectionState("reconnectFailure",t)}),this.onStateEvent("reconnected",()=>h(this,null,function*(){u.info("SocketService::Reconnected to socket-edge",{connectionState:{joinAttempted:a(this,Le,Ue).mediaJoinAttempted}}),a(this,ci)&&(clearTimeout(a(this,ci)),v(this,ci,void 0)),P.emit(R.SOCKET_SERVICE_RECONNECTED,{wasJoinAttempted:a(this,Le,Ue).mediaJoinAttempted}),a(this,Le,Ue).updateSocketConnectionState("reconnected")})),this.onStateEvent("failed",()=>h(this,null,function*(){u.info("SocketService::Failed to connect to socket-edge",{country:S.location.country}),P.emit(R.SOCKET_SERVICE_FAILED),a(this,Le,Ue).updateSocketConnectionState("failed")}))}},Qn=new WeakMap,Ne=new WeakMap,Le=new WeakSet,Ue=function(){return a(this,pn).getValue("connectionHandler")},ci=new WeakMap,pn=new WeakMap,Tc=new WeakSet,Ql=function(t){let e=ly.getSocketEdgeDomain(a(this,pn).getValue("baseURI"));typeof wd(a(this,pn),"socket_server_base")=="string"&&(e=wd(a(this,pn),"socket_server_base"));const i=`wss://${e}`,n=new URL(`${i}/ws`),r=this.peerId,s=q(x({roomID:this.roomName,peerID:t,authToken:this.authToken,useMediaV2:!0},r!==t&&{oldPeerID:r}),{ping:this.capabilities.includes("PING"),capabilities:this.capabilities.map(o=>Id[o]).join(" "),joinWithDetails:!0,useCfWorker:!0});return Object.entries(s).forEach(([o,c])=>{n.searchParams.append(o,c.toString())}),n.href},kc=new WeakSet,Xl=function(){return`${this.peerId}-${(Math.random()+1).toString(36).substring(7)}`},pg);let Go=ly;hl([S.trace("SocketService.connect")],Go.prototype,"connect",1);hl([S.trace("SocketService.disconnect")],Go.prototype,"disconnect",1);hl([S.trace("SocketService.sendMessagePromise")],Go.prototype,"sendMessagePromise",1);hl([S.trace("SocketService.sendMessagePromiseWithTimeout")],Go.prototype,"sendMessagePromiseWithTimeout",1);const gr=class{static handleConnectedRoomsDumpRaw({payload:t}){var e;const i=BC.fromBinary(t),n=i.meetings.map(r=>{var s;return{id:r.id,title:r.title,participants:(s=r.participants)!=null?s:[]}});return{parentMeeting:{id:i.parentMeeting.id,title:i.parentMeeting.title,participants:(e=i.parentMeeting.participants)!=null?e:[]},meetings:n}}static handleTransferPeerRaw({payload:t}){const e=hP.fromBinary(t);return{authToken:e.authToken,meetingId:e.meetingId}}static handleMovedPeerRaw({payload:t}){const e=tv.fromBinary(t);return{meetingId:e.meetingId,customParticipantId:e.customParticipantId}}static handleConnectedRoomsUpdatedRaw({payload:t}){return mm.fromBinary(t).payloads.map(e=>({id:e.id,title:e.title}))}static handleConnectedRoomsDeletedRaw({payload:t}){return iP.fromBinary(t).payloads}static getConnectedRoomsDump(){return h(this,null,function*(){const t=yield gr.socketService.sendMessagePromise(B.getConnectedRoomsDump);return gr.handleConnectedRoomsDumpRaw(t)})}static createConnectedRooms(t){return h(this,null,function*(){const{payload:e}=yield gr.socketService.sendMessagePromise(B.createConnectedRooms,GC.toBinary({payloads:t}));return mm.fromBinary(e).payloads.map(i=>({id:i.id,title:i.title}))})}static updateConnectedRooms(t){return h(this,null,function*(){})}static disableConnectedRooms(t){return h(this,null,function*(){const e=t.map(n=>({id:n})),i=yield gr.socketService.sendMessagePromise(B.deleteConnectedRooms,eP.toBinary({payloads:e}));return gr.handleConnectedRoomsDeletedRaw(i)})}static movePeersBetweenRooms(t){return h(this,null,function*(){try{const e=yield gr.socketService.sendMessagePromise(B.movePeers,cP.toBinary({sourceMeetingId:t.sourceMeetingId,destinationMeetingId:t.destinationMeetingId,participants:t.participants}));return new TextDecoder().decode(e.payload).includes("error")?{success:!1,error:"failed to move participants"}:{success:!0}}catch(e){return{success:!1,error:e}}})}};let Oe=gr;m(Oe,"socketService"),m(Oe,"currentMeetingId");var yO=Object.defineProperty,SO=Object.getOwnPropertyDescriptor,pl=(t,e,i,n)=>{for(var r=n>1?void 0:n?SO(e,i):e,s=t.length-1,o;s>=0;s--)(o=t[s])&&(r=(n?o(e,i,r):o(r))||r);return n&&r&&yO(e,i,r),r};const vs=class{constructor(t,e){m(this,"apiBase"),m(this,"selfController"),m(this,"pollController"),m(this,"chatController"),m(this,"metaController"),m(this,"storesManager"),m(this,"stageController"),m(this,"pluginController"),m(this,"internalsController"),m(this,"recordingController"),m(this,"livestreamController"),m(this,"participantController"),this.apiBase=t,this.storesManager=e.storesManager,this.metaController=e.metaController,this.selfController=e.selfController,this.chatController=e.chatController,this.pollController=e.pollController,this.stageController=e.stageController,this.pluginController=e.pluginController,this.recordingController=e.recordingController,this.internalsController=e.internalsController,this.participantController=e.participantController,this.livestreamController=e.livestreamController}static init(t){return h(this,null,function*(){var e,i;const{peerId:n,apiBase:r,authToken:s,meetingId:o,organizationId:c,cachedUserDetails:d}=t.getAllValues();if(P.reset(),Md.cleanup(),zv(t),Ie.isSupported()===!1)throw new w("Browser not supported","0010",!0);const l=_A(t,{authToken:s,baseURL:r,cachedUserDetails:d});l.setRoomName(o),l.setRoomUUID(o),l.setOrganizationId(c),l.setHeader("dyte-tracing-id",n),t.setValue("apiClient",l);const p=new a1;t.setValue("connectionHandler",p);const g=vs.createSocketService(t),y=g.connect(),T=l.getUserDetails(),b=l.getPlugins();let O=it.HIVE,M,F="";try{yield vs.setupFlagsmith(t)}catch(ne){u.error("Failed to setup flagsmith",{error:ne})}try{yield y}catch(ne){u.error("[Controller]: Failed to connect to socket server:",{error:ne})}try{({sfu:O,meetingTitle:F}=yield l.getRoomNodeData()),M=yield T,u.info(`SFU ${O} is being used.`),t.setValue("presetName",M.preset.name),t.setValue("roomNodeOptions",{sfu:O})}catch(ne){u.error("Failed to get room metadata",{error:ne})}const H=G1.init(M.preset,!t.getValue("modules").theme),J=vs.setupControllers(g,t,M,b,F,H);zA(H)&&((e=vs.createRoomNodeClient(t,g).partialJoinRoom(M.participant.name,o,void 0))==null||e.catch(ne=>{u.error("[Controller]: Failed to queue partial media room promise:",{error:ne})})),S.location.country=(i=l.ipInfo)==null?void 0:i.country;const{controllers:I}=yield J;return Q_(),new vs(r,I)})}static setupFlagsmith(t){return h(this,null,function*(){var e;const{peerId:i,baseURI:n,overrides:r,meetingId:s,organizationId:o}=t.getAllValues(),c=z_(s),d=q(x({entity:gu.PEER,clientId:o,isAnonUser:!o,sdkVersion:t.getValue("sdkVersion"),presetName:t.getValue("presetName"),meetingHash:c,roomName:s},Ie.getDeviceInfo()),{isReactNative:navigator.isReactNative});try{const l=(e=r==null?void 0:r.whitelabelled_flags_endpoint)==null||e?_s({servicePrefix:"flags",baseURI:n}):"edge.api.flagsmith.com";yield Q.identify(`${gu.PEER}_${i}`,JSON.parse(JSON.stringify(d)),!1,5e3,l,u),u.info("flagsmith::allFlags",{flags:JSON.stringify(Q.getAllFlags())},!0)}catch{u.error("Failed to fetch flagsmith flags")}})}static setupControllers(t,e,i,n,r,s){return h(this,null,function*(){var o,c,d;const l=e.getValue("modules"),{preset:p,participant:g}=i,y=e.getValue("defaults"),{sfu:T}=e.getValue("roomNodeOptions"),{viewType:b,mediaConstraints:{audio:O}}=s;e.setValue("viewType",b),e.setValue("defaults",x({mediaConfiguration:{audio:{enableHighBitrate:(o=O.enableHighBitrate)!=null?o:!1,enableStereo:(c=O.enableStereo)!=null?c:!1}}},y));const M=uD.init(e,b,p.permissions);e.setValue("maxPreferredStreams",Ie.isMobile()?s.maxVideoStreams.mobile:s.maxVideoStreams.desktop);let F,H,J,I,ne,ae,Me,Ae;const dt=new $D(t);Oe.socketService=t;const Ft=new ll(t),A=new ii(t),k=new YD(t),_=Md.create(t,e),W=new QD(t),be=new JD(t),Ke=new Rr(t),U=yield Gn.init(e,_,g,M,s),C=yield pv.init(e,U.self,_,dt,r);if(l.participant&&(Ae=new on(e,U.self,_,T)),(d=l.e2ee)!=null&&d.enabled&&l.e2ee.manager.init(u,P),l.chat&&(H=yield Zi.init(e,A,Ke,U.self,Ae.participants)),l.internals&&(ne=yield Jh.init()),l.livestream&&s.viewType===Pt.Livestream&&Q.hasFeature(re.LIVESTREAM)&&(Me=new kv(U.self,be)),s.viewType!==Pt.Chat){if(l.poll&&(F=yield dv.init(e,U.self,Ft)),l.recording&&(ae=new vv(e,U.self,_)),l.stage&&(J=new mv(e,k,_,U.self,Ae.participants)),l.plugin){if(!Ae)throw new w("The plugin module cannot be initialized without the `participant` module","0102");const Fi=yield n;I=yield Bo.init(e,Fi,W,A,H==null?void 0:H.chat,U.self,Ae.participants,r)}if(l.pip){const Fi=yield ew._init(e,U.self);e.setValue("pip",Fi)}}const ze={storesManager:new X1(e,W),pollController:F,selfController:U,metaController:C,chatController:H,stageController:J,pluginController:I,recordingController:ae,internalsController:ne,livestreamController:Me,participantController:Ae};return{theme:s,permissions:M,controllers:ze}})}static createRoomNodeClient(t,e){const{peerId:i,roomNodeOptions:n}=t.getAllValues(),{sfu:r}=n;return Kv(t,r,{socket:e,peerId:i})}static createSocketService(t){const{peerId:e,meetingId:i,authToken:n}=t.getAllValues(),r=["PING"];return new Go(t,{peerId:e,meetingId:i,authToken:n,capabilities:r})}};let qo=vs;pl([S.trace("Controller.init")],qo,"init",1);pl([S.trace("setupFlagsmith")],qo,"setupFlagsmith",1);pl([S.trace("Controller.createRoomNodeClient")],qo,"createRoomNodeClient",1);pl([S.trace("Controller.createSocketService")],qo,"createSocketService",1);var EO=Object.defineProperty,TO=Object.getOwnPropertyDescriptor,kO=(t,e,i,n)=>{for(var r=n>1?void 0:n?TO(e,i):e,s=t.length-1,o;s>=0;s--)(o=t[s])&&(r=(n?o(e,i,r):o(r))||r);return n&&r&&EO(e,i,r),r},dd,kh;class uy extends $t{constructor(e,i){super(),f(this,dd,void 0),m(this,"meetings",[]),m(this,"parentMeeting",null),f(this,kh,void 0),v(this,kh,e),v(this,dd,i.self)}get supportsConnectedMeetings(){return a(this,dd).id!==""}get isActive(){return this.meetings.length!==0}get currentMeetingId(){return Oe.currentMeetingId}validateConnectedMeetingsAction(){if(!this.supportsConnectedMeetings)throw new Error(`You are not allowed to perform this action.
21
21
  Please connect with Dyte team to move you to V2 APIs & to enable connected meetings.`)}getConnectedMeetings(){return h(this,null,function*(){return this.validateConnectedMeetingsAction(),yield Oe.getConnectedRoomsDump()})}createMeetings(e){return h(this,null,function*(){return this.validateConnectedMeetingsAction(),(yield Oe.createConnectedRooms(e)).map(i=>({id:i.id,title:i.title}))})}updateMeetings(e){return h(this,null,function*(){this.validateConnectedMeetingsAction(),yield Oe.updateConnectedRooms(e.map(i=>({meetingId:i.id,title:i.title})))})}deleteMeetings(e){return h(this,null,function*(){this.validateConnectedMeetingsAction();const i=this.meetings.map(n=>e.includes(n.id)&&n.participants.length!==0?this.moveParticipants(n.id,this.parentMeeting.id,n.participants.map(r=>r.id)):Promise.resolve());return yield Promise.all(i),yield Oe.disableConnectedRooms(e)})}moveParticipants(e,i,n){return h(this,null,function*(){this.validateConnectedMeetingsAction();const r=yield Oe.movePeersBetweenRooms({sourceMeetingId:e,destinationMeetingId:i,participants:n.map(s=>({id:s}))});return r.success&&this.moveSuccessHandler(e,i,n),r})}moveParticipantsWithCustomPreset(e,i,n){return h(this,null,function*(){this.validateConnectedMeetingsAction();const r=yield Oe.movePeersBetweenRooms({sourceMeetingId:e,destinationMeetingId:i,participants:n});return r.success&&this.moveSuccessHandler(e,i,n.map(s=>s.id)),r})}moveSuccessHandler(e,i,n){const r=new Map;[...this.parentMeeting.participants,...this.meetings.flatMap(s=>s.participants)].forEach(s=>r.set(s.id,s)),i===this.parentMeeting.id&&(this.parentMeeting.participants=this.parentMeeting.participants.concat(n.map(s=>r.get(s)))),e===this.parentMeeting.id&&(this.parentMeeting.participants=this.parentMeeting.participants.filter(s=>!n.includes(s.id))),this.meetings=this.meetings.map(s=>{if(i===s.id){const o=s.participants.concat(n.map(c=>r.get(c)));return q(x({},s),{participants:o})}if(e===s.id){const o=s.participants.filter(c=>!n.includes(c.id));return q(x({},s),{participants:o})}return s})}}dd=new WeakMap,kh=new WeakMap;kO([Vt({maxInvocations:60,period:60})],uy.prototype,"getConnectedMeetings",1);var bO=Object.defineProperty,_O=Object.getOwnPropertyDescriptor,rp=(t,e,i,n)=>{for(var r=n>1?void 0:n?_O(e,i):e,s=t.length-1,o;s>=0;s--)(o=t[s])&&(r=(n?o(e,i,r):o(r))||r);return n&&r&&bO(e,i,r),r},Aa,di,Zl,eu;const Rn=(Zl=class{constructor(t,e,i){m(this,"connectedMeetings"),f(this,Aa,void 0),f(this,di,void 0),f(this,eu,void 0),v(this,eu,t),v(this,Aa,i),this.connectedMeetings=new uy(t,e),this.setCurrentMeeting(e)}static init(t,e,i){return Rn.instance||(Rn.instance=new Rn(t,e,i)),Rn.instance.connectedMeetings.supportsConnectedMeetings&&(Rn.instance.setupEvents(),e.self.once("roomJoined",()=>Rn.instance.getConnectedMeetings())),Rn.instance}setCurrentMeeting(t){v(this,di,t),Oe.currentMeetingId=t.meta.meetingId}getConnectedMeetings(){this.connectedMeetings.getConnectedMeetings()}setupEvents(){Oe.socketService&&(Oe.socketService.on(B.getConnectedRoomsDump,this.handleConnectedRoomsDump.bind(this)),Oe.socketService.on(B.transferPeer,this.handleTransferPeer.bind(this)),Oe.socketService.on(B.movedPeer,this.handleMovedPeer.bind(this)),Oe.socketService.on(B.connectedRoomsUpdated,this.handleConnectedRoomsUpdated.bind(this)),Oe.socketService.on(B.connectedRoomsDeleted,this.handleConnectedRoomsDeleted.bind(this)))}handleTransferPeer(t){const e=Oe.handleTransferPeerRaw(t);return this.switchMeeting(e)}switchMeeting(t){return h(this,arguments,function*({authToken:e,meetingId:i}){var n,r,s,o;if(!this.connectedMeetings.supportsConnectedMeetings)throw new Error(`You are not allowed to perform this action.
22
22
  Please connect with Dyte team to move you to V2 APIs & to enable connected meetings.`);u.info("ConnectedMeetingsController::switchMeeting:: asking ui-kit to show switching breakout UI"),this.connectedMeetings.emit("changingMeeting",i);const c={video:a(this,di).self.videoEnabled,audio:a(this,di).self.audioEnabled};try{a(this,di).self.cleanupEvents(),yield a(this,di).leave("connected-meeting")}catch(l){u.error(`ConnectedMeetingsController:: switchMeeting:: issues in leaving previous meeting. Meeting Id: ${(r=(n=a(this,di))==null?void 0:n.meta)==null?void 0:r.meetingId}`,{error:l})}Oe.socketService=void 0,u.info(`ConnectedMeetingsController::switchMeeting:: initializing new meeting. Meeting Id: ${i}`);const d=yield hy.init(q(x({},a(this,Aa)),{cachedUserDetails:null,defaults:q(x(x({},a(this,Aa).defaults),c),{mediaHandler:a(this,di).self}),authToken:e}));u.info(`ConnectedMeetingsController::switchMeeting:: initialized new meeting. Meeting Id: ${(s=d==null?void 0:d.meta)==null?void 0:s.meetingId}`);try{const{hidden:l}=a(this,di).self;d.self.setName(a(this,di).self.name),yield d.join(),l&&d.self.hide()}catch(l){u.error("ConnectedMeetingsController.joinRoom",{error:l})}return u.info(`ConnectedMeetingsController::switchMeeting:: asking ui-kit to show in-meeting ui of newly joined meeting id: ${(o=d==null?void 0:d.meta)==null?void 0:o.meetingId}`),this.connectedMeetings.emit("meetingChanged",d),this.setCurrentMeeting(d),d})}handleConnectedRoomsDump(t){const e=Oe.handleConnectedRoomsDumpRaw(t);this.connectedMeetings.meetings=e.meetings.map(i=>({id:i.id,title:i.title,participants:i.participants||[]})),this.connectedMeetings.parentMeeting={id:e.parentMeeting.id,title:e.parentMeeting.title,participants:e.parentMeeting.participants},this.emitStateUpdate()}handleMovedPeer(t){return Oe.handleMovedPeerRaw(t)}handleConnectedRoomsUpdated(t){const e=Oe.handleConnectedRoomsUpdatedRaw(t),i=new Map;this.connectedMeetings.meetings.forEach(n=>{i.set(n.id,n)}),e.forEach(n=>{i.has(n.id)?i.get(n.id).title=n.title:i.set(n.id,q(x({},n),{participants:[]}))}),this.connectedMeetings.meetings=Array.from(i.values()),this.emitStateUpdate()}handleConnectedRoomsDeleted(t){const e=Oe.handleConnectedRoomsDeletedRaw(t).map(i=>i.id);this.connectedMeetings.meetings=this.connectedMeetings.meetings.filter(i=>!e.includes(i.id)),this.emitStateUpdate()}emitStateUpdate(){this.connectedMeetings.emit("stateUpdate",{meetings:this.connectedMeetings.meetings,parentMeeting:this.connectedMeetings.parentMeeting})}},Aa=new WeakMap,di=new WeakMap,eu=new WeakMap,m(Zl,"instance"),Zl);let ml=Rn;rp([S.trace("ConnectedMeetingsController.getConnectedMeetings")],ml.prototype,"getConnectedMeetings",1);rp([S.trace("ConnectedMeetingsController.setupEvents")],ml.prototype,"setupEvents",1);rp([S.trace("ConnectedMeetingsController.switchMeeting")],ml.prototype,"switchMeeting",1);class wO{constructor(){m(this,"battery"),m(this,"init",()=>h(this,null,function*(){try{"getBattery"in navigator&&(this.battery=yield navigator.getBattery(),this.battery.addEventListener("chargingchange",this.updateChargeInfo),this.battery.addEventListener("levelchange",this.updateLevelInfo),this.updateLevelInfo(),this.updateChargeInfo())}catch(e){u.error("Error getting battery",e)}})),m(this,"updateChargeInfo",()=>{var e;u.log(`Battery charging? ${(e=this.battery)!=null&&e.charging?"Yes":"No"}`)}),m(this,"updateLevelInfo",()=>{if(!this.battery){u.log("Battery level: Not known");return}u.log(`Battery level: ${this.battery.level*100}%`)}),m(this,"cleanup",()=>{var e,i;"getBattery"in navigator&&((e=this.battery)==null||e.removeEventListener("chargingchange",this.updateChargeInfo),(i=this.battery)==null||i.removeEventListener("levelchange",this.updateLevelInfo))})}}const mg=new wO;function IO(t,e){t.startsWith("eyJ")||console.error("Invalid auth token provided. Ensure you are passing a %cparticipant `authToken`%c \u2014 not an Org API Key or an incorrectly formatted token.\nYou get the participant token from the Add Participant API: https://docs.dyte.io/api#/operations/add_participant","font-weight: bold","font-weight: normal");try{const{meetingId:i,orgId:n,participantId:r}=JSON.parse(atob(t.split(".")[1]));if(!i)throw Error(`Received V1 auth token ${t}`);let s="dyte.io";e&&(s=e);const o=`https://api.${s}`;return{meetingId:i,orgId:n,participantId:r,baseURI:s,apiBase:o}}catch(i){throw u.error("constants::decodeAuthToken",{error:i,debuggingHint:`Unable to decode auth token: ${t}`},!0),new w("Invalid auth token","0004")}}var CO=Object.defineProperty,PO=Object.getOwnPropertyDescriptor,gl=(t,e,i,n)=>{for(var r=n>1?void 0:n?PO(e,i):e,s=t.length-1,o;s>=0;s--)(o=t[s])&&(r=(n?o(e,i,r):o(r))||r);return n&&r&&CO(e,i,r),r},at,bc,_c,tu,gg,fg;let Wn=(fg=class{constructor(t,e){f(this,tu),f(this,at,void 0),f(this,bc,void 0),f(this,_c,void 0),v(this,_c,t),v(this,at,e)}static init(t){return h(this,null,function*(){var e,i,n,r,s,o,c;J_(),Ie.init();const d=(i=(e=t==null?void 0:t.cachedUserDetails)==null?void 0:e.peerId)!=null?i:Os();mg.init();const{authToken:l,baseURI:p}=t,g=IO(l,p),{meetingId:y}=g,T=$d(g,["meetingId"]);window.__zone_symbol__DISABLE_WRAPPING_UNCAUGHT_PROMISE_REJECTION=!0;const b=Wn.setupContext(d,t,y,T);S.meetingMetadata.roomName=y,S.meetingMetadata.userId=T.participantId,S.meetingMetadata.organizationId=T.orgId,S.init(b,(r=(n=t.modules)==null?void 0:n.tracing)!=null?r:!0),u.info("DyteClient::init::options",{dyteClientInitOptions:q(x({},t),{authToken:`${(s=t.authToken)==null?void 0:s.slice(0,10)}...
23
- ${(o=t.authToken)==null?void 0:o.slice(-10)}`})});const O=yield qo.init(b),M=new Wn(b,O);return j(c=M,tu,gg).call(c,t),M})}static setupContext(t,e,i,n){var r;const s=wr.createContext(t,e),o=x(x({},B_),e==null?void 0:e.modules);return s.setValue("peerId",t),s.setValue("modules",o),s.setValue("sdkName","web-core"),s.setValue("meetingId",i),s.setValue("apiBase",n.apiBase),s.setValue("baseURI",n.baseURI),s.setValue("userId",n.participantId),s.setValue("organizationId",n.orgId),s.setValue("authToken",e.authToken),s.setValue("overrides",(r=e.overrides)!=null?r:{}),s.setValue("env",W_({baseURI:n.baseURI})),s.setValue("defaults",e.defaults||{audio:!0,video:!0}),s.setValue("onError",e.onError||(()=>{})),s.setValue("cachedUserDetails",Si(e.cachedUserDetails)),s.setValue("sdkVersion","2.5.0-staging.106"),s}join(){return h(this,null,function*(){const{selfController:t}=a(this,at);return t.self.roomJoined?null:t.joinRoom()})}leave(t){return h(this,null,function*(){mg.cleanup();const{selfController:e}=a(this,at);return e.leaveRoom(t)})}get participants(){var t;return(t=a(this,at).participantController)==null?void 0:t.participants}get self(){var t;return(t=a(this,at).selfController)==null?void 0:t.self}get meta(){var t;return(t=a(this,at).metaController)==null?void 0:t.meta}get ai(){var t;return(t=a(this,at).metaController)==null?void 0:t.ai}get plugins(){var t;return(t=a(this,at).pluginController)==null?void 0:t.plugins}get chat(){var t;return(t=a(this,at).chatController)==null?void 0:t.chat}get polls(){var t;return(t=a(this,at).pollController)==null?void 0:t.polls}get connectedMeetings(){var t;return(t=a(this,bc))==null?void 0:t.connectedMeetings}get recording(){var t;return(t=a(this,at).recordingController)==null?void 0:t.recording}get livestream(){var t;return(t=a(this,at).livestreamController)==null?void 0:t.livestream}get stage(){var t;return(t=a(this,at).stageController)==null?void 0:t.stage}get stores(){return a(this,at).storesManager}get __internals__(){var t;return(t=a(this,at).internalsController)==null?void 0:t.internals}joinRoom(){return h(this,null,function*(){return this.join()})}leaveRoom(t){return h(this,null,function*(){return this.leave(t)})}},at=new WeakMap,bc=new WeakMap,_c=new WeakMap,tu=new WeakSet,gg=function(t){v(this,bc,ml.init(a(this,_c),this,t))},fg);gl([gt("0002"),Hn.executeWithLock({methodName:"meeting.join",lockName:"DyteClient.join",timeout:3e3})],Wn.prototype,"join",1);gl([gt("0003")],Wn.prototype,"leave",1);gl([gt("0001"),Hn.executeWithLock({methodName:"DyteClient.init",lockName:"DyteClient.init",timeout:3e3})],Wn,"init",1);Wn=gl([gt("0000")],Wn);const hy=Wn;exports.RTKSelfMedia=Pv;exports.default=hy;
23
+ ${(o=t.authToken)==null?void 0:o.slice(-10)}`})});const O=yield qo.init(b),M=new Wn(b,O);return j(c=M,tu,gg).call(c,t),M})}static setupContext(t,e,i,n){var r;const s=wr.createContext(t,e),o=x(x({},B_),e==null?void 0:e.modules);return s.setValue("peerId",t),s.setValue("modules",o),s.setValue("sdkName","web-core"),s.setValue("meetingId",i),s.setValue("apiBase",n.apiBase),s.setValue("baseURI",n.baseURI),s.setValue("userId",n.participantId),s.setValue("organizationId",n.orgId),s.setValue("authToken",e.authToken),s.setValue("overrides",(r=e.overrides)!=null?r:{}),s.setValue("env",W_({baseURI:n.baseURI})),s.setValue("defaults",e.defaults||{audio:!0,video:!0}),s.setValue("onError",e.onError||(()=>{})),s.setValue("cachedUserDetails",Si(e.cachedUserDetails)),s.setValue("sdkVersion","2.5.0-staging.108"),s}join(){return h(this,null,function*(){const{selfController:t}=a(this,at);return t.self.roomJoined?null:t.joinRoom()})}leave(t){return h(this,null,function*(){mg.cleanup();const{selfController:e}=a(this,at);return e.leaveRoom(t)})}get participants(){var t;return(t=a(this,at).participantController)==null?void 0:t.participants}get self(){var t;return(t=a(this,at).selfController)==null?void 0:t.self}get meta(){var t;return(t=a(this,at).metaController)==null?void 0:t.meta}get ai(){var t;return(t=a(this,at).metaController)==null?void 0:t.ai}get plugins(){var t;return(t=a(this,at).pluginController)==null?void 0:t.plugins}get chat(){var t;return(t=a(this,at).chatController)==null?void 0:t.chat}get polls(){var t;return(t=a(this,at).pollController)==null?void 0:t.polls}get connectedMeetings(){var t;return(t=a(this,bc))==null?void 0:t.connectedMeetings}get recording(){var t;return(t=a(this,at).recordingController)==null?void 0:t.recording}get livestream(){var t;return(t=a(this,at).livestreamController)==null?void 0:t.livestream}get stage(){var t;return(t=a(this,at).stageController)==null?void 0:t.stage}get stores(){return a(this,at).storesManager}get __internals__(){var t;return(t=a(this,at).internalsController)==null?void 0:t.internals}joinRoom(){return h(this,null,function*(){return this.join()})}leaveRoom(t){return h(this,null,function*(){return this.leave(t)})}},at=new WeakMap,bc=new WeakMap,_c=new WeakMap,tu=new WeakSet,gg=function(t){v(this,bc,ml.init(a(this,_c),this,t))},fg);gl([gt("0002"),Hn.executeWithLock({methodName:"meeting.join",lockName:"DyteClient.join",timeout:3e3})],Wn.prototype,"join",1);gl([gt("0003")],Wn.prototype,"leave",1);gl([gt("0001"),Hn.executeWithLock({methodName:"DyteClient.init",lockName:"DyteClient.init",timeout:3e3})],Wn,"init",1);Wn=gl([gt("0000")],Wn);const hy=Wn;exports.RTKSelfMedia=Pv;exports.default=hy;
package/dist/index.d.ts CHANGED
@@ -2569,6 +2569,25 @@ type BroadcastMessageTarget = {
2569
2569
  } | {
2570
2570
  meetingIds: string[];
2571
2571
  };
2572
+ type JoinedPeer = {
2573
+ id: string;
2574
+ userId: string;
2575
+ name: string;
2576
+ stageType?: StageStatus;
2577
+ customParticipantId?: string;
2578
+ presetId?: string;
2579
+ picture?: string;
2580
+ waitlisted: boolean;
2581
+ recorderType?: string;
2582
+ stageStatus?: StageStatus;
2583
+ metadata?: {
2584
+ preset_name?: string;
2585
+ };
2586
+ flags?: {
2587
+ hiddenParticipant?: boolean;
2588
+ recorder?: boolean;
2589
+ };
2590
+ };
2572
2591
  type ParticipantsEvents = {
2573
2592
  ['viewModeChanged']: (payload: {
2574
2593
  viewMode: string;
@@ -4653,13 +4672,27 @@ declare class RealtimeKitClient {
4653
4672
  leaveRoom(state?: LeaveRoomState): Promise<void>;
4654
4673
  }
4655
4674
 
4675
+ declare enum RequestToJoinType {
4676
+ PRESENT = "REQUEST_TO_PRESENT"
4677
+ }
4678
+
4656
4679
  type RTKParticipant = Readonly<RTKParticipant$1>;
4657
4680
 
4658
4681
  type RTKParticipants = Readonly<RTKParticipants$1>;
4659
4682
  type RTKParticipantMap = Readonly<RTKParticipantMap$1>;
4660
4683
 
4661
4684
  type RTKPlugin = Readonly<RTKPlugin$1>;
4685
+ type RTKPlugins = Readonly<RTKPlugins$1>;
4686
+ type RTKPluginMap = Readonly<RTKPluginMap$1>;
4687
+ type RTKMeta = Readonly<RTKMeta$1>;
4662
4688
  type RTKSelf = Readonly<RTKSelf$1>;
4689
+ type RTKChat = Readonly<RTKChat$1>;
4690
+ type RTKPolls = Readonly<RTKPolls$1>;
4691
+ type RTKRecording = Readonly<RTKRecording$1>;
4692
+
4693
+ type RTKLivestream = Readonly<RTKLivestream$1>;
4694
+
4695
+ type RTKStore = RTKStore$1;
4663
4696
 
4664
4697
  type RTKConnectedMeetings = Readonly<RTKConnectedMeetings$1>;
4665
4698
 
@@ -4684,4 +4717,4 @@ declare global {
4684
4717
  }
4685
4718
  }
4686
4719
 
4687
- export { ActiveTab, ActiveTabType, AudioProducerScoreStats, ChatChannel, ChatUpdateParams, CustomMessage, DeviceConfig, RTKBasicParticipant, RealtimeKitClientOptions, RTKConnectedMeetings, RTKParticipant, RTKParticipantMap, RTKParticipants, RTKPermissionsPreset, RTKPlugin, RTKSelf, RTKThemePreset, FileMessage, ImageMessage, LivestreamState, MediaConnectionState, MediaKind$1 as MediaKind, Message, ProducerScoreStats, RTKSelfMedia as RTKSelfMedia, RecordingState, SocketConnectionState, StageStatus, TextMessage, VideoProducerScoreStats, RealtimeKitClient as default, LeaveRoomState as leaveRoomState };
4720
+ export { ActiveTab, ActiveTabType, AudioConsumerScoreStats, AudioMiddleware, AudioProducerScoreStats, BroadcastMessagePayload, ChatChannel, ChatUpdateParams, CustomMessage, DeviceConfig, RTKBasicParticipant, RTKChat, RealtimeKitClientOptions, RTKConnectedMeetings, RTKLivestream, RTKMeta, RTKParticipant, RTKParticipantMap, RTKParticipants, RTKPermissionsPreset, RTKPlugin, RTKPluginMap, RTKPlugins, RTKPolls, RTKRecording, RTKSelf, RTKStore, RTKThemePreset, FileMessage, ImageMessage, JoinedPeer, LeaveRoomState, LivestreamIngestionCredentials, LivestreamState, LogData, MediaConnectionState, MediaConnectionUpdate, MediaKind$1 as MediaKind, MediaPermission, Message, ProducerScoreStats, RTKSelfMedia as RTKSelfMedia, RecordingState, RequestToJoinType, SocketConnectionState, StageStatus, StartLivestreamConfig, TextMessage, VideoConsumerScoreStats, VideoMiddleware, VideoProducerScoreStats, VideoQualityConstraints, RealtimeKitClient as default, LeaveRoomState as leaveRoomState };
package/dist/index.es.js CHANGED
@@ -29885,7 +29885,7 @@ let Xr = (Tm = class {
29885
29885
  var d;
29886
29886
  const n = Hi.createContext(t, e), o = O(O({}, $P), e == null ? void 0 : e.modules);
29887
29887
  return n.setValue("peerId", t), n.setValue("modules", o), n.setValue("sdkName", "web-core"), n.setValue("meetingId", r), n.setValue("apiBase", i.apiBase), n.setValue("baseURI", i.baseURI), n.setValue("userId", i.participantId), n.setValue("organizationId", i.orgId), n.setValue("authToken", e.authToken), n.setValue("overrides", (d = e.overrides) != null ? d : {}), n.setValue("env", FP({ baseURI: i.baseURI })), n.setValue("defaults", e.defaults || { audio: true, video: true }), n.setValue("onError", e.onError || (() => {
29888
- })), n.setValue("cachedUserDetails", ms(e.cachedUserDetails)), n.setValue("sdkVersion", "2.5.0-staging.106"), n;
29888
+ })), n.setValue("cachedUserDetails", ms(e.cachedUserDetails)), n.setValue("sdkVersion", "2.5.0-staging.108"), n;
29889
29889
  }
29890
29890
  join() {
29891
29891
  return l(this, null, function* () {
@@ -2565,6 +2565,25 @@ type BroadcastMessageTarget = {
2565
2565
  } | {
2566
2566
  meetingIds: string[];
2567
2567
  };
2568
+ type JoinedPeer = {
2569
+ id: string;
2570
+ userId: string;
2571
+ name: string;
2572
+ stageType?: StageStatus;
2573
+ customParticipantId?: string;
2574
+ presetId?: string;
2575
+ picture?: string;
2576
+ waitlisted: boolean;
2577
+ recorderType?: string;
2578
+ stageStatus?: StageStatus;
2579
+ metadata?: {
2580
+ preset_name?: string;
2581
+ };
2582
+ flags?: {
2583
+ hiddenParticipant?: boolean;
2584
+ recorder?: boolean;
2585
+ };
2586
+ };
2568
2587
  type ParticipantsEvents = {
2569
2588
  ['viewModeChanged']: (payload: {
2570
2589
  viewMode: string;
@@ -4603,11 +4622,22 @@ declare class RealtimeKitClient {
4603
4622
  joinRoom(): Promise<void>;
4604
4623
  leaveRoom(state?: LeaveRoomState): Promise<void>;
4605
4624
  }
4625
+ declare enum RequestToJoinType {
4626
+ PRESENT = "REQUEST_TO_PRESENT"
4627
+ }
4606
4628
  type RTKParticipant = Readonly<RTKParticipant$1>;
4607
4629
  type RTKParticipants = Readonly<RTKParticipants$1>;
4608
4630
  type RTKParticipantMap = Readonly<RTKParticipantMap$1>;
4609
4631
  type RTKPlugin = Readonly<RTKPlugin$1>;
4632
+ type RTKPlugins = Readonly<RTKPlugins$1>;
4633
+ type RTKPluginMap = Readonly<RTKPluginMap$1>;
4634
+ type RTKMeta = Readonly<RTKMeta$1>;
4610
4635
  type RTKSelf = Readonly<RTKSelf$1>;
4636
+ type RTKChat = Readonly<RTKChat$1>;
4637
+ type RTKPolls = Readonly<RTKPolls$1>;
4638
+ type RTKRecording = Readonly<RTKRecording$1>;
4639
+ type RTKLivestream = Readonly<RTKLivestream$1>;
4640
+ type RTKStore = RTKStore$1;
4611
4641
  type RTKConnectedMeetings = Readonly<RTKConnectedMeetings$1>;
4612
4642
  type RTKPermissionsPreset = Readonly<RTKPermissionsPreset$1>;
4613
4643
  type RTKThemePreset = Readonly<RTKThemePreset$1>;
@@ -4628,4 +4658,4 @@ declare global {
4628
4658
  TransformStream?: any;
4629
4659
  }
4630
4660
  }
4631
- export { ActiveTab, ActiveTabType, AudioProducerScoreStats, ChatChannel, ChatUpdateParams, CustomMessage, DeviceConfig, RTKBasicParticipant, RealtimeKitClientOptions, RTKConnectedMeetings, RTKParticipant, RTKParticipantMap, RTKParticipants, RTKPermissionsPreset, RTKPlugin, RTKSelf, RTKThemePreset, FileMessage, ImageMessage, LivestreamState, MediaConnectionState, MediaKind$1 as MediaKind, Message, ProducerScoreStats, RTKSelfMedia as RTKSelfMedia, RecordingState, SocketConnectionState, StageStatus, TextMessage, VideoProducerScoreStats, RealtimeKitClient as default, LeaveRoomState as leaveRoomState };
4661
+ export { ActiveTab, ActiveTabType, AudioConsumerScoreStats, AudioMiddleware, AudioProducerScoreStats, BroadcastMessagePayload, ChatChannel, ChatUpdateParams, CustomMessage, DeviceConfig, RTKBasicParticipant, RTKChat, RealtimeKitClientOptions, RTKConnectedMeetings, RTKLivestream, RTKMeta, RTKParticipant, RTKParticipantMap, RTKParticipants, RTKPermissionsPreset, RTKPlugin, RTKPluginMap, RTKPlugins, RTKPolls, RTKRecording, RTKSelf, RTKStore, RTKThemePreset, FileMessage, ImageMessage, JoinedPeer, LeaveRoomState, LivestreamIngestionCredentials, LivestreamState, LogData, MediaConnectionState, MediaConnectionUpdate, MediaKind$1 as MediaKind, MediaPermission, Message, ProducerScoreStats, RTKSelfMedia as RTKSelfMedia, RecordingState, RequestToJoinType, SocketConnectionState, StageStatus, StartLivestreamConfig, TextMessage, VideoConsumerScoreStats, VideoMiddleware, VideoProducerScoreStats, VideoQualityConstraints, RealtimeKitClient as default, LeaveRoomState as leaveRoomState };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudflare/realtimekit",
3
- "version": "0.5.0-staging.106",
3
+ "version": "0.5.0-staging.108",
4
4
  "description": "A real-time video and audio SDK for building custom, collaborative communication experiences.",
5
5
  "main": "./dist/index.cjs.js",
6
6
  "module": "./dist/index.es.js",