@realsee/live 0.6.15 → 0.7.1

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.
Files changed (167) hide show
  1. package/README.md +50 -55
  2. package/dist/index.cjs.js +38 -24
  3. package/dist/index.d.cts +1336 -0
  4. package/dist/index.d.ts +1336 -5
  5. package/dist/index.esm.js +10 -0
  6. package/docs/README.md +435 -0
  7. package/docs/classes/BrowserRTC.md +436 -0
  8. package/docs/classes/BrowserRTC4Chime.md +558 -0
  9. package/docs/classes/CoreRTC.md +448 -0
  10. package/docs/classes/Live.md +797 -0
  11. package/docs/classes/Subscribe.md +211 -0
  12. package/docs/classes/VRWebViewRTC.md +436 -0
  13. package/docs/enumerations/BuiltInRTCType.md +27 -0
  14. package/docs/enumerations/BuiltinActionType.md +81 -0
  15. package/docs/enumerations/BuiltinEventType.md +33 -0
  16. package/docs/enumerations/Command.md +107 -0
  17. package/docs/enumerations/LiveState.md +53 -0
  18. package/docs/enumerations/MemUserStatus.md +67 -0
  19. package/docs/enumerations/MicroStatus.md +33 -0
  20. package/docs/enumerations/RTCJoinedInfoCodeEnum.md +69 -0
  21. package/docs/enumerations/RTCType.md +39 -0
  22. package/docs/enumerations/UserStatus.md +45 -0
  23. package/docs/enumerations/WebSocketCloseError.md +117 -0
  24. package/docs/enumerations/WebSocketErrorType.md +77 -0
  25. package/docs/enumerations/WebSocketState.md +69 -0
  26. package/docs/functions/GetVoiceSignFn.md +27 -0
  27. package/docs/functions/clearLiveInstanceIfNeed.md +17 -0
  28. package/docs/functions/createLive.md +27 -0
  29. package/docs/functions/createLiveReact.md +449 -0
  30. package/docs/functions/parseLiveMsg.md +27 -0
  31. package/docs/functions/parseWSClsErr.md +21 -0
  32. package/docs/globals.md +77 -0
  33. package/docs/interfaces/AttendeeResponse.md +37 -0
  34. package/docs/interfaces/LiveOptions.md +246 -0
  35. package/docs/interfaces/MeetingResponse.md +55 -0
  36. package/docs/interfaces/MeetingSessionConfigurationOptions.md +93 -0
  37. package/docs/interfaces/Permission.md +147 -0
  38. package/docs/interfaces/RTCJoinedInfo.md +67 -0
  39. package/docs/interfaces/RTCProtocol.md +404 -0
  40. package/docs/interfaces/VRWebViewRTCOptions.md +41 -0
  41. package/docs/namespaces/SubscribeMixinType/README.md +17 -0
  42. package/docs/namespaces/SubscribeMixinType/interfaces/emit.md +31 -0
  43. package/docs/namespaces/SubscribeMixinType/interfaces/hasListener.md +25 -0
  44. package/docs/namespaces/SubscribeMixinType/interfaces/off.md +31 -0
  45. package/docs/namespaces/SubscribeMixinType/interfaces/on.md +37 -0
  46. package/docs/namespaces/SubscribeMixinType/interfaces/once.md +35 -0
  47. package/docs/type-aliases/BuiltinMsg.md +41 -0
  48. package/docs/type-aliases/EventMap.md +17 -0
  49. package/docs/type-aliases/EventType.md +19 -0
  50. package/docs/type-aliases/GetVoiceSign.md +15 -0
  51. package/docs/type-aliases/GetVoiceSignParams.md +35 -0
  52. package/docs/type-aliases/GetVoiceSignReturnType.md +41 -0
  53. package/docs/type-aliases/KeyframeEventType.md +19 -0
  54. package/docs/type-aliases/LiveBuiltInData.md +47 -0
  55. package/docs/type-aliases/LiveConnectOptions.md +47 -0
  56. package/docs/type-aliases/LiveEventType.md +165 -0
  57. package/docs/type-aliases/LiveMsg.md +53 -0
  58. package/docs/type-aliases/LiveProviderPropTypes.md +27 -0
  59. package/docs/type-aliases/RTCActionReactCallback.md +13 -0
  60. package/docs/type-aliases/RTCEventType.md +65 -0
  61. package/docs/type-aliases/ReqLiveMsg.md +45 -0
  62. package/docs/type-aliases/RoomInfo.md +55 -0
  63. package/docs/type-aliases/UserInfo.md +77 -0
  64. package/docs/type-aliases/UserInfoExt.md +33 -0
  65. package/docs/type-aliases/UserVolume.md +25 -0
  66. package/docs/type-aliases/WebSocketError.md +31 -0
  67. package/package.json +39 -32
  68. package/dist/index.cjs.js.map +0 -1
  69. package/dist/index.es.js +0 -2328
  70. package/dist/index.es.js.map +0 -1
  71. package/dist/live/controller.d.ts +0 -118
  72. package/dist/live/createLive.d.ts +0 -8
  73. package/dist/live/createLiveReact.d.ts +0 -52
  74. package/dist/live/live.d.ts +0 -182
  75. package/dist/rtc/BrowserRTC.d.ts +0 -39
  76. package/dist/rtc/BrowserRTC4Chime.d.ts +0 -60
  77. package/dist/rtc/CoreRTC.d.ts +0 -23
  78. package/dist/rtc/VRWebViewRTC.d.ts +0 -97
  79. package/dist/rtc/index.d.ts +0 -5
  80. package/dist/typings/chime/AttendeeResponse.d.ts +0 -5
  81. package/dist/typings/chime/MeetingResponse.d.ts +0 -12
  82. package/dist/typings/chime/MeetingSessionConfigurationOptions.d.ts +0 -16
  83. package/dist/typings/chime/index.d.ts +0 -3
  84. package/dist/typings/index.d.ts +0 -4
  85. package/dist/typings/live/EventType.d.ts +0 -74
  86. package/dist/typings/live/GetVoiceSign.d.ts +0 -45
  87. package/dist/typings/live/LiveConnectOptions.d.ts +0 -24
  88. package/dist/typings/live/LiveMsg.d.ts +0 -133
  89. package/dist/typings/live/LiveOptions.d.ts +0 -79
  90. package/dist/typings/live/LiveState.d.ts +0 -15
  91. package/dist/typings/live/RoomInfo.d.ts +0 -13
  92. package/dist/typings/live/UserInfo.d.ts +0 -103
  93. package/dist/typings/live/UserVolume.d.ts +0 -7
  94. package/dist/typings/live/WebSocket.d.ts +0 -82
  95. package/dist/typings/live/index.d.ts +0 -10
  96. package/dist/typings/react/RTCActionReactCallback.d.ts +0 -2
  97. package/dist/typings/react/index.d.ts +0 -1
  98. package/dist/typings/rtc/VRWebViewRTCOptions.d.ts +0 -6
  99. package/dist/typings/rtc/eventType.d.ts +0 -44
  100. package/dist/typings/rtc/index.d.ts +0 -5
  101. package/dist/typings/rtc/joinedInfo.d.ts +0 -38
  102. package/dist/typings/rtc/protocol.d.ts +0 -62
  103. package/dist/typings/rtc/type.d.ts +0 -12
  104. package/dist/utils/RobustWebSocket.d.ts +0 -160
  105. package/dist/utils/appendUri.d.ts +0 -1
  106. package/dist/utils/clientDetector.d.ts +0 -4
  107. package/dist/utils/equal.d.ts +0 -10
  108. package/dist/utils/logger.d.ts +0 -16
  109. package/dist/utils/subscribe.d.ts +0 -75
  110. package/dist/utils/uuid.d.ts +0 -4
  111. package/docs/.nojekyll +0 -1
  112. package/docs/assets/highlight.css +0 -120
  113. package/docs/assets/main.js +0 -58
  114. package/docs/assets/search.js +0 -1
  115. package/docs/assets/style.css +0 -1280
  116. package/docs/classes/BrowserRTC.html +0 -561
  117. package/docs/classes/BrowserRTC4Chime.html +0 -602
  118. package/docs/classes/CoreRTC.html +0 -432
  119. package/docs/classes/Live.html +0 -812
  120. package/docs/classes/VRWebViewRTC.html +0 -639
  121. package/docs/enums/BuiltInRTCType.html +0 -69
  122. package/docs/enums/BuiltinActionType.html +0 -112
  123. package/docs/enums/BuiltinEventType.html +0 -76
  124. package/docs/enums/Command.html +0 -134
  125. package/docs/enums/LiveState.html +0 -89
  126. package/docs/enums/MemUserStatus.html +0 -97
  127. package/docs/enums/MicroStatus.html +0 -76
  128. package/docs/enums/RTCJoinedInfoCodeEnum.html +0 -103
  129. package/docs/enums/RTCType.html +0 -79
  130. package/docs/enums/UserStatus.html +0 -85
  131. package/docs/enums/WebSocketCloseError.html +0 -139
  132. package/docs/enums/WebSocketErrorType.html +0 -104
  133. package/docs/enums/WebSocketState.html +0 -103
  134. package/docs/functions/_clearLiveInstanceIfNeed.html +0 -98
  135. package/docs/functions/createLive.html +0 -111
  136. package/docs/functions/createLiveReact.html +0 -579
  137. package/docs/functions/parseLiveMsg.html +0 -109
  138. package/docs/functions/parseWSClsErr.html +0 -103
  139. package/docs/index.html +0 -474
  140. package/docs/interfaces/AttendeeResponse.html +0 -80
  141. package/docs/interfaces/LiveOptions.html +0 -272
  142. package/docs/interfaces/MeetingResponse.html +0 -90
  143. package/docs/interfaces/MeetingSessionConfigurationOptions.html +0 -119
  144. package/docs/interfaces/Permission.html +0 -157
  145. package/docs/interfaces/RTCJoinedInfo.html +0 -104
  146. package/docs/interfaces/RTCProtocol.html +0 -424
  147. package/docs/interfaces/VRWebViewRTCOptions.html +0 -73
  148. package/docs/modules.html +0 -156
  149. package/docs/types/BuiltinMsg.html +0 -112
  150. package/docs/types/EventType.html +0 -101
  151. package/docs/types/GetVoiceSign.html +0 -109
  152. package/docs/types/GetVoiceSignParams.html +0 -111
  153. package/docs/types/GetVoiceSignReturnType.html +0 -115
  154. package/docs/types/KeyframeTypes.html +0 -101
  155. package/docs/types/LiveBuiltInData.html +0 -117
  156. package/docs/types/LiveConnectOptions.html +0 -123
  157. package/docs/types/LiveEventType.html +0 -276
  158. package/docs/types/LiveMsg.html +0 -117
  159. package/docs/types/LiveProviderPropTypes.html +0 -106
  160. package/docs/types/RTCActionReactCallback.html +0 -94
  161. package/docs/types/RTCEventType.html +0 -210
  162. package/docs/types/ReqLiveMsg.html +0 -118
  163. package/docs/types/RoomInfo.html +0 -118
  164. package/docs/types/UserInfo.html +0 -139
  165. package/docs/types/UserInfoExt.html +0 -109
  166. package/docs/types/UserVolume.html +0 -103
  167. package/docs/types/WebSocketError.html +0 -105
package/dist/index.cjs.js CHANGED
@@ -1,27 +1,41 @@
1
- "use strict";var Kt=Object.defineProperty;var Gt=(r,o,e)=>o in r?Kt(r,o,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[o]=e;var s=(r,o,e)=>(Gt(r,typeof o!="symbol"?o+"":o,e),e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const Yt=require("@realsee/jsbridge-x"),Me=require("trtc-js-sdk"),X=require("amazon-chime-sdk-js"),V=require("react"),le=Symbol("$$REALSEE_LIVE_EVENT$$");function ye(r){return r[le]||(r[le]={}),r[le]}function Jt(r){r[le]||delete r[le]}class fe{hasListener(o){const e=ye(this);return e&&e[o]&&e[o].length>0}on(o,e,i){const n=ye(this);return n[o]||(n[o]=[]),n[o].push([e,i||!1]),()=>this.off(o,e)}once(o,e){return this.on(o,e,!0)}off(o,e){if(o===void 0){Jt(this);return}const i=ye(this);if(i[o]||(i[o]=[]),e===void 0){i[o].length=0;return}let n=0;for(;n<i[o].length&&i[o][n][0]!==e;n++);n<i[o].length&&i[o].splice(n,1)}emit(o,...e){let i=!1;const a=ye(this)[o]||[];for(let u of a.slice()){const[d,g=!1]=u,_=d(...e);g&&this.off(o,d),_===!1&&(i=!0)}return i}}class we extends fe{}var ee=(r=>(r.RealseeBrowserRTC="RealseeBrowserRTC",r.RealseeVRWebViewRTC="RealseeVRWebViewRTC",r.RealseeBrowserChimeRTC="RealseeBrowserChimeRTC",r))(ee||{}),We=(r=>(r.RealseeXTRTC="trtc",r.RealseeXChimeRTC="chime",r))(We||{});const Ht=()=>{const r=new Date,o=r.getFullYear(),e=(r.getMonth()+1).toString().padStart(2,"0"),i=r.getDate().toString().padStart(2,"0"),n=r.getHours().toString().padStart(2,"0"),a=r.getMinutes().toString().padStart(2,"0"),u=r.getSeconds().toString().padStart(2,"0"),d=r.getMilliseconds();return`[${o}-${e}-${i} ${n}:${a}:${u}.${d}]`},Re=(r,o=[])=>{switch(o.unshift(`Realsee Live ${Ht()} <${r}> `),r){case"INFO":return console.info(...o);case"ERROR":return console.error(...o);case"WARN":return console.warn(...o);default:return console.log(...o)}},zt=(...r)=>Re("LOG",r),Xt=(...r)=>Re("INFO",r),Zt=(...r)=>Re("ERROR",r),Qt=(...r)=>Re("WARN",r),er={log:zt,info:Xt,error:Zt,warn:Qt},O=er;function Z(){return((1+Math.random())*65536|0).toString(16).substring(1)}function be(){return(Z()+Z()+"-"+Z()+"-4"+Z().substr(0,3)+"-"+Z()+"-"+Z()+Z()+Z()).toLowerCase()}class De extends we{constructor(e){super();s(this,"type",ee.RealseeBrowserRTC);s(this,"joined",!1);s(this,"micro",!1);s(this,"voiceId","");s(this,"_getVoiceSign",()=>{throw new Error("方法 getVoiceSign 未实现")});s(this,"_autoPlayConfirm");s(this,"checkRequirement",()=>Me.checkSystemRequirements());s(this,"$dom",document.createElement("div"));s(this,"_trtc",{client:null,stream:null});s(this,"join",async e=>{var a;this.emit("joinWillStart");const i=await this._getVoiceSign({voiceId:e.voiceId,roomId:e.roomId,userId:e.userId});this._trtc.client=Me.createClient({mode:"rtc",...i,enableAutoPlayDialog:typeof this._autoPlayConfirm!="function"}),(a=this._trtc.client)==null||a.enableAudioVolumeEvaluation(),this._registerRtcEvent();let n=await new Promise(u=>{var d;(d=this._trtc.client)==null||d.join({roomId:Number(e.voiceId)}).then(()=>u(!0)).catch(()=>u(!1))});return this.joined=n,n?(this._trtc.stream=Me.createStream({userId:i.userId,audio:!0,video:!1}),n=await new Promise(u=>{var d;(d=this._trtc.stream)==null||d.initialize().then(()=>u(!0)).catch(()=>u(!1))}),n=await new Promise(u=>{var d;(d=this._trtc.client)==null||d.publish(this._trtc.stream).then(()=>u(!0)).catch(()=>u(!1))}),this.joined=n,this.joined&&this.emit("joined"),n):!1});s(this,"_handleStreamAdded",e=>{var n;const i=e.stream;console.log("远端流增加: "+i.getId()),(n=this._trtc.client)==null||n.subscribe(i)});s(this,"_handleStreamSubscribed",e=>{const i=e.stream;console.log("远端流订阅成功:"+i.getId());const a=`rs-rtc-remote_stream-${i.getId()}`,u=document.createElement("div");u.id=a,this.$dom.appendChild(u),typeof this._autoPlayConfirm=="function"?(i.play(a).catch(d=>{}),i.on("error",d=>{if(d.getCode()===16451){const _=()=>i.resume();this._autoPlayConfirm({onConfirm:_})}})):i.play(a)});this._getVoiceSign=e.getVoiceSign,this._autoPlayConfirm=e.autoPlayConfirm,this._initParentDom()}_initParentDom(){this.$dom.id=`rs-rtc-${be()}`,this.$dom.style.display="none",document.body.appendChild(this.$dom)}quit(){return new Promise(async e=>{var i,n;this.joined=!1,this._trtc.stream&&(await((i=this._trtc.client)==null?void 0:i.unpublish(this._trtc.stream)),this._trtc.stream.stop(),this._trtc.stream.close(),this._trtc.stream=null),(n=this._trtc.client)==null||n.leave().then(()=>this._trtc.client=null).then(()=>e(!0)).catch(()=>e(!1)),e(!0)})}detectMicro(){return new Promise(e=>{const i={audio:!0,video:!1};try{navigator.mediaDevices.getUserMedia(i).then(()=>e(!0)).catch(n=>{O.error(n.message),e(!1)})}catch(n){console.error(n),e(!1)}})}toggleMicro(e){var i,n,a,u;return Promise.resolve((e?(n=(i=this._trtc)==null?void 0:i.stream)==null?void 0:n.unmuteAudio():(u=(a=this._trtc)==null?void 0:a.stream)==null?void 0:u.muteAudio())||!1)}shock(){throw new Error("Method not implemented.")}_registerRtcEvent(){var e,i,n,a;(e=this._trtc.client)==null||e.on("stream-added",this._handleStreamAdded),(i=this._trtc.client)==null||i.on("stream-subscribed",this._handleStreamSubscribed),(n=this._trtc.client)==null||n.on("audio-volume",u=>this.emit("userVolumes",u.result.map(({userId:d,audioVolume:g})=>({userId:d,audioVolume:g})))),(a=this._trtc.client)==null||a.on("error",u=>this.emit("error",u))}}class $e extends we{constructor(e){super();s(this,"type",ee.RealseeBrowserChimeRTC);s(this,"joined",!1);s(this,"micro",!1);s(this,"voiceId","");s(this,"userId","");s(this,"logger");s(this,"deviceController");s(this,"meetingSession");s(this,"audioInput");s(this,"audioOutput");s(this,"deviceChangeObserver",{});s(this,"audioVideoObserver",{});s(this,"audioMixObserver");s(this,"_getVoiceSign",()=>{throw new Error("方法 getVoiceSign 未实现")});s(this,"_autoPlayConfirm");s(this,"$dom",document.createElement("div"));s(this,"$audio",document.createElement("audio"));s(this,"_initDom",()=>{this.$audio.id=`rs-rtc-${be()}`,this.$dom.id=`rs-rtc-${be()}`,this.$dom.appendChild(this.$audio),document.body.appendChild(this.$dom)});s(this,"initObservers",()=>{this.deviceChangeObserver={audioInputsChanged:e=>{this.logger.info(`audioInputsChanged ${typeof e}`),e==null||e.forEach(i=>{this.logger.info(`Device ID: ${i.deviceId} Microphone: ${i.label}`)})},audioOutputsChanged:e=>{this.logger.info(`audioOutputsChanged ${typeof e}`),e==null||e.forEach(i=>{this.logger.info(`Device ID: ${i.deviceId} Speaker: ${i.label}`)})},audioInputMuteStateChanged:(e,i)=>{this.logger.info(`Device ${e.toString()} ${i?"is muted in hardware":"is not muted"}`)}},this.audioVideoObserver={audioVideoDidStart:()=>{this.logger.info("Started")},audioVideoDidStop:e=>{this.logger.info(`Stopped with a session status code: ${e.statusCode()}`)},audioVideoDidStartConnecting:e=>{e&&this.logger.info("Attempting to reconnect")}},this.audioMixObserver={meetingAudioStreamBecameActive:e=>{if(this.$audio.paused){const i=()=>this.$audio.play().then(()=>{}).catch(n=>{if(O.error("播放远端流失败!",n),typeof this._autoPlayConfirm=="function"){const a=()=>i();this._autoPlayConfirm({onConfirm:a})}});i()}},meetingAudioStreamBecameInactive:e=>{}}});s(this,"_registerRtcEvent",()=>{var i,n,a,u,d,g;const e=((a=(n=(i=this.meetingSession)==null?void 0:i.configuration)==null?void 0:n.credentials)==null?void 0:a.attendeeId)||"";if(e){const _=new Map,E=()=>{const y=[];return _.forEach((I,m)=>{y.push({userId:I.userId,volume:I.muted||I.signalStrength===0||!Boolean(I.volume)?0:I.volume})}),y};(u=this.meetingSession)==null||u.audioVideo.realtimeSubscribeToAttendeeIdPresence((y,I,m)=>{var D;if(!I){_.delete(y),this.emit("userVolumes",E());return}(D=this.meetingSession)==null||D.audioVideo.realtimeSubscribeToVolumeIndicator(y,(C,k,W,P)=>{new X.DefaultModality(C).base()===C&&(_.set(C,{userId:m||C,volume:k,muted:W,signalStrength:P}),this.emit("userVolumes",E()))})}),(d=this.meetingSession)==null||d.audioVideo.realtimeSubscribeToVolumeIndicator(e,(y,I,m,D)=>{new X.DefaultModality(y).base()===y&&D!==null&&D!==1&&this.emit("weakNetwork")}),(g=this.meetingSession)==null||g.audioVideo.realtimeSubscribeToFatalError(y=>this.emit("error",y))}});this._getVoiceSign=e.getVoiceSign,this._autoPlayConfirm=e.autoPlayConfirm,this._initDom(),this.logger=new X.ConsoleLogger("WebRTCLogger",e.logLevel||X.LogLevel.INFO),this.deviceController=new X.DefaultDeviceController(this.logger),this.initObservers()}async join(e){return new Promise(async(i,n)=>{var a,u;this.emit("joinWillStart");try{const{sdkAppId:d,userId:g,roomId:_,userSig:E}=await this._getVoiceSign({...e,roomId:e.roomId||0});this.userId=g;const{attendence:y,vendor_wrapper:I}=JSON.parse(decodeURIComponent(E)),m=new X.MeetingSessionConfiguration({Meeting:I},{Attendee:{ExternalUserId:y.external_user_id,AttendeeId:y.attendee_id,JoinToken:y.join_token}});this.meetingSession=new X.DefaultMeetingSession(m,this.logger,this.deviceController),this._registerRtcEvent(),this.meetingSession.audioVideo.addDeviceChangeObserver(this.deviceChangeObserver),this.meetingSession.audioVideo.addObserver(this.audioVideoObserver),this.meetingSession.audioVideo.bindAudioElement(this.$audio);const D={audioVideoDidStart:()=>{var C;(C=this.meetingSession)==null||C.audioVideo.realtimeMuteLocalAudio(),this.joined=!0,this.emit("joined"),i(!0)},audioVideoDidStop:()=>{this.joined=!1,i(!1)}};this.meetingSession.audioVideo.addObserver(D),this.audioMixObserver&&this.meetingSession.audioVideo.addAudioMixObserver(this.audioMixObserver),this.meetingSession.audioVideo.setDeviceLabelTrigger(async()=>await navigator.mediaDevices.getUserMedia({audio:!0,video:!1}));try{const C=await this.meetingSession.audioVideo.listAudioInputDevices();O.info("audioInputDevices ===>",C);const k=((a=C[0])==null?void 0:a.deviceId)||"default";await this.meetingSession.audioVideo.startAudioInput(k)}catch(C){O.error(`设置语音输入设备失败:${C.message}`)}try{const C=await this.meetingSession.audioVideo.listAudioOutputDevices();O.info("audioOutputDevices ===>",C);const k=((u=C[0])==null?void 0:u.deviceId)||"default";await this.meetingSession.audioVideo.chooseAudioOutput(k)}catch(C){O.error(`设置语音输出设备失败:${C.message}`)}this.meetingSession.audioVideo.start()}catch(d){this.emit("error",d),this.logger.error(d.message),i(!1)}})}quit(){return this.joined?new Promise((e,i)=>{var a,u;this.joined=!1;const n={audioVideoDidStop:async d=>{var _;const g=d.statusCode();(_=this.meetingSession)==null||_.deviceController.destroy(),g===X.MeetingSessionStatusCode.Left?(this.logger.info("You left the session"),e(!0)):(this.logger.info(`Stopped with a session status code: ${g}`),e(!0))}};(a=this.meetingSession)==null||a.audioVideo.addObserver(n),(u=this.meetingSession)==null||u.audioVideo.stop()}):Promise.resolve(!0)}async detectMicro(){return new Promise(e=>{const i={audio:!0,video:!1};try{navigator.mediaDevices.getUserMedia(i).then(()=>e(!0)).catch(()=>e(!1))}catch(n){this.logger.error(n.message),e(!1)}})}async toggleMicro(e){var n,a,u;e?(n=this.meetingSession)==null||n.audioVideo.realtimeUnmuteLocalAudio():(a=this.meetingSession)==null||a.audioVideo.realtimeMuteLocalAudio();const i=(u=this.meetingSession)==null?void 0:u.audioVideo.realtimeIsLocalAudioMuted();return i!==void 0?e!==i:!1}shock(){throw new Error("Method not implemented.")}}var te=(r=>(r[r.Success=0]="Success",r[r.Failure=1]="Failure",r[r.ReJoin=2]="ReJoin",r[r.NoMicroPermission=3]="NoMicroPermission",r[r.Unknown=500]="Unknown",r))(te||{});class xe extends we{constructor({jsBridge:e,getVoiceSign:i}){super();s(this,"type",ee.RealseeVRWebViewRTC);s(this,"joined",!1);s(this,"micro",!1);s(this,"voiceId","");s(this,"_joinOptions",null);s(this,"options");s(this,"handleUserVolumes",e=>{this.emit("userVolumes",e)});s(this,"handleWeakNetwork",e=>{e&&this.emit("weakNetwork")});s(this,"join",async e=>{this._joinOptions=e,this.emit("joinWillStart");const{sdkAppId:i,userId:n,userSig:a}=await this.getVoiceSignOrEmitError(e);return!i||!n||!a?!1:(this.type=e.type,this.jsBridge.webViewType==="WxMiniProgramWebView"?this.handleWxMiniProgramWebViewJoin({sdkAppId:i,userId:n,userSig:a,voiceId:e.voiceId}):this.handleAppWebViewJoin({sdkAppId:i,userId:n,userSig:a,voiceId:e.voiceId}))});s(this,"reJoin",async()=>this._joinOptions?this.join({voiceId:this._joinOptions.voiceId,userId:this._joinOptions.userId,roomId:this._joinOptions.roomId,type:this._joinOptions.type}):(this.emitErrorAndSetJoinedFalse("重连失败:未找到加入房间参数。"),!1));s(this,"getVoiceSignOrEmitError",async e=>{try{return await this.options.getVoiceSign(e)}catch(i){return this.emitErrorAndSetJoinedFalse("加入房间失败:rtc 签名请求异常"),{}}});s(this,"handleWxMiniProgramWebViewJoin",async e=>{const[i,n]=await this.joinRoomOrEmitError(e);return n?!1:this.handleJoinResult(i)});s(this,"handleAppWebViewJoin",e=>new Promise(i=>{this.off("inner.rtc.success");const n=a=>{this.off("inner.rtc.fail",n),this.off("inner.rtc.success",n),i(this.handleJoinResult(a))};this.once("inner.rtc.fail",n),this.once("inner.rtc.success",n);try{const{sdkAppId:a,userId:u,userSig:d,voiceId:g}=e;this.jsBridge.callAndListen(`live/join?sdkAppID=${a}&userID=${u}&roomID=${g}&userSig=${d}`,_=>{_===!0?this.emit("inner.rtc.success",_):typeof _=="object"?_.code===te.Success||_.code===te.ReJoin?this.emit("inner.rtc.success",_):this.emit("inner.rtc.fail",_):this.emit("inner.rtc.fail",_)})}catch(a){i(this.handleJoinResult({message:a.message,code:te.Unknown}))}}));s(this,"joinRoomOrEmitError",async({sdkAppId:e,userId:i,voiceId:n,userSig:a})=>{try{return await this.jsBridge.callAndBackfeed(`live/join?sdkAppID=${e}&userID=${i}&roomID=${Number(n)}&userSig=${a}`)}catch(u){return this.emitErrorAndSetJoinedFalse("加入房间失败:"+u.message),[null,u]}});s(this,"handleJoinResult",e=>{switch(!0){case e===!0:case(typeof e=="object"&&e.code===te.Success):case(typeof e=="object"&&e.code===te.ReJoin):{this.emit("joined"),this.joined=!0;break}default:{this.joined=!1;const i=typeof e=="object"?e.message:"加入房间失败:未知异常。";this.emit("error",new Error(i,{cause:e}))}}return this.joined});s(this,"emitErrorAndSetJoinedFalse",e=>{this.emit("error",new Error(e)),this.joined=!1});s(this,"quit",async()=>{const[e,i]=await this.jsBridge.callAndBackfeed("live/quit");return e===null&&this.emit("error",i||new Error("退出房间失败:未知异常。")),this.joined=!1,!!e});s(this,"detectMicro",async()=>{const[e,i]=await this.jsBridge.detectMicro();return e===null?(this.emit("error",i||new Error("麦克风监测异常!")),!1):e});s(this,"toggleMicro",async e=>{const[i,n]=await this.jsBridge.callAndBackfeed(`live/toggleMicro?flag=${Boolean(e)?1:0}`);return i===null?(this.emit("error",n||new Error("麦克风监测异常!")),!1):(this.micro=i,i)});s(this,"shock",()=>{this.jsBridge.shock(1)});this.options={jsBridge:e,getVoiceSign:i},this.jsBridge.webViewType!=="WxMiniProgramWebView"&&this.jsBridge.callAndListen("live/userVolumes",this.handleUserVolumes),this.jsBridge.callAndListen("live/weakNetwork",this.handleWeakNetwork),this.on("inner.rtc.fail",this.handleJoinResult)}get jsBridge(){return this.options.jsBridge}}var U=(r=>(r.SelfUserInfo="SELF_USER_INFO",r.RoomInfo="ROOM_INFO",r.RTCInfo="RTC_INFO",r.UserList="USER_LIST",r.BuiltinMsg="BUILTIN_MSG",r.CustomEvent="CUSTOM_EVENT",r.KeyframeSync="KEYFRAME_SYNC",r.UserKickOut="USER_KICK_OUT",r))(U||{}),K=(r=>(r.UserChange="user_change",r.RoomChange="room_change",r))(K||{}),Y=(r=>(r.UserMicroStatus="change_micro_status",r.UserMicroStatusSync="sync_micro_status",r.UserPermission="change_permission",r.UserStatus="change_status",r.UserInfo="change_info",r.RoomClose="close",r))(Y||{}),Q=(r=>(r.OPEN="OPEN",r.CLOSE="CLOSE",r))(Q||{});function tr(r){try{const o=JSON.parse(r),e={code:o.code,message:o.message,command:o.command,roomCode:o.room_code,appID:o.app_id,requestId:o.request_id,frontRequestId:o.front_request_id,triggerUserID:o.trigger_user_id,data:o.data||{}},i=Object.keys(e).filter(n=>e[n]===void 0);return i.length>0&&console.warn(`推送数据格式异常:${i.join(" ")} 值不存在!`),e}catch(o){return!1}}var $=(r=>(r[r.NOTINITIALIZED=-1]="NOTINITIALIZED",r[r.CONNECTING=0]="CONNECTING",r[r.OPEN=1]="OPEN",r[r.CLOSED=3]="CLOSED",r))($||{}),ft=(r=>(r[r.Normal=0]="Normal",r[r.Removed=1]="Removed",r[r.Replaced=2]="Replaced",r))(ft||{}),dt=(r=>(r.WAIT_ENTER="WAIT_ENTER",r.ONLINE="ONLINE",r.LEAVE="LEAVE",r.KICK_OUT="KICK_OUT",r.BE_REPLACE="BE_REPLACE",r.EXCEPTION="EXCEPTION",r))(dt||{}),Se=(r=>(r[r.NOTINITIALIZED=-1]="NOTINITIALIZED",r[r.CONNECTING=0]="CONNECTING",r[r.OPEN=1]="OPEN",r[r.CLOSING=2]="CLOSING",r[r.CLOSED=3]="CLOSED",r))(Se||{}),ht=(r=>(r.Error="Error",r.Close="Close",r.MicroAuth="MicroAuth",r.DuplicateConnect="DuplicateConnect",r.IllegalURL="IllegalURL",r.Unknown="Unknown",r.IllegalArgs="IllegalArgs",r))(ht||{}),_t=(r=>(r.Err_1000="CLOSE_NORMAL",r.Err_1001="CLOSE_GOING_AWAY",r.Err_1002="CLOSE_PROTOCOL_ERROR",r.Err_1003="CLOSE_UNSUPPORTED",r.Err_1006="CLOSE_ABNORMAL",r.Err_1007="Unsupported Data",r.Err_1008="Policy Violation",r.Err_1009="CLOSE_TOO_LARGE",r.Err_unknown="unknown",r))(_t||{});function gt(r){switch(r){case 1e3:return"CLOSE_NORMAL";case 1001:return"CLOSE_GOING_AWAY";case 1002:return"CLOSE_PROTOCOL_ERROR";case 1003:return"CLOSE_UNSUPPORTED";case 1006:return"CLOSE_ABNORMAL";case 1007:return"Unsupported Data";case 1008:return"Policy Violation";case 1009:return"CLOSE_TOO_LARGE"}return"unknown"}function rr(r){return r&&r.__esModule&&Object.prototype.hasOwnProperty.call(r,"default")?r.default:r}var mt={};(function(r){Object.defineProperty(r,"__esModule",{value:!0}),r.LogLevel=void 0;var o;(function(e){e[e.DEBUG=0]="DEBUG",e[e.INFO=1]="INFO",e[e.WARN=2]="WARN",e[e.ERROR=3]="ERROR",e[e.OFF=4]="OFF"})(o=r.LogLevel||(r.LogLevel={})),r.default=o})(mt);const at=rr(mt);function ir(r,o={}){const e=r.indexOf("?")!==-1,i=Object.keys(o).reduce((n,a,u)=>`${n}${u===0&&!e?"?":"&"}${a}=${o[a]}`,"");return r+i}const de=globalThis.navigator.userAgent,nr=/android/gi.test(de),sr=/iPhone|iPad\s+OS/gi.test(de),or=/MicroMessenger/gi.test(de)&&/miniProgram/gi.test(de),ar=/realsee/gi.test(de);function Ce(r){return Object.prototype.toString.call(r)==="[object Object]"}function Oe(r,o){return r===o?!0:typeof r!=typeof o?!1:!!(Number.isNaN(r)&&Number.isNaN(o))}function cr(r,o){const e=Object.getOwnPropertyNames(r),i=Object.getOwnPropertyNames(o);if(e.length!==i.length)return!1;for(let n=0,a=e.length;n<a;n++){const u=e[n];if(!Oe(r[u],o[u]))return!1}return!0}function ur(r,o){if(r.length!==o.length)return!1;for(let e=0,i=r.length;e<i;e++)if(!Oe(r[e],o[e]))return!1;return!0}function lr(r,o){return Oe(r,o)?!0:Ce(r)&&Ce(o)?cr(r,o):Array.isArray(r)&&Array.isArray(o)?ur(r,o):!1}function Fe(r,o){return Oe(r,o)?!0:Ce(r)&&Ce(o)?dr(r,o):Array.isArray(r)&&Array.isArray(o)?fr(r,o):!1}function fr(r,o){if(r.length!==o.length)return!1;for(let e=0,i=r.length;e<i;e++)if(!Fe(r[e],o[e]))return!1;return!0}function dr(r,o){const e=Object.getOwnPropertyNames(r),i=Object.getOwnPropertyNames(o);if(e.length!==i.length)return!1;for(let n=0,a=e.length;n<a;n++){const u=e[n];if(!Fe(r[u],o[u]))return!1}return!0}function ct(r,o,e={deep:!1}){return e.deep?Fe(r,o):lr(r,o)}class hr extends fe{constructor(e){super();s(this,"_realWebSocket");s(this,"_url");s(this,"_protocols");s(this,"_readyState",Se.NOTINITIALIZED);s(this,"_options",{timeout:1e4,shouldReconnect:(e,i)=>{if(!(e.code===1008||e.code===1011))return[0,1e3,2e3][i.attempts%3]},should1000Reconnect:!1,ignoreConnectivityEvents:!1,automaticOpen:!1});s(this,"_connectTimeout");s(this,"_attempts",0);s(this,"_reconnects",-1);s(this,"_reconnectWhenOnlineAgain",!1);s(this,"_explicitlyClosed",!1);s(this,"_pendingReconnect");s(this,"_connectivityEventsAttached",!1);s(this,"_heathCheckTimer");s(this,"_healthCheck",async()=>{this._realWebSocket&&this._realWebSocket.readyState!==this._readyState&&(this._readyState=this._realWebSocket.readyState,this._readyState===Se.CLOSING&&this.emit("closing")),await new Promise(e=>setTimeout(e,2e3)),this._heathCheckTimer=requestAnimationFrame(this._healthCheck)});s(this,"_clearConnectTimeoutIfNeed",()=>{this._connectTimeout&&(clearTimeout(this._connectTimeout),this._connectTimeout=void 0)});s(this,"_clearHeathCheckIfNeed",()=>{this._heathCheckTimer&&(cancelAnimationFrame(this._heathCheckTimer),this._heathCheckTimer=void 0)});s(this,"_startHealthCheck",()=>{this._clearHeathCheckIfNeed(),this._heathCheckTimer=requestAnimationFrame(this._healthCheck)});s(this,"_stopHealthCheck",()=>{this._clearHeathCheckIfNeed()});s(this,"_clearPendingReconnectIfNeeded",()=>{this._pendingReconnect&&(clearTimeout(this._pendingReconnect),this._pendingReconnect=void 0)});s(this,"_online",e=>{this._reconnectWhenOnlineAgain&&(this._clearPendingReconnectIfNeeded(),this._reconnect(e))});s(this,"_offline",()=>{var e;this._reconnectWhenOnlineAgain=!0,(e=this._realWebSocket)==null||e.close(1e3,"offline")});s(this,"_detachConnectivityEvents",()=>{this._connectivityEventsAttached&&(globalThis==null||globalThis.removeEventListener("online",this._online),globalThis==null||globalThis.removeEventListener("offline",this._offline),this._connectivityEventsAttached=!1)});s(this,"_attachConnectivityEvents",()=>{this._connectivityEventsAttached||(globalThis==null||globalThis.addEventListener("online",this._online),globalThis==null||globalThis.addEventListener("offline",this._offline),this._connectivityEventsAttached=!0)});s(this,"send",e=>{var i,n,a;((i=this._realWebSocket)==null?void 0:i.readyState)===((n=this._realWebSocket)==null?void 0:n.OPEN)&&((a=this._realWebSocket)==null||a.send(e))});s(this,"close",(e,i)=>{var n;return typeof e!="number"&&(i=e,e=1e3),this._clearPendingReconnectIfNeeded(),this._reconnectWhenOnlineAgain=!1,this._explicitlyClosed=!0,this._detachConnectivityEvents(),(n=this._realWebSocket)==null?void 0:n.close(e,i)});s(this,"open",e=>{var i,n;e&&(this._url=e),((i=this._realWebSocket)==null?void 0:i.readyState)!==WebSocket.OPEN&&((n=this._realWebSocket)==null?void 0:n.readyState)!==WebSocket.CONNECTING&&(this._clearPendingReconnectIfNeeded(),this._reconnectWhenOnlineAgain=!1,this._explicitlyClosed=!1,this._createWebSocket())});s(this,"_createWebSocket",()=>{var n,a,u;const e=typeof this._url=="string"?this._url:(n=this._url)==null?void 0:n.call(this,this);if(!e)return;this._clearConnectTimeoutIfNeed(),this._clearPendingReconnectIfNeeded(),this._removeWebSocketEvent(),this._realWebSocket=new WebSocket(e,this._protocols||void 0),this._attempts=this._attempts+1,this.emit("connecting",new CustomEvent("connecting",{detail:{attempts:this._attempts,reconnects:this._reconnects}}));const i=()=>{this._connectTimeout=void 0,this._detachConnectivityEvents(),this.emit("timeout",new CustomEvent("timeout",{detail:{attempts:this._attempts,reconnects:this._reconnects}}))};this._connectTimeout=setTimeout(i,(a=this._options)==null?void 0:a.timeout),this._dispatchWebSocketEvent(),(u=this._options)!=null&&u.ignoreConnectivityEvents||this._attachConnectivityEvents()});s(this,"_removeWebSocketEvent",()=>{var e,i,n,a;(e=this._realWebSocket)==null||e.removeEventListener("open",this._webSocketOpenHandler),(i=this._realWebSocket)==null||i.removeEventListener("close",this._webSocketCloseHandler),(n=this._realWebSocket)==null||n.removeEventListener("error",this._webSocketErrorHandler),(a=this._realWebSocket)==null||a.removeEventListener("message",this._webSocketMessageHandler)});s(this,"_dispatchWebSocketEvent",()=>{var e,i,n,a;(e=this._realWebSocket)==null||e.addEventListener("open",this._webSocketOpenHandler),(i=this._realWebSocket)==null||i.addEventListener("close",this._webSocketCloseHandler),(n=this._realWebSocket)==null||n.addEventListener("error",this._webSocketErrorHandler),(a=this._realWebSocket)==null||a.addEventListener("message",this._webSocketMessageHandler)});s(this,"_webSocketOpenHandler",e=>{this._connectTimeout&&(clearTimeout(this._connectTimeout),this._connectTimeout=void 0);const i=++this._reconnects,n=this._attempts;return this._attempts=0,this._reconnectWhenOnlineAgain=!1,this._startHealthCheck(),this.emit("open",Object.assign(e,{detail:{reconnects:i,attempts:n}}))});s(this,"_webSocketCloseHandler",e=>(this._reconnect(e),this._stopHealthCheck(),this.emit("close",e)));s(this,"_webSocketErrorHandler",e=>this.emit("error",new CustomEvent("error",{detail:{error:e}})));s(this,"_webSocketMessageHandler",e=>this.emit("message",e));e&&this.setOptions(e),this._startHealthCheck()}get attempts(){return this._attempts}setOptions(e){if(!e)return;this._url=e.url,this._protocols=e.protocols;const i=Object.assign(this._options,e.robustOptions||{});if(typeof(i==null?void 0:i.timeout)!="number")throw new Error("timeout must be the number of milliseconds to timeout a connection attempt");if(typeof(i==null?void 0:i.shouldReconnect)!="function")throw new Error("shouldReconnect must be a function that returns the number of milliseconds to wait for a reconnect attempt, or null or undefined to not reconnect.");this._options=i,this._options.automaticOpen&&this._createWebSocket()}_reconnect(e){var n,a,u,d;if(!((n=this._options)!=null&&n.should1000Reconnect)&&e.code===1e3||this._explicitlyClosed){this._attempts=0;return}if(this._connectivityEventsAttached&&((a=globalThis==null?void 0:globalThis.navigator)==null?void 0:a.onLine)===!1){this._reconnectWhenOnlineAgain=!0;return}const i=(d=(u=this._options)==null?void 0:u.shouldReconnect)==null?void 0:d.call(u,e,this);typeof i=="number"&&(this._pendingReconnect=setTimeout(this._createWebSocket,i))}}class _r extends fe{constructor(){super();s(this,"_ws",new hr({url:"",robustOptions:{should1000Reconnect:!0,ignoreConnectivityEvents:!0}}));s(this,"_state",$.NOTINITIALIZED);s(this,"_addWebSocketEventListeners",()=>{this._ws.on("close",this._handleCloseEvent),this._ws.on("closing",this._handleClosingEvent),this._ws.on("connecting",this._handleConnectingEvent),this._ws.on("error",this._handleErrorEvent),this._ws.on("message",this._handleMessageEvent),this._ws.on("open",this._handleOpenEvent),this._ws.on("timeout",this._handleTimeoutEvent)});s(this,"_removeWebSocketEventListeners",()=>{this._ws.off("close",this._handleCloseEvent),this._ws.off("closing",this._handleClosingEvent),this._ws.off("connecting",this._handleConnectingEvent),this._ws.off("error",this._handleErrorEvent),this._ws.off("message",this._handleMessageEvent),this._ws.off("open",this._handleOpenEvent),this._ws.off("timeout",this._handleTimeoutEvent)});s(this,"_handleCloseEvent",e=>{O.info(`live room closed bacause of ${e.code}-${e.reason||gt(e.code)}`),this.state=$.CLOSED});s(this,"_handleClosingEvent",()=>{var e;O.info("live room is closing, onLine:",(e=globalThis==null?void 0:globalThis.navigator)==null?void 0:e.onLine),this.state=$.CLOSED});s(this,"_handleConnectingEvent",e=>{O.info("live room is connecting"),this.state=$.CONNECTING,e.detail.reconnects>0&&this.emit("reconnecting",e.detail)});s(this,"_handleErrorEvent",e=>{O.error("live room error",e),this.state=$.CLOSED});s(this,"_handleMessageEvent",e=>{let i=(()=>{try{return JSON.parse(e.data)}catch(n){return e.data}})();this.emit("message",i)});s(this,"_handleOpenEvent",e=>{O.info("live room open",e.detail),this.state=$.OPEN,e.detail.reconnects>0&&this.emit("reconnected",e.detail)});s(this,"_handleTimeoutEvent",e=>{O.error("live room connect timeout!",e.detail),this.state=$.CLOSED});s(this,"dispose",async()=>(this._removeWebSocketEventListeners(),await this.close("live room close by controller disposed!")));s(this,"open",e=>this._ws.open(e));s(this,"close",(e,i)=>new Promise(n=>{this._ws.once("close",()=>n(!0)),this._ws.close(e,i)}));this._addWebSocketEventListeners()}set state(e){const i=JSON.parse(JSON.stringify(this._state));this._state=e,this.emit("stateChange",this.state,i)}get state(){return this._state}sendMessage(e=""){if(e==null||e==="")throw new Error("live message is empty!");if(this.state===$.OPEN)return this._ws.send(JSON.stringify(e));throw new Error("live has not yet been initialized!")}readyClose(){this._ws&&(this._ws._explicitlyClosed=!0)}}const gr=r=>Promise.reject("unimplemented method GetVoiceSign"),Ve=(r,o={},e=[])=>({command:r,front_request_id:be(),data:{...o,to_user_ids:Array.isArray(e)?e:[e]}}),vt=()=>{var r,o;window!=null&&window.__Realsee_Live__&&((o=(r=window==null?void 0:window.__Realsee_Live__)==null?void 0:r.dispose)==null||o.call(r),window.__Realsee_Live__=null)};class pt extends fe{constructor(e){var i;super();s(this,"_options",{});s(this,"keyframes",new fe);s(this,"_buildInData",{keyframes:{}});s(this,"getFramesByKey",e=>this.snapshot[e]);s(this,"sendKeyframe",(e,i)=>{if(this.state!==$.OPEN)return!1;this._buildInData.keyframes={...this._buildInData.keyframes,[e]:i};const n=Ve(U.KeyframeSync,this.snapshot);try{return this._controller.sendMessage(n),!0}catch(a){return O.error(a),!1}});s(this,"_controller",new _r);s(this,"_addLiveControllerEventListeners",()=>{this._controller.on("stateChange",this._handleStateChange),this._controller.on("message",this._handleMessage)});s(this,"_removeLiveControllerEventListeners",()=>{this._controller.off("stateChange",this._handleStateChange),this._controller.off("message",this._handleMessage)});s(this,"_handleStateChange",(e,i)=>this.emit("stateChange",e,i));s(this,"_handleMessage",async e=>{var i,n,a,u,d;if(typeof e=="object"){const{command:g,data:_={},frontRequestId:E,code:y,message:I}=e;if(y==="SUCCESS")switch(g){case U.SelfUserInfo:{const m=_;ct(this.selfInfo,m,{deep:!0})||(this._buildInData.selfInfo=m,this.emit("selfInfoUpdate",this._buildInData.selfInfo,E));break}case U.RoomInfo:{const m=_;this._buildInData.roomInfo=Object.assign({},m),this.emit("readyKeyframeSync",m.last_frame||{});break}case U.RTCInfo:{const{voice_id:m,type:D}=_;if(this._buildInData.rtcInfo={voiceId:m,type:D},(i=this.$RTC)!=null&&i.joined)O.warn("已加入语音房间,无需重复加入!");else if(await((u=this.$RTC)==null?void 0:u.join({voiceId:m,userId:((n=this.selfInfo)==null?void 0:n.id)||"",roomId:(a=this.roomInfo)==null?void 0:a.info.room_code,type:D}))){const k=(d=this._options.initialMicroStatus)!=null?d:Q.OPEN;await this.toggleMicro(k===Q.OPEN)}else O.error("加入语音房间失败");break}case U.UserList:{const m=_;this._buildInData.userList=m,this.emit("userListUpdate",this.userList,E);break}case U.CustomEvent:{const m=_;this.emit("broadcast",m,E);break}case U.KeyframeSync:{const m=_,D=Object.keys(m).reduce((C,k)=>{if(ct(m[k],this._buildInData.keyframes[k],{deep:!0}))return C;const W=[m[k],this._buildInData.keyframes[k],E],P=k;return this.keyframes.emit(P,...W),this._buildInData.keyframes[k]=m[k],C[k]=m[k],C},{});this.emit("keyframes",D,E);break}case U.BuiltinMsg:{const m=_;this.emit("builtinEvent",m),m.event_type===K.UserChange&&this.emit("userChange",m),m.event_type===K.RoomChange&&this.emit("roomChange",m),m.event_type===K.UserChange&&m.action===Y.UserMicroStatus&&await this.toggleMicro(m.data.status===Q.OPEN),m.event_type===K.RoomChange&&m.action===Y.RoomClose&&await this._exit();break}case U.UserKickOut:{this.emit("kickOut");break}default:console.warn("unknown command: ",g)}else this.emit("error",e)}});s(this,"_clearLiveData",()=>{this._buildInData={keyframes:{}}});s(this,"connect",async(e={})=>{var u,d,g,_;if(this._options.url=(d=(u=e.url)!=null?u:this._options.url)!=null?d:"",this._options.getTicket=(g=e.getTicket)!=null?g:this._options.getTicket,this._options.initialMicroStatus=(_=e.rtcMicStatus)!=null?_:this._options.initialMicroStatus,!/^ws(s):\/\//.test(this._options.url)||typeof this._options.getTicket!="function")return/^ws(s):\/\//.test(this._options.url)?typeof this._options.getTicket!="function"?new Error("getTicket muse be function"):!1:new Error("Illegal realsee live room link");const{force:i=!1}=e;if(this._options.rtc&&!await this._options.rtc.detectMicro())return new Error("Failed to obtain microphone authorization");const n=this.state;if(n===$.CONNECTING||n===$.OPEN)if(i)try{await this._controller.close("force close by connect")}catch(E){console.warn(E)}else return new Error("已有Live实例正在连接中,请勿重复连接!");this._clearLiveData();const a=ir(this._options.url,{ticket:await this._options.getTicket(),force:Number(!!i)});return this._controller.open(a),!0});s(this,"_exit",async()=>{var e;this._clearLiveData();try{await((e=this.$RTC)==null?void 0:e.quit())}catch(i){O.warn(i)}return this.state!==$.OPEN?!0:await this._controller.close()});s(this,"exit",async()=>this.close());s(this,"close",async()=>{var e;await this._controller.readyClose();try{await((e=this.$RTC)==null?void 0:e.quit())}catch(i){O.warn(i)}await this.updateStatus(K.RoomChange,Y.RoomClose,{})});s(this,"dispose",async()=>(this._removeLiveControllerEventListeners(),this._clearLiveData(),await this._controller.dispose()));s(this,"setSelfInfo",async e=>await this.updateStatus(K.UserChange,Y.UserInfo,e));s(this,"toggleMicro",async e=>{var n,a,u;if(!((a=(n=this.selfInfo)==null?void 0:n.permission)!=null&&a.control_own_micro))return!1;const i=await((u=this.$RTC)==null?void 0:u.toggleMicro(e));return i&&await this.updateStatus(K.UserChange,Y.UserMicroStatus,{status:e?Q.OPEN:Q.CLOSE},[]),i});s(this,"forbidMicro",async(e,i)=>{var n,a;return typeof this._options.canForbidUserMicro=="function"&&!this._options.canForbidUserMicro(i)||!((a=(n=this.selfInfo)==null?void 0:n.permission)!=null&&a.control_other_micro)?!1:await this.updateStatus(K.UserChange,Y.UserMicroStatus,{status:e},i)});s(this,"forbidSync",async(e,i)=>{var n,a;return typeof this._options.canForbidUserSync=="function"&&!this._options.canForbidUserSync(i)||!((a=(n=this.selfInfo)==null?void 0:n.permission)!=null&&a.control_other_sync)?!1:await this.updateStatus(K.UserChange,Y.UserPermission,{sync_frame:e},i)});s(this,"kick",async e=>{var i,n;return typeof this._options.canForbidUserKick=="function"&&!this._options.canForbidUserKick(e)||!((n=(i=this.selfInfo)==null?void 0:i.permission)!=null&&n.change_other_status)?!1:await this.updateStatus(K.UserChange,Y.UserStatus,{status:"KICK_OUT"},e)});this._addLiveControllerEventListeners(),this._options=Object.assign({initialMicroStatus:Q.OPEN},e),this._options.jsBridge=(()=>{if(e.jsBridge)return e.jsBridge;if(e.useBuiltInJsBridge)return new Yt})(),this._options.getVoiceSign=(i=e.getVoiceSign)!=null?i:gr,this._options.autoPlayConfirm=e.autoPlayConfirm,this._options.rtc=(()=>{if(e.rtc)return e.rtc;if(e.rtcType)switch(e.getVoiceSign||O.error("GetVoiceSign method must be passed when using built-in RTC instances"),e.rtcType){case ee.RealseeVRWebViewRTC:{if(this._options.jsBridge)return new xe({jsBridge:this._options.jsBridge,getVoiceSign:this._options.getVoiceSign});O.error("JsBridge instance must be passed when using built-in VRWebViewRTC instances");return}case ee.RealseeBrowserChimeRTC:return new $e({getVoiceSign:this._options.getVoiceSign,logLevel:e.__debug__?at.DEBUG:at.INFO});case ee.RealseeBrowserRTC:return this._options.autoPlayConfirm||O.error("autoPlayConfirm method must be passed when using built-in RealseeBrowserRTC instances"),new De({getVoiceSign:this._options.getVoiceSign,autoPlayConfirm:this._options.autoPlayConfirm});default:{O.error("unknown built-in RTC type");return}}if(e.useBuiltInRTC){if(e.getVoiceSign||O.error("GetVoiceSign method must be passed when using built-in RTC instances"),this._options.jsBridge)return ar&&(nr||sr)||or?new xe({jsBridge:this._options.jsBridge,getVoiceSign:this._options.getVoiceSign}):e.builtInRTCType===We.RealseeXChimeRTC?new $e({getVoiceSign:this._options.getVoiceSign}):new De({getVoiceSign:this._options.getVoiceSign,autoPlayConfirm:this._options.autoPlayConfirm});O.error("jsBridge instance must be passed when using built-in RTC instances");return}})(),this._options.rtc||O.warn("unused rtc"),this._options.url&&this._options.getTicket&&this.connect(),this._options.__debug__&&Object.assign(window,{$liveController:this._controller,$live:this})}get options(){return Object.freeze(this._options||{})}get state(){return this._controller.state}get readyState(){return this._controller.state}get url(){return this.options.url}get $RTC(){return this._options.rtc}get jsBridge(){return this._options.jsBridge}get snapshot(){return this._buildInData.keyframes}get selfInfo(){return this._buildInData.selfInfo}get userList(){return this._buildInData.userList||[]}get roomInfo(){return this._buildInData.roomInfo}async updateStatus(e,i,n,a){if(this.state!==$.OPEN)return!1;const u=Object.assign({event_type:e,action:i},{data:n}),d=Ve(U.BuiltinMsg,u,a);try{return this._controller.sendMessage(d),!0}catch(g){return O.error(g),!1}}broadcast(e,i,n){return this.state!==$.OPEN?!1:new Promise((a,u)=>{const d=Ve(U.CustomEvent,e,i),g=d.front_request_id,_=n?setTimeout(()=>{u(new Error("RESPONSE TIMEOUT")),this.off("broadcast",E)},n):void 0,E=(y,I)=>{I===g&&(_&&clearTimeout(_),this.off("broadcast",E),a(y))};this.on("broadcast",E);try{this._controller.sendMessage(d)}catch(y){u(y)}})}}const Et=r=>(vt(),new pt(r));var Ue={},mr={get exports(){return Ue},set exports(r){Ue=r}},ce={};/**
2
- * @license React
3
- * react-jsx-runtime.production.min.js
4
- *
5
- * Copyright (c) Facebook, Inc. and its affiliates.
6
- *
7
- * This source code is licensed under the MIT license found in the
8
- * LICENSE file in the root directory of this source tree.
9
- */var ut;function vr(){if(ut)return ce;ut=1;var r=V,o=Symbol.for("react.element"),e=Symbol.for("react.fragment"),i=Object.prototype.hasOwnProperty,n=r.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,a={key:!0,ref:!0,__self:!0,__source:!0};function u(d,g,_){var E,y={},I=null,m=null;_!==void 0&&(I=""+_),g.key!==void 0&&(I=""+g.key),g.ref!==void 0&&(m=g.ref);for(E in g)i.call(g,E)&&!a.hasOwnProperty(E)&&(y[E]=g[E]);if(d&&d.defaultProps)for(E in g=d.defaultProps,g)y[E]===void 0&&(y[E]=g[E]);return{$$typeof:o,type:d,key:I,ref:m,props:y,_owner:n.current}}return ce.Fragment=e,ce.jsx=u,ce.jsxs=u,ce}var ue={};/**
10
- * @license React
11
- * react-jsx-runtime.development.js
12
- *
13
- * Copyright (c) Facebook, Inc. and its affiliates.
14
- *
15
- * This source code is licensed under the MIT license found in the
16
- * LICENSE file in the root directory of this source tree.
17
- */var lt;function pr(){return lt||(lt=1,process.env.NODE_ENV!=="production"&&function(){var r=V,o=Symbol.for("react.element"),e=Symbol.for("react.portal"),i=Symbol.for("react.fragment"),n=Symbol.for("react.strict_mode"),a=Symbol.for("react.profiler"),u=Symbol.for("react.provider"),d=Symbol.for("react.context"),g=Symbol.for("react.forward_ref"),_=Symbol.for("react.suspense"),E=Symbol.for("react.suspense_list"),y=Symbol.for("react.memo"),I=Symbol.for("react.lazy"),m=Symbol.for("react.offscreen"),D=Symbol.iterator,C="@@iterator";function k(t){if(t===null||typeof t!="object")return null;var c=D&&t[D]||t[C];return typeof c=="function"?c:null}var W=r.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function P(t){{for(var c=arguments.length,l=new Array(c>1?c-1:0),h=1;h<c;h++)l[h-1]=arguments[h];he("error",t,l)}}function he(t,c,l){{var h=W.ReactDebugCurrentFrame,b=h.getStackAddendum();b!==""&&(c+="%s",l=l.concat([b]));var R=l.map(function(p){return String(p)});R.unshift("Warning: "+c),Function.prototype.apply.call(console[t],console,R)}}var f=!1,w=!1,A=!1,S=!1,N=!1,M;M=Symbol.for("react.module.reference");function F(t){return!!(typeof t=="string"||typeof t=="function"||t===i||t===a||N||t===n||t===_||t===E||S||t===m||f||w||A||typeof t=="object"&&t!==null&&(t.$$typeof===I||t.$$typeof===y||t.$$typeof===u||t.$$typeof===d||t.$$typeof===g||t.$$typeof===M||t.getModuleId!==void 0))}function H(t,c,l){var h=t.displayName;if(h)return h;var b=c.displayName||c.name||"";return b!==""?l+"("+b+")":l}function oe(t){return t.displayName||"Context"}function G(t){if(t==null)return null;if(typeof t.tag=="number"&&P("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),typeof t=="function")return t.displayName||t.name||null;if(typeof t=="string")return t;switch(t){case i:return"Fragment";case e:return"Portal";case a:return"Profiler";case n:return"StrictMode";case _:return"Suspense";case E:return"SuspenseList"}if(typeof t=="object")switch(t.$$typeof){case d:var c=t;return oe(c)+".Consumer";case u:var l=t;return oe(l._context)+".Provider";case g:return H(t,t.render,"ForwardRef");case y:var h=t.displayName||null;return h!==null?h:G(t.type)||"Memo";case I:{var b=t,R=b._payload,p=b._init;try{return G(p(R))}catch(v){return null}}}return null}var z=Object.assign,re=0,T,B,ie,_e,Be,qe,Ke;function Ge(){}Ge.__reactDisabledLog=!0;function yt(){{if(re===0){T=console.log,B=console.info,ie=console.warn,_e=console.error,Be=console.group,qe=console.groupCollapsed,Ke=console.groupEnd;var t={configurable:!0,enumerable:!0,value:Ge,writable:!0};Object.defineProperties(console,{info:t,log:t,warn:t,error:t,group:t,groupCollapsed:t,groupEnd:t})}re++}}function bt(){{if(re--,re===0){var t={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:z({},t,{value:T}),info:z({},t,{value:B}),warn:z({},t,{value:ie}),error:z({},t,{value:_e}),group:z({},t,{value:Be}),groupCollapsed:z({},t,{value:qe}),groupEnd:z({},t,{value:Ke})})}re<0&&P("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var Ie=W.ReactCurrentDispatcher,Te;function ge(t,c,l){{if(Te===void 0)try{throw Error()}catch(b){var h=b.stack.trim().match(/\n( *(at )?)/);Te=h&&h[1]||""}return`
18
- `+Te+t}}var ke=!1,me;{var St=typeof WeakMap=="function"?WeakMap:Map;me=new St}function Ye(t,c){if(!t||ke)return"";{var l=me.get(t);if(l!==void 0)return l}var h;ke=!0;var b=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var R;R=Ie.current,Ie.current=null,yt();try{if(c){var p=function(){throw Error()};if(Object.defineProperty(p.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(p,[])}catch(J){h=J}Reflect.construct(t,[],p)}else{try{p.call()}catch(J){h=J}t.call(p.prototype)}}else{try{throw Error()}catch(J){h=J}t()}}catch(J){if(J&&h&&typeof J.stack=="string"){for(var v=J.stack.split(`
19
- `),x=h.stack.split(`
20
- `),j=v.length-1,L=x.length-1;j>=1&&L>=0&&v[j]!==x[L];)L--;for(;j>=1&&L>=0;j--,L--)if(v[j]!==x[L]){if(j!==1||L!==1)do if(j--,L--,L<0||v[j]!==x[L]){var q=`
21
- `+v[j].replace(" at new "," at ");return t.displayName&&q.includes("<anonymous>")&&(q=q.replace("<anonymous>",t.displayName)),typeof t=="function"&&me.set(t,q),q}while(j>=1&&L>=0);break}}}finally{ke=!1,Ie.current=R,bt(),Error.prepareStackTrace=b}var se=t?t.displayName||t.name:"",ot=se?ge(se):"";return typeof t=="function"&&me.set(t,ot),ot}function Ct(t,c,l){return Ye(t,!1)}function wt(t){var c=t.prototype;return!!(c&&c.isReactComponent)}function ve(t,c,l){if(t==null)return"";if(typeof t=="function")return Ye(t,wt(t));if(typeof t=="string")return ge(t);switch(t){case _:return ge("Suspense");case E:return ge("SuspenseList")}if(typeof t=="object")switch(t.$$typeof){case g:return Ct(t.render);case y:return ve(t.type,c,l);case I:{var h=t,b=h._payload,R=h._init;try{return ve(R(b),c,l)}catch(p){}}}return""}var pe=Object.prototype.hasOwnProperty,Je={},He=W.ReactDebugCurrentFrame;function Ee(t){if(t){var c=t._owner,l=ve(t.type,t._source,c?c.type:null);He.setExtraStackFrame(l)}else He.setExtraStackFrame(null)}function Rt(t,c,l,h,b){{var R=Function.call.bind(pe);for(var p in t)if(R(t,p)){var v=void 0;try{if(typeof t[p]!="function"){var x=Error((h||"React class")+": "+l+" type `"+p+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof t[p]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw x.name="Invariant Violation",x}v=t[p](c,p,h,l,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(j){v=j}v&&!(v instanceof Error)&&(Ee(b),P("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).",h||"React class",l,p,typeof v),Ee(null)),v instanceof Error&&!(v.message in Je)&&(Je[v.message]=!0,Ee(b),P("Failed %s type: %s",l,v.message),Ee(null))}}}var Ot=Array.isArray;function Pe(t){return Ot(t)}function It(t){{var c=typeof Symbol=="function"&&Symbol.toStringTag,l=c&&t[Symbol.toStringTag]||t.constructor.name||"Object";return l}}function Tt(t){try{return ze(t),!1}catch(c){return!0}}function ze(t){return""+t}function Xe(t){if(Tt(t))return P("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",It(t)),ze(t)}var ae=W.ReactCurrentOwner,kt={key:!0,ref:!0,__self:!0,__source:!0},Ze,Qe,Ne;Ne={};function Pt(t){if(pe.call(t,"ref")){var c=Object.getOwnPropertyDescriptor(t,"ref").get;if(c&&c.isReactWarning)return!1}return t.ref!==void 0}function Nt(t){if(pe.call(t,"key")){var c=Object.getOwnPropertyDescriptor(t,"key").get;if(c&&c.isReactWarning)return!1}return t.key!==void 0}function jt(t,c){if(typeof t.ref=="string"&&ae.current&&c&&ae.current.stateNode!==c){var l=G(ae.current.type);Ne[l]||(P('Component "%s" contains the string ref "%s". Support for string refs will be removed in a future major release. This case cannot be automatically converted to an arrow function. We ask you to manually fix this case by using useRef() or createRef() instead. Learn more about using refs safely here: https://reactjs.org/link/strict-mode-string-ref',G(ae.current.type),t.ref),Ne[l]=!0)}}function Lt(t,c){{var l=function(){Ze||(Ze=!0,P("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",c))};l.isReactWarning=!0,Object.defineProperty(t,"key",{get:l,configurable:!0})}}function At(t,c){{var l=function(){Qe||(Qe=!0,P("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",c))};l.isReactWarning=!0,Object.defineProperty(t,"ref",{get:l,configurable:!0})}}var Mt=function(t,c,l,h,b,R,p){var v={$$typeof:o,type:t,key:c,ref:l,props:p,_owner:R};return v._store={},Object.defineProperty(v._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(v,"_self",{configurable:!1,enumerable:!1,writable:!1,value:h}),Object.defineProperty(v,"_source",{configurable:!1,enumerable:!1,writable:!1,value:b}),Object.freeze&&(Object.freeze(v.props),Object.freeze(v)),v};function Vt(t,c,l,h,b){{var R,p={},v=null,x=null;l!==void 0&&(Xe(l),v=""+l),Nt(c)&&(Xe(c.key),v=""+c.key),Pt(c)&&(x=c.ref,jt(c,b));for(R in c)pe.call(c,R)&&!kt.hasOwnProperty(R)&&(p[R]=c[R]);if(t&&t.defaultProps){var j=t.defaultProps;for(R in j)p[R]===void 0&&(p[R]=j[R])}if(v||x){var L=typeof t=="function"?t.displayName||t.name||"Unknown":t;v&&Lt(p,L),x&&At(p,L)}return Mt(t,v,x,b,h,ae.current,p)}}var je=W.ReactCurrentOwner,et=W.ReactDebugCurrentFrame;function ne(t){if(t){var c=t._owner,l=ve(t.type,t._source,c?c.type:null);et.setExtraStackFrame(l)}else et.setExtraStackFrame(null)}var Le;Le=!1;function Ae(t){return typeof t=="object"&&t!==null&&t.$$typeof===o}function tt(){{if(je.current){var t=G(je.current.type);if(t)return`
1
+ 'use strict';
22
2
 
23
- Check the render method of \``+t+"`."}return""}}function Dt(t){{if(t!==void 0){var c=t.fileName.replace(/^.*[\\\/]/,""),l=t.lineNumber;return`
3
+ var Et = require('trtc-js-sdk');
4
+ var amazonChimeSdkJs = require('amazon-chime-sdk-js');
5
+ var Xs = require('@realsee/jsbridge-x');
6
+ var U = require('react');
24
7
 
25
- Check your code at `+c+":"+l+"."}return""}}var rt={};function $t(t){{var c=tt();if(!c){var l=typeof t=="string"?t:t.displayName||t.name;l&&(c=`
8
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
26
9
 
27
- Check the top-level render call using <`+l+">.")}return c}}function it(t,c){{if(!t._store||t._store.validated||t.key!=null)return;t._store.validated=!0;var l=$t(c);if(rt[l])return;rt[l]=!0;var h="";t&&t._owner&&t._owner!==je.current&&(h=" It was passed a child from "+G(t._owner.type)+"."),ne(t),P('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',l,h),ne(null)}}function nt(t,c){{if(typeof t!="object")return;if(Pe(t))for(var l=0;l<t.length;l++){var h=t[l];Ae(h)&&it(h,c)}else if(Ae(t))t._store&&(t._store.validated=!0);else if(t){var b=k(t);if(typeof b=="function"&&b!==t.entries)for(var R=b.call(t),p;!(p=R.next()).done;)Ae(p.value)&&it(p.value,c)}}}function xt(t){{var c=t.type;if(c==null||typeof c=="string")return;var l;if(typeof c=="function")l=c.propTypes;else if(typeof c=="object"&&(c.$$typeof===g||c.$$typeof===y))l=c.propTypes;else return;if(l){var h=G(c);Rt(l,t.props,"prop",h,t)}else if(c.PropTypes!==void 0&&!Le){Le=!0;var b=G(c);P("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",b||"Unknown")}typeof c.getDefaultProps=="function"&&!c.getDefaultProps.isReactClassApproved&&P("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function Ut(t){{for(var c=Object.keys(t.props),l=0;l<c.length;l++){var h=c[l];if(h!=="children"&&h!=="key"){ne(t),P("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",h),ne(null);break}}t.ref!==null&&(ne(t),P("Invalid attribute `ref` supplied to `React.Fragment`."),ne(null))}}function st(t,c,l,h,b,R){{var p=F(t);if(!p){var v="";(t===void 0||typeof t=="object"&&t!==null&&Object.keys(t).length===0)&&(v+=" You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");var x=Dt(b);x?v+=x:v+=tt();var j;t===null?j="null":Pe(t)?j="array":t!==void 0&&t.$$typeof===o?(j="<"+(G(t.type)||"Unknown")+" />",v=" Did you accidentally export a JSX literal instead of a component?"):j=typeof t,P("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",j,v)}var L=Vt(t,c,l,b,R);if(L==null)return L;if(p){var q=c.children;if(q!==void 0)if(h)if(Pe(q)){for(var se=0;se<q.length;se++)nt(q[se],t);Object.freeze&&Object.freeze(q)}else P("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else nt(q,t)}return t===i?Ut(L):xt(L),L}}function Wt(t,c,l){return st(t,c,l,!0)}function Ft(t,c,l){return st(t,c,l,!1)}var Bt=Ft,qt=Wt;ue.Fragment=i,ue.jsx=Bt,ue.jsxs=qt}()),ue}(function(r){process.env.NODE_ENV==="production"?r.exports=vr():r.exports=pr()})(mr);const Er=Ue.jsx;function yr(r){const o=V.createContext(null),e=Et(r),i=e.jsBridge,n=f=>Er(o.Provider,{value:e,children:f.children}),a=()=>{const f=V.useContext(o);if(!f)throw new Error("LiveProvider never found.");return f},u=()=>e,d=()=>e.$RTC,g=()=>d(),_=()=>async f=>await e.connect(f);function E(f,w,A=[]){const S=a(),N=[S,name,...A],M=()=>S.keyframes.off(f,w);return V.useEffect(()=>(S.keyframes.on(f,w),M),N),M}function y(){const f=a();return{connect:async T=>await f.connect(T),broadcast:async(T,B,ie=0)=>await f.broadcast(T,B,ie),exit:async()=>await f.exit(),kick:async T=>await f.kick(T),toggleMicro:T=>f.toggleMicro(T),forbidMicro:async(T,B=[])=>await f.forbidMicro(T,B),forbidSync:(T,B=[])=>f.forbidSync(T,B),sendKeyframe:(T,B)=>f.sendKeyframe(T,B),getFramesByKey:T=>f.getFramesByKey(T),setSelfInfo:T=>f.setSelfInfo(T),updateStatus:(T,B,ie,_e)=>f.updateStatus(T,B,ie,_e)}}function I(f){const w=a(),[A,S]=V.useState(w.getFramesByKey(f));V.useEffect(()=>{const M=oe=>S(oe),F=f,H=M;return w.keyframes.on(F,H),()=>w.keyframes.off(F,H)},[w]);const N=V.useCallback(M=>w.sendKeyframe(f,M),[w]);return[A,N]}function m(f,w,A=[]){const S=a(),N=()=>S.off(f,w),M=[S,f,...A];return V.useEffect(()=>(S.on(f,w),N),M),N}function D(){const f=a(),[w,A]=V.useState(f.state);return V.useEffect(()=>{const S=N=>A(N);return f.on("stateChange",S),()=>f.off("stateChange",S)},[f]),w}function C(){const f=a();return{join:F=>f.$RTC.join(F),quit:()=>f.$RTC.quit(),shock:()=>{var F,H;return(H=(F=f.$RTC).shock)==null?void 0:H.call(F)},toggleMicro:F=>f.$RTC.toggleMicro(F),detectMicro:()=>f.$RTC.detectMicro()}}function k(f,w,A=[]){const S=a(),N=()=>S.$RTC.off(f,w),M=[S,f,...A];return V.useEffect(()=>(S.$RTC.on(f,w),N),M),N}function W(){const f=a(),[w,A]=V.useState(f.selfInfo||{}),S=M=>A(M);V.useEffect(()=>(f.on("selfInfoUpdate",S),()=>f.off("selfInfoUpdate",S)),[f]);const N=V.useCallback(async M=>await f.setSelfInfo(M),[f]);return[w,N]}function P(){const f=a(),[w,A]=V.useState(f.snapshot);return V.useEffect(()=>{const S=N=>A(N);return f.on("keyframes",S),()=>f.off("keyframes",S)}),w}function he(){const f=a(),[w,A]=V.useState(f.userList),S=N=>A(N);return V.useEffect(()=>(f.on("userListUpdate",S),()=>f.off("userListUpdate",S)),[f]),w}return{live:e,jsBridge:i,LiveProvider:n,unsafe__useLiveInstance:u,unsafe__useRTCInstance:g,useConnect:_,useKeyframe:I,useKeyframeUpdateCallback:E,useLiveAction:y,useLiveEventCallback:m,useLiveState:D,useRTCAction:C,useRTCEventCallback:k,useSelfInfo:W,useKeyframesSnapshot:P,useUserList:he}}exports.BrowserRTC=De;exports.BrowserRTC4Chime=$e;exports.BuiltInRTCType=We;exports.BuiltinActionType=Y;exports.BuiltinEventType=K;exports.Command=U;exports.CoreRTC=we;exports.Live=pt;exports.LiveState=$;exports.MemUserStatus=dt;exports.MicroStatus=Q;exports.RTCJoinedInfoCodeEnum=te;exports.RTCType=ee;exports.UserStatus=ft;exports.VRWebViewRTC=xe;exports.WebSocketCloseError=_t;exports.WebSocketErrorType=ht;exports.WebSocketState=Se;exports._clearLiveInstanceIfNeed=vt;exports.createLive=Et;exports.createLiveReact=yr;exports.parseLiveMsg=tr;exports.parseWSClsErr=gt;
10
+ var Et__default = /*#__PURE__*/_interopDefault(Et);
11
+ var Xs__default = /*#__PURE__*/_interopDefault(Xs);
12
+ var U__default = /*#__PURE__*/_interopDefault(U);
13
+
14
+ var ke=Symbol("$$REALSEE_LIVE_EVENT$$");function Ge(n){return n[ke]||(n[ke]={}),n[ke]}function ni(n){n[ke]?.length||delete n[ke];}var N=class{hasListener(e){let t=Ge(this);return t&&t[e]&&t[e].length>0}on(e,t,r){let i=Ge(this);return i[e]||(i[e]=[]),i[e].push([t,r||!1]),()=>this.off(e,t)}once(e,t){return this.on(e,t,!0)}off(e,t){let r=Ge(this);if(!e){ni(this);return}if(r[e]||(r[e]=[]),t===void 0){r[e].length=0;return}let i=r[e].findIndex(s=>s[0]===t);i!==-1&&r[e].splice(i,1);}emit(e,...t){let r=!1,s=Ge(this)[e]||[];for(let o of s.slice()){let[c,a=!1]=o,l=c(...t);a&&this.off(e,c),l===!1&&(r=!0);}return r}};var J=class extends N{};var ri=(r=>(r.RealseeBrowserRTC="RealseeBrowserRTC",r.RealseeVRWebViewRTC="RealseeVRWebViewRTC",r.RealseeBrowserChimeRTC="RealseeBrowserChimeRTC",r))(ri||{}),ii=(t=>(t.RealseeXTRTC="trtc",t.RealseeXChimeRTC="chime",t))(ii||{});var si=()=>{let n=new Date,e=n.getFullYear(),t=(n.getMonth()+1).toString().padStart(2,"0"),r=n.getDate().toString().padStart(2,"0"),i=n.getHours().toString().padStart(2,"0"),s=n.getMinutes().toString().padStart(2,"0"),o=n.getSeconds().toString().padStart(2,"0"),c=n.getMilliseconds().toString().padStart(3,"0");return `[${e}-${t}-${r} ${i}:${s}:${o}.${c}]`};var Ce=(n,e=[])=>{let t=`Realsee Live ${si()} <${n}> `;switch(n){case"INFO":console.info(t,...e);break;case"ERROR":console.error(t,...e);break;case"WARN":console.warn(t,...e);break;case"DEBUG":console.debug(t,...e);break;default:console.log(t,...e);}},oi={log:(...n)=>Ce("LOG",n),info:(...n)=>Ce("INFO",n),error:(...n)=>Ce("ERROR",n),warn:(...n)=>Ce("WARN",n),debug:(...n)=>Ce("DEBUG",n)},m=oi;function X(){return ((1+Math.random())*65536|0).toString(16).substring(1)}function Z(){return [X(),X(),"4"+X().substring(0,3),X(),X(),X()+X()+X()].join("-").toLowerCase()}var xe=class extends J{type="RealseeBrowserRTC";joined=!1;micro=!1;voiceId="";_getVoiceSign=()=>{throw new Error("\u65B9\u6CD5 getVoiceSign \u672A\u5B9E\u73B0")};_autoPlayConfirm;checkRequirement=()=>Et__default.default.checkSystemRequirements();$dom=document.createElement("div");_trtc={client:null,stream:null};constructor(e){super(),this._getVoiceSign=e.getVoiceSign,this._autoPlayConfirm=e.autoPlayConfirm,this._initParentDom();}_initParentDom(){this.$dom.id=`rs-rtc-${Z()}`,this.$dom.style.display="none",document.body.appendChild(this.$dom);}join=async e=>{this.emit("joinWillStart");let t=await this._getVoiceSign({voiceId:e.voiceId,roomId:e.roomId,userId:e.userId});this._trtc.client=Et__default.default.createClient({mode:"rtc",...t,enableAutoPlayDialog:typeof this._autoPlayConfirm!="function"}),this._trtc.client?.enableAudioVolumeEvaluation(),this._registerRtcEvent();let r=await new Promise(i=>{this._trtc.client?.join({roomId:Number(e.voiceId)}).then(()=>i(!0)).catch(()=>i(!1));});return this.joined=r,r?(this._trtc.stream=Et__default.default.createStream({userId:t.userId,audio:!0,video:!1}),r=await new Promise(i=>{this._trtc.stream?.initialize().then(()=>i(!0)).catch(()=>i(!1));}),r=await new Promise(i=>{this._trtc.client?.publish(this._trtc.stream).then(()=>i(!0)).catch(()=>i(!1));}),this.joined=r,this.joined&&this.emit("joined"),r):!1};quit(){return new Promise(async e=>{this.joined=!1,this._trtc.stream&&(await this._trtc.client?.unpublish(this._trtc.stream),this._trtc.stream.stop(),this._trtc.stream.close(),this._trtc.stream=null),this._trtc.client?.leave().then(()=>this._trtc.client=null).then(()=>e(!0)).catch(()=>e(!1)),e(!0);})}detectMicro(){return new Promise(e=>{let t={audio:!0,video:!1};try{navigator.mediaDevices.getUserMedia(t).then(()=>e(!0)).catch(r=>{m.error(r.message),e(!1);});}catch(r){console.error(r),e(!1);}})}toggleMicro(e){return Promise.resolve((e?this._trtc?.stream?.unmuteAudio():this._trtc?.stream?.muteAudio())||!1)}shock(){throw new Error("Method not implemented.")}_registerRtcEvent(){this._trtc.client?.on("stream-added",this._handleStreamAdded),this._trtc.client?.on("stream-subscribed",this._handleStreamSubscribed),this._trtc.client?.on("audio-volume",e=>this.emit("userVolumes",e.result.map(({userId:t,audioVolume:r})=>({userId:t,audioVolume:r})))),this._trtc.client?.on("error",e=>this.emit("error",e));}_handleStreamAdded=e=>{let t=e.stream;console.log("\u8FDC\u7AEF\u6D41\u589E\u52A0: "+t.getId()),this._trtc.client?.subscribe(t);};_handleStreamSubscribed=e=>{let t=e.stream;console.log("\u8FDC\u7AEF\u6D41\u8BA2\u9605\u6210\u529F\uFF1A"+t.getId());let i=`rs-rtc-remote_stream-${t.getId()}`,s=document.createElement("div");s.id=i,this.$dom.appendChild(s),typeof this._autoPlayConfirm=="function"?(t.play(i).catch(o=>{}),t.on("error",o=>{if(o.getCode()===16451){let a=()=>t.resume();this._autoPlayConfirm({onConfirm:a});}})):t.play(i);}};var fe=class extends J{type="RealseeBrowserChimeRTC";joined=!1;micro=!1;voiceId="";userId="";logger;deviceController;meetingSession;audioInput;audioOutput;deviceChangeObserver={};audioVideoObserver={};audioMixObserver;_getVoiceSign=()=>{throw new Error("\u65B9\u6CD5 getVoiceSign \u672A\u5B9E\u73B0")};_autoPlayConfirm;$dom=document.createElement("div");$audio=document.createElement("audio");constructor(e){super(),this._getVoiceSign=e.getVoiceSign,this._autoPlayConfirm=e.autoPlayConfirm,this._initDom(),this.logger=new amazonChimeSdkJs.ConsoleLogger("WebRTCLogger",e.logLevel||amazonChimeSdkJs.LogLevel.INFO),this.deviceController=new amazonChimeSdkJs.DefaultDeviceController(this.logger),this.initObservers();}_initDom=()=>{this.$audio.id=`rs-rtc-${Z()}`,this.$dom.id=`rs-rtc-${Z()}`,this.$dom.appendChild(this.$audio),document.body.appendChild(this.$dom);};initObservers=()=>{this.deviceChangeObserver={audioInputsChanged:e=>{this.logger.info(`audioInputsChanged ${typeof e}`),e?.forEach(t=>{this.logger.info(`Device ID: ${t.deviceId} Microphone: ${t.label}`);});},audioOutputsChanged:e=>{this.logger.info(`audioOutputsChanged ${typeof e}`),e?.forEach(t=>{this.logger.info(`Device ID: ${t.deviceId} Speaker: ${t.label}`);});},audioInputMuteStateChanged:(e,t)=>{this.logger.info(`Device ${e.toString()} ${t?"is muted in hardware":"is not muted"}`);}},this.audioVideoObserver={audioVideoDidStart:()=>{this.logger.info("Started");},audioVideoDidStop:e=>{this.logger.info(`Stopped with a session status code: ${e.statusCode()}`);},audioVideoDidStartConnecting:e=>{e&&this.logger.info("Attempting to reconnect");}},this.audioMixObserver={meetingAudioStreamBecameActive:e=>{if(this.$audio.paused){let t=()=>this.$audio.play().then(()=>{}).catch(r=>{if(m.error("\u64AD\u653E\u8FDC\u7AEF\u6D41\u5931\u8D25\uFF01",r),typeof this._autoPlayConfirm=="function"){let i=()=>t();this._autoPlayConfirm({onConfirm:i});}});t();}},meetingAudioStreamBecameInactive:e=>{}};};async join(e){return new Promise(async(t,r)=>{this.emit("joinWillStart");try{let{sdkAppId:i,userId:s,roomId:o,userSig:c}=await this._getVoiceSign({...e,roomId:e.roomId||0});this.userId=s;let{attendence:a,vendor_wrapper:l}=JSON.parse(decodeURIComponent(c)),d=new amazonChimeSdkJs.MeetingSessionConfiguration({Meeting:l},{Attendee:{ExternalUserId:a.external_user_id,AttendeeId:a.attendee_id,JoinToken:a.join_token}});this.meetingSession=new amazonChimeSdkJs.DefaultMeetingSession(d,this.logger,this.deviceController),this._registerRtcEvent(),this.meetingSession.audioVideo.addDeviceChangeObserver(this.deviceChangeObserver),this.meetingSession.audioVideo.addObserver(this.audioVideoObserver),this.meetingSession.audioVideo.bindAudioElement(this.$audio);let u={audioVideoDidStart:()=>{this.meetingSession?.audioVideo.realtimeMuteLocalAudio(),this.joined=!0,this.emit("joined"),t(!0);},audioVideoDidStop:()=>{this.joined=!1,t(!1);}};this.meetingSession.audioVideo.addObserver(u),this.audioMixObserver&&this.meetingSession.audioVideo.addAudioMixObserver(this.audioMixObserver),this.meetingSession.audioVideo.setDeviceLabelTrigger(async()=>await navigator.mediaDevices.getUserMedia({audio:!0,video:!1}));try{let p=await this.meetingSession.audioVideo.listAudioInputDevices();m.info("audioInputDevices ===>",p);let g=p[0]?.deviceId||"default";await this.meetingSession.audioVideo.startAudioInput(g);}catch(p){m.error(`\u8BBE\u7F6E\u8BED\u97F3\u8F93\u5165\u8BBE\u5907\u5931\u8D25:${p.message}`);}try{let p=await this.meetingSession.audioVideo.listAudioOutputDevices();m.info("audioOutputDevices ===>",p);let g=p[0]?.deviceId||"default";await this.meetingSession.audioVideo.chooseAudioOutput(g);}catch(p){m.error(`\u8BBE\u7F6E\u8BED\u97F3\u8F93\u51FA\u8BBE\u5907\u5931\u8D25:${p.message}`);}this.meetingSession.audioVideo.start();}catch(i){this.emit("error",i),this.logger.error(i.message),t(!1);}})}_registerRtcEvent=()=>{let e=this.meetingSession?.configuration?.credentials?.attendeeId||"";if(e){let t=new Map,r=()=>{let i=[];return t.forEach((s,o)=>{i.push({userId:s.userId,volume:s.muted||s.signalStrength===0||!s.volume?0:s.volume});}),i};this.meetingSession?.audioVideo.realtimeSubscribeToAttendeeIdPresence((i,s,o)=>{if(!s){t.delete(i),this.emit("userVolumes",r());return}this.meetingSession?.audioVideo.realtimeSubscribeToVolumeIndicator(i,(c,a,l,d)=>{new amazonChimeSdkJs.DefaultModality(c).base()===c&&(t.set(c,{userId:o||c,volume:a,muted:l,signalStrength:d}),this.emit("userVolumes",r()));});}),this.meetingSession?.audioVideo.realtimeSubscribeToVolumeIndicator(e,(i,s,o,c)=>{new amazonChimeSdkJs.DefaultModality(i).base()===i&&c!==null&&c!==1&&this.emit("weakNetwork");}),this.meetingSession?.audioVideo.realtimeSubscribeToFatalError(i=>this.emit("error",i));}};quit(){return this.joined?new Promise((e,t)=>{this.joined=!1;let r={audioVideoDidStop:async i=>{let s=i.statusCode();this.meetingSession?.deviceController.destroy(),s===amazonChimeSdkJs.MeetingSessionStatusCode.Left?(this.logger.info("You left the session"),e(!0)):(this.logger.info(`Stopped with a session status code: ${s}`),e(!0));}};this.meetingSession?.audioVideo.addObserver(r),this.meetingSession?.audioVideo.stop();}):Promise.resolve(!0)}async detectMicro(){return new Promise(e=>{let t={audio:!0,video:!1};try{navigator.mediaDevices.getUserMedia(t).then(()=>e(!0)).catch(()=>e(!1));}catch(r){this.logger.error(r.message),e(!1);}})}async toggleMicro(e){e?this.meetingSession?.audioVideo.realtimeUnmuteLocalAudio():this.meetingSession?.audioVideo.realtimeMuteLocalAudio();let t=this.meetingSession?.audioVideo.realtimeIsLocalAudioMuted();return t!==void 0?e!==t:!1}shock(){throw new Error("Method not implemented.")}};var fi=(s=>(s[s.Success=0]="Success",s[s.Failure=1]="Failure",s[s.ReJoin=2]="ReJoin",s[s.NoMicroPermission=3]="NoMicroPermission",s[s.Unknown=500]="Unknown",s))(fi||{});var Ie=class extends J{type="RealseeVRWebViewRTC";joined=!1;micro=!1;voiceId="";_joinOptions=null;options;get jsBridge(){return this.options.jsBridge}constructor({jsBridge:e,getVoiceSign:t}){super(),this.options={jsBridge:e,getVoiceSign:t},this.jsBridge.webViewType!=="WxMiniProgramWebView"&&this.jsBridge.callAndListen("live/userVolumes",this.handleUserVolumes),this.jsBridge.callAndListen("live/weakNetwork",this.handleWeakNetwork),this.on("inner.rtc.fail",this.handleJoinResult);}handleUserVolumes=e=>{this.emit("userVolumes",e);};handleWeakNetwork=e=>{e&&this.emit("weakNetwork");};join=async e=>{this._joinOptions=e,this.emit("joinWillStart");let{sdkAppId:t,userId:r,userSig:i}=await this.getVoiceSignOrEmitError(e);return !t||!r||!i?!1:(this.type=e.type,this.jsBridge.webViewType==="WxMiniProgramWebView"?this.handleWxMiniProgramWebViewJoin({sdkAppId:t,userId:r,userSig:i,voiceId:e.voiceId}):this.handleAppWebViewJoin({sdkAppId:t,userId:r,userSig:i,voiceId:e.voiceId}))};reJoin=async()=>this._joinOptions?this.join({voiceId:this._joinOptions.voiceId,userId:this._joinOptions.userId,roomId:this._joinOptions.roomId,type:this._joinOptions.type}):(this.emitErrorAndSetJoinedFalse("\u91CD\u8FDE\u5931\u8D25\uFF1A\u672A\u627E\u5230\u52A0\u5165\u623F\u95F4\u53C2\u6570\u3002"),!1);getVoiceSignOrEmitError=async e=>{try{return await this.options.getVoiceSign(e)}catch{return this.emitErrorAndSetJoinedFalse("\u52A0\u5165\u623F\u95F4\u5931\u8D25\uFF1Artc \u7B7E\u540D\u8BF7\u6C42\u5F02\u5E38"),{}}};handleWxMiniProgramWebViewJoin=async e=>{let[t,r]=await this.joinRoomOrEmitError(e);return r?!1:this.handleJoinResult(t)};handleAppWebViewJoin=e=>new Promise(t=>{this.off("inner.rtc.success");let r=i=>{this.off("inner.rtc.fail",r),this.off("inner.rtc.success",r),t(this.handleJoinResult(i));};this.once("inner.rtc.fail",r),this.once("inner.rtc.success",r);try{let{sdkAppId:i,userId:s,userSig:o,voiceId:c}=e;this.jsBridge.callAndListen(`live/join?sdkAppID=${i}&userID=${s}&roomID=${c}&userSig=${o}`,a=>{a===!0?this.emit("inner.rtc.success",a):typeof a=="object"?a.code===0||a.code===2?this.emit("inner.rtc.success",a):this.emit("inner.rtc.fail",a):this.emit("inner.rtc.fail",a);});}catch(i){t(this.handleJoinResult({message:i.message,code:500}));}});joinRoomOrEmitError=async({sdkAppId:e,userId:t,voiceId:r,userSig:i})=>{try{return await this.jsBridge.callAndBackfeed(`live/join?sdkAppID=${e}&userID=${t}&roomID=${Number(r)}&userSig=${i}`)}catch(s){return this.emitErrorAndSetJoinedFalse("\u52A0\u5165\u623F\u95F4\u5931\u8D25\uFF1A"+s.message),[null,s]}};handleJoinResult=e=>{switch(!0){case e===!0:case(typeof e=="object"&&e.code===0):case(typeof e=="object"&&e.code===2):{this.emit("joined"),this.joined=!0;break}default:{this.joined=!1;let t=typeof e=="object"?e.message:"\u52A0\u5165\u623F\u95F4\u5931\u8D25\uFF1A\u672A\u77E5\u5F02\u5E38\u3002";this.emit("error",new Error(t,{cause:e}));}}return this.joined};emitErrorAndSetJoinedFalse=e=>{this.emit("error",new Error(e)),this.joined=!1;};quit=async()=>{let[e,t]=await this.jsBridge.callAndBackfeed("live/quit");return e===null&&this.emit("error",t||new Error("\u9000\u51FA\u623F\u95F4\u5931\u8D25\uFF1A\u672A\u77E5\u5F02\u5E38\u3002")),this.joined=!1,!!e};detectMicro=async()=>{let[e,t]=await this.jsBridge.detectMicro();return e===null?(this.emit("error",t||new Error("\u9EA6\u514B\u98CE\u76D1\u6D4B\u5F02\u5E38\uFF01")),!1):e};toggleMicro=async e=>{let[t,r]=await this.jsBridge.callAndBackfeed(`live/toggleMicro?flag=${e?1:0}`);return t===null?(this.emit("error",r||new Error("\u9EA6\u514B\u98CE\u76D1\u6D4B\u5F02\u5E38\uFF01")),!1):(this.micro=t,t)};shock=()=>{this.jsBridge.shock(1);}};var gi=(a=>(a.SelfUserInfo="SELF_USER_INFO",a.RoomInfo="ROOM_INFO",a.RTCInfo="RTC_INFO",a.UserList="USER_LIST",a.BuiltinMsg="BUILTIN_MSG",a.CustomEvent="CUSTOM_EVENT",a.KeyframeSync="KEYFRAME_SYNC",a.UserKickOut="USER_KICK_OUT",a))(gi||{}),pi=(t=>(t.UserChange="user_change",t.RoomChange="room_change",t))(pi||{}),mi=(o=>(o.UserMicroStatus="change_micro_status",o.UserMicroStatusSync="sync_micro_status",o.UserPermission="change_permission",o.UserStatus="change_status",o.UserInfo="change_info",o.RoomClose="close",o))(mi||{}),yi=(t=>(t.OPEN="OPEN",t.CLOSE="CLOSE",t))(yi||{});function Po(n){try{let e=JSON.parse(n),t={code:e.code,message:e.message,command:e.command,roomCode:e.room_code,appID:e.app_id,requestId:e.request_id,frontRequestId:e.front_request_id,triggerUserID:e.trigger_user_id,data:e.data||{}},r=Object.keys(t).filter(i=>t[i]===void 0);return r.length>0&&console.warn(`\u63A8\u9001\u6570\u636E\u683C\u5F0F\u5F02\u5E38\uFF1A${r.join(" ")} \u503C\u4E0D\u5B58\u5728\uFF01`),t}catch{return !1}}var wi=(i=>(i[i.NOTINITIALIZED=-1]="NOTINITIALIZED",i[i.CONNECTING=0]="CONNECTING",i[i.OPEN=1]="OPEN",i[i.CLOSED=3]="CLOSED",i))(wi||{});var _i=(r=>(r[r.Normal=0]="Normal",r[r.Removed=1]="Removed",r[r.Replaced=2]="Replaced",r))(_i||{}),bi=(o=>(o.WAIT_ENTER="WAIT_ENTER",o.ONLINE="ONLINE",o.LEAVE="LEAVE",o.KICK_OUT="KICK_OUT",o.BE_REPLACE="BE_REPLACE",o.EXCEPTION="EXCEPTION",o))(bi||{});var Si=(s=>(s[s.NOTINITIALIZED=-1]="NOTINITIALIZED",s[s.CONNECTING=0]="CONNECTING",s[s.OPEN=1]="OPEN",s[s.CLOSING=2]="CLOSING",s[s.CLOSED=3]="CLOSED",s))(Si||{}),vi=(c=>(c.Error="Error",c.Close="Close",c.MicroAuth="MicroAuth",c.DuplicateConnect="DuplicateConnect",c.IllegalURL="IllegalURL",c.Unknown="Unknown",c.IllegalArgs="IllegalArgs",c))(vi||{}),Ei=(l=>(l.Err_1000="CLOSE_NORMAL",l.Err_1001="CLOSE_GOING_AWAY",l.Err_1002="CLOSE_PROTOCOL_ERROR",l.Err_1003="CLOSE_UNSUPPORTED",l.Err_1006="CLOSE_ABNORMAL",l.Err_1007="Unsupported Data",l.Err_1008="Policy Violation",l.Err_1009="CLOSE_TOO_LARGE",l.Err_unknown="unknown",l))(Ei||{});function Sn(n){switch(n){case 1e3:return "CLOSE_NORMAL";case 1001:return "CLOSE_GOING_AWAY";case 1002:return "CLOSE_PROTOCOL_ERROR";case 1003:return "CLOSE_UNSUPPORTED";case 1006:return "CLOSE_ABNORMAL";case 1007:return "Unsupported Data";case 1008:return "Policy Violation";case 1009:return "CLOSE_TOO_LARGE";}return "unknown"}function vn(n,e={}){let t=new URL(n,"http://localhost"),r=new URLSearchParams(t.search);return Object.entries(e).forEach(([i,s])=>{r.append(i,String(s));}),n.split("?")[0]+"?"+r.toString()}var En=(()=>{let n=typeof process<"u"&&process.versions?.node!=null;return typeof window<"u"&&"Deno"in window||n||typeof window>"u"})();var Te=En?"":navigator.userAgent,kn=/android/i.test(Te),Cn=/iPhone|iPad\s+OS/i.test(Te),xn=/MicroMessenger/i.test(Te)&&/miniProgram/i.test(Te),In=/realsee/i.test(Te);function qe(n){return Object.prototype.toString.call(n)==="[object Object]"}function Je(n,e){return n===e?!0:n==null||e==null||typeof n!=typeof e?!1:Number.isNaN(n)&&Number.isNaN(e)}function ki(n,e){if(n===e)return !0;if(n==null||e==null)return !1;let t=Object.keys(n),r=Object.keys(e);return t.length!==r.length?!1:t.every(i=>Je(n[i],e[i]))}function Ci(n,e){return n===e?!0:n==null||e==null||n.length!==e.length?!1:n.every((t,r)=>Je(t,e[r]))}function xi(n,e){return Je(n,e)?!0:qe(n)&&qe(e)?ki(n,e):Array.isArray(n)&&Array.isArray(e)?Ci(n,e):!1}function kt(n,e){return Je(n,e)?!0:qe(n)&&qe(e)?Ti(n,e):Array.isArray(n)&&Array.isArray(e)?Ii(n,e):!1}function Ii(n,e){if(n.length!==e.length)return !1;for(let t=0,r=n.length;t<r;t++)if(!kt(n[t],e[t]))return !1;return !0}function Ti(n,e){if(n===e)return !0;if(n==null||e==null)return !1;let t=Object.keys(n),r=Object.keys(e);return t.length!==r.length?!1:t.every(i=>kt(n[i],e[i]))}function Tn(n,e,t={deep:!1}){return t.deep?kt(n,e):xi(n,e)}var He=class extends N{_realWebSocket;_url;_protocols;_readyState=-1;_options={timeout:1e4,shouldReconnect:(e,t)=>{if(!(e.code===1008||e.code===1011))return [0,1e3,2e3][t.attempts%3]},should1000Reconnect:!1,ignoreConnectivityEvents:!1,automaticOpen:!1};_connectTimeout;_attempts=0;_reconnects=-1;_reconnectWhenOnlineAgain=!1;_explicitlyClosed=!1;_pendingReconnect;_connectivityEventsAttached=!1;_heathCheckTimer;get attempts(){return this._attempts}constructor(e){super(),e&&this.setOptions(e),this._startHealthCheck();}setOptions(e){if(!e)return;this._url=e.url,this._protocols=e.protocols;let t=Object.assign(this._options,e.robustOptions||{});if(typeof t?.timeout!="number")throw new Error("timeout must be the number of milliseconds to timeout a connection attempt");if(typeof t?.shouldReconnect!="function")throw new Error("shouldReconnect must be a function that returns the number of milliseconds to wait for a reconnect attempt, or null or undefined to not reconnect.");this._options=t,this._options.automaticOpen&&this._createWebSocket();}_healthCheck=async()=>{if(this._realWebSocket){let e=this._realWebSocket.readyState;e!==this._readyState&&(this._readyState=e,this._readyState===2&&this.emit("closing"));}await new Promise(e=>setTimeout(e,2e3)),this._heathCheckTimer=requestAnimationFrame(this._healthCheck);};_clearConnectTimeoutIfNeed=()=>{this._connectTimeout&&(clearTimeout(this._connectTimeout),this._connectTimeout=void 0);};_clearHeathCheckIfNeed=()=>{this._heathCheckTimer&&(cancelAnimationFrame(this._heathCheckTimer),this._heathCheckTimer=void 0);};_startHealthCheck=()=>{this._clearHeathCheckIfNeed(),this._heathCheckTimer=requestAnimationFrame(this._healthCheck);};_stopHealthCheck=()=>{this._clearHeathCheckIfNeed();};_clearPendingReconnectIfNeeded=()=>{this._pendingReconnect&&(clearTimeout(this._pendingReconnect),this._pendingReconnect=void 0);};_online=e=>{this._reconnectWhenOnlineAgain&&(this._clearPendingReconnectIfNeeded(),this._reconnect(e));};_offline=()=>{this._reconnectWhenOnlineAgain=!0,this._realWebSocket?.close(1e3,"offline");};_detachConnectivityEvents=()=>{this._connectivityEventsAttached&&(globalThis?.removeEventListener("online",this._online),globalThis?.removeEventListener("offline",this._offline),this._connectivityEventsAttached=!1);};_attachConnectivityEvents=()=>{this._connectivityEventsAttached||(globalThis?.addEventListener("online",this._online),globalThis?.addEventListener("offline",this._offline),this._connectivityEventsAttached=!0);};send=e=>{this._realWebSocket?.readyState===this._realWebSocket?.OPEN&&this._realWebSocket?.send(e);};close=(e,t)=>(typeof e!="number"&&(t=e,e=1e3),this._clearPendingReconnectIfNeeded(),this._reconnectWhenOnlineAgain=!1,this._explicitlyClosed=!0,this._detachConnectivityEvents(),this._realWebSocket?.close(e,t));open=e=>{e&&(this._url=e),this._realWebSocket?.readyState!==WebSocket.OPEN&&this._realWebSocket?.readyState!==WebSocket.CONNECTING&&(this._clearPendingReconnectIfNeeded(),this._reconnectWhenOnlineAgain=!1,this._explicitlyClosed=!1,this._createWebSocket());};_createWebSocket=()=>{let e=typeof this._url=="string"?this._url:this._url?.(this);if(!e)return;this._clearConnectTimeoutIfNeed(),this._clearPendingReconnectIfNeeded(),this._removeWebSocketEvent(),this._realWebSocket=new WebSocket(e,this._protocols||void 0),this._attempts++,this.emit("connecting",new CustomEvent("connecting",{detail:{attempts:this._attempts,reconnects:this._reconnects}}));let t=()=>{this._connectTimeout=void 0,this._detachConnectivityEvents(),this.emit("timeout",new CustomEvent("timeout",{detail:{attempts:this._attempts,reconnects:this._reconnects}}));};this._connectTimeout=setTimeout(t,this._options.timeout),this._dispatchWebSocketEvent(),this._options.ignoreConnectivityEvents||this._attachConnectivityEvents();};_removeWebSocketEvent=()=>{this._realWebSocket?.removeEventListener("open",this._webSocketOpenHandler),this._realWebSocket?.removeEventListener("close",this._webSocketCloseHandler),this._realWebSocket?.removeEventListener("error",this._webSocketErrorHandler),this._realWebSocket?.removeEventListener("message",this._webSocketMessageHandler);};_dispatchWebSocketEvent=()=>{this._realWebSocket?.addEventListener("open",this._webSocketOpenHandler),this._realWebSocket?.addEventListener("close",this._webSocketCloseHandler),this._realWebSocket?.addEventListener("error",this._webSocketErrorHandler),this._realWebSocket?.addEventListener("message",this._webSocketMessageHandler);};_webSocketOpenHandler=e=>{this._connectTimeout&&(clearTimeout(this._connectTimeout),this._connectTimeout=void 0);let t=++this._reconnects,r=this._attempts;return this._attempts=0,this._reconnectWhenOnlineAgain=!1,this._startHealthCheck(),this.emit("open",Object.assign(e,{detail:{reconnects:t,attempts:r}}))};_webSocketCloseHandler=e=>(this._reconnect(e),this._stopHealthCheck(),this.emit("close",e));_webSocketErrorHandler=e=>this.emit("error",new CustomEvent("error",{detail:{error:e}}));_webSocketMessageHandler=e=>this.emit("message",e);_reconnect(e){if(!this._options.should1000Reconnect&&e.code===1e3||this._explicitlyClosed){this._attempts=0;return}if(this._connectivityEventsAttached&&globalThis?.navigator?.onLine===!1){this._reconnectWhenOnlineAgain=!0;return}let i=this._options.shouldReconnect?.(e,this);typeof i=="number"?(console.log(`Reconnecting in ${i}ms...`),this._pendingReconnect=setTimeout(this._createWebSocket,i)):console.log("No reconnection will be attempted.");}};var ze=class extends N{_ws=new He({url:"",robustOptions:{should1000Reconnect:!0,ignoreConnectivityEvents:!0}});_state=-1;set state(e){let t=JSON.parse(JSON.stringify(this._state));this._state=e,this.emit("stateChange",this.state,t);}get state(){return this._state}constructor(){super(),this._addWebSocketEventListeners();}_addWebSocketEventListeners=()=>{this._ws.on("close",this._handleCloseEvent),this._ws.on("closing",this._handleClosingEvent),this._ws.on("connecting",this._handleConnectingEvent),this._ws.on("error",this._handleErrorEvent),this._ws.on("message",this._handleMessageEvent),this._ws.on("open",this._handleOpenEvent),this._ws.on("timeout",this._handleTimeoutEvent);};_removeWebSocketEventListeners=()=>{this._ws.off("close",this._handleCloseEvent),this._ws.off("closing",this._handleClosingEvent),this._ws.off("connecting",this._handleConnectingEvent),this._ws.off("error",this._handleErrorEvent),this._ws.off("message",this._handleMessageEvent),this._ws.off("open",this._handleOpenEvent),this._ws.off("timeout",this._handleTimeoutEvent);};_handleCloseEvent=e=>{m.info(`live room closed bacause of ${e.code}-${e.reason||Sn(e.code)}`),this.state=3;};_handleClosingEvent=()=>{m.info("live room is closing, onLine:",globalThis?.navigator?.onLine),this.state=3;};_handleConnectingEvent=e=>{m.info("live room is connecting"),this.state=0,e.detail.reconnects>0&&this.emit("reconnecting",e.detail);};_handleErrorEvent=e=>{m.error("live room error",e),this.state=3;};_handleMessageEvent=e=>{let t=(()=>{try{return JSON.parse(e.data)}catch{return e.data}})();this.emit("message",t);};_handleOpenEvent=e=>{m.info("live room open",e.detail),this.state=1,e.detail.reconnects>0&&this.emit("reconnected",e.detail);};_handleTimeoutEvent=e=>{m.error("live room connect timeout!",e.detail),this.state=3;};dispose=async()=>(this._removeWebSocketEventListeners(),await this.close("live room close by controller disposed!"));open=e=>this._ws.open(e);close=(e,t)=>new Promise(r=>{this._ws.once("close",()=>r(!0)),this._ws.close(e,t);});sendMessage(e=""){if(e==null)throw new Error("live message is empty!");if(this.state!==1)throw new Error("live has not yet been initialized!");return this._ws.send(JSON.stringify(e))}readyClose(){this._ws&&(this._ws._explicitlyClosed=!0);}};var L=()=>new Map,Ye=n=>{let e=L();return n.forEach((t,r)=>{e.set(r,t);}),e},Q=(n,e,t)=>{let r=n.get(e);return r===void 0&&n.set(e,r=t()),r},Rn=(n,e)=>{let t=[];for(let[r,i]of n)t.push(e(i,r));return t},Dn=(n,e)=>{for(let[t,r]of n)if(e(r,t))return !0;return !1};var H=()=>new Set;var Xe=n=>n[n.length-1];var ee=Array.from;var xt=Array.isArray;var Ze=class{constructor(){this._observers=L();}on(e,t){return Q(this._observers,e,H).add(t),t}once(e,t){let r=(...i)=>{this.off(e,r),t(...i);};this.on(e,r);}off(e,t){let r=this._observers.get(e);r!==void 0&&(r.delete(t),r.size===0&&this._observers.delete(e));}emit(e,t){return ee((this._observers.get(e)||L()).values()).forEach(r=>r(...t))}destroy(){this._observers=L();}};var P=Math.floor;var ge=Math.abs;var Qe=(n,e)=>n<e?n:e,te=(n,e)=>n>e?n:e;var Un=n=>n!==0?n<0:1/n<0;var On=Number.isInteger||(n=>typeof n=="number"&&isFinite(n)&&P(n)===n);var Ui=n=>n.toLowerCase(),Oi=/^\s*/g,Ai=n=>n.replace(Oi,""),Li=/([A-Z])/g,Dt=(n,e)=>Ai(n.replace(Li,t=>`${e}${Ui(t)}`));var Vi=n=>{let e=unescape(encodeURIComponent(n)),t=e.length,r=new Uint8Array(t);for(let i=0;i<t;i++)r[i]=e.codePointAt(i);return r},pe=typeof TextEncoder<"u"?new TextEncoder:null,Mi=n=>pe.encode(n),An=pe?Mi:Vi;var Rt=typeof TextDecoder>"u"?null:new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0});Rt&&Rt.decode(new Uint8Array).length===1&&(Rt=null);var ce=class{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[];}},nt=()=>new ce;var Ki=n=>{let e=n.cpos;for(let t=0;t<n.bufs.length;t++)e+=n.bufs[t].length;return e};var j=n=>{let e=new Uint8Array(Ki(n)),t=0;for(let r=0;r<n.bufs.length;r++){let i=n.bufs[r];e.set(i,t),t+=i.length;}return e.set(new Uint8Array(n.cbuf.buffer,0,n.cpos),t),e},Pi=(n,e)=>{let t=n.cbuf.length;t-n.cpos<e&&(n.bufs.push(new Uint8Array(n.cbuf.buffer,0,n.cpos)),n.cbuf=new Uint8Array(te(t,e)*2),n.cpos=0);},T=(n,e)=>{let t=n.cbuf.length;n.cpos===t&&(n.bufs.push(n.cbuf),n.cbuf=new Uint8Array(t*2),n.cpos=0),n.cbuf[n.cpos++]=e;};var rt=T;var w=(n,e)=>{for(;e>127;)T(n,128|127&e),e=P(e/128);T(n,127&e);},it=(n,e)=>{let t=Un(e);for(t&&(e=-e),T(n,(e>63?128:0)|(t?64:0)|63&e),e=P(e/64);e>0;)T(n,(e>127?128:0)|127&e),e=P(e/128);},Ot=new Uint8Array(3e4),ji=Ot.length/3,Fi=(n,e)=>{if(e.length<ji){let t=pe.encodeInto(e,Ot).written||0;w(n,t);for(let r=0;r<t;r++)T(n,Ot[r]);}else V(n,An(e));},Wi=(n,e)=>{let t=unescape(encodeURIComponent(e)),r=t.length;w(n,r);for(let i=0;i<r;i++)T(n,t.codePointAt(i));},ae=pe&&pe.encodeInto?Fi:Wi;var st=(n,e)=>{let t=n.cbuf.length,r=n.cpos,i=Qe(t-r,e.length),s=e.length-i;n.cbuf.set(e.subarray(0,i),r),n.cpos+=i,s>0&&(n.bufs.push(n.cbuf),n.cbuf=new Uint8Array(te(t*2,s)),n.cbuf.set(e.subarray(i)),n.cpos=s);},V=(n,e)=>{w(n,e.byteLength),st(n,e);},At=(n,e)=>{Pi(n,e);let t=new DataView(n.cbuf.buffer,n.cpos,e);return n.cpos+=e,t},$i=(n,e)=>At(n,4).setFloat32(0,e,!1),Gi=(n,e)=>At(n,8).setFloat64(0,e,!1),qi=(n,e)=>At(n,8).setBigInt64(0,e,!1);var Vn=new DataView(new ArrayBuffer(4)),Ji=n=>(Vn.setFloat32(0,n),Vn.getFloat32(0)===n),me=(n,e)=>{switch(typeof e){case"string":T(n,119),ae(n,e);break;case"number":On(e)&&ge(e)<=2147483647?(T(n,125),it(n,e)):Ji(e)?(T(n,124),$i(n,e)):(T(n,123),Gi(n,e));break;case"bigint":T(n,122),qi(n,e);break;case"object":if(e===null)T(n,126);else if(xt(e)){T(n,117),w(n,e.length);for(let t=0;t<e.length;t++)me(n,e[t]);}else if(e instanceof Uint8Array)T(n,116),V(n,e);else {T(n,118);let t=Object.keys(e);w(n,t.length);for(let r=0;r<t.length;r++){let i=t[r];ae(n,i),me(n,e[i]);}}break;case"boolean":T(n,e?120:121);break;default:T(n,127);}},De=class extends ce{constructor(e){super(),this.w=e,this.s=null,this.count=0;}write(e){this.s===e?this.count++:(this.count>0&&w(this,this.count-1),this.count=1,this.w(this,e),this.s=e);}};var Mn=n=>{n.count>0&&(it(n.encoder,n.count===1?n.s:-n.s),n.count>1&&w(n.encoder,n.count-2));},le=class{constructor(){this.encoder=new ce,this.s=0,this.count=0;}write(e){this.s===e?this.count++:(Mn(this),this.count=1,this.s=e);}toUint8Array(){return Mn(this),j(this.encoder)}};var Nn=n=>{if(n.count>0){let e=n.diff*2+(n.count===1?0:1);it(n.encoder,e),n.count>1&&w(n.encoder,n.count-2);}},ye=class{constructor(){this.encoder=new ce,this.s=0,this.count=0,this.diff=0;}write(e){this.diff===e-this.s?(this.s=e,this.count++):(Nn(this),this.count=1,this.diff=e-this.s,this.s=e);}toUint8Array(){return Nn(this),j(this.encoder)}},tt=class{constructor(){this.sarr=[],this.s="",this.lensE=new le;}write(e){this.s+=e,this.s.length>19&&(this.sarr.push(this.s),this.s=""),this.lensE.write(e.length);}toUint8Array(){let e=new ce;return this.sarr.push(this.s),this.s="",ae(e,this.sarr.join("")),st(e,this.lensE.toUint8Array()),j(e)}};var de=n=>new Error(n),B=()=>{throw de("Method unimplemented")},ne=()=>{throw de("Unexpected case")};var Bn=crypto.getRandomValues.bind(crypto);var Lt=()=>Bn(new Uint32Array(1))[0];var Yi="10000000-1000-4000-8000"+-1e11,Kn=()=>Yi.replace(/[018]/g,n=>(n^Lt()&15>>n/4).toString(16));var Vt=n=>new Promise(n);Promise.all.bind(Promise);var Mt=n=>n===void 0?null:n;var Nt=class{constructor(){this.map=new Map;}setItem(e,t){this.map.set(e,t);}getItem(e){return this.map.get(e)}},jn=new Nt,ts=!0;try{typeof localStorage<"u"&&localStorage&&(jn=localStorage,ts=!1);}catch{}var Fn=jn;var $n=Object.assign,rs=Object.keys,Gn=(n,e)=>{for(let t in n)e(n[t],t);};var Wn=n=>rs(n).length;var qn=n=>{for(let e in n)return !1;return !0},is=(n,e)=>{for(let t in n)if(!e(n[t],t))return !1;return !0},ss=(n,e)=>Object.prototype.hasOwnProperty.call(n,e),Jn=(n,e)=>n===e||Wn(n)===Wn(e)&&is(n,(t,r)=>(t!==void 0||ss(e,r))&&e[r]===t),os=Object.freeze,Bt=n=>{for(let e in n){let t=n[e];(typeof t=="object"||typeof t=="function")&&Bt(n[e]);}return os(n)};var Ue=(n,e,t=0)=>{try{for(;t<n.length;t++)n[t](...e);}finally{t<n.length&&Ue(n,e,t+1);}};var Hn=(n,e)=>e.includes(n);var Oe=typeof process<"u"&&process.release&&/node|io\.js/.test(process.release.name)&&Object.prototype.toString.call(typeof process<"u"?process:0)==="[object process]";var F,as=[],ls=()=>{if(F===void 0)if(Oe){F=L();let n=process.argv,e=null;for(let t=0;t<n.length;t++){let r=n[t];r[0]==="-"?(e!==null&&F.set(e,""),e=r):e!==null?(F.set(e,r),e=null):as.push(r);}e!==null&&F.set(e,"");}else typeof location=="object"?(F=L(),(location.search||"?").slice(1).split("&").forEach(n=>{if(n.length!==0){let[e,t]=n.split("=");F.set(`--${Dt(e,"-")}`,t),F.set(`-${Dt(e,"-")}`,t);}})):F=L();return F},Kt=n=>ls().has(n);var Ae=n=>Oe?Mt(process.env[n.toUpperCase().replaceAll("-","_")]):Mt(Fn.getItem(n));var Yn=n=>Kt("--"+n)||Ae(n)!==null;Yn("production");var ds=Oe&&Hn(process.env.FORCE_COLOR,["true","1","2"]),Xn=ds||!Kt("--no-colors")&&!Yn("no-color")&&(!Oe||process.stdout.isTTY)&&(!Oe||Kt("--color")||Ae("COLORTERM")!==null||(Ae("TERM")||"").includes("color"));var Pt=class{constructor(e,t){this.left=e,this.right=t;}},W=(n,e)=>new Pt(n,e);typeof DOMParser<"u"?new DOMParser:null;var Qn=n=>Rn(n,(e,t)=>`${t}:${e};`).join("");var $=Symbol;var Le=$(),Ve=$(),jt=$(),Ft=$(),Wt=$(),Me=$(),$t=$(),we=$(),Gt=$(),er=n=>{n.length===1&&n[0]?.constructor===Function&&(n=n[0]());let e=[],t=[],r=0;for(;r<n.length;r++){let i=n[r];if(i===void 0)break;if(i.constructor===String||i.constructor===Number)e.push(i);else if(i.constructor===Object)break}for(r>0&&t.push(e.join(""));r<n.length;r++){let i=n[r];i instanceof Symbol||t.push(i);}return t};var ps={[Le]:W("font-weight","bold"),[Ve]:W("font-weight","normal"),[jt]:W("color","blue"),[Wt]:W("color","green"),[Ft]:W("color","grey"),[Me]:W("color","red"),[$t]:W("color","purple"),[we]:W("color","orange"),[Gt]:W("color","black")},ms=n=>{n.length===1&&n[0]?.constructor===Function&&(n=n[0]());let e=[],t=[],r=L(),i=[],s=0;for(;s<n.length;s++){let o=n[s],c=ps[o];if(c!==void 0)r.set(c.left,c.right);else {if(o===void 0)break;if(o.constructor===String||o.constructor===Number){let a=Qn(r);s>0||a.length>0?(e.push("%c"+o),t.push(a)):e.push(o);}else break}}for(s>0&&(i=t,i.unshift(e.join("")));s<n.length;s++){let o=n[s];o instanceof Symbol||i.push(o);}return i},tr=Xn?ms:er,nr=(...n)=>{console.log(...tr(n)),ir.forEach(e=>e.print(n));},rr=(...n)=>{console.warn(...tr(n)),n.unshift(we),ir.forEach(e=>e.print(n));};var ir=H();var sr=n=>({[Symbol.iterator](){return this},next:n}),or=(n,e)=>sr(()=>{let t;do t=n.next();while(!t.done&&!e(t.value));return t}),ot=(n,e)=>sr(()=>{let{done:t,value:r}=n.next();return {done:t,value:t?void 0:e(r)}});var Ht=class{constructor(e,t){this.clock=e,this.len=t;}},ht=class{constructor(){this.clients=new Map;}},_r=(n,e,t)=>e.clients.forEach((r,i)=>{let s=n.doc.store.clients.get(i);for(let o=0;o<r.length;o++){let c=r[o];xr(n,s,c.clock,c.len,t);}}),Ss=(n,e)=>{let t=0,r=n.length-1;for(;t<=r;){let i=P((t+r)/2),s=n[i],o=s.clock;if(o<=e){if(e<o+s.len)return i;t=i+1;}else r=i-1;}return null},br=(n,e)=>{let t=n.clients.get(e.client);return t!==void 0&&Ss(t,e.clock)!==null},Sr=n=>{n.clients.forEach(e=>{e.sort((i,s)=>i.clock-s.clock);let t,r;for(t=1,r=1;t<e.length;t++){let i=e[r-1],s=e[t];i.clock+i.len>=s.clock?i.len=te(i.len,s.clock+s.len-i.clock):(r<t&&(e[r]=s),r++);}e.length=r;});};var vr=(n,e,t,r)=>{Q(n.clients,e,()=>[]).push(new Ht(t,r));};var Es=(n,e)=>{w(n.restEncoder,e.clients.size),ee(e.clients.entries()).sort((t,r)=>r[0]-t[0]).forEach(([t,r])=>{n.resetDsCurVal(),w(n.restEncoder,t);let i=r.length;w(n.restEncoder,i);for(let s=0;s<i;s++){let o=r[s];n.writeDsClock(o.clock),n.writeDsLen(o.len);}});};var Er=Lt,ue=class n extends Ze{constructor({guid:e=Kn(),collectionid:t=null,gc:r=!0,gcFilter:i=()=>!0,meta:s=null,autoLoad:o=!1,shouldLoad:c=!0}={}){super(),this.gc=r,this.gcFilter=i,this.clientID=Er(),this.guid=e,this.collectionid=t,this.share=new Map,this.store=new nn,this._transaction=null,this._transactionCleanups=[],this.subdocs=new Set,this._item=null,this.shouldLoad=c,this.autoLoad=o,this.meta=s,this.isLoaded=!1,this.isSynced=!1,this.isDestroyed=!1,this.whenLoaded=Vt(l=>{this.on("load",()=>{this.isLoaded=!0,l(this);});});let a=()=>Vt(l=>{let d=u=>{(u===void 0||u===!0)&&(this.off("sync",d),l());};this.on("sync",d);});this.on("sync",l=>{l===!1&&this.isSynced&&(this.whenSynced=a()),this.isSynced=l===void 0||l===!0,this.isSynced&&!this.isLoaded&&this.emit("load",[this]);}),this.whenSynced=a();}load(){let e=this._item;e!==null&&!this.shouldLoad&&S(e.parent.doc,t=>{t.subdocsLoaded.add(this);},null,!0),this.shouldLoad=!0;}getSubdocs(){return this.subdocs}getSubdocGuids(){return new Set(ee(this.subdocs).map(e=>e.guid))}transact(e,t=null){return S(this,e,t)}get(e,t=C){let r=Q(this.share,e,()=>{let s=new t;return s._integrate(this,null),s}),i=r.constructor;if(t!==C&&i!==t)if(i===C){let s=new t;s._map=r._map,r._map.forEach(o=>{for(;o!==null;o=o.left)o.parent=s;}),s._start=r._start;for(let o=s._start;o!==null;o=o.right)o.parent=s;return s._length=r._length,this.share.set(e,s),s._integrate(this,null),s}else throw new Error(`Type with the name ${e} has already been defined with a different constructor`);return r}getArray(e=""){return this.get(e,an)}getText(e=""){return this.get(e,un)}getMap(e=""){return this.get(e,dn)}getXmlElement(e=""){return this.get(e,gt)}getXmlFragment(e=""){return this.get(e,je)}toJSON(){let e={};return this.share.forEach((t,r)=>{e[r]=t.toJSON();}),e}destroy(){this.isDestroyed=!0,ee(this.subdocs).forEach(t=>t.destroy());let e=this._item;if(e!==null){this._item=null;let t=e.content;t.doc=new n({guid:this.guid,...t.opts,shouldLoad:!1}),t.doc._item=e,S(e.parent.doc,r=>{let i=t.doc;e.deleted||r.subdocsAdded.add(i),r.subdocsRemoved.add(this);},null,!0);}this.emit("destroyed",[!0]),this.emit("destroy",[this]),super.destroy();}};var zt=class{constructor(){this.restEncoder=nt();}toUint8Array(){return j(this.restEncoder)}resetDsCurVal(){}writeDsClock(e){w(this.restEncoder,e);}writeDsLen(e){w(this.restEncoder,e);}},Yt=class extends zt{writeLeftID(e){w(this.restEncoder,e.client),w(this.restEncoder,e.clock);}writeRightID(e){w(this.restEncoder,e.client),w(this.restEncoder,e.clock);}writeClient(e){w(this.restEncoder,e);}writeInfo(e){rt(this.restEncoder,e);}writeString(e){ae(this.restEncoder,e);}writeParentInfo(e){w(this.restEncoder,e?1:0);}writeTypeRef(e){w(this.restEncoder,e);}writeLen(e){w(this.restEncoder,e);}writeAny(e){me(this.restEncoder,e);}writeBuf(e){V(this.restEncoder,e);}writeJSON(e){ae(this.restEncoder,JSON.stringify(e));}writeKey(e){ae(this.restEncoder,e);}},Xt=class{constructor(){this.restEncoder=nt(),this.dsCurrVal=0;}toUint8Array(){return j(this.restEncoder)}resetDsCurVal(){this.dsCurrVal=0;}writeDsClock(e){let t=e-this.dsCurrVal;this.dsCurrVal=e,w(this.restEncoder,t);}writeDsLen(e){e===0&&ne(),w(this.restEncoder,e-1),this.dsCurrVal+=e;}},Zt=class extends Xt{constructor(){super(),this.keyMap=new Map,this.keyClock=0,this.keyClockEncoder=new ye,this.clientEncoder=new le,this.leftClockEncoder=new ye,this.rightClockEncoder=new ye,this.infoEncoder=new De(rt),this.stringEncoder=new tt,this.parentInfoEncoder=new De(rt),this.typeRefEncoder=new le,this.lenEncoder=new le;}toUint8Array(){let e=nt();return w(e,0),V(e,this.keyClockEncoder.toUint8Array()),V(e,this.clientEncoder.toUint8Array()),V(e,this.leftClockEncoder.toUint8Array()),V(e,this.rightClockEncoder.toUint8Array()),V(e,j(this.infoEncoder)),V(e,this.stringEncoder.toUint8Array()),V(e,j(this.parentInfoEncoder)),V(e,this.typeRefEncoder.toUint8Array()),V(e,this.lenEncoder.toUint8Array()),st(e,j(this.restEncoder)),j(e)}writeLeftID(e){this.clientEncoder.write(e.client),this.leftClockEncoder.write(e.clock);}writeRightID(e){this.clientEncoder.write(e.client),this.rightClockEncoder.write(e.clock);}writeClient(e){this.clientEncoder.write(e);}writeInfo(e){this.infoEncoder.write(e);}writeString(e){this.stringEncoder.write(e);}writeParentInfo(e){this.parentInfoEncoder.write(e?1:0);}writeTypeRef(e){this.typeRefEncoder.write(e);}writeLen(e){this.lenEncoder.write(e);}writeAny(e){me(this.restEncoder,e);}writeBuf(e){V(this.restEncoder,e);}writeJSON(e){me(this.restEncoder,e);}writeKey(e){let t=this.keyMap.get(e);t===void 0?(this.keyClockEncoder.write(this.keyClock++),this.stringEncoder.write(e)):this.keyClockEncoder.write(t);}},ks=(n,e,t,r)=>{r=te(r,e[0].id.clock);let i=z(e,r);w(n.restEncoder,e.length-i),n.writeClient(t),w(n.restEncoder,r);let s=e[i];s.write(n,r-s.id.clock);for(let o=i+1;o<e.length;o++)e[o].write(n,0);},Cs=(n,e,t)=>{let r=new Map;t.forEach((i,s)=>{M(e,s)>i&&r.set(s,i);}),pn(e).forEach((i,s)=>{t.has(s)||r.set(s,0);}),w(n.restEncoder,r.size),ee(r.entries()).sort((i,s)=>s[0]-i[0]).forEach(([i,s])=>{ks(n,e.clients.get(i),i,s);});};var xs=(n,e)=>Cs(n,e.doc.store,e.beforeState);var Qt=class{constructor(){this.l=[];}},lr=()=>new Qt,dr=(n,e)=>n.l.push(e),hr=(n,e)=>{let t=n.l,r=t.length;n.l=t.filter(i=>e!==i),r===n.l.length&&console.error("[yjs] Tried to remove event handler that doesn't exist.");},kr=(n,e,t)=>Ue(n.l,[e,t]),be=class{constructor(e,t){this.client=e,this.clock=t;}},ct=(n,e)=>n===e||n!==null&&e!==null&&n.client===e.client&&n.clock===e.clock,v=(n,e)=>new be(n,e);var Is=n=>{for(let[e,t]of n.doc.share.entries())if(t===n)return e;throw ne()};var _e=(n,e)=>e===void 0?!n.deleted:e.sv.has(n.id.client)&&(e.sv.get(n.id.client)||0)>n.id.clock&&!br(e.ds,n.id),tn=(n,e)=>{let t=Q(n.meta,tn,H),r=n.doc.store;t.has(e)||(e.sv.forEach((i,s)=>{i<M(r,s)&&ie(n,v(s,i));}),_r(n,e.ds,i=>{}),t.add(e));};var nn=class{constructor(){this.clients=new Map,this.pendingStructs=null,this.pendingDs=null;}},pn=n=>{let e=new Map;return n.clients.forEach((t,r)=>{let i=t[t.length-1];e.set(r,i.id.clock+i.length);}),e},M=(n,e)=>{let t=n.clients.get(e);if(t===void 0)return 0;let r=t[t.length-1];return r.id.clock+r.length},Cr=(n,e)=>{let t=n.clients.get(e.id.client);if(t===void 0)t=[],n.clients.set(e.id.client,t);else {let r=t[t.length-1];if(r.id.clock+r.length!==e.id.clock)throw ne()}t.push(e);},z=(n,e)=>{let t=0,r=n.length-1,i=n[r],s=i.id.clock;if(s===e)return r;let o=P(e/(s+i.length-1)*r);for(;t<=r;){if(i=n[o],s=i.id.clock,s<=e){if(e<s+i.length)return o;t=o+1;}else r=o-1;o=P((t+r)/2);}throw ne()},Rs=(n,e)=>{let t=n.clients.get(e.client);return t[z(t,e.clock)]},qt=Rs,rn=(n,e,t)=>{let r=z(e,t),i=e[r];return i.id.clock<t&&i instanceof A?(e.splice(r+1,0,Wr(n,i,t-i.id.clock)),r+1):r},ie=(n,e)=>{let t=n.doc.store.clients.get(e.client);return t[rn(n,t,e.clock)]},ur=(n,e,t)=>{let r=e.clients.get(t.client),i=z(r,t.clock),s=r[i];return t.clock!==s.id.clock+s.length-1&&s.constructor!==G&&r.splice(i+1,0,Wr(n,s,t.clock-s.id.clock+1)),s},Ds=(n,e,t)=>{let r=n.clients.get(e.id.client);r[z(r,e.id.clock)]=t;},xr=(n,e,t,r,i)=>{if(r===0)return;let s=t+r,o=rn(n,e,t),c;do c=e[o++],s<c.id.clock+c.length&&rn(n,e,s),i(c);while(o<e.length&&e[o].id.clock<s)},sn=class{constructor(e,t,r){this.doc=e,this.deleteSet=new ht,this.beforeState=pn(e.store),this.afterState=new Map,this.changed=new Map,this.changedParentTypes=new Map,this._mergeStructs=[],this.origin=t,this.meta=new Map,this.local=r,this.subdocsAdded=new Set,this.subdocsRemoved=new Set,this.subdocsLoaded=new Set,this._needFormattingCleanup=!1;}},fr=(n,e)=>e.deleteSet.clients.size===0&&!Dn(e.afterState,(t,r)=>e.beforeState.get(r)!==t)?!1:(Sr(e.deleteSet),xs(n,e),Es(n,e.deleteSet),!0),gr=(n,e,t)=>{let r=e._item;(r===null||r.id.clock<(n.beforeState.get(r.id.client)||0)&&!r.deleted)&&Q(n.changed,e,H).add(t);},dt=(n,e)=>{let t=n[e],r=n[e-1],i=e;for(;i>0;t=r,r=n[--i-1]){if(r.deleted===t.deleted&&r.constructor===t.constructor&&r.mergeWith(t)){t instanceof A&&t.parentSub!==null&&t.parent._map.get(t.parentSub)===t&&t.parent._map.set(t.parentSub,r);continue}break}let s=e-i;return s&&n.splice(e+1-s,s),s},Us=(n,e,t)=>{for(let[r,i]of n.clients.entries()){let s=e.clients.get(r);for(let o=i.length-1;o>=0;o--){let c=i[o],a=c.clock+c.len;for(let l=z(s,c.clock),d=s[l];l<s.length&&d.id.clock<a;d=s[++l]){let u=s[l];if(c.clock+c.len<=u.id.clock)break;u instanceof A&&u.deleted&&!u.keep&&t(u)&&u.gc(e,!1);}}}},Os=(n,e)=>{n.clients.forEach((t,r)=>{let i=e.clients.get(r);for(let s=t.length-1;s>=0;s--){let o=t[s],c=Qe(i.length-1,1+z(i,o.clock+o.len-1));for(let a=c,l=i[a];a>0&&l.id.clock>=o.clock;l=i[a])a-=1+dt(i,a);}});};var Ir=(n,e)=>{if(e<n.length){let t=n[e],r=t.doc,i=r.store,s=t.deleteSet,o=t._mergeStructs;try{Sr(s),t.afterState=pn(t.doc.store),r.emit("beforeObserverCalls",[t,r]);let c=[];t.changed.forEach((a,l)=>c.push(()=>{(l._item===null||!l._item.deleted)&&l._callObserver(t,a);})),c.push(()=>{t.changedParentTypes.forEach((a,l)=>{l._dEH.l.length>0&&(l._item===null||!l._item.deleted)&&(a=a.filter(d=>d.target._item===null||!d.target._item.deleted),a.forEach(d=>{d.currentTarget=l,d._path=null;}),a.sort((d,u)=>d.path.length-u.path.length),kr(l._dEH,a,t));});}),c.push(()=>r.emit("afterTransaction",[t,r])),Ue(c,[]),t._needFormattingCleanup&&js(t);}finally{r.gc&&Us(s,i,r.gcFilter),Os(s,i),t.afterState.forEach((d,u)=>{let p=t.beforeState.get(u)||0;if(p!==d){let g=i.clients.get(u),_=te(z(g,p),1);for(let x=g.length-1;x>=_;)x-=1+dt(g,x);}});for(let d=o.length-1;d>=0;d--){let{client:u,clock:p}=o[d].id,g=i.clients.get(u),_=z(g,p);_+1<g.length&&dt(g,_+1)>1||_>0&&dt(g,_);}if(!t.local&&t.afterState.get(r.clientID)!==t.beforeState.get(r.clientID)&&(nr(we,Le,"[yjs] ",Ve,Me,"Changed the client-id because another client seems to be using it."),r.clientID=Er()),r.emit("afterTransactionCleanup",[t,r]),r._observers.has("update")){let d=new Yt;fr(d,t)&&r.emit("update",[d.toUint8Array(),t.origin,r,t]);}if(r._observers.has("updateV2")){let d=new Zt;fr(d,t)&&r.emit("updateV2",[d.toUint8Array(),t.origin,r,t]);}let{subdocsAdded:c,subdocsLoaded:a,subdocsRemoved:l}=t;(c.size>0||l.size>0||a.size>0)&&(c.forEach(d=>{d.clientID=r.clientID,d.collectionid==null&&(d.collectionid=r.collectionid),r.subdocs.add(d);}),l.forEach(d=>r.subdocs.delete(d)),r.emit("subdocs",[{loaded:a,added:c,removed:l},r,t]),l.forEach(d=>d.destroy())),n.length<=e+1?(r._transactionCleanups=[],r.emit("afterAllTransactions",[r,n])):Ir(n,e+1);}}},S=(n,e,t=null,r=!0)=>{let i=n._transactionCleanups,s=!1,o=null;n._transaction===null&&(s=!0,n._transaction=new sn(n,t,r),i.push(n._transaction),i.length===1&&n.emit("beforeAllTransactions",[n]),n.emit("beforeTransaction",[n._transaction,n]));try{o=e(n._transaction);}finally{if(s){let c=n._transaction===i[0];n._transaction=null,c&&Ir(i,0);}}return o};var pr="You must not compute changes after the event-handler fired.",Se=class{constructor(e,t){this.target=e,this.currentTarget=e,this.transaction=t,this._changes=null,this._keys=null,this._delta=null,this._path=null;}get path(){return this._path||(this._path=As(this.currentTarget,this.target))}deletes(e){return br(this.transaction.deleteSet,e.id)}get keys(){if(this._keys===null){if(this.transaction.doc._transactionCleanups.length===0)throw de(pr);let e=new Map,t=this.target;this.transaction.changed.get(t).forEach(i=>{if(i!==null){let s=t._map.get(i),o,c;if(this.adds(s)){let a=s.left;for(;a!==null&&this.adds(a);)a=a.left;if(this.deletes(s))if(a!==null&&this.deletes(a))o="delete",c=Xe(a.content.getContent());else return;else a!==null&&this.deletes(a)?(o="update",c=Xe(a.content.getContent())):(o="add",c=void 0);}else if(this.deletes(s))o="delete",c=Xe(s.content.getContent());else return;e.set(i,{action:o,oldValue:c});}}),this._keys=e;}return this._keys}get delta(){return this.changes.delta}adds(e){return e.id.clock>=(this.transaction.beforeState.get(e.id.client)||0)}get changes(){let e=this._changes;if(e===null){if(this.transaction.doc._transactionCleanups.length===0)throw de(pr);let t=this.target,r=H(),i=H(),s=[];if(e={added:r,deleted:i,delta:s,keys:this.keys},this.transaction.changed.get(t).has(null)){let c=null,a=()=>{c&&s.push(c);};for(let l=t._start;l!==null;l=l.right)l.deleted?this.deletes(l)&&!this.adds(l)&&((c===null||c.delete===void 0)&&(a(),c={delete:0}),c.delete+=l.length,i.add(l)):this.adds(l)?((c===null||c.insert===void 0)&&(a(),c={insert:[]}),c.insert=c.insert.concat(l.content.getContent()),r.add(l)):((c===null||c.retain===void 0)&&(a(),c={retain:0}),c.retain+=l.length);c!==null&&c.retain===void 0&&a();}this._changes=e;}return e}},As=(n,e)=>{let t=[];for(;e._item!==null&&e!==n;){if(e._item.parentSub!==null)t.unshift(e._item.parentSub);else {let r=0,i=e._item.parent._start;for(;i!==e._item&&i!==null;)!i.deleted&&i.countable&&(r+=i.length),i=i.right;t.unshift(r);}e=e._item.parent;}return t},O=()=>{rr("Invalid access: Add Yjs type to a document before reading data.");},Tr=80,mn=0,on=class{constructor(e,t){e.marker=!0,this.p=e,this.index=t,this.timestamp=mn++;}},Ls=n=>{n.timestamp=mn++;},Rr=(n,e,t)=>{n.p.marker=!1,n.p=e,e.marker=!0,n.index=t,n.timestamp=mn++;},Vs=(n,e,t)=>{if(n.length>=Tr){let r=n.reduce((i,s)=>i.timestamp<s.timestamp?i:s);return Rr(r,e,t),r}else {let r=new on(e,t);return n.push(r),r}},wt=(n,e)=>{if(n._start===null||e===0||n._searchMarker===null)return null;let t=n._searchMarker.length===0?null:n._searchMarker.reduce((s,o)=>ge(e-s.index)<ge(e-o.index)?s:o),r=n._start,i=0;for(t!==null&&(r=t.p,i=t.index,Ls(t));r.right!==null&&i<e;){if(!r.deleted&&r.countable){if(e<i+r.length)break;i+=r.length;}r=r.right;}for(;r.left!==null&&i>e;)r=r.left,!r.deleted&&r.countable&&(i-=r.length);for(;r.left!==null&&r.left.id.client===r.id.client&&r.left.id.clock+r.left.length===r.id.clock;)r=r.left,!r.deleted&&r.countable&&(i-=r.length);return t!==null&&ge(t.index-i)<r.parent.length/Tr?(Rr(t,r,i),t):Vs(n._searchMarker,r,i)},Be=(n,e,t)=>{for(let r=n.length-1;r>=0;r--){let i=n[r];if(t>0){let s=i.p;for(s.marker=!1;s&&(s.deleted||!s.countable);)s=s.left,s&&!s.deleted&&s.countable&&(i.index-=s.length);if(s===null||s.marker===!0){n.splice(r,1);continue}i.p=s,s.marker=!0;}(e<i.index||t>0&&e===i.index)&&(i.index=te(e,i.index+t));}};var _t=(n,e,t)=>{let r=n,i=e.changedParentTypes;for(;Q(i,n,()=>[]).push(t),n._item!==null;)n=n._item.parent;kr(r._eH,t,e);},C=class{constructor(){this._item=null,this._map=new Map,this._start=null,this.doc=null,this._length=0,this._eH=lr(),this._dEH=lr(),this._searchMarker=null;}get parent(){return this._item?this._item.parent:null}_integrate(e,t){this.doc=e,this._item=t;}_copy(){throw B()}clone(){throw B()}_write(e){}get _first(){let e=this._start;for(;e!==null&&e.deleted;)e=e.right;return e}_callObserver(e,t){!e.local&&this._searchMarker&&(this._searchMarker.length=0);}observe(e){dr(this._eH,e);}observeDeep(e){dr(this._dEH,e);}unobserve(e){hr(this._eH,e);}unobserveDeep(e){hr(this._dEH,e);}toJSON(){}},Dr=(n,e,t)=>{n.doc??O(),e<0&&(e=n._length+e),t<0&&(t=n._length+t);let r=t-e,i=[],s=n._start;for(;s!==null&&r>0;){if(s.countable&&!s.deleted){let o=s.content.getContent();if(o.length<=e)e-=o.length;else {for(let c=e;c<o.length&&r>0;c++)i.push(o[c]),r--;e=0;}}s=s.right;}return i},Ur=n=>{n.doc??O();let e=[],t=n._start;for(;t!==null;){if(t.countable&&!t.deleted){let r=t.content.getContent();for(let i=0;i<r.length;i++)e.push(r[i]);}t=t.right;}return e};var Ke=(n,e)=>{let t=0,r=n._start;for(n.doc??O();r!==null;){if(r.countable&&!r.deleted){let i=r.content.getContent();for(let s=0;s<i.length;s++)e(i[s],t++,n);}r=r.right;}},Or=(n,e)=>{let t=[];return Ke(n,(r,i)=>{t.push(e(r,i,n));}),t},Ms=n=>{let e=n._start,t=null,r=0;return {[Symbol.iterator](){return this},next:()=>{if(t===null){for(;e!==null&&e.deleted;)e=e.right;if(e===null)return {done:!0,value:void 0};t=e.content.getContent(),r=0,e=e.right;}let i=t[r++];return t.length<=r&&(t=null),{done:!1,value:i}}}},Ar=(n,e)=>{n.doc??O();let t=wt(n,e),r=n._start;for(t!==null&&(r=t.p,e-=t.index);r!==null;r=r.right)if(!r.deleted&&r.countable){if(e<r.length)return r.content.getContent()[e];e-=r.length;}},ut=(n,e,t,r)=>{let i=t,s=n.doc,o=s.clientID,c=s.store,a=t===null?e._start:t.right,l=[],d=()=>{l.length>0&&(i=new A(v(o,M(c,o)),i,i&&i.lastId,a,a&&a.id,e,null,new Fe(l)),i.integrate(n,0),l=[]);};r.forEach(u=>{if(u===null)l.push(u);else switch(u.constructor){case Number:case Object:case Boolean:case Array:case String:l.push(u);break;default:switch(d(),u.constructor){case Uint8Array:case ArrayBuffer:i=new A(v(o,M(c,o)),i,i&&i.lastId,a,a&&a.id,e,null,new mt(new Uint8Array(u))),i.integrate(n,0);break;case ue:i=new A(v(o,M(c,o)),i,i&&i.lastId,a,a&&a.id,e,null,new yt(u)),i.integrate(n,0);break;default:if(u instanceof C)i=new A(v(o,M(c,o)),i,i&&i.lastId,a,a&&a.id,e,null,new oe(u)),i.integrate(n,0);else throw new Error("Unexpected content type in insert operation")}}}),d();},Lr=()=>de("Length exceeded!"),Vr=(n,e,t,r)=>{if(t>e._length)throw Lr();if(t===0)return e._searchMarker&&Be(e._searchMarker,t,r.length),ut(n,e,null,r);let i=t,s=wt(e,t),o=e._start;for(s!==null&&(o=s.p,t-=s.index,t===0&&(o=o.prev,t+=o&&o.countable&&!o.deleted?o.length:0));o!==null;o=o.right)if(!o.deleted&&o.countable){if(t<=o.length){t<o.length&&ie(n,v(o.id.client,o.id.clock+t));break}t-=o.length;}return e._searchMarker&&Be(e._searchMarker,i,r.length),ut(n,e,o,r)},Ns=(n,e,t)=>{let i=(e._searchMarker||[]).reduce((s,o)=>o.index>s.index?o:s,{index:0,p:e._start}).p;if(i)for(;i.right;)i=i.right;return ut(n,e,i,t)},Mr=(n,e,t,r)=>{if(r===0)return;let i=t,s=r,o=wt(e,t),c=e._start;for(o!==null&&(c=o.p,t-=o.index);c!==null&&t>0;c=c.right)!c.deleted&&c.countable&&(t<c.length&&ie(n,v(c.id.client,c.id.clock+t)),t-=c.length);for(;r>0&&c!==null;)c.deleted||(r<c.length&&ie(n,v(c.id.client,c.id.clock+r)),c.delete(n),r-=c.length),c=c.right;if(r>0)throw Lr();e._searchMarker&&Be(e._searchMarker,i,-s+r);},ft=(n,e,t)=>{let r=e._map.get(t);r!==void 0&&r.delete(n);},yn=(n,e,t,r)=>{let i=e._map.get(t)||null,s=n.doc,o=s.clientID,c;if(r==null)c=new Fe([r]);else switch(r.constructor){case Number:case Object:case Boolean:case Array:case String:c=new Fe([r]);break;case Uint8Array:c=new mt(r);break;case ue:c=new yt(r);break;default:if(r instanceof C)c=new oe(r);else throw new Error("Unexpected content type")}new A(v(o,M(s.store,o)),i,i&&i.lastId,null,null,e,t,c).integrate(n,0);},wn=(n,e)=>{n.doc??O();let t=n._map.get(e);return t!==void 0&&!t.deleted?t.content.getContent()[t.length-1]:void 0},Nr=n=>{let e={};return n.doc??O(),n._map.forEach((t,r)=>{t.deleted||(e[r]=t.content.getContent()[t.length-1]);}),e},Br=(n,e)=>{n.doc??O();let t=n._map.get(e);return t!==void 0&&!t.deleted};var Bs=(n,e)=>{let t={};return n._map.forEach((r,i)=>{let s=r;for(;s!==null&&(!e.sv.has(s.id.client)||s.id.clock>=(e.sv.get(s.id.client)||0));)s=s.left;s!==null&&_e(s,e)&&(t[i]=s.content.getContent()[s.length-1]);}),t},at=n=>(n.doc??O(),or(n._map.entries(),e=>!e[1].deleted)),cn=class extends Se{},an=class n extends C{constructor(){super(),this._prelimContent=[],this._searchMarker=[];}static from(e){let t=new n;return t.push(e),t}_integrate(e,t){super._integrate(e,t),this.insert(0,this._prelimContent),this._prelimContent=null;}_copy(){return new n}clone(){let e=new n;return e.insert(0,this.toArray().map(t=>t instanceof C?t.clone():t)),e}get length(){return this.doc??O(),this._length}_callObserver(e,t){super._callObserver(e,t),_t(this,e,new cn(this,e));}insert(e,t){this.doc!==null?S(this.doc,r=>{Vr(r,this,e,t);}):this._prelimContent.splice(e,0,...t);}push(e){this.doc!==null?S(this.doc,t=>{Ns(t,this,e);}):this._prelimContent.push(...e);}unshift(e){this.insert(0,e);}delete(e,t=1){this.doc!==null?S(this.doc,r=>{Mr(r,this,e,t);}):this._prelimContent.splice(e,t);}get(e){return Ar(this,e)}toArray(){return Ur(this)}slice(e=0,t=this.length){return Dr(this,e,t)}toJSON(){return this.map(e=>e instanceof C?e.toJSON():e)}map(e){return Or(this,e)}forEach(e){Ke(this,e);}[Symbol.iterator](){return Ms(this)}_write(e){e.writeTypeRef(Gs);}};var ln=class extends Se{constructor(e,t,r){super(e,t),this.keysChanged=r;}},dn=class n extends C{constructor(e){super(),this._prelimContent=null,e===void 0?this._prelimContent=new Map:this._prelimContent=new Map(e);}_integrate(e,t){super._integrate(e,t),this._prelimContent.forEach((r,i)=>{this.set(i,r);}),this._prelimContent=null;}_copy(){return new n}clone(){let e=new n;return this.forEach((t,r)=>{e.set(r,t instanceof C?t.clone():t);}),e}_callObserver(e,t){_t(this,e,new ln(this,e,t));}toJSON(){this.doc??O();let e={};return this._map.forEach((t,r)=>{if(!t.deleted){let i=t.content.getContent()[t.length-1];e[r]=i instanceof C?i.toJSON():i;}}),e}get size(){return [...at(this)].length}keys(){return ot(at(this),e=>e[0])}values(){return ot(at(this),e=>e[1].content.getContent()[e[1].length-1])}entries(){return ot(at(this),e=>[e[0],e[1].content.getContent()[e[1].length-1]])}forEach(e){this.doc??O(),this._map.forEach((t,r)=>{t.deleted||e(t.content.getContent()[t.length-1],r,this);});}[Symbol.iterator](){return this.entries()}delete(e){this.doc!==null?S(this.doc,t=>{ft(t,this,e);}):this._prelimContent.delete(e);}set(e,t){return this.doc!==null?S(this.doc,r=>{yn(r,this,e,t);}):this._prelimContent.set(e,t),t}get(e){return wn(this,e)}has(e){return Br(this,e)}clear(){this.doc!==null?S(this.doc,e=>{this.forEach(function(t,r,i){ft(e,i,r);});}):this._prelimContent.clear();}_write(e){e.writeTypeRef(qs);}};var re=(n,e)=>n===e||typeof n=="object"&&typeof e=="object"&&n&&e&&Jn(n,e),Pe=class{constructor(e,t,r,i){this.left=e,this.right=t,this.index=r,this.currentAttributes=i;}forward(){switch(this.right===null&&ne(),this.right.content.constructor){case R:this.right.deleted||Ee(this.currentAttributes,this.right.content);break;default:this.right.deleted||(this.index+=this.right.length);break}this.left=this.right,this.right=this.right.right;}},mr=(n,e,t)=>{for(;e.right!==null&&t>0;){switch(e.right.content.constructor){case R:e.right.deleted||Ee(e.currentAttributes,e.right.content);break;default:e.right.deleted||(t<e.right.length&&ie(n,v(e.right.id.client,e.right.id.clock+t)),e.index+=e.right.length,t-=e.right.length);break}e.left=e.right,e.right=e.right.right;}return e},lt=(n,e,t,r)=>{let i=new Map,s=r?wt(e,t):null;if(s){let o=new Pe(s.p.left,s.p,s.index,i);return mr(n,o,t-s.index)}else {let o=new Pe(null,e._start,0,i);return mr(n,o,t)}},Kr=(n,e,t,r)=>{for(;t.right!==null&&(t.right.deleted===!0||t.right.content.constructor===R&&re(r.get(t.right.content.key),t.right.content.value));)t.right.deleted||r.delete(t.right.content.key),t.forward();let i=n.doc,s=i.clientID;r.forEach((o,c)=>{let a=t.left,l=t.right,d=new A(v(s,M(i.store,s)),a,a&&a.lastId,l,l&&l.id,e,null,new R(c,o));d.integrate(n,0),t.right=d,t.forward();});},Ee=(n,e)=>{let{key:t,value:r}=e;r===null?n.delete(t):n.set(t,r);},Pr=(n,e)=>{for(;n.right!==null;){if(!(n.right.deleted||n.right.content.constructor===R&&re(e[n.right.content.key]??null,n.right.content.value)))break;n.forward();}},jr=(n,e,t,r)=>{let i=n.doc,s=i.clientID,o=new Map;for(let c in r){let a=r[c],l=t.currentAttributes.get(c)??null;if(!re(l,a)){o.set(c,l);let{left:d,right:u}=t;t.right=new A(v(s,M(i.store,s)),d,d&&d.lastId,u,u&&u.id,e,null,new R(c,a)),t.right.integrate(n,0),t.forward();}}return o},Jt=(n,e,t,r,i)=>{t.currentAttributes.forEach((p,g)=>{i[g]===void 0&&(i[g]=null);});let s=n.doc,o=s.clientID;Pr(t,i);let c=jr(n,e,t,i),a=r.constructor===String?new se(r):r instanceof C?new oe(r):new ve(r),{left:l,right:d,index:u}=t;e._searchMarker&&Be(e._searchMarker,t.index,a.getLength()),d=new A(v(o,M(s.store,o)),l,l&&l.lastId,d,d&&d.id,e,null,a),d.integrate(n,0),t.right=d,t.index=u,t.forward(),Kr(n,e,t,c);},yr=(n,e,t,r,i)=>{let s=n.doc,o=s.clientID;Pr(t,i);let c=jr(n,e,t,i);e:for(;t.right!==null&&(r>0||c.size>0&&(t.right.deleted||t.right.content.constructor===R));){if(!t.right.deleted)switch(t.right.content.constructor){case R:{let{key:a,value:l}=t.right.content,d=i[a];if(d!==void 0){if(re(d,l))c.delete(a);else {if(r===0)break e;c.set(a,l);}t.right.delete(n);}else t.currentAttributes.set(a,l);break}default:r<t.right.length&&ie(n,v(t.right.id.client,t.right.id.clock+r)),r-=t.right.length;break}t.forward();}if(r>0){let a="";for(;r>0;r--)a+=`
15
+ `;t.right=new A(v(o,M(s.store,o)),t.left,t.left&&t.left.lastId,t.right,t.right&&t.right.id,e,null,new se(a)),t.right.integrate(n,0),t.forward();}Kr(n,e,t,c);},Fr=(n,e,t,r,i)=>{let s=e,o=L();for(;s&&(!s.countable||s.deleted);){if(!s.deleted&&s.content.constructor===R){let l=s.content;o.set(l.key,l);}s=s.right;}let c=0,a=!1;for(;e!==s;){if(t===e&&(a=!0),!e.deleted){let l=e.content;switch(l.constructor){case R:{let{key:d,value:u}=l,p=r.get(d)??null;(o.get(d)!==l||p===u)&&(e.delete(n),c++,!a&&(i.get(d)??null)===u&&p!==u&&(p===null?i.delete(d):i.set(d,p))),!a&&!e.deleted&&Ee(i,l);break}}}e=e.right;}return c},Ks=(n,e)=>{for(;e&&e.right&&(e.right.deleted||!e.right.countable);)e=e.right;let t=new Set;for(;e&&(e.deleted||!e.countable);){if(!e.deleted&&e.content.constructor===R){let r=e.content.key;t.has(r)?e.delete(n):t.add(r);}e=e.left;}},Ps=n=>{let e=0;return S(n.doc,t=>{let r=n._start,i=n._start,s=L(),o=Ye(s);for(;i;){if(i.deleted===!1)switch(i.content.constructor){case R:Ee(o,i.content);break;default:e+=Fr(t,r,i,s,o),s=Ye(o),r=i;break}i=i.right;}}),e},js=n=>{let e=new Set,t=n.doc;for(let[r,i]of n.afterState.entries()){let s=n.beforeState.get(r)||0;i!==s&&xr(n,t.store.clients.get(r),s,i,o=>{!o.deleted&&o.content.constructor===R&&o.constructor!==G&&e.add(o.parent);});}S(t,r=>{_r(n,n.deleteSet,i=>{if(i instanceof G||!i.parent._hasFormatting||e.has(i.parent))return;let s=i.parent;i.content.constructor===R?e.add(s):Ks(r,i);});for(let i of e)Ps(i);});},wr=(n,e,t)=>{let r=t,i=Ye(e.currentAttributes),s=e.right;for(;t>0&&e.right!==null;){if(e.right.deleted===!1)switch(e.right.content.constructor){case oe:case ve:case se:t<e.right.length&&ie(n,v(e.right.id.client,e.right.id.clock+t)),t-=e.right.length,e.right.delete(n);break}e.forward();}s&&Fr(n,s,e.right,i,e.currentAttributes);let o=(e.left||e.right).parent;return o._searchMarker&&Be(o._searchMarker,e.index,-r+t),e},hn=class extends Se{constructor(e,t,r){super(e,t),this.childListChanged=!1,this.keysChanged=new Set,r.forEach(i=>{i===null?this.childListChanged=!0:this.keysChanged.add(i);});}get changes(){if(this._changes===null){let e={keys:this.keys,delta:this.delta,added:new Set,deleted:new Set};this._changes=e;}return this._changes}get delta(){if(this._delta===null){let e=this.target.doc,t=[];S(e,r=>{let i=new Map,s=new Map,o=this.target._start,c=null,a={},l="",d=0,u=0,p=()=>{if(c!==null){let g=null;switch(c){case"delete":u>0&&(g={delete:u}),u=0;break;case"insert":(typeof l=="object"||l.length>0)&&(g={insert:l},i.size>0&&(g.attributes={},i.forEach((_,x)=>{_!==null&&(g.attributes[x]=_);}))),l="";break;case"retain":d>0&&(g={retain:d},qn(a)||(g.attributes=$n({},a))),d=0;break}g&&t.push(g),c=null;}};for(;o!==null;){switch(o.content.constructor){case oe:case ve:this.adds(o)?this.deletes(o)||(p(),c="insert",l=o.content.getContent()[0],p()):this.deletes(o)?(c!=="delete"&&(p(),c="delete"),u+=1):o.deleted||(c!=="retain"&&(p(),c="retain"),d+=1);break;case se:this.adds(o)?this.deletes(o)||(c!=="insert"&&(p(),c="insert"),l+=o.content.str):this.deletes(o)?(c!=="delete"&&(p(),c="delete"),u+=o.length):o.deleted||(c!=="retain"&&(p(),c="retain"),d+=o.length);break;case R:{let{key:g,value:_}=o.content;if(this.adds(o)){if(!this.deletes(o)){let x=i.get(g)??null;re(x,_)?_!==null&&o.delete(r):(c==="retain"&&p(),re(_,s.get(g)??null)?delete a[g]:a[g]=_);}}else if(this.deletes(o)){s.set(g,_);let x=i.get(g)??null;re(x,_)||(c==="retain"&&p(),a[g]=x);}else if(!o.deleted){s.set(g,_);let x=a[g];x!==void 0&&(re(x,_)?x!==null&&o.delete(r):(c==="retain"&&p(),_===null?delete a[g]:a[g]=_));}o.deleted||(c==="insert"&&p(),Ee(i,o.content));break}}o=o.right;}for(p();t.length>0;){let g=t[t.length-1];if(g.retain!==void 0&&g.attributes===void 0)t.pop();else break}}),this._delta=t;}return this._delta}},un=class n extends C{constructor(e){super(),this._pending=e!==void 0?[()=>this.insert(0,e)]:[],this._searchMarker=[],this._hasFormatting=!1;}get length(){return this.doc??O(),this._length}_integrate(e,t){super._integrate(e,t);try{this._pending.forEach(r=>r());}catch(r){console.error(r);}this._pending=null;}_copy(){return new n}clone(){let e=new n;return e.applyDelta(this.toDelta()),e}_callObserver(e,t){super._callObserver(e,t);let r=new hn(this,e,t);_t(this,e,r),!e.local&&this._hasFormatting&&(e._needFormattingCleanup=!0);}toString(){this.doc??O();let e="",t=this._start;for(;t!==null;)!t.deleted&&t.countable&&t.content.constructor===se&&(e+=t.content.str),t=t.right;return e}toJSON(){return this.toString()}applyDelta(e,{sanitize:t=!0}={}){this.doc!==null?S(this.doc,r=>{let i=new Pe(null,this._start,0,new Map);for(let s=0;s<e.length;s++){let o=e[s];if(o.insert!==void 0){let c=!t&&typeof o.insert=="string"&&s===e.length-1&&i.right===null&&o.insert.slice(-1)===`
16
+ `?o.insert.slice(0,-1):o.insert;(typeof c!="string"||c.length>0)&&Jt(r,this,i,c,o.attributes||{});}else o.retain!==void 0?yr(r,this,i,o.retain,o.attributes||{}):o.delete!==void 0&&wr(r,i,o.delete);}}):this._pending.push(()=>this.applyDelta(e));}toDelta(e,t,r){this.doc??O();let i=[],s=new Map,o=this.doc,c="",a=this._start;function l(){if(c.length>0){let u={},p=!1;s.forEach((_,x)=>{p=!0,u[x]=_;});let g={insert:c};p&&(g.attributes=u),i.push(g),c="";}}let d=()=>{for(;a!==null;){if(_e(a,e)||t!==void 0&&_e(a,t))switch(a.content.constructor){case se:{let u=s.get("ychange");e!==void 0&&!_e(a,e)?(u===void 0||u.user!==a.id.client||u.type!=="removed")&&(l(),s.set("ychange",r?r("removed",a.id):{type:"removed"})):t!==void 0&&!_e(a,t)?(u===void 0||u.user!==a.id.client||u.type!=="added")&&(l(),s.set("ychange",r?r("added",a.id):{type:"added"})):u!==void 0&&(l(),s.delete("ychange")),c+=a.content.str;break}case oe:case ve:{l();let u={insert:a.content.getContent()[0]};if(s.size>0){let p={};u.attributes=p,s.forEach((g,_)=>{p[_]=g;});}i.push(u);break}case R:_e(a,e)&&(l(),Ee(s,a.content));break}a=a.right;}l();};return e||t?S(o,u=>{e&&tn(u,e),t&&tn(u,t),d();},"cleanup"):d(),i}insert(e,t,r){if(t.length<=0)return;let i=this.doc;i!==null?S(i,s=>{let o=lt(s,this,e,!r);r||(r={},o.currentAttributes.forEach((c,a)=>{r[a]=c;})),Jt(s,this,o,t,r);}):this._pending.push(()=>this.insert(e,t,r));}insertEmbed(e,t,r){let i=this.doc;i!==null?S(i,s=>{let o=lt(s,this,e,!r);Jt(s,this,o,t,r||{});}):this._pending.push(()=>this.insertEmbed(e,t,r||{}));}delete(e,t){if(t===0)return;let r=this.doc;r!==null?S(r,i=>{wr(i,lt(i,this,e,!0),t);}):this._pending.push(()=>this.delete(e,t));}format(e,t,r){if(t===0)return;let i=this.doc;i!==null?S(i,s=>{let o=lt(s,this,e,!1);o.right!==null&&yr(s,this,o,t,r);}):this._pending.push(()=>this.format(e,t,r));}removeAttribute(e){this.doc!==null?S(this.doc,t=>{ft(t,this,e);}):this._pending.push(()=>this.removeAttribute(e));}setAttribute(e,t){this.doc!==null?S(this.doc,r=>{yn(r,this,e,t);}):this._pending.push(()=>this.setAttribute(e,t));}getAttribute(e){return wn(this,e)}getAttributes(){return Nr(this)}_write(e){e.writeTypeRef(Js);}};var Ne=class{constructor(e,t=()=>!0){this._filter=t,this._root=e,this._currentNode=e._start,this._firstCall=!0,e.doc??O();}[Symbol.iterator](){return this}next(){let e=this._currentNode,t=e&&e.content&&e.content.type;if(e!==null&&(!this._firstCall||e.deleted||!this._filter(t)))do if(t=e.content.type,!e.deleted&&(t.constructor===gt||t.constructor===je)&&t._start!==null)e=t._start;else for(;e!==null;)if(e.right!==null){e=e.right;break}else e.parent===this._root?e=null:e=e.parent._item;while(e!==null&&(e.deleted||!this._filter(e.content.type)));return this._firstCall=!1,e===null?{value:void 0,done:!0}:(this._currentNode=e,{value:e.content.type,done:!1})}},je=class n extends C{constructor(){super(),this._prelimContent=[];}get firstChild(){let e=this._first;return e?e.content.getContent()[0]:null}_integrate(e,t){super._integrate(e,t),this.insert(0,this._prelimContent),this._prelimContent=null;}_copy(){return new n}clone(){let e=new n;return e.insert(0,this.toArray().map(t=>t instanceof C?t.clone():t)),e}get length(){return this.doc??O(),this._prelimContent===null?this._length:this._prelimContent.length}createTreeWalker(e){return new Ne(this,e)}querySelector(e){e=e.toUpperCase();let r=new Ne(this,i=>i.nodeName&&i.nodeName.toUpperCase()===e).next();return r.done?null:r.value}querySelectorAll(e){return e=e.toUpperCase(),ee(new Ne(this,t=>t.nodeName&&t.nodeName.toUpperCase()===e))}_callObserver(e,t){_t(this,e,new fn(this,t,e));}toString(){return Or(this,e=>e.toString()).join("")}toJSON(){return this.toString()}toDOM(e=document,t={},r){let i=e.createDocumentFragment();return r!==void 0&&r._createAssociation(i,this),Ke(this,s=>{i.insertBefore(s.toDOM(e,t,r),null);}),i}insert(e,t){this.doc!==null?S(this.doc,r=>{Vr(r,this,e,t);}):this._prelimContent.splice(e,0,...t);}insertAfter(e,t){if(this.doc!==null)S(this.doc,r=>{let i=e&&e instanceof C?e._item:e;ut(r,this,i,t);});else {let r=this._prelimContent,i=e===null?0:r.findIndex(s=>s===e)+1;if(i===0&&e!==null)throw de("Reference item not found");r.splice(i,0,...t);}}delete(e,t=1){this.doc!==null?S(this.doc,r=>{Mr(r,this,e,t);}):this._prelimContent.splice(e,t);}toArray(){return Ur(this)}push(e){this.insert(this.length,e);}unshift(e){this.insert(0,e);}get(e){return Ar(this,e)}slice(e=0,t=this.length){return Dr(this,e,t)}forEach(e){Ke(this,e);}_write(e){e.writeTypeRef(zs);}};var gt=class n extends je{constructor(e="UNDEFINED"){super(),this.nodeName=e,this._prelimAttrs=new Map;}get nextSibling(){let e=this._item?this._item.next:null;return e?e.content.type:null}get prevSibling(){let e=this._item?this._item.prev:null;return e?e.content.type:null}_integrate(e,t){super._integrate(e,t),this._prelimAttrs.forEach((r,i)=>{this.setAttribute(i,r);}),this._prelimAttrs=null;}_copy(){return new n(this.nodeName)}clone(){let e=new n(this.nodeName),t=this.getAttributes();return Gn(t,(r,i)=>{typeof r=="string"&&e.setAttribute(i,r);}),e.insert(0,this.toArray().map(r=>r instanceof C?r.clone():r)),e}toString(){let e=this.getAttributes(),t=[],r=[];for(let c in e)r.push(c);r.sort();let i=r.length;for(let c=0;c<i;c++){let a=r[c];t.push(a+'="'+e[a]+'"');}let s=this.nodeName.toLocaleLowerCase(),o=t.length>0?" "+t.join(" "):"";return `<${s}${o}>${super.toString()}</${s}>`}removeAttribute(e){this.doc!==null?S(this.doc,t=>{ft(t,this,e);}):this._prelimAttrs.delete(e);}setAttribute(e,t){this.doc!==null?S(this.doc,r=>{yn(r,this,e,t);}):this._prelimAttrs.set(e,t);}getAttribute(e){return wn(this,e)}hasAttribute(e){return Br(this,e)}getAttributes(e){return e?Bs(this,e):Nr(this)}toDOM(e=document,t={},r){let i=e.createElement(this.nodeName),s=this.getAttributes();for(let o in s){let c=s[o];typeof c=="string"&&i.setAttribute(o,c);}return Ke(this,o=>{i.appendChild(o.toDOM(e,t,r));}),r!==void 0&&r._createAssociation(i,this),i}_write(e){e.writeTypeRef(Hs),e.writeKey(this.nodeName);}};var fn=class extends Se{constructor(e,t,r){super(e,r),this.childListChanged=!1,this.attributesChanged=new Set,t.forEach(i=>{i===null?this.childListChanged=!0:this.attributesChanged.add(i);});}};var pt=class{constructor(e,t){this.id=e,this.length=t;}get deleted(){throw B()}mergeWith(e){return !1}write(e,t,r){throw B()}integrate(e,t){throw B()}},Fs=0,G=class extends pt{get deleted(){return !0}delete(){}mergeWith(e){return this.constructor!==e.constructor?!1:(this.length+=e.length,!0)}integrate(e,t){t>0&&(this.id.clock+=t,this.length-=t),Cr(e.doc.store,this);}write(e,t){e.writeInfo(Fs),e.writeLen(this.length-t);}getMissing(e,t){return null}},mt=class n{constructor(e){this.content=e;}getLength(){return 1}getContent(){return [this.content]}isCountable(){return !0}copy(){return new n(this.content)}splice(e){throw B()}mergeWith(e){return !1}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeBuf(this.content);}getRef(){return 3}};var gn=class n{constructor(e){this.len=e;}getLength(){return this.len}getContent(){return []}isCountable(){return !1}copy(){return new n(this.len)}splice(e){let t=new n(this.len-e);return this.len=e,t}mergeWith(e){return this.len+=e.len,!0}integrate(e,t){vr(e.deleteSet,t.id.client,t.id.clock,this.len),t.markDeleted();}delete(e){}gc(e){}write(e,t){e.writeLen(this.len-t);}getRef(){return 1}};var Ws=(n,e)=>new ue({guid:n,...e,shouldLoad:e.shouldLoad||e.autoLoad||!1}),yt=class n{constructor(e){e._item&&console.error("This document was already integrated as a sub-document. You should create a second instance instead with the same guid."),this.doc=e;let t={};this.opts=t,e.gc||(t.gc=!1),e.autoLoad&&(t.autoLoad=!0),e.meta!==null&&(t.meta=e.meta);}getLength(){return 1}getContent(){return [this.doc]}isCountable(){return !0}copy(){return new n(Ws(this.doc.guid,this.opts))}splice(e){throw B()}mergeWith(e){return !1}integrate(e,t){this.doc._item=t,e.subdocsAdded.add(this.doc),this.doc.shouldLoad&&e.subdocsLoaded.add(this.doc);}delete(e){e.subdocsAdded.has(this.doc)?e.subdocsAdded.delete(this.doc):e.subdocsRemoved.add(this.doc);}gc(e){}write(e,t){e.writeString(this.doc.guid),e.writeAny(this.opts);}getRef(){return 9}};var ve=class n{constructor(e){this.embed=e;}getLength(){return 1}getContent(){return [this.embed]}isCountable(){return !0}copy(){return new n(this.embed)}splice(e){throw B()}mergeWith(e){return !1}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeJSON(this.embed);}getRef(){return 5}};var R=class n{constructor(e,t){this.key=e,this.value=t;}getLength(){return 1}getContent(){return []}isCountable(){return !1}copy(){return new n(this.key,this.value)}splice(e){throw B()}mergeWith(e){return !1}integrate(e,t){let r=t.parent;r._searchMarker=null,r._hasFormatting=!0;}delete(e){}gc(e){}write(e,t){e.writeKey(this.key),e.writeJSON(this.value);}getRef(){return 6}};var $s=Ae("node_env")==="development",Fe=class n{constructor(e){this.arr=e,$s&&Bt(e);}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return !0}copy(){return new n(this.arr)}splice(e){let t=new n(this.arr.slice(e));return this.arr=this.arr.slice(0,e),t}mergeWith(e){return this.arr=this.arr.concat(e.arr),!0}integrate(e,t){}delete(e){}gc(e){}write(e,t){let r=this.arr.length;e.writeLen(r-t);for(let i=t;i<r;i++){let s=this.arr[i];e.writeAny(s);}}getRef(){return 8}};var se=class n{constructor(e){this.str=e;}getLength(){return this.str.length}getContent(){return this.str.split("")}isCountable(){return !0}copy(){return new n(this.str)}splice(e){let t=new n(this.str.slice(e));this.str=this.str.slice(0,e);let r=this.str.charCodeAt(e-1);return r>=55296&&r<=56319&&(this.str=this.str.slice(0,e-1)+"\uFFFD",t.str="\uFFFD"+t.str.slice(1)),t}mergeWith(e){return this.str+=e.str,!0}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeString(t===0?this.str:this.str.slice(t));}getRef(){return 4}};var Gs=0,qs=1,Js=2,Hs=3,zs=4;var oe=class n{constructor(e){this.type=e;}getLength(){return 1}getContent(){return [this.type]}isCountable(){return !0}copy(){return new n(this.type._copy())}splice(e){throw B()}mergeWith(e){return !1}integrate(e,t){this.type._integrate(e.doc,t);}delete(e){let t=this.type._start;for(;t!==null;)t.deleted?t.id.clock<(e.beforeState.get(t.id.client)||0)&&e._mergeStructs.push(t):t.delete(e),t=t.right;this.type._map.forEach(r=>{r.deleted?r.id.clock<(e.beforeState.get(r.id.client)||0)&&e._mergeStructs.push(r):r.delete(e);}),e.changed.delete(this.type);}gc(e){let t=this.type._start;for(;t!==null;)t.gc(e,!0),t=t.right;this.type._start=null,this.type._map.forEach(r=>{for(;r!==null;)r.gc(e,!0),r=r.left;}),this.type._map=new Map;}write(e,t){this.type._write(e);}getRef(){return 7}};var Wr=(n,e,t)=>{let{client:r,clock:i}=e.id,s=new A(v(r,i+t),e,v(r,i+t-1),e.right,e.rightOrigin,e.parent,e.parentSub,e.content.splice(t));return e.deleted&&s.markDeleted(),e.keep&&(s.keep=!0),e.redone!==null&&(s.redone=v(e.redone.client,e.redone.clock+t)),e.right=s,s.right!==null&&(s.right.left=s),n._mergeStructs.push(s),s.parentSub!==null&&s.right===null&&s.parent._map.set(s.parentSub,s),e.length=t,s};var A=class n extends pt{constructor(e,t,r,i,s,o,c,a){super(e,a.getLength()),this.origin=r,this.left=t,this.right=i,this.rightOrigin=s,this.parent=o,this.parentSub=c,this.redone=null,this.content=a,this.info=this.content.isCountable()?2:0;}set marker(e){(this.info&8)>0!==e&&(this.info^=8);}get marker(){return (this.info&8)>0}get keep(){return (this.info&1)>0}set keep(e){this.keep!==e&&(this.info^=1);}get countable(){return (this.info&2)>0}get deleted(){return (this.info&4)>0}set deleted(e){this.deleted!==e&&(this.info^=4);}markDeleted(){this.info|=4;}getMissing(e,t){if(this.origin&&this.origin.client!==this.id.client&&this.origin.clock>=M(t,this.origin.client))return this.origin.client;if(this.rightOrigin&&this.rightOrigin.client!==this.id.client&&this.rightOrigin.clock>=M(t,this.rightOrigin.client))return this.rightOrigin.client;if(this.parent&&this.parent.constructor===be&&this.id.client!==this.parent.client&&this.parent.clock>=M(t,this.parent.client))return this.parent.client;if(this.origin&&(this.left=ur(e,t,this.origin),this.origin=this.left.lastId),this.rightOrigin&&(this.right=ie(e,this.rightOrigin),this.rightOrigin=this.right.id),this.left&&this.left.constructor===G||this.right&&this.right.constructor===G)this.parent=null;else if(!this.parent)this.left&&this.left.constructor===n&&(this.parent=this.left.parent,this.parentSub=this.left.parentSub),this.right&&this.right.constructor===n&&(this.parent=this.right.parent,this.parentSub=this.right.parentSub);else if(this.parent.constructor===be){let r=qt(t,this.parent);r.constructor===G?this.parent=null:this.parent=r.content.type;}return null}integrate(e,t){if(t>0&&(this.id.clock+=t,this.left=ur(e,e.doc.store,v(this.id.client,this.id.clock-1)),this.origin=this.left.lastId,this.content=this.content.splice(t),this.length-=t),this.parent){if(!this.left&&(!this.right||this.right.left!==null)||this.left&&this.left.right!==this.right){let r=this.left,i;if(r!==null)i=r.right;else if(this.parentSub!==null)for(i=this.parent._map.get(this.parentSub)||null;i!==null&&i.left!==null;)i=i.left;else i=this.parent._start;let s=new Set,o=new Set;for(;i!==null&&i!==this.right;){if(o.add(i),s.add(i),ct(this.origin,i.origin)){if(i.id.client<this.id.client)r=i,s.clear();else if(ct(this.rightOrigin,i.rightOrigin))break}else if(i.origin!==null&&o.has(qt(e.doc.store,i.origin)))s.has(qt(e.doc.store,i.origin))||(r=i,s.clear());else break;i=i.right;}this.left=r;}if(this.left!==null){let r=this.left.right;this.right=r,this.left.right=this;}else {let r;if(this.parentSub!==null)for(r=this.parent._map.get(this.parentSub)||null;r!==null&&r.left!==null;)r=r.left;else r=this.parent._start,this.parent._start=this;this.right=r;}this.right!==null?this.right.left=this:this.parentSub!==null&&(this.parent._map.set(this.parentSub,this),this.left!==null&&this.left.delete(e)),this.parentSub===null&&this.countable&&!this.deleted&&(this.parent._length+=this.length),Cr(e.doc.store,this),this.content.integrate(e,this),gr(e,this.parent,this.parentSub),(this.parent._item!==null&&this.parent._item.deleted||this.parentSub!==null&&this.right!==null)&&this.delete(e);}else new G(this.id,this.length).integrate(e,0);}get next(){let e=this.right;for(;e!==null&&e.deleted;)e=e.right;return e}get prev(){let e=this.left;for(;e!==null&&e.deleted;)e=e.left;return e}get lastId(){return this.length===1?this.id:v(this.id.client,this.id.clock+this.length-1)}mergeWith(e){if(this.constructor===e.constructor&&ct(e.origin,this.lastId)&&this.right===e&&ct(this.rightOrigin,e.rightOrigin)&&this.id.client===e.id.client&&this.id.clock+this.length===e.id.clock&&this.deleted===e.deleted&&this.redone===null&&e.redone===null&&this.content.constructor===e.content.constructor&&this.content.mergeWith(e.content)){let t=this.parent._searchMarker;return t&&t.forEach(r=>{r.p===e&&(r.p=this,!this.deleted&&this.countable&&(r.index-=this.length));}),e.keep&&(this.keep=!0),this.right=e.right,this.right!==null&&(this.right.left=this),this.length+=e.length,!0}return !1}delete(e){if(!this.deleted){let t=this.parent;this.countable&&this.parentSub===null&&(t._length-=this.length),this.markDeleted(),vr(e.deleteSet,this.id.client,this.id.clock,this.length),gr(e,t,this.parentSub),this.content.delete(e);}}gc(e,t){if(!this.deleted)throw ne();this.content.gc(e),t?Ds(e,this,new G(this.id,this.length)):this.content=new gn(this.length);}write(e,t){let r=t>0?v(this.id.client,this.id.clock+t-1):this.origin,i=this.rightOrigin,s=this.parentSub,o=this.content.getRef()&31|(r===null?0:128)|(i===null?0:64)|(s===null?0:32);if(e.writeInfo(o),r!==null&&e.writeLeftID(r),i!==null&&e.writeRightID(i),r===null&&i===null){let c=this.parent;if(c._item!==void 0){let a=c._item;if(a===null){let l=Is(c);e.writeParentInfo(!0),e.writeString(l);}else e.writeParentInfo(!1),e.writeLeftID(a.id);}else c.constructor===String?(e.writeParentInfo(!0),e.writeString(c)):c.constructor===be?(e.writeParentInfo(!1),e.writeLeftID(c)):ne();s!==null&&e.writeString(s);}this.content.write(e,t);}};var $r=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:{},Gr="__ $YJS$ __";$r[Gr]===!0&&console.error("Yjs was already imported. This breaks constructor checks and will lead to issues! - https://github.com/yjs/yjs/issues/438");$r[Gr]=!0;var We=n=>Promise.reject("unimplemented method GetVoiceSign"),_n=(n,e={},t=[])=>({command:n,front_request_id:Z(),data:{...e,to_user_ids:Array.isArray(t)?t:[t]}}),qr=()=>{window?.__Realsee_Live__&&(window?.__Realsee_Live__?.dispose?.(),window.__Realsee_Live__=null);},bt=class extends N{_options={};get options(){return Object.freeze(this._options||{})}get state(){return this._controller.state}get readyState(){return this._controller.state}get url(){return this.options.url}get $RTC(){return this._options.rtc}get jsBridge(){return this._options.jsBridge}keyframes=new N;_yDoc;_buildInData;constructor(e){super(),m.info("Initializing Live instance with options:",e),this._addLiveControllerEventListeners(),this._yDoc=new ue({guid:Z()}),this._buildInData={keyframes:this._yDoc.getMap("keyframes")},this._initializeKeyframesObservers(),this._initializeOptions(e),this._autoConnect(),this._debugSetup();}get _buildInKeyframes(){return this._buildInData.keyframes}get snapshot(){return this._buildInData.keyframes.toJSON()}_initializeKeyframesObservers=()=>{this._buildInKeyframes.observe(this._handleKeyframesChange);};_handleKeyframesChange=e=>{let{transaction:t,target:r,changes:i}=e;if(r===this._buildInKeyframes)if(t.origin.triggerUserId===this.selfInfo?.id){let s=_n("KEYFRAME_SYNC",this.snapshot,void 0);try{this._controller.sendMessage(s);}catch(o){m.error("Failed to send keyframe sync message:",o);}}else i.keys.forEach((s,o)=>{let c=s.oldValue,a=this.getFramesByKey(o),l=t.origin.frontRequestId;this.keyframes.emit(o,a,c,l);}),i.keys.size!==0&&this.emit("keyframes",this.snapshot,t.origin.frontRequestId);};getFramesByKey=e=>this.snapshot[e];sendKeyframe=(e,t)=>this.state!==1?(m.warn("Attempted to send keyframe while connection is not open"),!1):(this._yDoc.transact(()=>{this._buildInKeyframes.set(e,t);},{triggerUserId:this.selfInfo?.id,frontRequestId:""}),!0);get selfInfo(){return this._buildInData.selfInfo}get userList(){return this._buildInData.userList||[]}get roomInfo(){return this._buildInData.roomInfo}_controller=new ze;_initializeOptions(e){this._options=Object.assign({initialMicroStatus:"OPEN"},e),this._options.jsBridge=this._initializeJsBridge(e),this._options.getVoiceSign=e.getVoiceSign??We,this._options.autoPlayConfirm=e.autoPlayConfirm,this._options.rtc=this._initializeRTC(e);}_initializeJsBridge(e){if(e.jsBridge)return e.jsBridge;if(e.useBuiltInJsBridge)return new Xs__default.default}_initializeRTC(e){if(e.rtc)return e.rtc;if(e.rtcType)return this._createBuiltInRTC(e);if(e.useBuiltInRTC)return this._createDefaultRTC(e)}_createBuiltInRTC(e){if(!e.getVoiceSign){m.error("GetVoiceSign method must be passed when using built-in RTC instances");return}switch(e.rtcType){case"RealseeVRWebViewRTC":return this._createVRWebViewRTC();case"RealseeBrowserChimeRTC":return new fe({getVoiceSign:this._options.getVoiceSign??We,logLevel:e.__debug__?0:1});case"RealseeBrowserRTC":return this._createBrowserRTC();default:m.error("unknown built-in RTC type");return}}_createVRWebViewRTC(){if(this._options.jsBridge)return new Ie({jsBridge:this._options.jsBridge,getVoiceSign:this._options.getVoiceSign??We});m.error("JsBridge instance must be passed when using built-in VRWebViewRTC instances");}_createBrowserRTC(){if(!this._options.autoPlayConfirm){m.error("autoPlayConfirm method must be passed when using built-in RealseeBrowserRTC instances");return}return new xe({getVoiceSign:this._options.getVoiceSign??We,autoPlayConfirm:this._options.autoPlayConfirm})}_createDefaultRTC(e){if(!e.getVoiceSign){m.error("GetVoiceSign method must be passed when using built-in RTC instances");return}if(this._options.jsBridge){if(In&&(kn||Cn)||xn)return this._createVRWebViewRTC();{let t=this._options.getVoiceSign??We;return e.builtInRTCType==="chime"?new fe({getVoiceSign:t}):this._createBrowserRTC()}}else {m.error("jsBridge instance must be passed when using built-in RTC instances");return}}_autoConnect(){this._options.url&&this._options.getTicket&&this.connect();}_debugSetup(){this._options.__debug__&&Object.assign(window,{$liveController:this._controller,$live:this});}_addLiveControllerEventListeners=()=>{this._controller.on("stateChange",this._handleStateChange),this._controller.on("message",this._handleMessage);};_removeLiveControllerEventListeners=()=>{this._controller.off("stateChange",this._handleStateChange),this._controller.off("message",this._handleMessage);};_handleStateChange=(e,t)=>{m.info(`State changed from ${t} to ${e}`),this.emit("stateChange",e,t);};_handleMessage=async e=>{if(m.debug("Received message:",e),typeof e=="object"){let{command:t,data:r={},frontRequestId:i,code:s,message:o,triggerUserId:c}=e;if(s==="SUCCESS")switch(t){case"SELF_USER_INFO":{let a=r;Tn(this.selfInfo,a,{deep:!0})||(this._buildInData.selfInfo=a,this.emit("selfInfoUpdate",this._buildInData.selfInfo,i));break}case"ROOM_INFO":{let a=r;this._buildInData.roomInfo=Object.assign({},a);let l=a.last_frame||{};this._yDoc.transact(()=>{for(let d in l)this._buildInKeyframes.set(d,l[d]);},{triggerUserId:"readyKeyframeSync",frontRequestId:i}),this.emit("readyKeyframeSync",a.last_frame||{});break}case"RTC_INFO":{m.info("RTC info updated:",r);let{voice_id:a,type:l}=r;if(this._buildInData.rtcInfo={voiceId:a,type:l},this.$RTC?.joined)m.warn("\u5DF2\u52A0\u5165\u8BED\u97F3\u623F\u95F4\uFF0C\u65E0\u9700\u91CD\u590D\u52A0\u5165\uFF01");else if(await this.$RTC?.join({voiceId:a,userId:this.selfInfo?.id||"",roomId:this.roomInfo?.info.room_code,type:l})){let u=this._options.initialMicroStatus??"OPEN";await this.toggleMicro(u==="OPEN");}else m.error("\u52A0\u5165\u8BED\u97F3\u623F\u95F4\u5931\u8D25");break}case"USER_LIST":{let a=r;this._buildInData.userList=a,this.emit("userListUpdate",this.userList,i);break}case"CUSTOM_EVENT":{let a=r;this.emit("broadcast",a,i);break}case"KEYFRAME_SYNC":{let a=r;if(c===this.selfInfo?.id)return;this._yDoc.transact(()=>{for(let l in a)this._buildInKeyframes.set(l,a[l]);},{triggerUserId:c,frontRequestId:i});break}case"BUILTIN_MSG":{let a=r;this.emit("builtinEvent",a),a.event_type==="user_change"&&this.emit("userChange",a),a.event_type==="room_change"&&this.emit("roomChange",a),a.event_type==="user_change"&&a.action==="change_micro_status"&&await this.toggleMicro(a.data.status==="OPEN"),a.event_type==="room_change"&&a.action==="close"&&await this._exit();break}case"USER_KICK_OUT":{this.emit("kickOut");break}default:m.warn("Unknown command received:",t);}else m.error("Error in message:",o),this.emit("error",e);}};_clearLiveData=()=>{this._buildInKeyframes.clear(),this._buildInData={keyframes:this._yDoc.getMap("keyframes")};};connect=async(e={})=>{if(m.info("Attempting to connect with options:",e),this._options.url=e.url??this._options.url??"",this._options.getTicket=e.getTicket??this._options.getTicket,this._options.initialMicroStatus=e.rtcMicStatus??this._options.initialMicroStatus,!/^ws(s):\/\//.test(this._options.url)||typeof this._options.getTicket!="function")return new Error("Invalid connection parameters");if(this._options.rtc&&!await this._options.rtc.detectMicro())return new Error("Failed to obtain microphone authorization");let t=this.state;if(t===0||t===1)if(e.force)await this._controller.close("force close by connect").catch(console.warn);else return new Error("\u5DF2\u6709Live\u5B9E\u4F8B\u6B63\u5728\u8FDE\u63A5\u4E2D\uFF0C\u8BF7\u52FF\u91CD\u590D\u8FDE\u63A5\uFF01");this._clearLiveData();try{let r=await this._options.getTicket(),i=vn(this._options.url,{ticket:r,force:+!!e.force});return this._controller.open(i),m.info("Connection established successfully"),!0}catch(r){return m.error("Failed to connect:",r),new Error("Failed to connect")}};_exit=async()=>{this._clearLiveData();try{await this.$RTC?.quit();}catch(e){m.warn(e);}return this.state!==1?!0:await this._controller.close()};exit=async()=>this.close();close=async()=>{await this._controller.readyClose();try{await this.$RTC?.quit();}catch(e){m.warn(e);}await this.updateStatus("room_change","close",{});};dispose=async()=>(this._removeLiveControllerEventListeners(),this._clearLiveData(),await this._controller.dispose());async updateStatus(e,t,r,i){if(this.state!==1)return !1;let s=Object.assign({event_type:e,action:t},{data:r}),o=_n("BUILTIN_MSG",s,i);try{return this._controller.sendMessage(o),!0}catch(c){return m.error(c),!1}}setSelfInfo=async e=>await this.updateStatus("user_change","change_info",e);broadcast(e,t,r){return this.state!==1?!1:new Promise((i,s)=>{let o=_n("CUSTOM_EVENT",e,t),c=o.front_request_id,a=r?setTimeout(()=>{s(new Error("RESPONSE TIMEOUT")),this.off("broadcast",l);},r):void 0,l=(d,u)=>{u===c&&(a&&clearTimeout(a),this.off("broadcast",l),i(d));};this.on("broadcast",l);try{this._controller.sendMessage(o);}catch(d){s(d);}})}toggleMicro=async e=>{if(!this.selfInfo?.permission?.control_own_micro)return !1;let t=await this.$RTC?.toggleMicro(e);return t&&await this.updateStatus("user_change","change_micro_status",{status:e?"OPEN":"CLOSE"},[]),t};forbidMicro=async(e,t)=>typeof this._options.canForbidUserMicro=="function"&&!this._options.canForbidUserMicro(t)||!this.selfInfo?.permission?.control_other_micro?!1:await this.updateStatus("user_change","change_micro_status",{status:e},t);forbidSync=async(e,t)=>typeof this._options.canForbidUserSync=="function"&&!this._options.canForbidUserSync(t)||!this.selfInfo?.permission?.control_other_sync?!1:await this.updateStatus("user_change","change_permission",{sync_frame:e},t);kick=async e=>typeof this._options.canForbidUserKick=="function"&&!this._options.canForbidUserKick(e)||!this.selfInfo?.permission?.change_other_status?!1:await this.updateStatus("user_change","change_status",{status:"KICK_OUT"},e);getSnapshotForKey(e){return this.snapshot[e]}};var Jr=n=>(qr(),new bt(n));function qa(n){let e=U.createContext(null),t=Jr(n),r=t.jsBridge,i=h=>U__default.default.createElement(e.Provider,{value:t},h.children),s=()=>{let h=U__default.default.useContext(e);if(!h)throw new Error("LiveProvider never found.");return h},o=()=>t,c=()=>t.$RTC,a=()=>c(),l=()=>async h=>await t.connect(h);function d(h,b,I=[]){let y=s(),E=[y,name,...I],D=()=>y.keyframes.off(h,b);return U__default.default.useEffect(()=>(y.keyframes.on(h,b),D),E),D}function u(){let h=s(),b=U.useCallback(async k=>{await h.connect(k);},[h]),I=U.useCallback(k=>{h.toggleMicro(k);},[h]),y=U.useCallback(async(k,q,vt=0)=>{await h.broadcast(k,q,vt);},[h]),E=U.useCallback(async()=>{await h.exit();},[h]),D=U.useCallback(async k=>{await h.kick(k);},[h]),Y=U.useCallback(async(k,q=[])=>{await h.forbidMicro(k,q);},[h]),$e=U.useCallback((k,q=[])=>{h.forbidSync(k,q);},[h]),St=U.useCallback(k=>h.getFramesByKey(k),[h]),Zr=U.useCallback((k,q)=>{h.sendKeyframe(k,q);},[h]),Qr=U.useCallback(k=>{h.setSelfInfo(k);},[h]),ei=U.useCallback((k,q,vt,ti)=>{h.updateStatus(k,q,vt,ti);},[h]);return {connect:b,broadcast:y,exit:E,kick:D,toggleMicro:I,forbidMicro:Y,forbidSync:$e,sendKeyframe:Zr,getFramesByKey:St,setSelfInfo:Qr,updateStatus:ei}}function p(h){let b=s(),[I,y]=U__default.default.useState(b.getFramesByKey(h));U__default.default.useEffect(()=>{let D=St=>y(St),Y=h,$e=D;return b.keyframes.on(Y,$e),()=>b.keyframes.off(Y,$e)},[b]);let E=U__default.default.useCallback(D=>b.sendKeyframe(h,D),[b]);return [I,E]}function g(h,b,I=[]){let y=s(),E=()=>y.off(h,b),D=[y,h,...I];return U__default.default.useEffect(()=>(y.on(h,b),E),D),E}function _(){let h=s(),[b,I]=U__default.default.useState(h.state);return U__default.default.useEffect(()=>{let y=E=>I(E);return h.on("stateChange",y),()=>h.off("stateChange",y)},[h]),b}function x(){let h=s();return {join:Y=>h.$RTC.join(Y),quit:()=>h.$RTC.quit(),shock:()=>h.$RTC.shock?.(),toggleMicro:Y=>h.$RTC.toggleMicro(Y),detectMicro:()=>h.$RTC.detectMicro()}}function Hr(h,b,I=[]){let y=s(),E=()=>y.$RTC.off(h,b),D=[y,h,...I];return U__default.default.useEffect(()=>(y.$RTC.on(h,b),E),D),E}function zr(){let h=s(),[b,I]=U__default.default.useState(h.selfInfo||{}),y=D=>I(D);U__default.default.useEffect(()=>(h.on("selfInfoUpdate",y),()=>h.off("selfInfoUpdate",y)),[h]);let E=U__default.default.useCallback(async D=>await h.setSelfInfo(D),[h]);return [b,E]}function Yr(){let h=s(),[b,I]=U__default.default.useState(h.snapshot);return U__default.default.useEffect(()=>{let y=E=>I(E);return h.on("keyframes",y),()=>h.off("keyframes",y)},[h]),b}function Xr(){let h=s(),[b,I]=U__default.default.useState(h.userList),y=E=>I(E);return U__default.default.useEffect(()=>(h.on("userListUpdate",y),()=>h.off("userListUpdate",y)),[h]),b}return {live:t,jsBridge:r,LiveProvider:i,unsafe__useLiveInstance:o,unsafe__useRTCInstance:a,useConnect:l,useKeyframe:p,useKeyframeUpdateCallback:d,useLiveAction:u,useLiveEventCallback:g,useLiveState:_,useRTCAction:x,useRTCEventCallback:Hr,useSelfInfo:zr,useKeyframesSnapshot:Yr,useUserList:Xr}}console.log(`%c${process.env.__REALSEE_LIVE_VERSION__}`,"background: #237804; color: white; padding: 2px 4px; border-radius: 4px;");
17
+
18
+ exports.BrowserRTC = xe;
19
+ exports.BrowserRTC4Chime = fe;
20
+ exports.BuiltInRTCType = ii;
21
+ exports.BuiltinActionType = mi;
22
+ exports.BuiltinEventType = pi;
23
+ exports.Command = gi;
24
+ exports.CoreRTC = J;
25
+ exports.Live = bt;
26
+ exports.LiveState = wi;
27
+ exports.MemUserStatus = bi;
28
+ exports.MicroStatus = yi;
29
+ exports.RTCJoinedInfoCodeEnum = fi;
30
+ exports.RTCType = ri;
31
+ exports.Subscribe = N;
32
+ exports.UserStatus = _i;
33
+ exports.VRWebViewRTC = Ie;
34
+ exports.WebSocketCloseError = Ei;
35
+ exports.WebSocketErrorType = vi;
36
+ exports.WebSocketState = Si;
37
+ exports._clearLiveInstanceIfNeed = qr;
38
+ exports.createLive = Jr;
39
+ exports.createLiveReact = qa;
40
+ exports.parseLiveMsg = Po;
41
+ exports.parseWSClsErr = Sn;