@realsee/live 0.7.5 → 0.7.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  ## 功能说明
6
6
 
7
- **Live** 是 [如视开发者中心 VRTC 服务](https://developers.realsee.com/docs/#/docs/live/README) 的核心客户端 Web SDK,搭配 Live Container
7
+ **Live** 是 [如视开放平台线上带看](https://open-platform.realsee.com/developer/docs/live/intro/) 的核心客户端 Web SDK,搭配 Live Container
8
8
  SDKs(iOS/Android/微信小程序)和 Live API 可以快速实现实时同屏、实时语音、IM 等功能。
9
9
 
10
10
  ### 名词释义
@@ -64,7 +64,9 @@ await live.connect()
64
64
  在创建 `live` 实例时配置了两个参数:
65
65
 
66
66
  - `url`:连接 WebSocket 服务的 URL(可选),如果在创建 `live` 实例阶段并不知道 URL,您可以在合适的时机通过 `live.connect({ url })` 方法进行 WebSocket 连接。
67
- - `getTicket()`:是一个异步回调函数(可选),其返回值是连接 WebSocket 服务的 **"门票"**,关于如何获取 `ticket` 请查阅 [VR 带看 API](https://developers.realsee.com/docs/#/docs/live/server/README)。也可以在 `connect` 时提供。
67
+ - `getTicket()`:是一个异步回调函数(可选),其返回值是连接 WebSocket 服务的 **"门票"**,关于如何获取 `ticket` 请查阅 [如视开放平台带看文档](https://open-platform.realsee.com/developer/docs/live/intro/)。也可以在 `connect` 时提供。
68
+
69
+ > **提示**:如果在创建实例时同时提供了 `url` 和 `getTicket`,Live 会自动尝试连接,无需手动调用 `connect()` 方法。
68
70
 
69
71
  > 关于 `createLive()` 函数的更多参数配置请参考 [LiveOptions](https://unpkg.com/@realsee/live/docs/interfaces/live.LiveOptions.html) 文档。
70
72
 
@@ -197,9 +199,39 @@ live.on('stateChange', (state, prevState) => {
197
199
 
198
200
  - `error(liveMsg: LiveMsg): void` - 服务端推送出现异常
199
201
 
200
- `live` 实例提供了很多诸如`live.connect()`、`live.broadcast()`、`live.sendKeyframe()`等方法,这些方法都是异步反馈且可能会影响房间内的其他用户。
202
+ `live` 实例提供了很多诸如`live.connect()`、`live.broadcast()`、`live.sendKeyframe()`、`live.exit()`、`live.close()`、`live.dispose()`等方法,这些方法都是异步反馈且可能会影响房间内的其他用户。
201
203
  您可以通过监听以上事件来获知这些影响。
202
204
 
205
+ ### 主要方法说明
206
+
207
+ - `connect(options?)` - 连接带看房间,建立 WebSocket 连接
208
+ - `exit()` - 退出带看房间(不发送房间关闭消息)
209
+ - `close()` - 关闭带看房间(会发送房间关闭消息,通知服务器)
210
+ - `dispose()` - 销毁带看实例,清理所有资源(事件监听、Yjs 文档等)
211
+ - `sendKeyframe(key, frame)` - 发送帧数据
212
+ - `getFramesByKey(key)` - 根据键获取对应的帧数据
213
+ - `broadcast(data, toUserIds, timeout?)` - 向指定用户广播消息
214
+ - `setSelfInfo(userInfo)` - 更新本地用户信息
215
+ - `toggleMicro(status)` - 切换麦克风状态
216
+ - `kick(toUserIds)` - 踢出指定用户
217
+ - `forbidMicro(status, toUserIds?)` - 禁止/允许指定用户的麦克风
218
+ - `forbidSync(sync, toUserIds?)` - 禁止/允许指定用户的帧数据同步
219
+ - `updateStatus(evtType, atnType, status, toUserIds?)` - 更新带看状态(用户或房间状态)
220
+
221
+ ### 主要属性说明
222
+
223
+ - `state` - 当前带看连接状态(LiveState)
224
+ - `readyState` - WebSocket 就绪状态
225
+ - `url` - WebSocket 连接 URL
226
+ - `options` - 配置选项(只读)
227
+ - `snapshot` - 当前所有帧数据的快照
228
+ - `selfInfo` - 本地用户信息
229
+ - `userList` - 房间内所有用户列表
230
+ - `roomInfo` - 房间信息
231
+ - `$RTC` - RTC 实例(用于语音通信)
232
+ - `jsBridge` - JSBridge 实例(用于 App/WebView 环境)
233
+ - `keyframes` - 帧数据监听器(Subscribe 实例)
234
+
203
235
  ### RTC 事件
204
236
 
205
237
  RTC 相关事件通过 `live.$RTC.on('/*事件名*/', /*事件回调*/)` 方式来监听。
@@ -235,7 +267,7 @@ live.$RTC.on('userVolumes', (userVolumes: UserVolume[]) => {
235
267
  | 名称 | 类型 | 描述 |
236
268
  | --------------- | ------------------- | ----------------------------------------------------------------------------------------------------- |
237
269
  | appId | string | 应用ID |
238
- | code | string | 返回码,详情参照[服务端 API Code 码表](https://developers.realsee.com/docs/#/docs/live/server/README) |
270
+ | code | string | 返回码,详情参照[如视开放平台带看文档](https://open-platform.realsee.com/developer/docs/live/intro/) |
239
271
  | command | 指令 | WebSocket 通信指令类型,详情请查看[Live API](https://unpkg.com/@realsee/live/docs/index.html) 文档 |
240
272
  | data | Record<string, any> | 本条指令对应的业务数据 |
241
273
  | frontRequestId | string | 前端的请求 ID,由 WS 服务原样透传回前端 |
@@ -254,7 +286,7 @@ live.$RTC.on('userVolumes', (userVolumes: UserVolume[]) => {
254
286
 
255
287
  语音能力需依赖 WebView/Browser 容器,即需要容器端实现 RTC 能力。
256
288
 
257
- 为了方便开发者接入,**如视开发者中心 VRTC 服务** 为主流平台提供 [容器 SDK](https://developers.realsee.com/docs/#/docs/live/client/container/README)
289
+ 为了方便开发者接入,**如视开放平台** 为主流平台提供 [容器 SDK](https://open-platform.realsee.com/developer/docs/live/intro/)
258
290
  和 [jsbridge-x](https://www.npmjs.com/package/@realsee/jsbridge-x) 。
259
291
 
260
292
  **Live** 通过 **jsbridge-x** 与 集成了**容器 SDK** 的客户端应用或微信小程序应用程序桥接,实现原生能力的调用。这个 `jsbridge-x`
@@ -552,4 +584,4 @@ function CameraControl() {
552
584
 
553
585
  - [@realsee/five](https://www.npmjs.com/package/@realsee/five)
554
586
  - [@realsee/jsbridge-x](https://www.npmjs.com/package/@realsee/jsbridge-x)
555
- - [如视开发者中心 VRTC 服务](https://developers.realsee.com/docs/#/docs/live/README)
587
+ - [如视开放平台线上带看](https://open-platform.realsee.com/developer/docs/live/intro/)
package/dist/index.cjs.js CHANGED
@@ -1,3 +1,3 @@
1
1
  "use strict";var pn=Object.defineProperty;var _n=(i,e,t)=>e in i?pn(i,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[e]=t;var a=(i,e,t)=>_n(i,typeof e!="symbol"?e+"":e,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const ht=require("trtc-js-sdk"),Q=require("amazon-chime-sdk-js"),mn=require("@realsee/jsbridge-x"),y=require("react"),de=Symbol("$$REALSEE_LIVE_EVENT$$");function Be(i){return i[de]||(i[de]={}),i[de]}function Pt(i){const e=i[de];if(!e)return;Object.keys(e).some(n=>Array.isArray(e[n])&&e[n].length>0)||delete i[de]}class ge{hasListener(e){const t=Be(this);return t&&t[e]&&t[e].length>0}on(e,t,n){const s=Be(this);return s[e]||(s[e]=[]),s[e].push([t,n||!1]),()=>this.off(e,t)}once(e,t){return this.on(e,t,!0)}off(e,t){const n=Be(this);if(!e){delete this[de];return}if(n[e]||(n[e]=[]),t===void 0){n[e].length=0,Pt(this);return}const s=n[e].findIndex(r=>r[0]===t);s!==-1&&n[e].splice(s,1),Pt(this)}emit(e,...t){let n=!1;const r=Be(this)[e]||[];for(let o of r.slice()){const[c,l=!1]=o,h=c(...t);l&&this.off(e,c),h===!1&&(n=!0)}return n}}class tt extends ge{}var se=(i=>(i.RealseeBrowserRTC="RealseeBrowserRTC",i.RealseeVRWebViewRTC="RealseeVRWebViewRTC",i.RealseeBrowserChimeRTC="RealseeBrowserChimeRTC",i))(se||{}),Tt=(i=>(i.RealseeXTRTC="trtc",i.RealseeXChimeRTC="chime",i))(Tt||{});const wn=()=>{const i=new Date,e=i.getFullYear(),t=(i.getMonth()+1).toString().padStart(2,"0"),n=i.getDate().toString().padStart(2,"0"),s=i.getHours().toString().padStart(2,"0"),r=i.getMinutes().toString().padStart(2,"0"),o=i.getSeconds().toString().padStart(2,"0"),c=i.getMilliseconds().toString().padStart(3,"0");return`[${e}-${t}-${n} ${s}:${r}:${o}.${c}]`},Ie=(i,e=[])=>{const t=`Realsee Live ${wn()} <${i}> `;switch(i){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)}},m={log:(...i)=>Ie("LOG",i),info:(...i)=>Ie("INFO",i),error:(...i)=>Ie("ERROR",i),warn:(...i)=>Ie("WARN",i),debug:(...i)=>Ie("DEBUG",i)};function ee(){return((1+Math.random())*65536|0).toString(16).substring(1)}function Te(){return[ee(),ee(),"4"+ee().substring(0,3),ee(),ee(),ee()+ee()+ee()].join("-").toLowerCase()}class fi extends tt{constructor(t){super();a(this,"type",se.RealseeBrowserRTC);a(this,"joined",!1);a(this,"micro",!1);a(this,"voiceId","");a(this,"_getVoiceSign",()=>{throw new Error("方法 getVoiceSign 未实现")});a(this,"_autoPlayConfirm");a(this,"checkRequirement",()=>ht.checkSystemRequirements());a(this,"$dom",document.createElement("div"));a(this,"_trtc",{client:null,stream:null});a(this,"join",async t=>{var r;this.emit("joinWillStart");const n=await this._getVoiceSign({voiceId:t.voiceId,roomId:t.roomId,userId:t.userId});this._trtc.client=ht.createClient({mode:"rtc",...n,enableAutoPlayDialog:typeof this._autoPlayConfirm!="function"}),(r=this._trtc.client)==null||r.enableAudioVolumeEvaluation(),this._registerRtcEvent();let s=await new Promise(o=>{var c;(c=this._trtc.client)==null||c.join({roomId:Number(t.voiceId)}).then(()=>o(!0)).catch(()=>o(!1))});return this.joined=s,s?(this._trtc.stream=ht.createStream({userId:n.userId,audio:!0,video:!1}),s=await new Promise(o=>{var c;(c=this._trtc.stream)==null||c.initialize().then(()=>o(!0)).catch(()=>o(!1))}),s=await new Promise(o=>{var c;(c=this._trtc.client)==null||c.publish(this._trtc.stream).then(()=>o(!0)).catch(()=>o(!1))}),this.joined=s,this.joined&&this.emit("joined"),s):!1});a(this,"_handleStreamAdded",t=>{var s;const n=t.stream;m.info("远端流增加:",n.getId()),(s=this._trtc.client)==null||s.subscribe(n)});a(this,"_handleStreamSubscribed",t=>{const n=t.stream;m.info("远端流订阅成功:",n.getId());const r=`rs-rtc-remote_stream-${n.getId()}`,o=document.createElement("div");o.id=r,this.$dom.appendChild(o),typeof this._autoPlayConfirm=="function"?(n.play(r).catch(c=>{m.warn("远端流播放失败(将尝试用户确认恢复)")}),n.on("error",c=>{if(c.getCode()===16451){const h=()=>n.resume();this._autoPlayConfirm({onConfirm:h})}})):n.play(r)});this._getVoiceSign=t.getVoiceSign,this._autoPlayConfirm=t.autoPlayConfirm,this._initParentDom()}_initParentDom(){this.$dom.id=`rs-rtc-${Te()}`,this.$dom.style.display="none",document.body.appendChild(this.$dom)}quit(){return new Promise(async t=>{var n,s;this.joined=!1,this._trtc.stream&&(await((n=this._trtc.client)==null?void 0:n.unpublish(this._trtc.stream)),this._trtc.stream.stop(),this._trtc.stream.close(),this._trtc.stream=null),(s=this._trtc.client)==null||s.leave().then(()=>this._trtc.client=null).then(()=>t(!0)).catch(()=>t(!1)),t(!0)})}detectMicro(){return new Promise(t=>{const n={audio:!0,video:!1};try{navigator.mediaDevices.getUserMedia(n).then(()=>t(!0)).catch(s=>{m.error(s.message),t(!1)})}catch(s){console.error(s),t(!1)}})}toggleMicro(t){return new Promise(n=>{var s,r,o,c;try{t?((r=(s=this._trtc)==null?void 0:s.stream)==null||r.unmuteAudio(),this.micro=!0):((c=(o=this._trtc)==null?void 0:o.stream)==null||c.muteAudio(),this.micro=!1),n(!0)}catch(l){n(!1)}})}shock(){throw new Error("Method not implemented.")}_registerRtcEvent(){var t,n,s,r;(t=this._trtc.client)==null||t.on("stream-added",this._handleStreamAdded),(n=this._trtc.client)==null||n.on("stream-subscribed",this._handleStreamSubscribed),(s=this._trtc.client)==null||s.on("audio-volume",o=>this.emit("userVolumes",o.result.map(({userId:c,audioVolume:l})=>({userId:c,audioVolume:l})))),(r=this._trtc.client)==null||r.on("error",o=>this.emit("error",o))}}class Ct extends tt{constructor(t){super();a(this,"type",se.RealseeBrowserChimeRTC);a(this,"joined",!1);a(this,"micro",!1);a(this,"voiceId","");a(this,"userId","");a(this,"logger");a(this,"deviceController");a(this,"meetingSession");a(this,"audioInput");a(this,"audioOutput");a(this,"deviceChangeObserver",{});a(this,"audioVideoObserver",{});a(this,"audioMixObserver");a(this,"_getVoiceSign",()=>{throw new Error("方法 getVoiceSign 未实现")});a(this,"_autoPlayConfirm");a(this,"$dom",document.createElement("div"));a(this,"$audio",document.createElement("audio"));a(this,"_initDom",()=>{this.$audio.id=`rs-rtc-${Te()}`,this.$dom.id=`rs-rtc-${Te()}`,this.$dom.appendChild(this.$audio),document.body.appendChild(this.$dom)});a(this,"initObservers",()=>{this.deviceChangeObserver={audioInputsChanged:t=>{this.logger.info(`audioInputsChanged ${typeof t}`),t==null||t.forEach(n=>{this.logger.info(`Device ID: ${n.deviceId} Microphone: ${n.label}`)})},audioOutputsChanged:t=>{this.logger.info(`audioOutputsChanged ${typeof t}`),t==null||t.forEach(n=>{this.logger.info(`Device ID: ${n.deviceId} Speaker: ${n.label}`)})},audioInputMuteStateChanged:(t,n)=>{this.logger.info(`Device ${t.toString()} ${n?"is muted in hardware":"is not muted"}`)}},this.audioVideoObserver={audioVideoDidStart:()=>{this.logger.info("Started")},audioVideoDidStop:t=>{this.logger.info(`Stopped with a session status code: ${t.statusCode()}`)},audioVideoDidStartConnecting:t=>{t&&this.logger.info("Attempting to reconnect")}},this.audioMixObserver={meetingAudioStreamBecameActive:t=>{if(this.$audio.paused){const n=()=>this.$audio.play().then(()=>{}).catch(s=>{if(m.error("播放远端流失败!",s),typeof this._autoPlayConfirm=="function"){const r=()=>n();this._autoPlayConfirm({onConfirm:r})}});n()}},meetingAudioStreamBecameInactive:t=>{}}});a(this,"_registerRtcEvent",()=>{var n,s,r,o,c,l;const t=((r=(s=(n=this.meetingSession)==null?void 0:n.configuration)==null?void 0:s.credentials)==null?void 0:r.attendeeId)||"";if(t){const h=new Map,u=()=>{const d=[];return h.forEach((g,w)=>{d.push({userId:g.userId,volume:g.muted||g.signalStrength===0||!g.volume?0:g.volume})}),d};(o=this.meetingSession)==null||o.audioVideo.realtimeSubscribeToAttendeeIdPresence((d,g,w)=>{var b;if(!g){h.delete(d),this.emit("userVolumes",u());return}(b=this.meetingSession)==null||b.audioVideo.realtimeSubscribeToVolumeIndicator(d,(p,_,I,N)=>{new Q.DefaultModality(p).base()===p&&(h.set(p,{userId:w||p,volume:_,muted:I,signalStrength:N}),this.emit("userVolumes",u()))})}),(c=this.meetingSession)==null||c.audioVideo.realtimeSubscribeToVolumeIndicator(t,(d,g,w,b)=>{new Q.DefaultModality(d).base()===d&&b!==null&&b!==1&&this.emit("weakNetwork")}),(l=this.meetingSession)==null||l.audioVideo.realtimeSubscribeToFatalError(d=>this.emit("error",d))}});this._getVoiceSign=t.getVoiceSign,this._autoPlayConfirm=t.autoPlayConfirm,this._initDom(),this.logger=new Q.ConsoleLogger("WebRTCLogger",t.logLevel||Q.LogLevel.INFO),this.deviceController=new Q.DefaultDeviceController(this.logger),this.initObservers()}async join(t){return new Promise(async(n,s)=>{var r,o;this.emit("joinWillStart");try{const{sdkAppId:c,userId:l,roomId:h,userSig:u}=await this._getVoiceSign({...t,roomId:t.roomId||0});this.userId=l;const{attendence:d,vendor_wrapper:g}=JSON.parse(decodeURIComponent(u)),w=new Q.MeetingSessionConfiguration({Meeting:g},{Attendee:{ExternalUserId:d.external_user_id,AttendeeId:d.attendee_id,JoinToken:d.join_token}});this.meetingSession=new Q.DefaultMeetingSession(w,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 b={audioVideoDidStart:()=>{var p;(p=this.meetingSession)==null||p.audioVideo.realtimeMuteLocalAudio(),this.joined=!0,this.emit("joined"),n(!0)},audioVideoDidStop:()=>{this.joined=!1,n(!1)}};this.meetingSession.audioVideo.addObserver(b),this.audioMixObserver&&this.meetingSession.audioVideo.addAudioMixObserver(this.audioMixObserver),this.meetingSession.audioVideo.setDeviceLabelTrigger(async()=>await navigator.mediaDevices.getUserMedia({audio:!0,video:!1}));try{const p=await this.meetingSession.audioVideo.listAudioInputDevices();m.info("audioInputDevices ===>",p);const _=((r=p[0])==null?void 0:r.deviceId)||"default";await this.meetingSession.audioVideo.startAudioInput(_)}catch(p){m.error(`设置语音输入设备失败:${p.message}`)}try{const p=await this.meetingSession.audioVideo.listAudioOutputDevices();m.info("audioOutputDevices ===>",p);const _=((o=p[0])==null?void 0:o.deviceId)||"default";await this.meetingSession.audioVideo.chooseAudioOutput(_)}catch(p){m.error(`设置语音输出设备失败:${p.message}`)}this.meetingSession.audioVideo.start()}catch(c){this.emit("error",c),this.logger.error(c.message),n(!1)}})}quit(){return this.joined?new Promise((t,n)=>{var r,o;this.joined=!1;const s={audioVideoDidStop:async c=>{var h;const l=c.statusCode();(h=this.meetingSession)==null||h.deviceController.destroy(),l===Q.MeetingSessionStatusCode.Left?(this.logger.info("You left the session"),t(!0)):(this.logger.info(`Stopped with a session status code: ${l}`),t(!0))}};(r=this.meetingSession)==null||r.audioVideo.addObserver(s),(o=this.meetingSession)==null||o.audioVideo.stop()}):Promise.resolve(!0)}async detectMicro(){return new Promise(t=>{const n={audio:!0,video:!1};try{navigator.mediaDevices.getUserMedia(n).then(()=>t(!0)).catch(()=>t(!1))}catch(s){this.logger.error(s.message),t(!1)}})}async toggleMicro(t){var s,r,o;t?(s=this.meetingSession)==null||s.audioVideo.realtimeUnmuteLocalAudio():(r=this.meetingSession)==null||r.audioVideo.realtimeMuteLocalAudio();const n=(o=this.meetingSession)==null?void 0:o.audioVideo.realtimeIsLocalAudioMuted();return n!==void 0?t!==n:!1}shock(){throw new Error("Method not implemented.")}}var le=(i=>(i[i.Success=0]="Success",i[i.Failure=1]="Failure",i[i.ReJoin=2]="ReJoin",i[i.NoMicroPermission=3]="NoMicroPermission",i[i.Unknown=500]="Unknown",i))(le||{});class gi extends tt{constructor({jsBridge:t,getVoiceSign:n}){super();a(this,"type",se.RealseeVRWebViewRTC);a(this,"joined",!1);a(this,"micro",!1);a(this,"voiceId","");a(this,"_joinOptions",null);a(this,"options");a(this,"handleUserVolumes",t=>{this.emit("userVolumes",t)});a(this,"handleWeakNetwork",t=>{t&&this.emit("weakNetwork")});a(this,"join",async t=>{this._joinOptions=t,this.emit("joinWillStart");const{sdkAppId:n,userId:s,userSig:r}=await this.getVoiceSignOrEmitError(t);return!n||!s||!r?!1:(this.type=t.type,this.jsBridge.webViewType==="WxMiniProgramWebView"?this.handleWxMiniProgramWebViewJoin({sdkAppId:n,userId:s,userSig:r,voiceId:t.voiceId}):this.handleAppWebViewJoin({sdkAppId:n,userId:s,userSig:r,voiceId:t.voiceId}))});a(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));a(this,"getVoiceSignOrEmitError",async t=>{try{return await this.options.getVoiceSign(t)}catch(n){return this.emitErrorAndSetJoinedFalse("加入房间失败:rtc 签名请求异常"),{}}});a(this,"handleWxMiniProgramWebViewJoin",async t=>{const[n,s]=await this.joinRoomOrEmitError(t);return s?!1:this.handleJoinResult(n)});a(this,"handleAppWebViewJoin",t=>new Promise(n=>{this.off("inner.rtc.success");const s=r=>{this.off("inner.rtc.fail",s),this.off("inner.rtc.success",s),n(this.handleJoinResult(r))};this.once("inner.rtc.fail",s),this.once("inner.rtc.success",s);try{const{sdkAppId:r,userId:o,userSig:c,voiceId:l}=t;this.jsBridge.callAndListen(`live/join?sdkAppID=${r}&userID=${o}&roomID=${l}&userSig=${c}`,h=>{h===!0?this.emit("inner.rtc.success",h):typeof h=="object"?h.code===le.Success||h.code===le.ReJoin?this.emit("inner.rtc.success",h):this.emit("inner.rtc.fail",h):this.emit("inner.rtc.fail",h)})}catch(r){n(this.handleJoinResult({message:r.message,code:le.Unknown}))}}));a(this,"joinRoomOrEmitError",async({sdkAppId:t,userId:n,voiceId:s,userSig:r})=>{try{return await this.jsBridge.callAndBackfeed(`live/join?sdkAppID=${t}&userID=${n}&roomID=${Number(s)}&userSig=${r}`)}catch(o){return this.emitErrorAndSetJoinedFalse("加入房间失败:"+o.message),[null,o]}});a(this,"handleJoinResult",t=>{switch(!0){case t===!0:case(typeof t=="object"&&t.code===le.Success):case(typeof t=="object"&&t.code===le.ReJoin):{this.emit("joined"),this.joined=!0;break}default:{this.joined=!1;const n=typeof t=="object"?t.message:"加入房间失败:未知异常。";this.emit("error",new Error(n,{cause:t}))}}return this.joined});a(this,"emitErrorAndSetJoinedFalse",t=>{this.emit("error",new Error(t)),this.joined=!1});a(this,"quit",async()=>{const[t,n]=await this.jsBridge.callAndBackfeed("live/quit");return t===null&&this.emit("error",n||new Error("退出房间失败:未知异常。")),this.joined=!1,!!t});a(this,"detectMicro",async()=>{const[t,n]=await this.jsBridge.detectMicro();return t===null?(this.emit("error",n||new Error("麦克风监测异常!")),!1):t});a(this,"toggleMicro",async t=>{const[n,s]=await this.jsBridge.callAndBackfeed(`live/toggleMicro?flag=${t?1:0}`);return n===null?(this.emit("error",s||new Error("麦克风监测异常!")),!1):(this.micro=n,n)});a(this,"shock",()=>{this.jsBridge.shock(1)});this.options={jsBridge:t,getVoiceSign:n},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 $=(i=>(i.SelfUserInfo="SELF_USER_INFO",i.RoomInfo="ROOM_INFO",i.RTCInfo="RTC_INFO",i.UserList="USER_LIST",i.BuiltinMsg="BUILTIN_MSG",i.CustomEvent="CUSTOM_EVENT",i.KeyframeSync="KEYFRAME_SYNC",i.UserKickOut="USER_KICK_OUT",i))($||{}),F=(i=>(i.UserChange="user_change",i.RoomChange="room_change",i))(F||{}),K=(i=>(i.UserMicroStatus="change_micro_status",i.UserMicroStatusSync="sync_micro_status",i.UserPermission="change_permission",i.UserStatus="change_status",i.UserInfo="change_info",i.RoomClose="close",i))(K||{}),te=(i=>(i.OPEN="OPEN",i.CLOSE="CLOSE",i))(te||{});function bn(i){try{const e=JSON.parse(i),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||{}},n=Object.keys(t).filter(s=>t[s]===void 0);return n.length>0&&console.warn(`推送数据格式异常:${n.join(" ")} 值不存在!`),t}catch(e){return!1}}var V=(i=>(i[i.NOTINITIALIZED=-1]="NOTINITIALIZED",i[i.CONNECTING=0]="CONNECTING",i[i.OPEN=1]="OPEN",i[i.CLOSED=3]="CLOSED",i))(V||{}),pi=(i=>(i[i.Normal=0]="Normal",i[i.Removed=1]="Removed",i[i.Replaced=2]="Replaced",i))(pi||{}),_i=(i=>(i.WAIT_ENTER="WAIT_ENTER",i.ONLINE="ONLINE",i.LEAVE="LEAVE",i.KICK_OUT="KICK_OUT",i.BE_REPLACE="BE_REPLACE",i.EXCEPTION="EXCEPTION",i))(_i||{}),Ge=(i=>(i[i.NOTINITIALIZED=-1]="NOTINITIALIZED",i[i.CONNECTING=0]="CONNECTING",i[i.OPEN=1]="OPEN",i[i.CLOSING=2]="CLOSING",i[i.CLOSED=3]="CLOSED",i))(Ge||{}),mi=(i=>(i.Error="Error",i.Close="Close",i.MicroAuth="MicroAuth",i.DuplicateConnect="DuplicateConnect",i.IllegalURL="IllegalURL",i.Unknown="Unknown",i.IllegalArgs="IllegalArgs",i))(mi||{}),wi=(i=>(i.Err_1000="CLOSE_NORMAL",i.Err_1001="CLOSE_GOING_AWAY",i.Err_1002="CLOSE_PROTOCOL_ERROR",i.Err_1003="CLOSE_UNSUPPORTED",i.Err_1006="CLOSE_ABNORMAL",i.Err_1007="Unsupported Data",i.Err_1008="Policy Violation",i.Err_1009="CLOSE_TOO_LARGE",i.Err_unknown="unknown",i))(wi||{});function bi(i){switch(i){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 yn(i,e={}){var c;const t=new URL(i,"http://localhost"),n=new URLSearchParams(t.search);for(const[l,h]of Object.entries(e))n.set(l,String(h));const s=n.toString(),r=i.split("#")[0].split("?")[0],o=(c=t.hash)!=null?c:"";return`${r}${s?`?${s}`:""}${o}`}const yi=(()=>{var t;const i=typeof process!="undefined"&&((t=process.versions)==null?void 0:t.node)!=null;return typeof window!="undefined"&&"Deno"in window||i||typeof window=="undefined"})(),pe=yi?"":navigator.userAgent,Sn=/android/i.test(pe),Cn=/iPhone|iPad|iPod|iPadOS/i.test(pe)||!yi&&/Macintosh/.test(pe)&&"ontouchend"in globalThis,Kt=/MicroMessenger/i.test(pe)&&/miniProgram/i.test(pe),Jt=/realsee/i.test(pe);function qe(i){return Object.prototype.toString.call(i)==="[object Object]"}function it(i,e){return i===e?!0:i==null||e==null||typeof i!=typeof e?!1:Number.isNaN(i)&&Number.isNaN(e)}function En(i,e){if(i===e)return!0;if(i==null||e==null)return!1;const t=Object.keys(i),n=Object.keys(e);return t.length!==n.length?!1:t.every(s=>it(i[s],e[s]))}function kn(i,e){return i===e?!0:i==null||e==null||i.length!==e.length?!1:i.every((t,n)=>it(t,e[n]))}function vn(i,e){return it(i,e)?!0:qe(i)&&qe(e)?En(i,e):Array.isArray(i)&&Array.isArray(e)?kn(i,e):!1}function Lt(i,e){return it(i,e)?!0:qe(i)&&qe(e)?On(i,e):Array.isArray(i)&&Array.isArray(e)?In(i,e):!1}function In(i,e){if(i.length!==e.length)return!1;for(let t=0,n=i.length;t<n;t++)if(!Lt(i[t],e[t]))return!1;return!0}function On(i,e){if(i===e)return!0;if(i==null||e==null)return!1;const t=Object.keys(i),n=Object.keys(e);return t.length!==n.length?!1:t.every(s=>Lt(i[s],e[s]))}function Rn(i,e,t={deep:!1}){return t.deep?Lt(i,e):vn(i,e)}class An extends ge{constructor(t){super();a(this,"_realWebSocket");a(this,"_url");a(this,"_protocols");a(this,"_readyState",Ge.NOTINITIALIZED);a(this,"_options",{timeout:1e4,shouldReconnect:(t,n)=>{if(!(t.code===1008||t.code===1011))return[0,1e3,2e3][n.attempts%3]},should1000Reconnect:!1,ignoreConnectivityEvents:!1,automaticOpen:!1});a(this,"_connectTimeout");a(this,"_attempts",0);a(this,"_reconnects",-1);a(this,"_reconnectWhenOnlineAgain",!1);a(this,"_explicitlyClosed",!1);a(this,"_pendingReconnect");a(this,"_connectivityEventsAttached",!1);a(this,"_heathCheckTimer");a(this,"_healthCheck",async()=>{if(this._realWebSocket){const t=this._realWebSocket.readyState;t!==this._readyState&&(this._readyState=t,this._readyState===Ge.CLOSING&&this.emit("closing"))}await new Promise(t=>setTimeout(t,2e3)),this._heathCheckTimer=requestAnimationFrame(this._healthCheck)});a(this,"_clearConnectTimeoutIfNeed",()=>{this._connectTimeout&&(clearTimeout(this._connectTimeout),this._connectTimeout=void 0)});a(this,"_clearHeathCheckIfNeed",()=>{this._heathCheckTimer&&(cancelAnimationFrame(this._heathCheckTimer),this._heathCheckTimer=void 0)});a(this,"_startHealthCheck",()=>{this._clearHeathCheckIfNeed(),this._heathCheckTimer=requestAnimationFrame(this._healthCheck)});a(this,"_stopHealthCheck",()=>{this._clearHeathCheckIfNeed()});a(this,"_clearPendingReconnectIfNeeded",()=>{this._pendingReconnect&&(clearTimeout(this._pendingReconnect),this._pendingReconnect=void 0)});a(this,"_online",t=>{this._reconnectWhenOnlineAgain&&(this._clearPendingReconnectIfNeeded(),this._reconnect(t))});a(this,"_offline",()=>{var t;this._reconnectWhenOnlineAgain=!0,(t=this._realWebSocket)==null||t.close(1e3,"offline")});a(this,"_detachConnectivityEvents",()=>{this._connectivityEventsAttached&&(globalThis==null||globalThis.removeEventListener("online",this._online),globalThis==null||globalThis.removeEventListener("offline",this._offline),this._connectivityEventsAttached=!1)});a(this,"_attachConnectivityEvents",()=>{this._connectivityEventsAttached||(globalThis==null||globalThis.addEventListener("online",this._online),globalThis==null||globalThis.addEventListener("offline",this._offline),this._connectivityEventsAttached=!0)});a(this,"send",t=>{var n,s,r;((n=this._realWebSocket)==null?void 0:n.readyState)===((s=this._realWebSocket)==null?void 0:s.OPEN)&&((r=this._realWebSocket)==null||r.send(t))});a(this,"close",(t,n)=>{var s;return typeof t!="number"&&(n=t,t=1e3),this._clearPendingReconnectIfNeeded(),this._reconnectWhenOnlineAgain=!1,this._explicitlyClosed=!0,this._detachConnectivityEvents(),(s=this._realWebSocket)==null?void 0:s.close(t,n)});a(this,"open",t=>{var n,s;t&&(this._url=t),((n=this._realWebSocket)==null?void 0:n.readyState)!==WebSocket.OPEN&&((s=this._realWebSocket)==null?void 0:s.readyState)!==WebSocket.CONNECTING&&(this._clearPendingReconnectIfNeeded(),this._reconnectWhenOnlineAgain=!1,this._explicitlyClosed=!1,this._createWebSocket())});a(this,"_createWebSocket",()=>{var s;const t=typeof this._url=="string"?this._url:(s=this._url)==null?void 0:s.call(this,this);if(!t)return;this._clearConnectTimeoutIfNeed(),this._clearPendingReconnectIfNeeded(),this._removeWebSocketEvent(),this._realWebSocket=new WebSocket(t,this._protocols||void 0),this._attempts++,this.emit("connecting",new CustomEvent("connecting",{detail:{attempts:this._attempts,reconnects:this._reconnects}}));const n=()=>{this._connectTimeout=void 0,this._detachConnectivityEvents(),this.emit("timeout",new CustomEvent("timeout",{detail:{attempts:this._attempts,reconnects:this._reconnects}}))};this._connectTimeout=setTimeout(n,this._options.timeout),this._dispatchWebSocketEvent(),this._options.ignoreConnectivityEvents||this._attachConnectivityEvents()});a(this,"_removeWebSocketEvent",()=>{var t,n,s,r;(t=this._realWebSocket)==null||t.removeEventListener("open",this._webSocketOpenHandler),(n=this._realWebSocket)==null||n.removeEventListener("close",this._webSocketCloseHandler),(s=this._realWebSocket)==null||s.removeEventListener("error",this._webSocketErrorHandler),(r=this._realWebSocket)==null||r.removeEventListener("message",this._webSocketMessageHandler)});a(this,"_dispatchWebSocketEvent",()=>{var t,n,s,r;(t=this._realWebSocket)==null||t.addEventListener("open",this._webSocketOpenHandler),(n=this._realWebSocket)==null||n.addEventListener("close",this._webSocketCloseHandler),(s=this._realWebSocket)==null||s.addEventListener("error",this._webSocketErrorHandler),(r=this._realWebSocket)==null||r.addEventListener("message",this._webSocketMessageHandler)});a(this,"_webSocketOpenHandler",t=>{this._connectTimeout&&(clearTimeout(this._connectTimeout),this._connectTimeout=void 0);const n=++this._reconnects,s=this._attempts;return this._attempts=0,this._reconnectWhenOnlineAgain=!1,this._startHealthCheck(),this.emit("open",Object.assign(t,{detail:{reconnects:n,attempts:s}}))});a(this,"_webSocketCloseHandler",t=>(this._reconnect(t),this._stopHealthCheck(),this.emit("close",t)));a(this,"_webSocketErrorHandler",t=>this.emit("error",new CustomEvent("error",{detail:{error:t}})));a(this,"_webSocketMessageHandler",t=>this.emit("message",t));t&&this.setOptions(t),this._startHealthCheck()}get attempts(){return this._attempts}setOptions(t){if(!t)return;this._url=t.url,this._protocols=t.protocols;const n=Object.assign(this._options,t.robustOptions||{});if(typeof(n==null?void 0:n.timeout)!="number")throw new Error("timeout must be the number of milliseconds to timeout a connection attempt");if(typeof(n==null?void 0:n.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=n,this._options.automaticOpen&&this._createWebSocket()}_reconnect(t){var o,c,l;if(!this._options.should1000Reconnect&&t.code===1e3||this._explicitlyClosed){this._attempts=0;return}if(this._connectivityEventsAttached&&((o=globalThis==null?void 0:globalThis.navigator)==null?void 0:o.onLine)===!1){this._reconnectWhenOnlineAgain=!0;return}const r=(l=(c=this._options).shouldReconnect)==null?void 0:l.call(c,t,this);typeof r=="number"?(m.debug(`RobustWebSocket: Reconnecting in ${r}ms...`),this._pendingReconnect=setTimeout(this._createWebSocket,r)):m.debug("RobustWebSocket: No reconnection will be attempted.")}}class Tn extends ge{constructor(){super();a(this,"_ws",new An({url:"",robustOptions:{should1000Reconnect:!0,ignoreConnectivityEvents:!0}}));a(this,"_state",V.NOTINITIALIZED);a(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)});a(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)});a(this,"_handleCloseEvent",t=>{m.info(`live room closed bacause of ${t.code}-${t.reason||bi(t.code)}`),this.state=V.CLOSED});a(this,"_handleClosingEvent",()=>{var t;m.info("live room is closing, onLine:",(t=globalThis==null?void 0:globalThis.navigator)==null?void 0:t.onLine),this.state=V.CLOSED});a(this,"_handleConnectingEvent",t=>{m.info("live room is connecting"),this.state=V.CONNECTING,t.detail.reconnects>0&&this.emit("reconnecting",t.detail)});a(this,"_handleErrorEvent",t=>{m.error("live room error",t),this.state=V.CLOSED});a(this,"_handleMessageEvent",t=>{let n=(()=>{try{return JSON.parse(t.data)}catch(s){return t.data}})();this.emit("message",n)});a(this,"_handleOpenEvent",t=>{m.info("live room open",t.detail),this.state=V.OPEN,t.detail.reconnects>0&&this.emit("reconnected",t.detail)});a(this,"_handleTimeoutEvent",t=>{m.error("live room connect timeout!",t.detail),this.state=V.CLOSED});a(this,"dispose",async()=>(this._removeWebSocketEventListeners(),await this.close("live room close by controller disposed!")));a(this,"open",t=>this._ws.open(t));a(this,"close",(t,n)=>new Promise(s=>{this._ws.once("close",()=>s(!0)),this._ws.close(t,n)}));a(this,"sendMessage",(t="")=>{if(t==null)throw new Error("live message is empty!");if(this.state!==V.OPEN)throw new Error("live has not yet been initialized!");return this._ws.send(JSON.stringify(t))});a(this,"readyClose",()=>{this._ws&&(this._ws._explicitlyClosed=!0)});this._addWebSocketEventListeners()}set state(t){const n=JSON.parse(JSON.stringify(this._state));this._state=t,this.emit("stateChange",this.state,n)}get state(){return this._state}}const J=()=>new Map,Et=i=>{const e=J();return i.forEach((t,n)=>{e.set(n,t)}),e},Se=(i,e,t)=>{let n=i.get(e);return n===void 0&&i.set(e,n=t()),n},Ln=(i,e)=>{const t=[];for(const[n,s]of i)t.push(e(s,n));return t},Mn=(i,e)=>{for(const[t,n]of i)if(e(n,t))return!0;return!1},_e=()=>new Set,ut=i=>i[i.length-1],me=Array.from,Dn=Array.isArray;class Nn{constructor(){this._observers=J()}on(e,t){return Se(this._observers,e,_e).add(t),t}once(e,t){const n=(...s)=>{this.off(e,n),t(...s)};this.on(e,n)}off(e,t){const n=this._observers.get(e);n!==void 0&&(n.delete(t),n.size===0&&this._observers.delete(e))}emit(e,t){return me((this._observers.get(e)||J()).values()).forEach(n=>n(...t))}destroy(){this._observers=J()}}const ae=Math.floor,We=Math.abs,Si=(i,e)=>i<e?i:e,Ce=(i,e)=>i>e?i:e,Vn=i=>i!==0?i<0:1/i<0,Gt=1,qt=2,dt=4,ft=8,Un=32,Ci=64,He=128,jn=31,Ht=63,Re=127,Bn=2147483647,$n=Number.isInteger||(i=>typeof i=="number"&&isFinite(i)&&ae(i)===i),xn=i=>i.toLowerCase(),Fn=/^\s*/g,Wn=i=>i.replace(Fn,""),Pn=/([A-Z])/g,zt=(i,e)=>Wn(i.replace(Pn,t=>`${e}${xn(t)}`)),Kn=i=>{const e=unescape(encodeURIComponent(i)),t=e.length,n=new Uint8Array(t);for(let s=0;s<t;s++)n[s]=e.codePointAt(s);return n},Le=typeof TextEncoder!="undefined"?new TextEncoder:null,Jn=i=>Le.encode(i),Gn=Le?Jn:Kn;let gt=typeof TextDecoder=="undefined"?null:new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0});gt&&gt.decode(new Uint8Array).length===1&&(gt=null);class je{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}}const Mt=()=>new je,qn=i=>{let e=i.cpos;for(let t=0;t<i.bufs.length;t++)e+=i.bufs[t].length;return e},z=i=>{const e=new Uint8Array(qn(i));let t=0;for(let n=0;n<i.bufs.length;n++){const s=i.bufs[n];e.set(s,t),t+=s.length}return e.set(new Uint8Array(i.cbuf.buffer,0,i.cpos),t),e},Hn=(i,e)=>{const t=i.cbuf.length;t-i.cpos<e&&(i.bufs.push(new Uint8Array(i.cbuf.buffer,0,i.cpos)),i.cbuf=new Uint8Array(Ce(t,e)*2),i.cpos=0)},T=(i,e)=>{const t=i.cbuf.length;i.cpos===t&&(i.bufs.push(i.cbuf),i.cbuf=new Uint8Array(t*2),i.cpos=0),i.cbuf[i.cpos++]=e},kt=T,C=(i,e)=>{for(;e>Re;)T(i,He|Re&e),e=ae(e/128);T(i,Re&e)},Dt=(i,e)=>{const t=Vn(e);for(t&&(e=-e),T(i,(e>Ht?He:0)|(t?Ci:0)|Ht&e),e=ae(e/64);e>0;)T(i,(e>Re?He:0)|Re&e),e=ae(e/128)},vt=new Uint8Array(3e4),zn=vt.length/3,Yn=(i,e)=>{if(e.length<zn){const t=Le.encodeInto(e,vt).written||0;C(i,t);for(let n=0;n<t;n++)T(i,vt[n])}else x(i,Gn(e))},Xn=(i,e)=>{const t=unescape(encodeURIComponent(e)),n=t.length;C(i,n);for(let s=0;s<n;s++)T(i,t.codePointAt(s))},fe=Le&&Le.encodeInto?Yn:Xn,Nt=(i,e)=>{const t=i.cbuf.length,n=i.cpos,s=Si(t-n,e.length),r=e.length-s;i.cbuf.set(e.subarray(0,s),n),i.cpos+=s,r>0&&(i.bufs.push(i.cbuf),i.cbuf=new Uint8Array(Ce(t*2,r)),i.cbuf.set(e.subarray(s)),i.cpos=r)},x=(i,e)=>{C(i,e.byteLength),Nt(i,e)},Vt=(i,e)=>{Hn(i,e);const t=new DataView(i.cbuf.buffer,i.cpos,e);return i.cpos+=e,t},Zn=(i,e)=>Vt(i,4).setFloat32(0,e,!1),Qn=(i,e)=>Vt(i,8).setFloat64(0,e,!1),es=(i,e)=>Vt(i,8).setBigInt64(0,e,!1),Yt=new DataView(new ArrayBuffer(4)),ts=i=>(Yt.setFloat32(0,i),Yt.getFloat32(0)===i),Me=(i,e)=>{switch(typeof e){case"string":T(i,119),fe(i,e);break;case"number":$n(e)&&We(e)<=Bn?(T(i,125),Dt(i,e)):ts(e)?(T(i,124),Zn(i,e)):(T(i,123),Qn(i,e));break;case"bigint":T(i,122),es(i,e);break;case"object":if(e===null)T(i,126);else if(Dn(e)){T(i,117),C(i,e.length);for(let t=0;t<e.length;t++)Me(i,e[t])}else if(e instanceof Uint8Array)T(i,116),x(i,e);else{T(i,118);const t=Object.keys(e);C(i,t.length);for(let n=0;n<t.length;n++){const s=t[n];fe(i,s),Me(i,e[s])}}break;case"boolean":T(i,e?120:121);break;default:T(i,127)}};class Xt extends je{constructor(e){super(),this.w=e,this.s=null,this.count=0}write(e){this.s===e?this.count++:(this.count>0&&C(this,this.count-1),this.count=1,this.w(this,e),this.s=e)}}const Zt=i=>{i.count>0&&(Dt(i.encoder,i.count===1?i.s:-i.s),i.count>1&&C(i.encoder,i.count-2))};class Pe{constructor(){this.encoder=new je,this.s=0,this.count=0}write(e){this.s===e?this.count++:(Zt(this),this.count=1,this.s=e)}toUint8Array(){return Zt(this),z(this.encoder)}}const Qt=i=>{if(i.count>0){const e=i.diff*2+(i.count===1?0:1);Dt(i.encoder,e),i.count>1&&C(i.encoder,i.count-2)}};class pt{constructor(){this.encoder=new je,this.s=0,this.count=0,this.diff=0}write(e){this.diff===e-this.s?(this.s=e,this.count++):(Qt(this),this.count=1,this.diff=e-this.s,this.s=e)}toUint8Array(){return Qt(this),z(this.encoder)}}class is{constructor(){this.sarr=[],this.s="",this.lensE=new Pe}write(e){this.s+=e,this.s.length>19&&(this.sarr.push(this.s),this.s=""),this.lensE.write(e.length)}toUint8Array(){const e=new je;return this.sarr.push(this.s),this.s="",fe(e,this.sarr.join("")),Nt(e,this.lensE.toUint8Array()),z(e)}}const we=i=>new Error(i),G=()=>{throw we("Method unimplemented")},he=()=>{throw we("Unexpected case")},ns=crypto.getRandomValues.bind(crypto),Ei=()=>ns(new Uint32Array(1))[0],ss="10000000-1000-4000-8000"+-1e11,rs=()=>ss.replace(/[018]/g,i=>(i^Ei()&15>>i/4).toString(16)),ei=i=>new Promise(i);Promise.all.bind(Promise);const ti=i=>i===void 0?null:i;class os{constructor(){this.map=new Map}setItem(e,t){this.map.set(e,t)}getItem(e){return this.map.get(e)}}let ki=new os,cs=!0;try{typeof localStorage!="undefined"&&localStorage&&(ki=localStorage,cs=!1)}catch(i){}const ls=ki,as=Object.assign,hs=Object.keys,us=(i,e)=>{for(const t in i)e(i[t],t)},ii=i=>hs(i).length,ds=i=>{for(const e in i)return!1;return!0},fs=(i,e)=>{for(const t in i)if(!e(i[t],t))return!1;return!0},gs=(i,e)=>Object.prototype.hasOwnProperty.call(i,e),ps=(i,e)=>i===e||ii(i)===ii(e)&&fs(i,(t,n)=>(t!==void 0||gs(e,n))&&e[n]===t),_s=Object.freeze,vi=i=>{for(const e in i){const t=i[e];(typeof t=="object"||typeof t=="function")&&vi(i[e])}return _s(i)},Ut=(i,e,t=0)=>{try{for(;t<i.length;t++)i[t](...e)}finally{t<i.length&&Ut(i,e,t+1)}},ms=(i,e)=>e.includes(i),De=typeof process!="undefined"&&process.release&&/node|io\.js/.test(process.release.name)&&Object.prototype.toString.call(typeof process!="undefined"?process:0)==="[object process]";let P;const ws=()=>{if(P===void 0)if(De){P=J();const i=process.argv;let e=null;for(let t=0;t<i.length;t++){const n=i[t];n[0]==="-"?(e!==null&&P.set(e,""),e=n):e!==null&&(P.set(e,n),e=null)}e!==null&&P.set(e,"")}else typeof location=="object"?(P=J(),(location.search||"?").slice(1).split("&").forEach(i=>{if(i.length!==0){const[e,t]=i.split("=");P.set(`--${zt(e,"-")}`,t),P.set(`-${zt(e,"-")}`,t)}})):P=J();return P},It=i=>ws().has(i),ze=i=>ti(De?process.env[i.toUpperCase().replaceAll("-","_")]:ls.getItem(i)),Ii=i=>It("--"+i)||ze(i)!==null;Ii("production");const bs=De&&ms(process.env.FORCE_COLOR,["true","1","2"]),ys=bs||!It("--no-colors")&&!Ii("no-color")&&(!De||process.stdout.isTTY)&&(!De||It("--color")||ze("COLORTERM")!==null||(ze("TERM")||"").includes("color"));class Ss{constructor(e,t){this.left=e,this.right=t}}const H=(i,e)=>new Ss(i,e);typeof DOMParser!="undefined"&&new DOMParser;const Cs=i=>Ln(i,(e,t)=>`${t}:${e};`).join(""),Z=Symbol,Oi=Z(),Ri=Z(),Es=Z(),ks=Z(),vs=Z(),Ai=Z(),Is=Z(),jt=Z(),Os=Z(),Rs=i=>{var s;i.length===1&&((s=i[0])==null?void 0:s.constructor)===Function&&(i=i[0]());const e=[],t=[];let n=0;for(;n<i.length;n++){const r=i[n];if(r===void 0)break;if(r.constructor===String||r.constructor===Number)e.push(r);else if(r.constructor===Object)break}for(n>0&&t.push(e.join(""));n<i.length;n++){const r=i[n];r instanceof Symbol||t.push(r)}return t},As={[Oi]:H("font-weight","bold"),[Ri]:H("font-weight","normal"),[Es]:H("color","blue"),[vs]:H("color","green"),[ks]:H("color","grey"),[Ai]:H("color","red"),[Is]:H("color","purple"),[jt]:H("color","orange"),[Os]:H("color","black")},Ts=i=>{var o;i.length===1&&((o=i[0])==null?void 0:o.constructor)===Function&&(i=i[0]());const e=[],t=[],n=J();let s=[],r=0;for(;r<i.length;r++){const c=i[r],l=As[c];if(l!==void 0)n.set(l.left,l.right);else{if(c===void 0)break;if(c.constructor===String||c.constructor===Number){const h=Cs(n);r>0||h.length>0?(e.push("%c"+c),t.push(h)):e.push(c)}else break}}for(r>0&&(s=t,s.unshift(e.join("")));r<i.length;r++){const c=i[r];c instanceof Symbol||s.push(c)}return s},Ti=ys?Ts:Rs,Ls=(...i)=>{console.log(...Ti(i)),Li.forEach(e=>e.print(i))},Ms=(...i)=>{console.warn(...Ti(i)),i.unshift(jt),Li.forEach(e=>e.print(i))},Li=_e(),Mi=i=>({[Symbol.iterator](){return this},next:i}),Ds=(i,e)=>Mi(()=>{let t;do t=i.next();while(!t.done&&!e(t.value));return t}),_t=(i,e)=>Mi(()=>{const{done:t,value:n}=i.next();return{done:t,value:t?void 0:e(n)}});class Ns{constructor(e,t){this.clock=e,this.len=t}}class Vs{constructor(){this.clients=new Map}}const Di=(i,e,t)=>e.clients.forEach((n,s)=>{const r=i.doc.store.clients.get(s);for(let o=0;o<n.length;o++){const c=n[o];xi(i,r,c.clock,c.len,t)}}),Us=(i,e)=>{let t=0,n=i.length-1;for(;t<=n;){const s=ae((t+n)/2),r=i[s],o=r.clock;if(o<=e){if(e<o+r.len)return s;t=s+1}else n=s-1}return null},Ni=(i,e)=>{const t=i.clients.get(e.client);return t!==void 0&&Us(t,e.clock)!==null},Vi=i=>{i.clients.forEach(e=>{e.sort((s,r)=>s.clock-r.clock);let t,n;for(t=1,n=1;t<e.length;t++){const s=e[n-1],r=e[t];s.clock+s.len>=r.clock?s.len=Ce(s.len,r.clock+r.len-s.clock):(n<t&&(e[n]=r),n++)}e.length=n})},Ui=(i,e,t,n)=>{Se(i.clients,e,()=>[]).push(new Ns(t,n))},js=(i,e)=>{C(i.restEncoder,e.clients.size),me(e.clients.entries()).sort((t,n)=>n[0]-t[0]).forEach(([t,n])=>{i.resetDsCurVal(),C(i.restEncoder,t);const s=n.length;C(i.restEncoder,s);for(let r=0;r<s;r++){const o=n[r];i.writeDsClock(o.clock),i.writeDsLen(o.len)}})},ji=Ei;class Ee extends Nn{constructor({guid:e=rs(),collectionid:t=null,gc:n=!0,gcFilter:s=()=>!0,meta:r=null,autoLoad:o=!1,shouldLoad:c=!0}={}){super(),this.gc=n,this.gcFilter=s,this.clientID=ji(),this.guid=e,this.collectionid=t,this.share=new Map,this.store=new qs,this._transaction=null,this._transactionCleanups=[],this.subdocs=new Set,this._item=null,this.shouldLoad=c,this.autoLoad=o,this.meta=r,this.isLoaded=!1,this.isSynced=!1,this.isDestroyed=!1,this.whenLoaded=ei(h=>{this.on("load",()=>{this.isLoaded=!0,h(this)})});const l=()=>ei(h=>{const u=d=>{(d===void 0||d===!0)&&(this.off("sync",u),h())};this.on("sync",u)});this.on("sync",h=>{h===!1&&this.isSynced&&(this.whenSynced=l()),this.isSynced=h===void 0||h===!0,this.isSynced&&!this.isLoaded&&this.emit("load",[this])}),this.whenSynced=l()}load(){const e=this._item;e!==null&&!this.shouldLoad&&k(e.parent.doc,t=>{t.subdocsLoaded.add(this)},null,!0),this.shouldLoad=!0}getSubdocs(){return this.subdocs}getSubdocGuids(){return new Set(me(this.subdocs).map(e=>e.guid))}transact(e,t=null){return k(this,e,t)}get(e,t=D){const n=Se(this.share,e,()=>{const r=new t;return r._integrate(this,null),r}),s=n.constructor;if(t!==D&&s!==t)if(s===D){const r=new t;r._map=n._map,n._map.forEach(o=>{for(;o!==null;o=o.left)o.parent=r}),r._start=n._start;for(let o=r._start;o!==null;o=o.right)o.parent=r;return r._length=n._length,this.share.set(e,r),r._integrate(this,null),r}else throw new Error(`Type with the name ${e} has already been defined with a different constructor`);return n}getArray(e=""){return this.get(e,Ae)}getText(e=""){return this.get(e,Qe)}getMap(e=""){return this.get(e,Ze)}getXmlElement(e=""){return this.get(e,Ue)}getXmlFragment(e=""){return this.get(e,be)}toJSON(){const e={};return this.share.forEach((t,n)=>{e[n]=t.toJSON()}),e}destroy(){this.isDestroyed=!0,me(this.subdocs).forEach(t=>t.destroy());const e=this._item;if(e!==null){this._item=null;const t=e.content;t.doc=new Ee({guid:this.guid,...t.opts,shouldLoad:!1}),t.doc._item=e,k(e.parent.doc,n=>{const s=t.doc;e.deleted||n.subdocsAdded.add(s),n.subdocsRemoved.add(this)},null,!0)}this.emit("destroyed",[!0]),this.emit("destroy",[this]),super.destroy()}}class Bs{constructor(){this.restEncoder=Mt()}toUint8Array(){return z(this.restEncoder)}resetDsCurVal(){}writeDsClock(e){C(this.restEncoder,e)}writeDsLen(e){C(this.restEncoder,e)}}class $s extends Bs{writeLeftID(e){C(this.restEncoder,e.client),C(this.restEncoder,e.clock)}writeRightID(e){C(this.restEncoder,e.client),C(this.restEncoder,e.clock)}writeClient(e){C(this.restEncoder,e)}writeInfo(e){kt(this.restEncoder,e)}writeString(e){fe(this.restEncoder,e)}writeParentInfo(e){C(this.restEncoder,e?1:0)}writeTypeRef(e){C(this.restEncoder,e)}writeLen(e){C(this.restEncoder,e)}writeAny(e){Me(this.restEncoder,e)}writeBuf(e){x(this.restEncoder,e)}writeJSON(e){fe(this.restEncoder,JSON.stringify(e))}writeKey(e){fe(this.restEncoder,e)}}class xs{constructor(){this.restEncoder=Mt(),this.dsCurrVal=0}toUint8Array(){return z(this.restEncoder)}resetDsCurVal(){this.dsCurrVal=0}writeDsClock(e){const t=e-this.dsCurrVal;this.dsCurrVal=e,C(this.restEncoder,t)}writeDsLen(e){e===0&&he(),C(this.restEncoder,e-1),this.dsCurrVal+=e}}class Fs extends xs{constructor(){super(),this.keyMap=new Map,this.keyClock=0,this.keyClockEncoder=new pt,this.clientEncoder=new Pe,this.leftClockEncoder=new pt,this.rightClockEncoder=new pt,this.infoEncoder=new Xt(kt),this.stringEncoder=new is,this.parentInfoEncoder=new Xt(kt),this.typeRefEncoder=new Pe,this.lenEncoder=new Pe}toUint8Array(){const e=Mt();return C(e,0),x(e,this.keyClockEncoder.toUint8Array()),x(e,this.clientEncoder.toUint8Array()),x(e,this.leftClockEncoder.toUint8Array()),x(e,this.rightClockEncoder.toUint8Array()),x(e,z(this.infoEncoder)),x(e,this.stringEncoder.toUint8Array()),x(e,z(this.parentInfoEncoder)),x(e,this.typeRefEncoder.toUint8Array()),x(e,this.lenEncoder.toUint8Array()),Nt(e,z(this.restEncoder)),z(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){x(this.restEncoder,e)}writeJSON(e){Me(this.restEncoder,e)}writeKey(e){const t=this.keyMap.get(e);t===void 0?(this.keyClockEncoder.write(this.keyClock++),this.stringEncoder.write(e)):this.keyClockEncoder.write(t)}}const Ws=(i,e,t,n)=>{n=Ce(n,e[0].id.clock);const s=Y(e,n);C(i.restEncoder,e.length-s),i.writeClient(t),C(i.restEncoder,n);const r=e[s];r.write(i,n-r.id.clock);for(let o=s+1;o<e.length;o++)e[o].write(i,0)},Ps=(i,e,t)=>{const n=new Map;t.forEach((s,r)=>{B(e,r)>s&&n.set(r,s)}),Bt(e).forEach((s,r)=>{t.has(r)||n.set(r,0)}),C(i.restEncoder,n.size),me(n.entries()).sort((s,r)=>r[0]-s[0]).forEach(([s,r])=>{Ws(i,e.clients.get(s),s,r)})},Ks=(i,e)=>Ps(i,e.doc.store,e.beforeState);class Js{constructor(){this.l=[]}}const ni=()=>new Js,si=(i,e)=>i.l.push(e),ri=(i,e)=>{const t=i.l,n=t.length;i.l=t.filter(s=>e!==s),n===i.l.length&&console.error("[yjs] Tried to remove event handler that doesn't exist.")},Bi=(i,e,t)=>Ut(i.l,[e,t]);class Ke{constructor(e,t){this.client=e,this.clock=t}}const $e=(i,e)=>i===e||i!==null&&e!==null&&i.client===e.client&&i.clock===e.clock,v=(i,e)=>new Ke(i,e),Gs=i=>{for(const[e,t]of i.doc.share.entries())if(t===i)return e;throw he()},ue=(i,e)=>e===void 0?!i.deleted:e.sv.has(i.id.client)&&(e.sv.get(i.id.client)||0)>i.id.clock&&!Ni(e.ds,i.id),Ot=(i,e)=>{const t=Se(i.meta,Ot,_e),n=i.doc.store;t.has(e)||(e.sv.forEach((s,r)=>{s<B(n,r)&&re(i,v(r,s))}),Di(i,e.ds,s=>{}),t.add(e))};class qs{constructor(){this.clients=new Map,this.pendingStructs=null,this.pendingDs=null}}const Bt=i=>{const e=new Map;return i.clients.forEach((t,n)=>{const s=t[t.length-1];e.set(n,s.id.clock+s.length)}),e},B=(i,e)=>{const t=i.clients.get(e);if(t===void 0)return 0;const n=t[t.length-1];return n.id.clock+n.length},$i=(i,e)=>{let t=i.clients.get(e.id.client);if(t===void 0)t=[],i.clients.set(e.id.client,t);else{const n=t[t.length-1];if(n.id.clock+n.length!==e.id.clock)throw he()}t.push(e)},Y=(i,e)=>{let t=0,n=i.length-1,s=i[n],r=s.id.clock;if(r===e)return n;let o=ae(e/(r+s.length-1)*n);for(;t<=n;){if(s=i[o],r=s.id.clock,r<=e){if(e<r+s.length)return o;t=o+1}else n=o-1;o=ae((t+n)/2)}throw he()},Hs=(i,e)=>{const t=i.clients.get(e.client);return t[Y(t,e.clock)]},mt=Hs,Rt=(i,e,t)=>{const n=Y(e,t),s=e[n];return s.id.clock<t&&s instanceof U?(e.splice(n+1,0,rn(i,s,t-s.id.clock)),n+1):n},re=(i,e)=>{const t=i.doc.store.clients.get(e.client);return t[Rt(i,t,e.clock)]},oi=(i,e,t)=>{const n=e.clients.get(t.client),s=Y(n,t.clock),r=n[s];return t.clock!==r.id.clock+r.length-1&&r.constructor!==ie&&n.splice(s+1,0,rn(i,r,t.clock-r.id.clock+1)),r},zs=(i,e,t)=>{const n=i.clients.get(e.id.client);n[Y(n,e.id.clock)]=t},xi=(i,e,t,n,s)=>{if(n===0)return;const r=t+n;let o=Rt(i,e,t),c;do c=e[o++],r<c.id.clock+c.length&&Rt(i,e,r),s(c);while(o<e.length&&e[o].id.clock<r)};class Ys{constructor(e,t,n){this.doc=e,this.deleteSet=new Vs,this.beforeState=Bt(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=n,this.subdocsAdded=new Set,this.subdocsRemoved=new Set,this.subdocsLoaded=new Set,this._needFormattingCleanup=!1}}const ci=(i,e)=>e.deleteSet.clients.size===0&&!Mn(e.afterState,(t,n)=>e.beforeState.get(n)!==t)?!1:(Vi(e.deleteSet),Ks(i,e),js(i,e.deleteSet),!0),li=(i,e,t)=>{const n=e._item;(n===null||n.id.clock<(i.beforeState.get(n.id.client)||0)&&!n.deleted)&&Se(i.changed,e,_e).add(t)},Je=(i,e)=>{let t=i[e],n=i[e-1],s=e;for(;s>0;t=n,n=i[--s-1]){if(n.deleted===t.deleted&&n.constructor===t.constructor&&n.mergeWith(t)){t instanceof U&&t.parentSub!==null&&t.parent._map.get(t.parentSub)===t&&t.parent._map.set(t.parentSub,n);continue}break}const r=e-s;return r&&i.splice(e+1-r,r),r},Xs=(i,e,t)=>{for(const[n,s]of i.clients.entries()){const r=e.clients.get(n);for(let o=s.length-1;o>=0;o--){const c=s[o],l=c.clock+c.len;for(let h=Y(r,c.clock),u=r[h];h<r.length&&u.id.clock<l;u=r[++h]){const d=r[h];if(c.clock+c.len<=d.id.clock)break;d instanceof U&&d.deleted&&!d.keep&&t(d)&&d.gc(e,!1)}}}},Zs=(i,e)=>{i.clients.forEach((t,n)=>{const s=e.clients.get(n);for(let r=t.length-1;r>=0;r--){const o=t[r],c=Si(s.length-1,1+Y(s,o.clock+o.len-1));for(let l=c,h=s[l];l>0&&h.id.clock>=o.clock;h=s[l])l-=1+Je(s,l)}})},Fi=(i,e)=>{if(e<i.length){const t=i[e],n=t.doc,s=n.store,r=t.deleteSet,o=t._mergeStructs;try{Vi(r),t.afterState=Bt(t.doc.store),n.emit("beforeObserverCalls",[t,n]);const c=[];t.changed.forEach((l,h)=>c.push(()=>{(h._item===null||!h._item.deleted)&&h._callObserver(t,l)})),c.push(()=>{t.changedParentTypes.forEach((l,h)=>{h._dEH.l.length>0&&(h._item===null||!h._item.deleted)&&(l=l.filter(u=>u.target._item===null||!u.target._item.deleted),l.forEach(u=>{u.currentTarget=h,u._path=null}),l.sort((u,d)=>u.path.length-d.path.length),Bi(h._dEH,l,t))})}),c.push(()=>n.emit("afterTransaction",[t,n])),Ut(c,[]),t._needFormattingCleanup&&hr(t)}finally{n.gc&&Xs(r,s,n.gcFilter),Zs(r,s),t.afterState.forEach((u,d)=>{const g=t.beforeState.get(d)||0;if(g!==u){const w=s.clients.get(d),b=Ce(Y(w,g),1);for(let p=w.length-1;p>=b;)p-=1+Je(w,p)}});for(let u=o.length-1;u>=0;u--){const{client:d,clock:g}=o[u].id,w=s.clients.get(d),b=Y(w,g);b+1<w.length&&Je(w,b+1)>1||b>0&&Je(w,b)}if(!t.local&&t.afterState.get(n.clientID)!==t.beforeState.get(n.clientID)&&(Ls(jt,Oi,"[yjs] ",Ri,Ai,"Changed the client-id because another client seems to be using it."),n.clientID=ji()),n.emit("afterTransactionCleanup",[t,n]),n._observers.has("update")){const u=new $s;ci(u,t)&&n.emit("update",[u.toUint8Array(),t.origin,n,t])}if(n._observers.has("updateV2")){const u=new Fs;ci(u,t)&&n.emit("updateV2",[u.toUint8Array(),t.origin,n,t])}const{subdocsAdded:c,subdocsLoaded:l,subdocsRemoved:h}=t;(c.size>0||h.size>0||l.size>0)&&(c.forEach(u=>{u.clientID=n.clientID,u.collectionid==null&&(u.collectionid=n.collectionid),n.subdocs.add(u)}),h.forEach(u=>n.subdocs.delete(u)),n.emit("subdocs",[{loaded:l,added:c,removed:h},n,t]),h.forEach(u=>u.destroy())),i.length<=e+1?(n._transactionCleanups=[],n.emit("afterAllTransactions",[n,i])):Fi(i,e+1)}}},k=(i,e,t=null,n=!0)=>{const s=i._transactionCleanups;let r=!1,o=null;i._transaction===null&&(r=!0,i._transaction=new Ys(i,t,n),s.push(i._transaction),s.length===1&&i.emit("beforeAllTransactions",[i]),i.emit("beforeTransaction",[i._transaction,i]));try{o=e(i._transaction)}finally{if(r){const c=i._transaction===s[0];i._transaction=null,c&&Fi(s,0)}}return o},ai="You must not compute changes after the event-handler fired.";class nt{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=Qs(this.currentTarget,this.target))}deletes(e){return Ni(this.transaction.deleteSet,e.id)}get keys(){if(this._keys===null){if(this.transaction.doc._transactionCleanups.length===0)throw we(ai);const e=new Map,t=this.target;this.transaction.changed.get(t).forEach(s=>{if(s!==null){const r=t._map.get(s);let o,c;if(this.adds(r)){let l=r.left;for(;l!==null&&this.adds(l);)l=l.left;if(this.deletes(r))if(l!==null&&this.deletes(l))o="delete",c=ut(l.content.getContent());else return;else l!==null&&this.deletes(l)?(o="update",c=ut(l.content.getContent())):(o="add",c=void 0)}else if(this.deletes(r))o="delete",c=ut(r.content.getContent());else return;e.set(s,{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 we(ai);const t=this.target,n=_e(),s=_e(),r=[];if(e={added:n,deleted:s,delta:r,keys:this.keys},this.transaction.changed.get(t).has(null)){let c=null;const l=()=>{c&&r.push(c)};for(let h=t._start;h!==null;h=h.right)h.deleted?this.deletes(h)&&!this.adds(h)&&((c===null||c.delete===void 0)&&(l(),c={delete:0}),c.delete+=h.length,s.add(h)):this.adds(h)?((c===null||c.insert===void 0)&&(l(),c={insert:[]}),c.insert=c.insert.concat(h.content.getContent()),n.add(h)):((c===null||c.retain===void 0)&&(l(),c={retain:0}),c.retain+=h.length);c!==null&&c.retain===void 0&&l()}this._changes=e}return e}}const Qs=(i,e)=>{const t=[];for(;e._item!==null&&e!==i;){if(e._item.parentSub!==null)t.unshift(e._item.parentSub);else{let n=0,s=e._item.parent._start;for(;s!==e._item&&s!==null;)!s.deleted&&s.countable&&(n+=s.length),s=s.right;t.unshift(n)}e=e._item.parent}return t},j=()=>{Ms("Invalid access: Add Yjs type to a document before reading data.")},Wi=80;let $t=0;class er{constructor(e,t){e.marker=!0,this.p=e,this.index=t,this.timestamp=$t++}}const tr=i=>{i.timestamp=$t++},Pi=(i,e,t)=>{i.p.marker=!1,i.p=e,e.marker=!0,i.index=t,i.timestamp=$t++},ir=(i,e,t)=>{if(i.length>=Wi){const n=i.reduce((s,r)=>s.timestamp<r.timestamp?s:r);return Pi(n,e,t),n}else{const n=new er(e,t);return i.push(n),n}},st=(i,e)=>{if(i._start===null||e===0||i._searchMarker===null)return null;const t=i._searchMarker.length===0?null:i._searchMarker.reduce((r,o)=>We(e-r.index)<We(e-o.index)?r:o);let n=i._start,s=0;for(t!==null&&(n=t.p,s=t.index,tr(t));n.right!==null&&s<e;){if(!n.deleted&&n.countable){if(e<s+n.length)break;s+=n.length}n=n.right}for(;n.left!==null&&s>e;)n=n.left,!n.deleted&&n.countable&&(s-=n.length);for(;n.left!==null&&n.left.id.client===n.id.client&&n.left.id.clock+n.left.length===n.id.clock;)n=n.left,!n.deleted&&n.countable&&(s-=n.length);return t!==null&&We(t.index-s)<n.parent.length/Wi?(Pi(t,n,s),t):ir(i._searchMarker,n,s)},Ne=(i,e,t)=>{for(let n=i.length-1;n>=0;n--){const s=i[n];if(t>0){let r=s.p;for(r.marker=!1;r&&(r.deleted||!r.countable);)r=r.left,r&&!r.deleted&&r.countable&&(s.index-=r.length);if(r===null||r.marker===!0){i.splice(n,1);continue}s.p=r,r.marker=!0}(e<s.index||t>0&&e===s.index)&&(s.index=Ce(e,s.index+t))}},rt=(i,e,t)=>{const n=i,s=e.changedParentTypes;for(;Se(s,i,()=>[]).push(t),i._item!==null;)i=i._item.parent;Bi(n._eH,t,e)};class D{constructor(){this._item=null,this._map=new Map,this._start=null,this.doc=null,this._length=0,this._eH=ni(),this._dEH=ni(),this._searchMarker=null}get parent(){return this._item?this._item.parent:null}_integrate(e,t){this.doc=e,this._item=t}_copy(){throw G()}clone(){throw G()}_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){si(this._eH,e)}observeDeep(e){si(this._dEH,e)}unobserve(e){ri(this._eH,e)}unobserveDeep(e){ri(this._dEH,e)}toJSON(){}}const Ki=(i,e,t)=>{var o;(o=i.doc)!=null||j(),e<0&&(e=i._length+e),t<0&&(t=i._length+t);let n=t-e;const s=[];let r=i._start;for(;r!==null&&n>0;){if(r.countable&&!r.deleted){const c=r.content.getContent();if(c.length<=e)e-=c.length;else{for(let l=e;l<c.length&&n>0;l++)s.push(c[l]),n--;e=0}}r=r.right}return s},Ji=i=>{var n;(n=i.doc)!=null||j();const e=[];let t=i._start;for(;t!==null;){if(t.countable&&!t.deleted){const s=t.content.getContent();for(let r=0;r<s.length;r++)e.push(s[r])}t=t.right}return e},Ve=(i,e)=>{var s;let t=0,n=i._start;for((s=i.doc)!=null||j();n!==null;){if(n.countable&&!n.deleted){const r=n.content.getContent();for(let o=0;o<r.length;o++)e(r[o],t++,i)}n=n.right}},Gi=(i,e)=>{const t=[];return Ve(i,(n,s)=>{t.push(e(n,s,i))}),t},nr=i=>{let e=i._start,t=null,n=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(),n=0,e=e.right}const s=t[n++];return t.length<=n&&(t=null),{done:!1,value:s}}}},qi=(i,e)=>{var s;(s=i.doc)!=null||j();const t=st(i,e);let n=i._start;for(t!==null&&(n=t.p,e-=t.index);n!==null;n=n.right)if(!n.deleted&&n.countable){if(e<n.length)return n.content.getContent()[e];e-=n.length}},Ye=(i,e,t,n)=>{let s=t;const r=i.doc,o=r.clientID,c=r.store,l=t===null?e._start:t.right;let h=[];const u=()=>{h.length>0&&(s=new U(v(o,B(c,o)),s,s&&s.lastId,l,l&&l.id,e,null,new ye(h)),s.integrate(i,0),h=[])};n.forEach(d=>{if(d===null)h.push(d);else switch(d.constructor){case Number:case Object:case Boolean:case Array:case String:h.push(d);break;default:switch(u(),d.constructor){case Uint8Array:case ArrayBuffer:s=new U(v(o,B(c,o)),s,s&&s.lastId,l,l&&l.id,e,null,new ot(new Uint8Array(d))),s.integrate(i,0);break;case Ee:s=new U(v(o,B(c,o)),s,s&&s.lastId,l,l&&l.id,e,null,new ct(d)),s.integrate(i,0);break;default:if(d instanceof D)s=new U(v(o,B(c,o)),s,s&&s.lastId,l,l&&l.id,e,null,new oe(d)),s.integrate(i,0);else throw new Error("Unexpected content type in insert operation")}}}),u()},Hi=()=>we("Length exceeded!"),zi=(i,e,t,n)=>{if(t>e._length)throw Hi();if(t===0)return e._searchMarker&&Ne(e._searchMarker,t,n.length),Ye(i,e,null,n);const s=t,r=st(e,t);let o=e._start;for(r!==null&&(o=r.p,t-=r.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&&re(i,v(o.id.client,o.id.clock+t));break}t-=o.length}return e._searchMarker&&Ne(e._searchMarker,s,n.length),Ye(i,e,o,n)},sr=(i,e,t)=>{let s=(e._searchMarker||[]).reduce((r,o)=>o.index>r.index?o:r,{index:0,p:e._start}).p;if(s)for(;s.right;)s=s.right;return Ye(i,e,s,t)},Yi=(i,e,t,n)=>{if(n===0)return;const s=t,r=n,o=st(e,t);let 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&&re(i,v(c.id.client,c.id.clock+t)),t-=c.length);for(;n>0&&c!==null;)c.deleted||(n<c.length&&re(i,v(c.id.client,c.id.clock+n)),c.delete(i),n-=c.length),c=c.right;if(n>0)throw Hi();e._searchMarker&&Ne(e._searchMarker,s,-r+n)},Xe=(i,e,t)=>{const n=e._map.get(t);n!==void 0&&n.delete(i)},xt=(i,e,t,n)=>{const s=e._map.get(t)||null,r=i.doc,o=r.clientID;let c;if(n==null)c=new ye([n]);else switch(n.constructor){case Number:case Object:case Boolean:case Array:case String:c=new ye([n]);break;case Uint8Array:c=new ot(n);break;case Ee:c=new ct(n);break;default:if(n instanceof D)c=new oe(n);else throw new Error("Unexpected content type")}new U(v(o,B(r.store,o)),s,s&&s.lastId,null,null,e,t,c).integrate(i,0)},Ft=(i,e)=>{var n;(n=i.doc)!=null||j();const t=i._map.get(e);return t!==void 0&&!t.deleted?t.content.getContent()[t.length-1]:void 0},Xi=i=>{var t;const e={};return(t=i.doc)!=null||j(),i._map.forEach((n,s)=>{n.deleted||(e[s]=n.content.getContent()[n.length-1])}),e},Zi=(i,e)=>{var n;(n=i.doc)!=null||j();const t=i._map.get(e);return t!==void 0&&!t.deleted},rr=(i,e)=>{const t={};return i._map.forEach((n,s)=>{let r=n;for(;r!==null&&(!e.sv.has(r.id.client)||r.id.clock>=(e.sv.get(r.id.client)||0));)r=r.left;r!==null&&ue(r,e)&&(t[s]=r.content.getContent()[r.length-1])}),t},xe=i=>{var e;return(e=i.doc)!=null||j(),Ds(i._map.entries(),t=>!t[1].deleted)};class or extends nt{}class Ae extends D{constructor(){super(),this._prelimContent=[],this._searchMarker=[]}static from(e){const t=new Ae;return t.push(e),t}_integrate(e,t){super._integrate(e,t),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new Ae}clone(){const e=new Ae;return e.insert(0,this.toArray().map(t=>t instanceof D?t.clone():t)),e}get length(){var e;return(e=this.doc)!=null||j(),this._length}_callObserver(e,t){super._callObserver(e,t),rt(this,e,new or(this,e))}insert(e,t){this.doc!==null?k(this.doc,n=>{zi(n,this,e,t)}):this._prelimContent.splice(e,0,...t)}push(e){this.doc!==null?k(this.doc,t=>{sr(t,this,e)}):this._prelimContent.push(...e)}unshift(e){this.insert(0,e)}delete(e,t=1){this.doc!==null?k(this.doc,n=>{Yi(n,this,e,t)}):this._prelimContent.splice(e,t)}get(e){return qi(this,e)}toArray(){return Ji(this)}slice(e=0,t=this.length){return Ki(this,e,t)}toJSON(){return this.map(e=>e instanceof D?e.toJSON():e)}map(e){return Gi(this,e)}forEach(e){Ve(this,e)}[Symbol.iterator](){return nr(this)}_write(e){e.writeTypeRef(_r)}}class cr extends nt{constructor(e,t,n){super(e,t),this.keysChanged=n}}class Ze extends D{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((n,s)=>{this.set(s,n)}),this._prelimContent=null}_copy(){return new Ze}clone(){const e=new Ze;return this.forEach((t,n)=>{e.set(n,t instanceof D?t.clone():t)}),e}_callObserver(e,t){rt(this,e,new cr(this,e,t))}toJSON(){var t;(t=this.doc)!=null||j();const e={};return this._map.forEach((n,s)=>{if(!n.deleted){const r=n.content.getContent()[n.length-1];e[s]=r instanceof D?r.toJSON():r}}),e}get size(){return[...xe(this)].length}keys(){return _t(xe(this),e=>e[0])}values(){return _t(xe(this),e=>e[1].content.getContent()[e[1].length-1])}entries(){return _t(xe(this),e=>[e[0],e[1].content.getContent()[e[1].length-1]])}forEach(e){var t;(t=this.doc)!=null||j(),this._map.forEach((n,s)=>{n.deleted||e(n.content.getContent()[n.length-1],s,this)})}[Symbol.iterator](){return this.entries()}delete(e){this.doc!==null?k(this.doc,t=>{Xe(t,this,e)}):this._prelimContent.delete(e)}set(e,t){return this.doc!==null?k(this.doc,n=>{xt(n,this,e,t)}):this._prelimContent.set(e,t),t}get(e){return Ft(this,e)}has(e){return Zi(this,e)}clear(){this.doc!==null?k(this.doc,e=>{this.forEach(function(t,n,s){Xe(e,s,n)})}):this._prelimContent.clear()}_write(e){e.writeTypeRef(mr)}}const ne=(i,e)=>i===e||typeof i=="object"&&typeof e=="object"&&i&&e&&ps(i,e);class At{constructor(e,t,n,s){this.left=e,this.right=t,this.index=n,this.currentAttributes=s}forward(){switch(this.right===null&&he(),this.right.content.constructor){case L:this.right.deleted||ke(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}}const hi=(i,e,t)=>{for(;e.right!==null&&t>0;){switch(e.right.content.constructor){case L:e.right.deleted||ke(e.currentAttributes,e.right.content);break;default:e.right.deleted||(t<e.right.length&&re(i,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},Fe=(i,e,t,n)=>{const s=new Map,r=n?st(e,t):null;if(r){const o=new At(r.p.left,r.p,r.index,s);return hi(i,o,t-r.index)}else{const o=new At(null,e._start,0,s);return hi(i,o,t)}},Qi=(i,e,t,n)=>{for(;t.right!==null&&(t.right.deleted===!0||t.right.content.constructor===L&&ne(n.get(t.right.content.key),t.right.content.value));)t.right.deleted||n.delete(t.right.content.key),t.forward();const s=i.doc,r=s.clientID;n.forEach((o,c)=>{const l=t.left,h=t.right,u=new U(v(r,B(s.store,r)),l,l&&l.lastId,h,h&&h.id,e,null,new L(c,o));u.integrate(i,0),t.right=u,t.forward()})},ke=(i,e)=>{const{key:t,value:n}=e;n===null?i.delete(t):i.set(t,n)},en=(i,e)=>{var t;for(;i.right!==null;){if(!(i.right.deleted||i.right.content.constructor===L&&ne((t=e[i.right.content.key])!=null?t:null,i.right.content.value)))break;i.forward()}},tn=(i,e,t,n)=>{var c;const s=i.doc,r=s.clientID,o=new Map;for(const l in n){const h=n[l],u=(c=t.currentAttributes.get(l))!=null?c:null;if(!ne(u,h)){o.set(l,u);const{left:d,right:g}=t;t.right=new U(v(r,B(s.store,r)),d,d&&d.lastId,g,g&&g.id,e,null,new L(l,h)),t.right.integrate(i,0),t.forward()}}return o},wt=(i,e,t,n,s)=>{t.currentAttributes.forEach((g,w)=>{s[w]===void 0&&(s[w]=null)});const r=i.doc,o=r.clientID;en(t,s);const c=tn(i,e,t,s),l=n.constructor===String?new X(n):n instanceof D?new oe(n):new ve(n);let{left:h,right:u,index:d}=t;e._searchMarker&&Ne(e._searchMarker,t.index,l.getLength()),u=new U(v(o,B(r.store,o)),h,h&&h.lastId,u,u&&u.id,e,null,l),u.integrate(i,0),t.right=u,t.index=d,t.forward(),Qi(i,e,t,c)},ui=(i,e,t,n,s)=>{const r=i.doc,o=r.clientID;en(t,s);const c=tn(i,e,t,s);e:for(;t.right!==null&&(n>0||c.size>0&&(t.right.deleted||t.right.content.constructor===L));){if(!t.right.deleted)switch(t.right.content.constructor){case L:{const{key:l,value:h}=t.right.content,u=s[l];if(u!==void 0){if(ne(u,h))c.delete(l);else{if(n===0)break e;c.set(l,h)}t.right.delete(i)}else t.currentAttributes.set(l,h);break}default:n<t.right.length&&re(i,v(t.right.id.client,t.right.id.clock+n)),n-=t.right.length;break}t.forward()}if(n>0){let l="";for(;n>0;n--)l+=`
2
2
  `;t.right=new U(v(o,B(r.store,o)),t.left,t.left&&t.left.lastId,t.right,t.right&&t.right.id,e,null,new X(l)),t.right.integrate(i,0),t.forward()}Qi(i,e,t,c)},nn=(i,e,t,n,s)=>{var h,u;let r=e;const o=J();for(;r&&(!r.countable||r.deleted);){if(!r.deleted&&r.content.constructor===L){const d=r.content;o.set(d.key,d)}r=r.right}let c=0,l=!1;for(;e!==r;){if(t===e&&(l=!0),!e.deleted){const d=e.content;switch(d.constructor){case L:{const{key:g,value:w}=d,b=(h=n.get(g))!=null?h:null;(o.get(g)!==d||b===w)&&(e.delete(i),c++,!l&&((u=s.get(g))!=null?u:null)===w&&b!==w&&(b===null?s.delete(g):s.set(g,b))),!l&&!e.deleted&&ke(s,d);break}}}e=e.right}return c},lr=(i,e)=>{for(;e&&e.right&&(e.right.deleted||!e.right.countable);)e=e.right;const t=new Set;for(;e&&(e.deleted||!e.countable);){if(!e.deleted&&e.content.constructor===L){const n=e.content.key;t.has(n)?e.delete(i):t.add(n)}e=e.left}},ar=i=>{let e=0;return k(i.doc,t=>{let n=i._start,s=i._start,r=J();const o=Et(r);for(;s;){if(s.deleted===!1)switch(s.content.constructor){case L:ke(o,s.content);break;default:e+=nn(t,n,s,r,o),r=Et(o),n=s;break}s=s.right}}),e},hr=i=>{const e=new Set,t=i.doc;for(const[n,s]of i.afterState.entries()){const r=i.beforeState.get(n)||0;s!==r&&xi(i,t.store.clients.get(n),r,s,o=>{!o.deleted&&o.content.constructor===L&&o.constructor!==ie&&e.add(o.parent)})}k(t,n=>{Di(i,i.deleteSet,s=>{if(s instanceof ie||!s.parent._hasFormatting||e.has(s.parent))return;const r=s.parent;s.content.constructor===L?e.add(r):lr(n,s)});for(const s of e)ar(s)})},di=(i,e,t)=>{const n=t,s=Et(e.currentAttributes),r=e.right;for(;t>0&&e.right!==null;){if(e.right.deleted===!1)switch(e.right.content.constructor){case oe:case ve:case X:t<e.right.length&&re(i,v(e.right.id.client,e.right.id.clock+t)),t-=e.right.length,e.right.delete(i);break}e.forward()}r&&nn(i,r,e.right,s,e.currentAttributes);const o=(e.left||e.right).parent;return o._searchMarker&&Ne(o._searchMarker,e.index,-n+t),e};class ur extends nt{constructor(e,t,n){super(e,t),this.childListChanged=!1,this.keysChanged=new Set,n.forEach(s=>{s===null?this.childListChanged=!0:this.keysChanged.add(s)})}get changes(){if(this._changes===null){const 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){const e=this.target.doc,t=[];k(e,n=>{var w,b,p;const s=new Map,r=new Map;let o=this.target._start,c=null;const l={};let h="",u=0,d=0;const g=()=>{if(c!==null){let _=null;switch(c){case"delete":d>0&&(_={delete:d}),d=0;break;case"insert":(typeof h=="object"||h.length>0)&&(_={insert:h},s.size>0&&(_.attributes={},s.forEach((I,N)=>{I!==null&&(_.attributes[N]=I)}))),h="";break;case"retain":u>0&&(_={retain:u},ds(l)||(_.attributes=as({},l))),u=0;break}_&&t.push(_),c=null}};for(;o!==null;){switch(o.content.constructor){case oe:case ve:this.adds(o)?this.deletes(o)||(g(),c="insert",h=o.content.getContent()[0],g()):this.deletes(o)?(c!=="delete"&&(g(),c="delete"),d+=1):o.deleted||(c!=="retain"&&(g(),c="retain"),u+=1);break;case X:this.adds(o)?this.deletes(o)||(c!=="insert"&&(g(),c="insert"),h+=o.content.str):this.deletes(o)?(c!=="delete"&&(g(),c="delete"),d+=o.length):o.deleted||(c!=="retain"&&(g(),c="retain"),u+=o.length);break;case L:{const{key:_,value:I}=o.content;if(this.adds(o)){if(!this.deletes(o)){const N=(w=s.get(_))!=null?w:null;ne(N,I)?I!==null&&o.delete(n):(c==="retain"&&g(),ne(I,(b=r.get(_))!=null?b:null)?delete l[_]:l[_]=I)}}else if(this.deletes(o)){r.set(_,I);const N=(p=s.get(_))!=null?p:null;ne(N,I)||(c==="retain"&&g(),l[_]=N)}else if(!o.deleted){r.set(_,I);const N=l[_];N!==void 0&&(ne(N,I)?N!==null&&o.delete(n):(c==="retain"&&g(),I===null?delete l[_]:l[_]=I))}o.deleted||(c==="insert"&&g(),ke(s,o.content));break}}o=o.right}for(g();t.length>0;){const _=t[t.length-1];if(_.retain!==void 0&&_.attributes===void 0)t.pop();else break}}),this._delta=t}return this._delta}}class Qe extends D{constructor(e){super(),this._pending=e!==void 0?[()=>this.insert(0,e)]:[],this._searchMarker=[],this._hasFormatting=!1}get length(){var e;return(e=this.doc)!=null||j(),this._length}_integrate(e,t){super._integrate(e,t);try{this._pending.forEach(n=>n())}catch(n){console.error(n)}this._pending=null}_copy(){return new Qe}clone(){const e=new Qe;return e.applyDelta(this.toDelta()),e}_callObserver(e,t){super._callObserver(e,t);const n=new ur(this,e,t);rt(this,e,n),!e.local&&this._hasFormatting&&(e._needFormattingCleanup=!0)}toString(){var n;(n=this.doc)!=null||j();let e="",t=this._start;for(;t!==null;)!t.deleted&&t.countable&&t.content.constructor===X&&(e+=t.content.str),t=t.right;return e}toJSON(){return this.toString()}applyDelta(e,{sanitize:t=!0}={}){this.doc!==null?k(this.doc,n=>{const s=new At(null,this._start,0,new Map);for(let r=0;r<e.length;r++){const o=e[r];if(o.insert!==void 0){const c=!t&&typeof o.insert=="string"&&r===e.length-1&&s.right===null&&o.insert.slice(-1)===`
3
- `?o.insert.slice(0,-1):o.insert;(typeof c!="string"||c.length>0)&&wt(n,this,s,c,o.attributes||{})}else o.retain!==void 0?ui(n,this,s,o.retain,o.attributes||{}):o.delete!==void 0&&di(n,s,o.delete)}}):this._pending.push(()=>this.applyDelta(e))}toDelta(e,t,n){var d;(d=this.doc)!=null||j();const s=[],r=new Map,o=this.doc;let c="",l=this._start;function h(){if(c.length>0){const g={};let w=!1;r.forEach((p,_)=>{w=!0,g[_]=p});const b={insert:c};w&&(b.attributes=g),s.push(b),c=""}}const u=()=>{for(;l!==null;){if(ue(l,e)||t!==void 0&&ue(l,t))switch(l.content.constructor){case X:{const g=r.get("ychange");e!==void 0&&!ue(l,e)?(g===void 0||g.user!==l.id.client||g.type!=="removed")&&(h(),r.set("ychange",n?n("removed",l.id):{type:"removed"})):t!==void 0&&!ue(l,t)?(g===void 0||g.user!==l.id.client||g.type!=="added")&&(h(),r.set("ychange",n?n("added",l.id):{type:"added"})):g!==void 0&&(h(),r.delete("ychange")),c+=l.content.str;break}case oe:case ve:{h();const g={insert:l.content.getContent()[0]};if(r.size>0){const w={};g.attributes=w,r.forEach((b,p)=>{w[p]=b})}s.push(g);break}case L:ue(l,e)&&(h(),ke(r,l.content));break}l=l.right}h()};return e||t?k(o,g=>{e&&Ot(g,e),t&&Ot(g,t),u()},"cleanup"):u(),s}insert(e,t,n){if(t.length<=0)return;const s=this.doc;s!==null?k(s,r=>{const o=Fe(r,this,e,!n);n||(n={},o.currentAttributes.forEach((c,l)=>{n[l]=c})),wt(r,this,o,t,n)}):this._pending.push(()=>this.insert(e,t,n))}insertEmbed(e,t,n){const s=this.doc;s!==null?k(s,r=>{const o=Fe(r,this,e,!n);wt(r,this,o,t,n||{})}):this._pending.push(()=>this.insertEmbed(e,t,n||{}))}delete(e,t){if(t===0)return;const n=this.doc;n!==null?k(n,s=>{di(s,Fe(s,this,e,!0),t)}):this._pending.push(()=>this.delete(e,t))}format(e,t,n){if(t===0)return;const s=this.doc;s!==null?k(s,r=>{const o=Fe(r,this,e,!1);o.right!==null&&ui(r,this,o,t,n)}):this._pending.push(()=>this.format(e,t,n))}removeAttribute(e){this.doc!==null?k(this.doc,t=>{Xe(t,this,e)}):this._pending.push(()=>this.removeAttribute(e))}setAttribute(e,t){this.doc!==null?k(this.doc,n=>{xt(n,this,e,t)}):this._pending.push(()=>this.setAttribute(e,t))}getAttribute(e){return Ft(this,e)}getAttributes(){return Xi(this)}_write(e){e.writeTypeRef(wr)}}class bt{constructor(e,t=()=>!0){var n;this._filter=t,this._root=e,this._currentNode=e._start,this._firstCall=!0,(n=e.doc)!=null||j()}[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===Ue||t.constructor===be)&&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})}}class be extends D{constructor(){super(),this._prelimContent=[]}get firstChild(){const 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 be}clone(){const e=new be;return e.insert(0,this.toArray().map(t=>t instanceof D?t.clone():t)),e}get length(){var e;return(e=this.doc)!=null||j(),this._prelimContent===null?this._length:this._prelimContent.length}createTreeWalker(e){return new bt(this,e)}querySelector(e){e=e.toUpperCase();const n=new bt(this,s=>s.nodeName&&s.nodeName.toUpperCase()===e).next();return n.done?null:n.value}querySelectorAll(e){return e=e.toUpperCase(),me(new bt(this,t=>t.nodeName&&t.nodeName.toUpperCase()===e))}_callObserver(e,t){rt(this,e,new dr(this,t,e))}toString(){return Gi(this,e=>e.toString()).join("")}toJSON(){return this.toString()}toDOM(e=document,t={},n){const s=e.createDocumentFragment();return n!==void 0&&n._createAssociation(s,this),Ve(this,r=>{s.insertBefore(r.toDOM(e,t,n),null)}),s}insert(e,t){this.doc!==null?k(this.doc,n=>{zi(n,this,e,t)}):this._prelimContent.splice(e,0,...t)}insertAfter(e,t){if(this.doc!==null)k(this.doc,n=>{const s=e&&e instanceof D?e._item:e;Ye(n,this,s,t)});else{const n=this._prelimContent,s=e===null?0:n.findIndex(r=>r===e)+1;if(s===0&&e!==null)throw we("Reference item not found");n.splice(s,0,...t)}}delete(e,t=1){this.doc!==null?k(this.doc,n=>{Yi(n,this,e,t)}):this._prelimContent.splice(e,t)}toArray(){return Ji(this)}push(e){this.insert(this.length,e)}unshift(e){this.insert(0,e)}get(e){return qi(this,e)}slice(e=0,t=this.length){return Ki(this,e,t)}forEach(e){Ve(this,e)}_write(e){e.writeTypeRef(yr)}}class Ue extends be{constructor(e="UNDEFINED"){super(),this.nodeName=e,this._prelimAttrs=new Map}get nextSibling(){const e=this._item?this._item.next:null;return e?e.content.type:null}get prevSibling(){const e=this._item?this._item.prev:null;return e?e.content.type:null}_integrate(e,t){super._integrate(e,t),this._prelimAttrs.forEach((n,s)=>{this.setAttribute(s,n)}),this._prelimAttrs=null}_copy(){return new Ue(this.nodeName)}clone(){const e=new Ue(this.nodeName),t=this.getAttributes();return us(t,(n,s)=>{typeof n=="string"&&e.setAttribute(s,n)}),e.insert(0,this.toArray().map(n=>n instanceof D?n.clone():n)),e}toString(){const e=this.getAttributes(),t=[],n=[];for(const c in e)n.push(c);n.sort();const s=n.length;for(let c=0;c<s;c++){const l=n[c];t.push(l+'="'+e[l]+'"')}const r=this.nodeName.toLocaleLowerCase(),o=t.length>0?" "+t.join(" "):"";return`<${r}${o}>${super.toString()}</${r}>`}removeAttribute(e){this.doc!==null?k(this.doc,t=>{Xe(t,this,e)}):this._prelimAttrs.delete(e)}setAttribute(e,t){this.doc!==null?k(this.doc,n=>{xt(n,this,e,t)}):this._prelimAttrs.set(e,t)}getAttribute(e){return Ft(this,e)}hasAttribute(e){return Zi(this,e)}getAttributes(e){return e?rr(this,e):Xi(this)}toDOM(e=document,t={},n){const s=e.createElement(this.nodeName),r=this.getAttributes();for(const o in r){const c=r[o];typeof c=="string"&&s.setAttribute(o,c)}return Ve(this,o=>{s.appendChild(o.toDOM(e,t,n))}),n!==void 0&&n._createAssociation(s,this),s}_write(e){e.writeTypeRef(br),e.writeKey(this.nodeName)}}class dr extends nt{constructor(e,t,n){super(e,n),this.childListChanged=!1,this.attributesChanged=new Set,t.forEach(s=>{s===null?this.childListChanged=!0:this.attributesChanged.add(s)})}}class sn{constructor(e,t){this.id=e,this.length=t}get deleted(){throw G()}mergeWith(e){return!1}write(e,t,n){throw G()}integrate(e,t){throw G()}}const fr=0;class ie extends sn{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),$i(e.doc.store,this)}write(e,t){e.writeInfo(fr),e.writeLen(this.length-t)}getMissing(e,t){return null}}class ot{constructor(e){this.content=e}getLength(){return 1}getContent(){return[this.content]}isCountable(){return!0}copy(){return new ot(this.content)}splice(e){throw G()}mergeWith(e){return!1}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeBuf(this.content)}getRef(){return 3}}class et{constructor(e){this.len=e}getLength(){return this.len}getContent(){return[]}isCountable(){return!1}copy(){return new et(this.len)}splice(e){const t=new et(this.len-e);return this.len=e,t}mergeWith(e){return this.len+=e.len,!0}integrate(e,t){Ui(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}}const gr=(i,e)=>new Ee({guid:i,...e,shouldLoad:e.shouldLoad||e.autoLoad||!1});class ct{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;const 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 ct(gr(this.doc.guid,this.opts))}splice(e){throw G()}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}}class ve{constructor(e){this.embed=e}getLength(){return 1}getContent(){return[this.embed]}isCountable(){return!0}copy(){return new ve(this.embed)}splice(e){throw G()}mergeWith(e){return!1}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeJSON(this.embed)}getRef(){return 5}}class L{constructor(e,t){this.key=e,this.value=t}getLength(){return 1}getContent(){return[]}isCountable(){return!1}copy(){return new L(this.key,this.value)}splice(e){throw G()}mergeWith(e){return!1}integrate(e,t){const n=t.parent;n._searchMarker=null,n._hasFormatting=!0}delete(e){}gc(e){}write(e,t){e.writeKey(this.key),e.writeJSON(this.value)}getRef(){return 6}}const pr=ze("node_env")==="development";class ye{constructor(e){this.arr=e,pr&&vi(e)}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new ye(this.arr)}splice(e){const t=new ye(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){const n=this.arr.length;e.writeLen(n-t);for(let s=t;s<n;s++){const r=this.arr[s];e.writeAny(r)}}getRef(){return 8}}class X{constructor(e){this.str=e}getLength(){return this.str.length}getContent(){return this.str.split("")}isCountable(){return!0}copy(){return new X(this.str)}splice(e){const t=new X(this.str.slice(e));this.str=this.str.slice(0,e);const n=this.str.charCodeAt(e-1);return n>=55296&&n<=56319&&(this.str=this.str.slice(0,e-1)+"�",t.str="�"+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}}const _r=0,mr=1,wr=2,br=3,yr=4;class oe{constructor(e){this.type=e}getLength(){return 1}getContent(){return[this.type]}isCountable(){return!0}copy(){return new oe(this.type._copy())}splice(e){throw G()}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(n=>{n.deleted?n.id.clock<(e.beforeState.get(n.id.client)||0)&&e._mergeStructs.push(n):n.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(n=>{for(;n!==null;)n.gc(e,!0),n=n.left}),this.type._map=new Map}write(e,t){this.type._write(e)}getRef(){return 7}}const rn=(i,e,t)=>{const{client:n,clock:s}=e.id,r=new U(v(n,s+t),e,v(n,s+t-1),e.right,e.rightOrigin,e.parent,e.parentSub,e.content.splice(t));return e.deleted&&r.markDeleted(),e.keep&&(r.keep=!0),e.redone!==null&&(r.redone=v(e.redone.client,e.redone.clock+t)),e.right=r,r.right!==null&&(r.right.left=r),i._mergeStructs.push(r),r.parentSub!==null&&r.right===null&&r.parent._map.set(r.parentSub,r),e.length=t,r};class U extends sn{constructor(e,t,n,s,r,o,c,l){super(e,l.getLength()),this.origin=n,this.left=t,this.right=s,this.rightOrigin=r,this.parent=o,this.parentSub=c,this.redone=null,this.content=l,this.info=this.content.isCountable()?qt:0}set marker(e){(this.info&ft)>0!==e&&(this.info^=ft)}get marker(){return(this.info&ft)>0}get keep(){return(this.info&Gt)>0}set keep(e){this.keep!==e&&(this.info^=Gt)}get countable(){return(this.info&qt)>0}get deleted(){return(this.info&dt)>0}set deleted(e){this.deleted!==e&&(this.info^=dt)}markDeleted(){this.info|=dt}getMissing(e,t){if(this.origin&&this.origin.client!==this.id.client&&this.origin.clock>=B(t,this.origin.client))return this.origin.client;if(this.rightOrigin&&this.rightOrigin.client!==this.id.client&&this.rightOrigin.clock>=B(t,this.rightOrigin.client))return this.rightOrigin.client;if(this.parent&&this.parent.constructor===Ke&&this.id.client!==this.parent.client&&this.parent.clock>=B(t,this.parent.client))return this.parent.client;if(this.origin&&(this.left=oi(e,t,this.origin),this.origin=this.left.lastId),this.rightOrigin&&(this.right=re(e,this.rightOrigin),this.rightOrigin=this.right.id),this.left&&this.left.constructor===ie||this.right&&this.right.constructor===ie)this.parent=null;else if(!this.parent)this.left&&this.left.constructor===U&&(this.parent=this.left.parent,this.parentSub=this.left.parentSub),this.right&&this.right.constructor===U&&(this.parent=this.right.parent,this.parentSub=this.right.parentSub);else if(this.parent.constructor===Ke){const n=mt(t,this.parent);n.constructor===ie?this.parent=null:this.parent=n.content.type}return null}integrate(e,t){if(t>0&&(this.id.clock+=t,this.left=oi(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 n=this.left,s;if(n!==null)s=n.right;else if(this.parentSub!==null)for(s=this.parent._map.get(this.parentSub)||null;s!==null&&s.left!==null;)s=s.left;else s=this.parent._start;const r=new Set,o=new Set;for(;s!==null&&s!==this.right;){if(o.add(s),r.add(s),$e(this.origin,s.origin)){if(s.id.client<this.id.client)n=s,r.clear();else if($e(this.rightOrigin,s.rightOrigin))break}else if(s.origin!==null&&o.has(mt(e.doc.store,s.origin)))r.has(mt(e.doc.store,s.origin))||(n=s,r.clear());else break;s=s.right}this.left=n}if(this.left!==null){const n=this.left.right;this.right=n,this.left.right=this}else{let n;if(this.parentSub!==null)for(n=this.parent._map.get(this.parentSub)||null;n!==null&&n.left!==null;)n=n.left;else n=this.parent._start,this.parent._start=this;this.right=n}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),$i(e.doc.store,this),this.content.integrate(e,this),li(e,this.parent,this.parentSub),(this.parent._item!==null&&this.parent._item.deleted||this.parentSub!==null&&this.right!==null)&&this.delete(e)}else new ie(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&&$e(e.origin,this.lastId)&&this.right===e&&$e(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)){const t=this.parent._searchMarker;return t&&t.forEach(n=>{n.p===e&&(n.p=this,!this.deleted&&this.countable&&(n.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){const t=this.parent;this.countable&&this.parentSub===null&&(t._length-=this.length),this.markDeleted(),Ui(e.deleteSet,this.id.client,this.id.clock,this.length),li(e,t,this.parentSub),this.content.delete(e)}}gc(e,t){if(!this.deleted)throw he();this.content.gc(e),t?zs(e,this,new ie(this.id,this.length)):this.content=new et(this.length)}write(e,t){const n=t>0?v(this.id.client,this.id.clock+t-1):this.origin,s=this.rightOrigin,r=this.parentSub,o=this.content.getRef()&jn|(n===null?0:He)|(s===null?0:Ci)|(r===null?0:Un);if(e.writeInfo(o),n!==null&&e.writeLeftID(n),s!==null&&e.writeRightID(s),n===null&&s===null){const c=this.parent;if(c._item!==void 0){const l=c._item;if(l===null){const h=Gs(c);e.writeParentInfo(!0),e.writeString(h)}else e.writeParentInfo(!1),e.writeLeftID(l.id)}else c.constructor===String?(e.writeParentInfo(!0),e.writeString(c)):c.constructor===Ke?(e.writeParentInfo(!1),e.writeLeftID(c)):he();r!==null&&e.writeString(r)}this.content.write(e,t)}}const on=typeof globalThis!="undefined"?globalThis:typeof window!="undefined"?window:typeof global!="undefined"?global:{},cn="__ $YJS$ __";on[cn]===!0&&console.error("Yjs was already imported. This breaks constructor checks and will lead to issues! - https://github.com/yjs/yjs/issues/438");on[cn]=!0;const Oe=i=>Promise.reject(new Error("unimplemented method GetVoiceSign")),yt=(i,e={},t=[])=>({command:i,front_request_id:Te(),data:{...e,to_user_ids:Array.isArray(t)?t:[t]}}),ln=()=>{var i,e;window!=null&&window.__Realsee_Live__&&((e=(i=window==null?void 0:window.__Realsee_Live__)==null?void 0:i.dispose)==null||e.call(i),window.__Realsee_Live__=null)};class an extends ge{constructor(t){super();a(this,"_options",{});a(this,"keyframes",new ge);a(this,"_yDoc");a(this,"_buildInData");a(this,"_initializeKeyframesObservers",()=>{this._yDoc.getMap("keyframes").observe(this._handleKeyframesChange)});a(this,"_handleKeyframesChange",t=>{var o;const{transaction:n,target:s,changes:r}=t;if(s===this._buildInData.keyframes)if(n.origin.triggerUserId===((o=this.selfInfo)==null?void 0:o.id)){const c=yt($.KeyframeSync,this.snapshot,void 0);try{this._controller.sendMessage(c)}catch(l){m.error("Failed to send keyframe sync message:",l)}}else r.keys.forEach((c,l)=>{const h=c.oldValue,u=this.getFramesByKey(l),d=n.origin.frontRequestId;this.keyframes.emit(l,u,h,d)}),r.keys.size!==0&&this.emit("keyframes",this.snapshot,n.origin.frontRequestId)});a(this,"getFramesByKey",t=>this.snapshot[t]);a(this,"sendKeyframe",(t,n)=>{var s;return this.state!==V.OPEN?(m.warn("Attempted to send keyframe while connection is not open"),!1):(this._yDoc.transact(()=>{this._buildInData.keyframes.set(t,n)},{triggerUserId:(s=this.selfInfo)==null?void 0:s.id,frontRequestId:""}),!0)});a(this,"_controller",new Tn);a(this,"_initializeOptions",t=>{var n;this._options=Object.assign({initialMicroStatus:te.OPEN},t),this._options.jsBridge=this._initializeJsBridge(t),this._options.getVoiceSign=(n=t.getVoiceSign)!=null?n:Oe,this._options.autoPlayConfirm=t.autoPlayConfirm,this._options.rtc=this._initializeRTC(t)});a(this,"_initializeJsBridge",t=>{if(t.jsBridge)return t.jsBridge;if(t.useBuiltInJsBridge)return new mn});a(this,"_initializeRTC",t=>{if(t.rtc)return t.rtc;if(t.rtcType)return this._createBuiltInRTC(t);if(t.useBuiltInRTC)return this._createDefaultRTC(t)});a(this,"_createBuiltInRTC",t=>{var n;if(!t.getVoiceSign){m.error("GetVoiceSign method must be passed when using built-in RTC instances");return}switch(t.rtcType){case se.RealseeVRWebViewRTC:return this._createVRWebViewRTC();case se.RealseeBrowserChimeRTC:return new Ct({getVoiceSign:(n=this._options.getVoiceSign)!=null?n:Oe,logLevel:t.__debug__?0:1});case se.RealseeBrowserRTC:return this._createBrowserRTC();default:m.error("unknown built-in RTC type");return}});a(this,"_createVRWebViewRTC",()=>{var t;if(this._options.jsBridge)return new gi({jsBridge:this._options.jsBridge,getVoiceSign:(t=this._options.getVoiceSign)!=null?t:Oe});m.error("JsBridge instance must be passed when using built-in VRWebViewRTC instances")});a(this,"_createBrowserRTC",()=>{var t;if(!this._options.autoPlayConfirm){m.error("autoPlayConfirm method must be passed when using built-in RealseeBrowserRTC instances");return}return new fi({getVoiceSign:(t=this._options.getVoiceSign)!=null?t:Oe,autoPlayConfirm:this._options.autoPlayConfirm})});a(this,"_createDefaultRTC",t=>{var s;const n=(s=this._options.getVoiceSign)!=null?s:Oe;return!this._options.jsBridge||!Jt&&!Kt?t.builtInRTCType===Tt.RealseeXChimeRTC?new Ct({getVoiceSign:n}):this._createBrowserRTC():Jt&&(Sn||Cn)||Kt?this._createVRWebViewRTC():this._createBrowserRTC()});a(this,"_autoConnect",()=>{this._options.url&&this._options.getTicket&&this.connect()});a(this,"_debugSetup",()=>{this._options.__debug__&&Object.assign(window,{$liveController:this._controller,$live:this})});a(this,"_addLiveControllerEventListeners",()=>{this._controller.on("stateChange",this._handleStateChange),this._controller.on("message",this._handleMessage)});a(this,"_removeLiveControllerEventListeners",()=>{this._controller.off("stateChange",this._handleStateChange),this._controller.off("message",this._handleMessage)});a(this,"_handleStateChange",(t,n)=>{m.info(`State changed from ${n} to ${t}`),this.emit("stateChange",t,n)});a(this,"_handleMessage",async t=>{var n,s,r,o,c,l;if(m.debug("Received message:",t),typeof t=="object"){const{command:h,data:u={},frontRequestId:d,code:g,message:w,triggerUserId:b}=t;if(g==="SUCCESS")switch(h){case $.SelfUserInfo:{const p=u;Rn(this.selfInfo,p,{deep:!0})||(this._buildInData.selfInfo=p,this.emit("selfInfoUpdate",this._buildInData.selfInfo,d));break}case $.RoomInfo:{const p=u;this._buildInData.roomInfo=Object.assign({},p);const _=p.last_frame||{};this._yDoc.transact(()=>{for(const I in _)this._buildInData.keyframes.set(I,_[I])},{triggerUserId:"readyKeyframeSync",frontRequestId:d}),this.emit("readyKeyframeSync",p.last_frame||{});break}case $.RTCInfo:{m.info("RTC info updated:",u);const{voice_id:p,type:_}=u;if(this._buildInData.rtcInfo={voiceId:p,type:_},(n=this.$RTC)!=null&&n.joined)m.warn("已加入语音房间,无需重复加入!");else if(await((o=this.$RTC)==null?void 0:o.join({voiceId:p,userId:((s=this.selfInfo)==null?void 0:s.id)||"",roomId:(r=this.roomInfo)==null?void 0:r.info.room_code,type:_}))){const N=(c=this._options.initialMicroStatus)!=null?c:te.OPEN;await this.toggleMicro(N===te.OPEN)}else m.error("加入语音房间失败");break}case $.UserList:{const p=u;this._buildInData.userList=p,this.emit("userListUpdate",this.userList,d);break}case $.CustomEvent:{const p=u;this.emit("broadcast",p,d);break}case $.KeyframeSync:{const p=u;if(b===((l=this.selfInfo)==null?void 0:l.id))return;this._yDoc.transact(()=>{for(const _ in p)this._buildInData.keyframes.set(_,p[_])},{triggerUserId:b,frontRequestId:d});break}case $.BuiltinMsg:{const p=u;this.emit("builtinEvent",p),p.event_type===F.UserChange&&this.emit("userChange",p),p.event_type===F.RoomChange&&this.emit("roomChange",p),p.event_type===F.UserChange&&p.action===K.UserMicroStatus&&await this.toggleMicro(p.data.status===te.OPEN),p.event_type===F.RoomChange&&p.action===K.RoomClose&&await this._exit();break}case $.UserKickOut:{this.emit("kickOut");break}default:m.warn("Unknown command received:",h)}else m.error("Error in message:",w),this.emit("error",t)}});a(this,"_clearLiveData",()=>{this._buildInData.keyframes.clear(),this._buildInData={keyframes:this._yDoc.getMap("keyframes")}});a(this,"connect",async(t={})=>{var s,r,o,c;if(m.info("Attempting to connect with options:",t),this._options.url=(r=(s=t.url)!=null?s:this._options.url)!=null?r:"",this._options.getTicket=(o=t.getTicket)!=null?o:this._options.getTicket,this._options.initialMicroStatus=(c=t.rtcMicStatus)!=null?c:this._options.initialMicroStatus,!/^wss?:\/\//.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");const n=this.state;if(n===V.CONNECTING||n===V.OPEN)if(t.force)await this._controller.close("force close by connect").catch(console.warn);else return new Error("已有Live实例正在连接中,请勿重复连接!");this._clearLiveData();try{const l=await this._options.getTicket(),h=yn(this._options.url,{ticket:l,force:+!!t.force});return this._controller.open(h),m.info("Connection established successfully"),!0}catch(l){return m.error("Failed to connect:",l),new Error("Failed to connect")}});a(this,"_exit",async()=>{var t;this._clearLiveData();try{await((t=this.$RTC)==null?void 0:t.quit())}catch(n){m.warn(n)}return this.state!==V.OPEN?!0:await this._controller.close()});a(this,"exit",async()=>this.close());a(this,"close",async()=>{var t;await this._controller.readyClose();try{await((t=this.$RTC)==null?void 0:t.quit())}catch(n){m.warn(n)}await this.updateStatus(F.RoomChange,K.RoomClose,{})});a(this,"dispose",async()=>{this._removeLiveControllerEventListeners();try{this._yDoc.getMap("keyframes").unobserve(this._handleKeyframesChange),this._yDoc.destroy()}catch(t){m.warn(t)}return this._clearLiveData(),await this._controller.dispose()});a(this,"setSelfInfo",async t=>await this.updateStatus(F.UserChange,K.UserInfo,t));a(this,"broadcast",(t,n,s)=>this.state!==V.OPEN?!1:new Promise((r,o)=>{const c=yt($.CustomEvent,t,n),l=c.front_request_id,h=s?setTimeout(()=>{o(new Error("RESPONSE TIMEOUT")),this.off("broadcast",u)},s):void 0,u=(d,g)=>{g===l&&(h&&clearTimeout(h),this.off("broadcast",u),r(d))};this.on("broadcast",u);try{this._controller.sendMessage(c)}catch(d){o(d)}}));a(this,"toggleMicro",async t=>{var s,r,o;if(!((r=(s=this.selfInfo)==null?void 0:s.permission)!=null&&r.control_own_micro))return!1;const n=await((o=this.$RTC)==null?void 0:o.toggleMicro(t));return n&&await this.updateStatus(F.UserChange,K.UserMicroStatus,{status:t?te.OPEN:te.CLOSE},[]),n});a(this,"forbidMicro",async(t,n)=>{var s,r;return typeof this._options.canForbidUserMicro=="function"&&!this._options.canForbidUserMicro(n)||!((r=(s=this.selfInfo)==null?void 0:s.permission)!=null&&r.control_other_micro)?!1:await this.updateStatus(F.UserChange,K.UserMicroStatus,{status:t},n)});a(this,"forbidSync",async(t,n)=>{var s,r;return typeof this._options.canForbidUserSync=="function"&&!this._options.canForbidUserSync(n)||!((r=(s=this.selfInfo)==null?void 0:s.permission)!=null&&r.control_other_sync)?!1:await this.updateStatus(F.UserChange,K.UserPermission,{sync_frame:t},n)});a(this,"kick",async t=>{var n,s;return typeof this._options.canForbidUserKick=="function"&&!this._options.canForbidUserKick(t)||!((s=(n=this.selfInfo)==null?void 0:n.permission)!=null&&s.change_other_status)?!1:await this.updateStatus(F.UserChange,K.UserStatus,{status:"KICK_OUT"},t)});a(this,"getSnapshotForKey",t=>this.snapshot[t]);m.info("Initializing Live instance with options:",t),this._addLiveControllerEventListeners(),this._yDoc=new Ee({guid:Te()}),this._buildInData={keyframes:this._yDoc.getMap("keyframes")},this._initializeKeyframesObservers(),this._initializeOptions(t),this._autoConnect(),this._debugSetup()}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.toJSON()}get selfInfo(){return this._buildInData.selfInfo}get userList(){return this._buildInData.userList||[]}get roomInfo(){return this._buildInData.roomInfo}async updateStatus(t,n,s,r){if(this.state!==V.OPEN)return!1;const o=Object.assign({event_type:t,action:n},{data:s}),c=yt($.BuiltinMsg,o,r);try{return this._controller.sendMessage(c),!0}catch(l){return m.error(l),!1}}}const hn=i=>(ln(),new an(i));function Sr(i){const e=y.createContext(null),t=hn(i),n=t.jsBridge,s=f=>y.createElement(e.Provider,{value:t},f.children),r=()=>{const f=y.useContext(e);if(!f)throw new Error("LiveProvider never found.");return f},o=()=>t,c=()=>t.$RTC,l=()=>c(),h=()=>async f=>await t.connect(f);function u(f,E,A=[]){const S=r(),O=[S,f,...A],M=()=>S.keyframes.off(f,E);return y.useEffect(()=>(S.keyframes.on(f,E),M),O),M}function d(){const f=r(),E=y.useCallback(async R=>{await f.connect(R)},[f]),A=y.useCallback(R=>{f.toggleMicro(R)},[f]),S=y.useCallback(async(R,q,at=0)=>{await f.broadcast(R,q,at)},[f]),O=y.useCallback(async()=>{await f.exit()},[f]),M=y.useCallback(async R=>{await f.kick(R)},[f]),W=y.useCallback(async(R,q=[])=>{await f.forbidMicro(R,q)},[f]),ce=y.useCallback((R,q=[])=>{f.forbidSync(R,q)},[f]),lt=y.useCallback(R=>f.getFramesByKey(R),[f]),un=y.useCallback((R,q)=>{f.sendKeyframe(R,q)},[f]),dn=y.useCallback(R=>{f.setSelfInfo(R)},[f]),fn=y.useCallback((R,q,at,gn)=>{f.updateStatus(R,q,at,gn)},[f]);return{connect:E,broadcast:S,exit:O,kick:M,toggleMicro:A,forbidMicro:W,forbidSync:ce,sendKeyframe:un,getFramesByKey:lt,setSelfInfo:dn,updateStatus:fn}}function g(f){const E=r(),[A,S]=y.useState(E.getFramesByKey(f));y.useEffect(()=>{const M=lt=>S(lt),W=f,ce=M;return E.keyframes.on(W,ce),()=>E.keyframes.off(W,ce)},[E]);const O=y.useCallback(M=>E.sendKeyframe(f,M),[E]);return[A,O]}function w(f,E,A=[]){const S=r(),O=()=>S.off(f,E),M=[S,f,...A];return y.useEffect(()=>(S.on(f,E),O),M),O}function b(){const f=r(),[E,A]=y.useState(f.state);return y.useEffect(()=>{const S=O=>A(O);return f.on("stateChange",S),()=>f.off("stateChange",S)},[f]),E}function p(){const f=r();return{join:W=>f.$RTC.join(W),quit:()=>f.$RTC.quit(),shock:()=>{var W,ce;return(ce=(W=f.$RTC).shock)==null?void 0:ce.call(W)},toggleMicro:W=>f.$RTC.toggleMicro(W),detectMicro:()=>f.$RTC.detectMicro()}}function _(f,E,A=[]){const S=r(),O=()=>S.$RTC.off(f,E),M=[S,f,...A];return y.useEffect(()=>(S.$RTC.on(f,E),O),M),O}function I(){const f=r(),[E,A]=y.useState(f.selfInfo||{}),S=M=>A(M);y.useEffect(()=>(f.on("selfInfoUpdate",S),()=>f.off("selfInfoUpdate",S)),[f]);const O=y.useCallback(async M=>await f.setSelfInfo(M),[f]);return[E,O]}function N(){const f=r(),[E,A]=y.useState(f.snapshot);return y.useEffect(()=>{const S=O=>A(O);return f.on("keyframes",S),()=>f.off("keyframes",S)},[f]),E}function Wt(){const f=r(),[E,A]=y.useState(f.userList),S=O=>A(O);return y.useEffect(()=>(f.on("userListUpdate",S),()=>f.off("userListUpdate",S)),[f]),E}return{live:t,jsBridge:n,LiveProvider:s,unsafe__useLiveInstance:o,unsafe__useRTCInstance:l,useConnect:h,useKeyframe:g,useKeyframeUpdateCallback:u,useLiveAction:d,useLiveEventCallback:w,useLiveState:b,useRTCAction:p,useRTCEventCallback:_,useSelfInfo:I,useKeyframesSnapshot:N,useUserList:Wt}}const St=globalThis.__REALSEE_LIVE_BADGE_LOG__;(St==null||St)&&console.log("%c@realsee/live@0.7.5 (12/4/2025, 11:37:10 AM)","background: linear-gradient(to right, #1890ff, #52c41a); color: white; padding: 3px 6px; border-radius: 4px; font-weight: bold; text-shadow: 0 1px 0 rgba(0,0,0,0.2);");exports.BrowserRTC=fi;exports.BrowserRTC4Chime=Ct;exports.BuiltInRTCType=Tt;exports.BuiltinActionType=K;exports.BuiltinEventType=F;exports.Command=$;exports.CoreRTC=tt;exports.Live=an;exports.LiveState=V;exports.MemUserStatus=_i;exports.MicroStatus=te;exports.RTCJoinedInfoCodeEnum=le;exports.RTCType=se;exports.Subscribe=ge;exports.UserStatus=pi;exports.VRWebViewRTC=gi;exports.WebSocketCloseError=wi;exports.WebSocketErrorType=mi;exports.WebSocketState=Ge;exports._clearLiveInstanceIfNeed=ln;exports.createLive=hn;exports.createLiveReact=Sr;exports.parseLiveMsg=bn;exports.parseWSClsErr=bi;
3
+ `?o.insert.slice(0,-1):o.insert;(typeof c!="string"||c.length>0)&&wt(n,this,s,c,o.attributes||{})}else o.retain!==void 0?ui(n,this,s,o.retain,o.attributes||{}):o.delete!==void 0&&di(n,s,o.delete)}}):this._pending.push(()=>this.applyDelta(e))}toDelta(e,t,n){var d;(d=this.doc)!=null||j();const s=[],r=new Map,o=this.doc;let c="",l=this._start;function h(){if(c.length>0){const g={};let w=!1;r.forEach((p,_)=>{w=!0,g[_]=p});const b={insert:c};w&&(b.attributes=g),s.push(b),c=""}}const u=()=>{for(;l!==null;){if(ue(l,e)||t!==void 0&&ue(l,t))switch(l.content.constructor){case X:{const g=r.get("ychange");e!==void 0&&!ue(l,e)?(g===void 0||g.user!==l.id.client||g.type!=="removed")&&(h(),r.set("ychange",n?n("removed",l.id):{type:"removed"})):t!==void 0&&!ue(l,t)?(g===void 0||g.user!==l.id.client||g.type!=="added")&&(h(),r.set("ychange",n?n("added",l.id):{type:"added"})):g!==void 0&&(h(),r.delete("ychange")),c+=l.content.str;break}case oe:case ve:{h();const g={insert:l.content.getContent()[0]};if(r.size>0){const w={};g.attributes=w,r.forEach((b,p)=>{w[p]=b})}s.push(g);break}case L:ue(l,e)&&(h(),ke(r,l.content));break}l=l.right}h()};return e||t?k(o,g=>{e&&Ot(g,e),t&&Ot(g,t),u()},"cleanup"):u(),s}insert(e,t,n){if(t.length<=0)return;const s=this.doc;s!==null?k(s,r=>{const o=Fe(r,this,e,!n);n||(n={},o.currentAttributes.forEach((c,l)=>{n[l]=c})),wt(r,this,o,t,n)}):this._pending.push(()=>this.insert(e,t,n))}insertEmbed(e,t,n){const s=this.doc;s!==null?k(s,r=>{const o=Fe(r,this,e,!n);wt(r,this,o,t,n||{})}):this._pending.push(()=>this.insertEmbed(e,t,n||{}))}delete(e,t){if(t===0)return;const n=this.doc;n!==null?k(n,s=>{di(s,Fe(s,this,e,!0),t)}):this._pending.push(()=>this.delete(e,t))}format(e,t,n){if(t===0)return;const s=this.doc;s!==null?k(s,r=>{const o=Fe(r,this,e,!1);o.right!==null&&ui(r,this,o,t,n)}):this._pending.push(()=>this.format(e,t,n))}removeAttribute(e){this.doc!==null?k(this.doc,t=>{Xe(t,this,e)}):this._pending.push(()=>this.removeAttribute(e))}setAttribute(e,t){this.doc!==null?k(this.doc,n=>{xt(n,this,e,t)}):this._pending.push(()=>this.setAttribute(e,t))}getAttribute(e){return Ft(this,e)}getAttributes(){return Xi(this)}_write(e){e.writeTypeRef(wr)}}class bt{constructor(e,t=()=>!0){var n;this._filter=t,this._root=e,this._currentNode=e._start,this._firstCall=!0,(n=e.doc)!=null||j()}[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===Ue||t.constructor===be)&&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})}}class be extends D{constructor(){super(),this._prelimContent=[]}get firstChild(){const 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 be}clone(){const e=new be;return e.insert(0,this.toArray().map(t=>t instanceof D?t.clone():t)),e}get length(){var e;return(e=this.doc)!=null||j(),this._prelimContent===null?this._length:this._prelimContent.length}createTreeWalker(e){return new bt(this,e)}querySelector(e){e=e.toUpperCase();const n=new bt(this,s=>s.nodeName&&s.nodeName.toUpperCase()===e).next();return n.done?null:n.value}querySelectorAll(e){return e=e.toUpperCase(),me(new bt(this,t=>t.nodeName&&t.nodeName.toUpperCase()===e))}_callObserver(e,t){rt(this,e,new dr(this,t,e))}toString(){return Gi(this,e=>e.toString()).join("")}toJSON(){return this.toString()}toDOM(e=document,t={},n){const s=e.createDocumentFragment();return n!==void 0&&n._createAssociation(s,this),Ve(this,r=>{s.insertBefore(r.toDOM(e,t,n),null)}),s}insert(e,t){this.doc!==null?k(this.doc,n=>{zi(n,this,e,t)}):this._prelimContent.splice(e,0,...t)}insertAfter(e,t){if(this.doc!==null)k(this.doc,n=>{const s=e&&e instanceof D?e._item:e;Ye(n,this,s,t)});else{const n=this._prelimContent,s=e===null?0:n.findIndex(r=>r===e)+1;if(s===0&&e!==null)throw we("Reference item not found");n.splice(s,0,...t)}}delete(e,t=1){this.doc!==null?k(this.doc,n=>{Yi(n,this,e,t)}):this._prelimContent.splice(e,t)}toArray(){return Ji(this)}push(e){this.insert(this.length,e)}unshift(e){this.insert(0,e)}get(e){return qi(this,e)}slice(e=0,t=this.length){return Ki(this,e,t)}forEach(e){Ve(this,e)}_write(e){e.writeTypeRef(yr)}}class Ue extends be{constructor(e="UNDEFINED"){super(),this.nodeName=e,this._prelimAttrs=new Map}get nextSibling(){const e=this._item?this._item.next:null;return e?e.content.type:null}get prevSibling(){const e=this._item?this._item.prev:null;return e?e.content.type:null}_integrate(e,t){super._integrate(e,t),this._prelimAttrs.forEach((n,s)=>{this.setAttribute(s,n)}),this._prelimAttrs=null}_copy(){return new Ue(this.nodeName)}clone(){const e=new Ue(this.nodeName),t=this.getAttributes();return us(t,(n,s)=>{typeof n=="string"&&e.setAttribute(s,n)}),e.insert(0,this.toArray().map(n=>n instanceof D?n.clone():n)),e}toString(){const e=this.getAttributes(),t=[],n=[];for(const c in e)n.push(c);n.sort();const s=n.length;for(let c=0;c<s;c++){const l=n[c];t.push(l+'="'+e[l]+'"')}const r=this.nodeName.toLocaleLowerCase(),o=t.length>0?" "+t.join(" "):"";return`<${r}${o}>${super.toString()}</${r}>`}removeAttribute(e){this.doc!==null?k(this.doc,t=>{Xe(t,this,e)}):this._prelimAttrs.delete(e)}setAttribute(e,t){this.doc!==null?k(this.doc,n=>{xt(n,this,e,t)}):this._prelimAttrs.set(e,t)}getAttribute(e){return Ft(this,e)}hasAttribute(e){return Zi(this,e)}getAttributes(e){return e?rr(this,e):Xi(this)}toDOM(e=document,t={},n){const s=e.createElement(this.nodeName),r=this.getAttributes();for(const o in r){const c=r[o];typeof c=="string"&&s.setAttribute(o,c)}return Ve(this,o=>{s.appendChild(o.toDOM(e,t,n))}),n!==void 0&&n._createAssociation(s,this),s}_write(e){e.writeTypeRef(br),e.writeKey(this.nodeName)}}class dr extends nt{constructor(e,t,n){super(e,n),this.childListChanged=!1,this.attributesChanged=new Set,t.forEach(s=>{s===null?this.childListChanged=!0:this.attributesChanged.add(s)})}}class sn{constructor(e,t){this.id=e,this.length=t}get deleted(){throw G()}mergeWith(e){return!1}write(e,t,n){throw G()}integrate(e,t){throw G()}}const fr=0;class ie extends sn{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),$i(e.doc.store,this)}write(e,t){e.writeInfo(fr),e.writeLen(this.length-t)}getMissing(e,t){return null}}class ot{constructor(e){this.content=e}getLength(){return 1}getContent(){return[this.content]}isCountable(){return!0}copy(){return new ot(this.content)}splice(e){throw G()}mergeWith(e){return!1}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeBuf(this.content)}getRef(){return 3}}class et{constructor(e){this.len=e}getLength(){return this.len}getContent(){return[]}isCountable(){return!1}copy(){return new et(this.len)}splice(e){const t=new et(this.len-e);return this.len=e,t}mergeWith(e){return this.len+=e.len,!0}integrate(e,t){Ui(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}}const gr=(i,e)=>new Ee({guid:i,...e,shouldLoad:e.shouldLoad||e.autoLoad||!1});class ct{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;const 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 ct(gr(this.doc.guid,this.opts))}splice(e){throw G()}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}}class ve{constructor(e){this.embed=e}getLength(){return 1}getContent(){return[this.embed]}isCountable(){return!0}copy(){return new ve(this.embed)}splice(e){throw G()}mergeWith(e){return!1}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeJSON(this.embed)}getRef(){return 5}}class L{constructor(e,t){this.key=e,this.value=t}getLength(){return 1}getContent(){return[]}isCountable(){return!1}copy(){return new L(this.key,this.value)}splice(e){throw G()}mergeWith(e){return!1}integrate(e,t){const n=t.parent;n._searchMarker=null,n._hasFormatting=!0}delete(e){}gc(e){}write(e,t){e.writeKey(this.key),e.writeJSON(this.value)}getRef(){return 6}}const pr=ze("node_env")==="development";class ye{constructor(e){this.arr=e,pr&&vi(e)}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new ye(this.arr)}splice(e){const t=new ye(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){const n=this.arr.length;e.writeLen(n-t);for(let s=t;s<n;s++){const r=this.arr[s];e.writeAny(r)}}getRef(){return 8}}class X{constructor(e){this.str=e}getLength(){return this.str.length}getContent(){return this.str.split("")}isCountable(){return!0}copy(){return new X(this.str)}splice(e){const t=new X(this.str.slice(e));this.str=this.str.slice(0,e);const n=this.str.charCodeAt(e-1);return n>=55296&&n<=56319&&(this.str=this.str.slice(0,e-1)+"�",t.str="�"+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}}const _r=0,mr=1,wr=2,br=3,yr=4;class oe{constructor(e){this.type=e}getLength(){return 1}getContent(){return[this.type]}isCountable(){return!0}copy(){return new oe(this.type._copy())}splice(e){throw G()}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(n=>{n.deleted?n.id.clock<(e.beforeState.get(n.id.client)||0)&&e._mergeStructs.push(n):n.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(n=>{for(;n!==null;)n.gc(e,!0),n=n.left}),this.type._map=new Map}write(e,t){this.type._write(e)}getRef(){return 7}}const rn=(i,e,t)=>{const{client:n,clock:s}=e.id,r=new U(v(n,s+t),e,v(n,s+t-1),e.right,e.rightOrigin,e.parent,e.parentSub,e.content.splice(t));return e.deleted&&r.markDeleted(),e.keep&&(r.keep=!0),e.redone!==null&&(r.redone=v(e.redone.client,e.redone.clock+t)),e.right=r,r.right!==null&&(r.right.left=r),i._mergeStructs.push(r),r.parentSub!==null&&r.right===null&&r.parent._map.set(r.parentSub,r),e.length=t,r};class U extends sn{constructor(e,t,n,s,r,o,c,l){super(e,l.getLength()),this.origin=n,this.left=t,this.right=s,this.rightOrigin=r,this.parent=o,this.parentSub=c,this.redone=null,this.content=l,this.info=this.content.isCountable()?qt:0}set marker(e){(this.info&ft)>0!==e&&(this.info^=ft)}get marker(){return(this.info&ft)>0}get keep(){return(this.info&Gt)>0}set keep(e){this.keep!==e&&(this.info^=Gt)}get countable(){return(this.info&qt)>0}get deleted(){return(this.info&dt)>0}set deleted(e){this.deleted!==e&&(this.info^=dt)}markDeleted(){this.info|=dt}getMissing(e,t){if(this.origin&&this.origin.client!==this.id.client&&this.origin.clock>=B(t,this.origin.client))return this.origin.client;if(this.rightOrigin&&this.rightOrigin.client!==this.id.client&&this.rightOrigin.clock>=B(t,this.rightOrigin.client))return this.rightOrigin.client;if(this.parent&&this.parent.constructor===Ke&&this.id.client!==this.parent.client&&this.parent.clock>=B(t,this.parent.client))return this.parent.client;if(this.origin&&(this.left=oi(e,t,this.origin),this.origin=this.left.lastId),this.rightOrigin&&(this.right=re(e,this.rightOrigin),this.rightOrigin=this.right.id),this.left&&this.left.constructor===ie||this.right&&this.right.constructor===ie)this.parent=null;else if(!this.parent)this.left&&this.left.constructor===U&&(this.parent=this.left.parent,this.parentSub=this.left.parentSub),this.right&&this.right.constructor===U&&(this.parent=this.right.parent,this.parentSub=this.right.parentSub);else if(this.parent.constructor===Ke){const n=mt(t,this.parent);n.constructor===ie?this.parent=null:this.parent=n.content.type}return null}integrate(e,t){if(t>0&&(this.id.clock+=t,this.left=oi(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 n=this.left,s;if(n!==null)s=n.right;else if(this.parentSub!==null)for(s=this.parent._map.get(this.parentSub)||null;s!==null&&s.left!==null;)s=s.left;else s=this.parent._start;const r=new Set,o=new Set;for(;s!==null&&s!==this.right;){if(o.add(s),r.add(s),$e(this.origin,s.origin)){if(s.id.client<this.id.client)n=s,r.clear();else if($e(this.rightOrigin,s.rightOrigin))break}else if(s.origin!==null&&o.has(mt(e.doc.store,s.origin)))r.has(mt(e.doc.store,s.origin))||(n=s,r.clear());else break;s=s.right}this.left=n}if(this.left!==null){const n=this.left.right;this.right=n,this.left.right=this}else{let n;if(this.parentSub!==null)for(n=this.parent._map.get(this.parentSub)||null;n!==null&&n.left!==null;)n=n.left;else n=this.parent._start,this.parent._start=this;this.right=n}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),$i(e.doc.store,this),this.content.integrate(e,this),li(e,this.parent,this.parentSub),(this.parent._item!==null&&this.parent._item.deleted||this.parentSub!==null&&this.right!==null)&&this.delete(e)}else new ie(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&&$e(e.origin,this.lastId)&&this.right===e&&$e(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)){const t=this.parent._searchMarker;return t&&t.forEach(n=>{n.p===e&&(n.p=this,!this.deleted&&this.countable&&(n.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){const t=this.parent;this.countable&&this.parentSub===null&&(t._length-=this.length),this.markDeleted(),Ui(e.deleteSet,this.id.client,this.id.clock,this.length),li(e,t,this.parentSub),this.content.delete(e)}}gc(e,t){if(!this.deleted)throw he();this.content.gc(e),t?zs(e,this,new ie(this.id,this.length)):this.content=new et(this.length)}write(e,t){const n=t>0?v(this.id.client,this.id.clock+t-1):this.origin,s=this.rightOrigin,r=this.parentSub,o=this.content.getRef()&jn|(n===null?0:He)|(s===null?0:Ci)|(r===null?0:Un);if(e.writeInfo(o),n!==null&&e.writeLeftID(n),s!==null&&e.writeRightID(s),n===null&&s===null){const c=this.parent;if(c._item!==void 0){const l=c._item;if(l===null){const h=Gs(c);e.writeParentInfo(!0),e.writeString(h)}else e.writeParentInfo(!1),e.writeLeftID(l.id)}else c.constructor===String?(e.writeParentInfo(!0),e.writeString(c)):c.constructor===Ke?(e.writeParentInfo(!1),e.writeLeftID(c)):he();r!==null&&e.writeString(r)}this.content.write(e,t)}}const on=typeof globalThis!="undefined"?globalThis:typeof window!="undefined"?window:typeof global!="undefined"?global:{},cn="__ $YJS$ __";on[cn]===!0&&console.error("Yjs was already imported. This breaks constructor checks and will lead to issues! - https://github.com/yjs/yjs/issues/438");on[cn]=!0;const Oe=i=>Promise.reject(new Error("unimplemented method GetVoiceSign")),yt=(i,e={},t=[])=>({command:i,front_request_id:Te(),data:{...e,to_user_ids:Array.isArray(t)?t:[t]}}),ln=()=>{var i,e;window!=null&&window.__Realsee_Live__&&((e=(i=window==null?void 0:window.__Realsee_Live__)==null?void 0:i.dispose)==null||e.call(i),window.__Realsee_Live__=null)};class an extends ge{constructor(t){super();a(this,"_options",{});a(this,"keyframes",new ge);a(this,"_yDoc");a(this,"_buildInData");a(this,"_initializeKeyframesObservers",()=>{this._yDoc.getMap("keyframes").observe(this._handleKeyframesChange)});a(this,"_handleKeyframesChange",t=>{var o;const{transaction:n,target:s,changes:r}=t;if(s===this._buildInData.keyframes)if(n.origin.triggerUserId===((o=this.selfInfo)==null?void 0:o.id)){const c=yt($.KeyframeSync,this.snapshot,void 0);try{this._controller.sendMessage(c)}catch(l){m.error("Failed to send keyframe sync message:",l)}}else r.keys.forEach((c,l)=>{const h=c.oldValue,u=this.getFramesByKey(l),d=n.origin.frontRequestId;this.keyframes.emit(l,u,h,d)}),r.keys.size!==0&&this.emit("keyframes",this.snapshot,n.origin.frontRequestId)});a(this,"getFramesByKey",t=>this.snapshot[t]);a(this,"sendKeyframe",(t,n)=>{var s;return this.state!==V.OPEN?(m.warn("Attempted to send keyframe while connection is not open"),!1):(this._yDoc.transact(()=>{this._buildInData.keyframes.set(t,n)},{triggerUserId:(s=this.selfInfo)==null?void 0:s.id,frontRequestId:""}),!0)});a(this,"_controller",new Tn);a(this,"_initializeOptions",t=>{var n;this._options=Object.assign({initialMicroStatus:te.OPEN},t),this._options.jsBridge=this._initializeJsBridge(t),this._options.getVoiceSign=(n=t.getVoiceSign)!=null?n:Oe,this._options.autoPlayConfirm=t.autoPlayConfirm,this._options.rtc=this._initializeRTC(t)});a(this,"_initializeJsBridge",t=>{if(t.jsBridge)return t.jsBridge;if(t.useBuiltInJsBridge)return new mn});a(this,"_initializeRTC",t=>{if(t.rtc)return t.rtc;if(t.rtcType)return this._createBuiltInRTC(t);if(t.useBuiltInRTC)return this._createDefaultRTC(t)});a(this,"_createBuiltInRTC",t=>{var n;if(!t.getVoiceSign){m.error("GetVoiceSign method must be passed when using built-in RTC instances");return}switch(t.rtcType){case se.RealseeVRWebViewRTC:return this._createVRWebViewRTC();case se.RealseeBrowserChimeRTC:return new Ct({getVoiceSign:(n=this._options.getVoiceSign)!=null?n:Oe,logLevel:t.__debug__?0:1});case se.RealseeBrowserRTC:return this._createBrowserRTC();default:m.error("unknown built-in RTC type");return}});a(this,"_createVRWebViewRTC",()=>{var t;if(this._options.jsBridge)return new gi({jsBridge:this._options.jsBridge,getVoiceSign:(t=this._options.getVoiceSign)!=null?t:Oe});m.error("JsBridge instance must be passed when using built-in VRWebViewRTC instances")});a(this,"_createBrowserRTC",()=>{var t;if(!this._options.autoPlayConfirm){m.error("autoPlayConfirm method must be passed when using built-in RealseeBrowserRTC instances");return}return new fi({getVoiceSign:(t=this._options.getVoiceSign)!=null?t:Oe,autoPlayConfirm:this._options.autoPlayConfirm})});a(this,"_createDefaultRTC",t=>{var s;const n=(s=this._options.getVoiceSign)!=null?s:Oe;return!this._options.jsBridge||!Jt&&!Kt?t.builtInRTCType===Tt.RealseeXChimeRTC?new Ct({getVoiceSign:n}):this._createBrowserRTC():Jt&&(Sn||Cn)||Kt?this._createVRWebViewRTC():this._createBrowserRTC()});a(this,"_autoConnect",()=>{this._options.url&&this._options.getTicket&&this.connect()});a(this,"_debugSetup",()=>{this._options.__debug__&&Object.assign(window,{$liveController:this._controller,$live:this})});a(this,"_addLiveControllerEventListeners",()=>{this._controller.on("stateChange",this._handleStateChange),this._controller.on("message",this._handleMessage)});a(this,"_removeLiveControllerEventListeners",()=>{this._controller.off("stateChange",this._handleStateChange),this._controller.off("message",this._handleMessage)});a(this,"_handleStateChange",(t,n)=>{m.info(`State changed from ${n} to ${t}`),this.emit("stateChange",t,n)});a(this,"_handleMessage",async t=>{var n,s,r,o,c,l;if(m.debug("Received message:",t),typeof t=="object"){const{command:h,data:u={},frontRequestId:d,code:g,message:w,triggerUserId:b}=t;if(g==="SUCCESS")switch(h){case $.SelfUserInfo:{const p=u;Rn(this.selfInfo,p,{deep:!0})||(this._buildInData.selfInfo=p,this.emit("selfInfoUpdate",this._buildInData.selfInfo,d));break}case $.RoomInfo:{const p=u;this._buildInData.roomInfo=Object.assign({},p);const _=p.last_frame||{};this._yDoc.transact(()=>{for(const I in _)this._buildInData.keyframes.set(I,_[I])},{triggerUserId:"readyKeyframeSync",frontRequestId:d}),this.emit("readyKeyframeSync",p.last_frame||{});break}case $.RTCInfo:{m.info("RTC info updated:",u);const{voice_id:p,type:_}=u;if(this._buildInData.rtcInfo={voiceId:p,type:_},(n=this.$RTC)!=null&&n.joined)m.warn("已加入语音房间,无需重复加入!");else if(await((o=this.$RTC)==null?void 0:o.join({voiceId:p,userId:((s=this.selfInfo)==null?void 0:s.id)||"",roomId:(r=this.roomInfo)==null?void 0:r.info.room_code,type:_}))){const N=(c=this._options.initialMicroStatus)!=null?c:te.OPEN;await this.toggleMicro(N===te.OPEN)}else m.error("加入语音房间失败");break}case $.UserList:{const p=u;this._buildInData.userList=p,this.emit("userListUpdate",this.userList,d);break}case $.CustomEvent:{const p=u;this.emit("broadcast",p,d);break}case $.KeyframeSync:{const p=u;if(b===((l=this.selfInfo)==null?void 0:l.id))return;this._yDoc.transact(()=>{for(const _ in p)this._buildInData.keyframes.set(_,p[_])},{triggerUserId:b,frontRequestId:d});break}case $.BuiltinMsg:{const p=u;this.emit("builtinEvent",p),p.event_type===F.UserChange&&this.emit("userChange",p),p.event_type===F.RoomChange&&this.emit("roomChange",p),p.event_type===F.UserChange&&p.action===K.UserMicroStatus&&await this.toggleMicro(p.data.status===te.OPEN),p.event_type===F.RoomChange&&p.action===K.RoomClose&&await this._exit();break}case $.UserKickOut:{this.emit("kickOut");break}default:m.warn("Unknown command received:",h)}else m.error("Error in message:",w),this.emit("error",t)}});a(this,"_clearLiveData",()=>{this._buildInData.keyframes.clear(),this._buildInData={keyframes:this._yDoc.getMap("keyframes")}});a(this,"connect",async(t={})=>{var s,r,o,c;if(m.info("Attempting to connect with options:",t),this._options.url=(r=(s=t.url)!=null?s:this._options.url)!=null?r:"",this._options.getTicket=(o=t.getTicket)!=null?o:this._options.getTicket,this._options.initialMicroStatus=(c=t.rtcMicStatus)!=null?c:this._options.initialMicroStatus,!/^wss?:\/\//.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");const n=this.state;if(n===V.CONNECTING||n===V.OPEN)if(t.force)await this._controller.close("force close by connect").catch(console.warn);else return new Error("已有Live实例正在连接中,请勿重复连接!");this._clearLiveData();try{const l=await this._options.getTicket(),h=yn(this._options.url,{ticket:l,force:+!!t.force});return this._controller.open(h),m.info("Connection established successfully"),!0}catch(l){return m.error("Failed to connect:",l),new Error("Failed to connect")}});a(this,"_exit",async()=>{var t;this._clearLiveData();try{await((t=this.$RTC)==null?void 0:t.quit())}catch(n){m.warn(n)}return this.state!==V.OPEN?!0:await this._controller.close()});a(this,"exit",async()=>this.close());a(this,"close",async()=>{var t;await this._controller.readyClose();try{await((t=this.$RTC)==null?void 0:t.quit())}catch(n){m.warn(n)}await this.updateStatus(F.RoomChange,K.RoomClose,{})});a(this,"dispose",async()=>{this._removeLiveControllerEventListeners();try{this._yDoc.getMap("keyframes").unobserve(this._handleKeyframesChange),this._yDoc.destroy()}catch(t){m.warn(t)}return this._clearLiveData(),await this._controller.dispose()});a(this,"setSelfInfo",async t=>await this.updateStatus(F.UserChange,K.UserInfo,t));a(this,"broadcast",(t,n,s)=>this.state!==V.OPEN?!1:new Promise((r,o)=>{const c=yt($.CustomEvent,t,n),l=c.front_request_id,h=s?setTimeout(()=>{o(new Error("RESPONSE TIMEOUT")),this.off("broadcast",u)},s):void 0,u=(d,g)=>{g===l&&(h&&clearTimeout(h),this.off("broadcast",u),r(d))};this.on("broadcast",u);try{this._controller.sendMessage(c)}catch(d){o(d)}}));a(this,"toggleMicro",async t=>{var s,r,o;if(!((r=(s=this.selfInfo)==null?void 0:s.permission)!=null&&r.control_own_micro))return!1;const n=await((o=this.$RTC)==null?void 0:o.toggleMicro(t));return n&&await this.updateStatus(F.UserChange,K.UserMicroStatus,{status:t?te.OPEN:te.CLOSE},[]),n});a(this,"forbidMicro",async(t,n)=>{var s,r;return typeof this._options.canForbidUserMicro=="function"&&!this._options.canForbidUserMicro(n)||!((r=(s=this.selfInfo)==null?void 0:s.permission)!=null&&r.control_other_micro)?!1:await this.updateStatus(F.UserChange,K.UserMicroStatus,{status:t},n)});a(this,"forbidSync",async(t,n)=>{var s,r;return typeof this._options.canForbidUserSync=="function"&&!this._options.canForbidUserSync(n)||!((r=(s=this.selfInfo)==null?void 0:s.permission)!=null&&r.control_other_sync)?!1:await this.updateStatus(F.UserChange,K.UserPermission,{sync_frame:t},n)});a(this,"kick",async t=>{var n,s;return typeof this._options.canForbidUserKick=="function"&&!this._options.canForbidUserKick(t)||!((s=(n=this.selfInfo)==null?void 0:n.permission)!=null&&s.change_other_status)?!1:await this.updateStatus(F.UserChange,K.UserStatus,{status:"KICK_OUT"},t)});a(this,"getSnapshotForKey",t=>this.snapshot[t]);m.info("Initializing Live instance with options:",t),this._addLiveControllerEventListeners(),this._yDoc=new Ee({guid:Te()}),this._buildInData={keyframes:this._yDoc.getMap("keyframes")},this._initializeKeyframesObservers(),this._initializeOptions(t),this._autoConnect(),this._debugSetup()}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.toJSON()}get selfInfo(){return this._buildInData.selfInfo}get userList(){return this._buildInData.userList||[]}get roomInfo(){return this._buildInData.roomInfo}async updateStatus(t,n,s,r){if(this.state!==V.OPEN)return!1;const o=Object.assign({event_type:t,action:n},{data:s}),c=yt($.BuiltinMsg,o,r);try{return this._controller.sendMessage(c),!0}catch(l){return m.error(l),!1}}}const hn=i=>(ln(),new an(i));function Sr(i){const e=y.createContext(null),t=hn(i),n=t.jsBridge,s=f=>y.createElement(e.Provider,{value:t},f.children),r=()=>{const f=y.useContext(e);if(!f)throw new Error("LiveProvider never found.");return f},o=()=>t,c=()=>t.$RTC,l=()=>c(),h=()=>async f=>await t.connect(f);function u(f,E,A=[]){const S=r(),O=[S,f,...A],M=()=>S.keyframes.off(f,E);return y.useEffect(()=>(S.keyframes.on(f,E),M),O),M}function d(){const f=r(),E=y.useCallback(async R=>{await f.connect(R)},[f]),A=y.useCallback(R=>{f.toggleMicro(R)},[f]),S=y.useCallback(async(R,q,at=0)=>{await f.broadcast(R,q,at)},[f]),O=y.useCallback(async()=>{await f.exit()},[f]),M=y.useCallback(async R=>{await f.kick(R)},[f]),W=y.useCallback(async(R,q=[])=>{await f.forbidMicro(R,q)},[f]),ce=y.useCallback((R,q=[])=>{f.forbidSync(R,q)},[f]),lt=y.useCallback(R=>f.getFramesByKey(R),[f]),un=y.useCallback((R,q)=>{f.sendKeyframe(R,q)},[f]),dn=y.useCallback(R=>{f.setSelfInfo(R)},[f]),fn=y.useCallback((R,q,at,gn)=>{f.updateStatus(R,q,at,gn)},[f]);return{connect:E,broadcast:S,exit:O,kick:M,toggleMicro:A,forbidMicro:W,forbidSync:ce,sendKeyframe:un,getFramesByKey:lt,setSelfInfo:dn,updateStatus:fn}}function g(f){const E=r(),[A,S]=y.useState(E.getFramesByKey(f));y.useEffect(()=>{const M=lt=>S(lt),W=f,ce=M;return E.keyframes.on(W,ce),()=>E.keyframes.off(W,ce)},[E]);const O=y.useCallback(M=>E.sendKeyframe(f,M),[E]);return[A,O]}function w(f,E,A=[]){const S=r(),O=()=>S.off(f,E),M=[S,f,...A];return y.useEffect(()=>(S.on(f,E),O),M),O}function b(){const f=r(),[E,A]=y.useState(f.state);return y.useEffect(()=>{const S=O=>A(O);return f.on("stateChange",S),()=>f.off("stateChange",S)},[f]),E}function p(){const f=r();return{join:W=>f.$RTC.join(W),quit:()=>f.$RTC.quit(),shock:()=>{var W,ce;return(ce=(W=f.$RTC).shock)==null?void 0:ce.call(W)},toggleMicro:W=>f.$RTC.toggleMicro(W),detectMicro:()=>f.$RTC.detectMicro()}}function _(f,E,A=[]){const S=r(),O=()=>S.$RTC.off(f,E),M=[S,f,...A];return y.useEffect(()=>(S.$RTC.on(f,E),O),M),O}function I(){const f=r(),[E,A]=y.useState(f.selfInfo||{}),S=M=>A(M);y.useEffect(()=>(f.on("selfInfoUpdate",S),()=>f.off("selfInfoUpdate",S)),[f]);const O=y.useCallback(async M=>await f.setSelfInfo(M),[f]);return[E,O]}function N(){const f=r(),[E,A]=y.useState(f.snapshot);return y.useEffect(()=>{const S=O=>A(O);return f.on("keyframes",S),()=>f.off("keyframes",S)},[f]),E}function Wt(){const f=r(),[E,A]=y.useState(f.userList),S=O=>A(O);return y.useEffect(()=>(f.on("userListUpdate",S),()=>f.off("userListUpdate",S)),[f]),E}return{live:t,jsBridge:n,LiveProvider:s,unsafe__useLiveInstance:o,unsafe__useRTCInstance:l,useConnect:h,useKeyframe:g,useKeyframeUpdateCallback:u,useLiveAction:d,useLiveEventCallback:w,useLiveState:b,useRTCAction:p,useRTCEventCallback:_,useSelfInfo:I,useKeyframesSnapshot:N,useUserList:Wt}}const St=globalThis.__REALSEE_LIVE_BADGE_LOG__;(St==null||St)&&console.log("%c@realsee/live@0.7.6 (12/4/2025, 12:08:28 PM)","background: linear-gradient(to right, #1890ff, #52c41a); color: white; padding: 3px 6px; border-radius: 4px; font-weight: bold; text-shadow: 0 1px 0 rgba(0,0,0,0.2);");exports.BrowserRTC=fi;exports.BrowserRTC4Chime=Ct;exports.BuiltInRTCType=Tt;exports.BuiltinActionType=K;exports.BuiltinEventType=F;exports.Command=$;exports.CoreRTC=tt;exports.Live=an;exports.LiveState=V;exports.MemUserStatus=_i;exports.MicroStatus=te;exports.RTCJoinedInfoCodeEnum=le;exports.RTCType=se;exports.Subscribe=ge;exports.UserStatus=pi;exports.VRWebViewRTC=gi;exports.WebSocketCloseError=wi;exports.WebSocketErrorType=mi;exports.WebSocketState=Ge;exports._clearLiveInstanceIfNeed=ln;exports.createLive=hn;exports.createLiveReact=Sr;exports.parseLiveMsg=bn;exports.parseWSClsErr=bi;
package/dist/index.es.js CHANGED
@@ -4,12 +4,12 @@ var a = (i, t, e) => cn(i, typeof t != "symbol" ? t + "" : t, e);
4
4
  import le from "trtc-js-sdk";
5
5
  import { ConsoleLogger as ln, LogLevel as an, DefaultDeviceController as hn, MeetingSessionConfiguration as un, DefaultMeetingSession as dn, DefaultModality as Fe, MeetingSessionStatusCode as fn } from "amazon-chime-sdk-js";
6
6
  import gn from "@realsee/jsbridge-x";
7
- import D, { createContext as pn, useCallback as W } from "react";
7
+ import D, { createContext as pn, useCallback as P } from "react";
8
8
  const dt = Symbol("$$REALSEE_LIVE_EVENT$$");
9
9
  function $t(i) {
10
10
  return i[dt] || (i[dt] = {}), i[dt];
11
11
  }
12
- function We(i) {
12
+ function Pe(i) {
13
13
  const t = i[dt];
14
14
  if (!t) return;
15
15
  Object.keys(t).some((n) => Array.isArray(t[n]) && t[n].length > 0) || delete i[dt];
@@ -63,11 +63,11 @@ class At {
63
63
  return;
64
64
  }
65
65
  if (n[t] || (n[t] = []), e === void 0) {
66
- n[t].length = 0, We(this);
66
+ n[t].length = 0, Pe(this);
67
67
  return;
68
68
  }
69
69
  const s = n[t].findIndex((r) => r[0] === e);
70
- s !== -1 && n[t].splice(s, 1), We(this);
70
+ s !== -1 && n[t].splice(s, 1), Pe(this);
71
71
  }
72
72
  /**
73
73
  * 触发事件
@@ -262,7 +262,7 @@ class mn extends Re {
262
262
  ), (r = this._trtc.client) == null || r.on("error", (o) => this.emit("error", o));
263
263
  }
264
264
  }
265
- class Pe extends Re {
265
+ class We extends Re {
266
266
  /**
267
267
  * 创建 BrowserRTC4Chime 实例
268
268
  *
@@ -709,7 +709,7 @@ class wn extends Re {
709
709
  return this.options.jsBridge;
710
710
  }
711
711
  }
712
- var B = /* @__PURE__ */ ((i) => (i.SelfUserInfo = "SELF_USER_INFO", i.RoomInfo = "ROOM_INFO", i.RTCInfo = "RTC_INFO", i.UserList = "USER_LIST", i.BuiltinMsg = "BUILTIN_MSG", i.CustomEvent = "CUSTOM_EVENT", i.KeyframeSync = "KEYFRAME_SYNC", i.UserKickOut = "USER_KICK_OUT", i))(B || {}), P = /* @__PURE__ */ ((i) => (i.UserChange = "user_change", i.RoomChange = "room_change", i))(P || {}), z = /* @__PURE__ */ ((i) => (i.UserMicroStatus = "change_micro_status", i.UserMicroStatusSync = "sync_micro_status", i.UserPermission = "change_permission", i.UserStatus = "change_status", i.UserInfo = "change_info", i.RoomClose = "close", i))(z || {}), ot = /* @__PURE__ */ ((i) => (i.OPEN = "OPEN", i.CLOSE = "CLOSE", i))(ot || {});
712
+ var B = /* @__PURE__ */ ((i) => (i.SelfUserInfo = "SELF_USER_INFO", i.RoomInfo = "ROOM_INFO", i.RTCInfo = "RTC_INFO", i.UserList = "USER_LIST", i.BuiltinMsg = "BUILTIN_MSG", i.CustomEvent = "CUSTOM_EVENT", i.KeyframeSync = "KEYFRAME_SYNC", i.UserKickOut = "USER_KICK_OUT", i))(B || {}), W = /* @__PURE__ */ ((i) => (i.UserChange = "user_change", i.RoomChange = "room_change", i))(W || {}), z = /* @__PURE__ */ ((i) => (i.UserMicroStatus = "change_micro_status", i.UserMicroStatusSync = "sync_micro_status", i.UserPermission = "change_permission", i.UserStatus = "change_status", i.UserInfo = "change_info", i.RoomClose = "close", i))(z || {}), ot = /* @__PURE__ */ ((i) => (i.OPEN = "OPEN", i.CLOSE = "CLOSE", i))(ot || {});
713
713
  function Mr(i) {
714
714
  try {
715
715
  const t = JSON.parse(i), e = {
@@ -1318,7 +1318,7 @@ class $n {
1318
1318
  this._observers = G();
1319
1319
  }
1320
1320
  }
1321
- const lt = Math.floor, Wt = Math.abs, pi = (i, t) => i < t ? i : t, St = (i, t) => i > t ? i : t, xn = (i) => i !== 0 ? i < 0 : 1 / i < 0, Je = 1, He = 2, he = 4, ue = 8, Bn = 32, _i = 64, Ht = 128, Fn = 31, qe = 63, Ot = 127, Wn = 2147483647, Pn = Number.isInteger || ((i) => typeof i == "number" && isFinite(i) && lt(i) === i), Kn = (i) => i.toLowerCase(), Gn = /^\s*/g, Jn = (i) => i.replace(Gn, ""), Hn = /([A-Z])/g, ze = (i, t) => Jn(i.replace(Hn, (e) => `${t}${Kn(e)}`)), qn = (i) => {
1321
+ const lt = Math.floor, Pt = Math.abs, pi = (i, t) => i < t ? i : t, St = (i, t) => i > t ? i : t, xn = (i) => i !== 0 ? i < 0 : 1 / i < 0, Je = 1, He = 2, he = 4, ue = 8, Bn = 32, _i = 64, Ht = 128, Fn = 31, qe = 63, Ot = 127, Pn = 2147483647, Wn = Number.isInteger || ((i) => typeof i == "number" && isFinite(i) && lt(i) === i), Kn = (i) => i.toLowerCase(), Gn = /^\s*/g, Jn = (i) => i.replace(Gn, ""), Hn = /([A-Z])/g, ze = (i, t) => Jn(i.replace(Hn, (e) => `${t}${Kn(e)}`)), qn = (i) => {
1322
1322
  const t = unescape(encodeURIComponent(i)), e = t.length, n = new Uint8Array(e);
1323
1323
  for (let s = 0; s < e; s++)
1324
1324
  n[s] = /** @type {number} */
@@ -1398,7 +1398,7 @@ Tt.encodeInto ? ts : es, De = (i, t) => {
1398
1398
  A(i, 119), ft(i, t);
1399
1399
  break;
1400
1400
  case "number":
1401
- Pn(t) && Wt(t) <= Wn ? (A(i, 125), Te(i, t)) : rs(t) ? (A(i, 124), is(i, t)) : (A(i, 123), ns(i, t));
1401
+ Wn(t) && Pt(t) <= Pn ? (A(i, 125), Te(i, t)) : rs(t) ? (A(i, 124), is(i, t)) : (A(i, 123), ns(i, t));
1402
1402
  break;
1403
1403
  case "bigint":
1404
1404
  A(i, 122), ss(i, t);
@@ -1446,7 +1446,7 @@ class Xe extends jt {
1446
1446
  const Ze = (i) => {
1447
1447
  i.count > 0 && (Te(i.encoder, i.count === 1 ? i.s : -i.s), i.count > 1 && S(i.encoder, i.count - 2));
1448
1448
  };
1449
- class Pt {
1449
+ class Wt {
1450
1450
  constructor() {
1451
1451
  this.encoder = new jt(), this.s = 0, this.count = 0;
1452
1452
  }
@@ -1492,7 +1492,7 @@ class fe {
1492
1492
  }
1493
1493
  class os {
1494
1494
  constructor() {
1495
- this.sarr = [], this.s = "", this.lensE = new Pt();
1495
+ this.sarr = [], this.s = "", this.lensE = new Wt();
1496
1496
  }
1497
1497
  /**
1498
1498
  * @param {string} string
@@ -1960,7 +1960,7 @@ class Ct extends $n {
1960
1960
  this.emit("destroyed", [!0]), this.emit("destroy", [this]), super.destroy();
1961
1961
  }
1962
1962
  }
1963
- class Ws {
1963
+ class Ps {
1964
1964
  constructor() {
1965
1965
  this.restEncoder = Le();
1966
1966
  }
@@ -1982,7 +1982,7 @@ class Ws {
1982
1982
  S(this.restEncoder, t);
1983
1983
  }
1984
1984
  }
1985
- class Ps extends Ws {
1985
+ class Ws extends Ps {
1986
1986
  /**
1987
1987
  * @param {ID} id
1988
1988
  */
@@ -2085,7 +2085,7 @@ class Ks {
2085
2085
  }
2086
2086
  class Gs extends Ks {
2087
2087
  constructor() {
2088
- super(), this.keyMap = /* @__PURE__ */ new Map(), this.keyClock = 0, this.keyClockEncoder = new fe(), this.clientEncoder = new Pt(), this.leftClockEncoder = new fe(), this.rightClockEncoder = new fe(), this.infoEncoder = new Xe(Ce), this.stringEncoder = new os(), this.parentInfoEncoder = new Xe(Ce), this.typeRefEncoder = new Pt(), this.lenEncoder = new Pt();
2088
+ super(), this.keyMap = /* @__PURE__ */ new Map(), this.keyClock = 0, this.keyClockEncoder = new fe(), this.clientEncoder = new Wt(), this.leftClockEncoder = new fe(), this.rightClockEncoder = new fe(), this.infoEncoder = new Xe(Ce), this.stringEncoder = new os(), this.parentInfoEncoder = new Xe(Ce), this.typeRefEncoder = new Wt(), this.lenEncoder = new Wt();
2089
2089
  }
2090
2090
  toUint8Array() {
2091
2091
  const t = Le();
@@ -2401,7 +2401,7 @@ const ci = (i, t) => t.deleteSet.clients.size === 0 && !Un(t.afterState, (e, n)
2401
2401
  y + 1 < w.length && Gt(w, y + 1) > 1 || y > 0 && Gt(w, y);
2402
2402
  }
2403
2403
  if (!e.local && e.afterState.get(n.clientID) !== e.beforeState.get(n.clientID) && (Vs(Ve, Si, "[yjs] ", Ci, Ei, "Changed the client-id because another client seems to be using it."), n.clientID = Ti()), n.emit("afterTransactionCleanup", [e, n]), n._observers.has("update")) {
2404
- const u = new Ps();
2404
+ const u = new Ws();
2405
2405
  ci(u, e) && n.emit("update", [u.toUint8Array(), e.origin, n, e]);
2406
2406
  }
2407
2407
  if (n._observers.has("updateV2")) {
@@ -2608,7 +2608,7 @@ const rr = (i) => {
2608
2608
  }, ie = (i, t) => {
2609
2609
  if (i._start === null || t === 0 || i._searchMarker === null)
2610
2610
  return null;
2611
- const e = i._searchMarker.length === 0 ? null : i._searchMarker.reduce((r, o) => Wt(t - r.index) < Wt(t - o.index) ? r : o);
2611
+ const e = i._searchMarker.length === 0 ? null : i._searchMarker.reduce((r, o) => Pt(t - r.index) < Pt(t - o.index) ? r : o);
2612
2612
  let n = i._start, s = 0;
2613
2613
  for (e !== null && (n = e.p, s = e.index, rr(e)); n.right !== null && s < t; ) {
2614
2614
  if (!n.deleted && n.countable) {
@@ -2622,7 +2622,7 @@ const rr = (i) => {
2622
2622
  n = n.left, !n.deleted && n.countable && (s -= n.length);
2623
2623
  for (; n.left !== null && n.left.id.client === n.id.client && n.left.id.clock + n.left.length === n.id.clock; )
2624
2624
  n = n.left, !n.deleted && n.countable && (s -= n.length);
2625
- return e !== null && Wt(e.index - s) < /** @type {YText|YArray<any>} */
2625
+ return e !== null && Pt(e.index - s) < /** @type {YText|YArray<any>} */
2626
2626
  n.parent.length / Ui ? (ji(e, n, s), e) : or(i._searchMarker, n, s);
2627
2627
  }, Nt = (i, t, e) => {
2628
2628
  for (let n = i.length - 1; n >= 0; n--) {
@@ -2878,9 +2878,9 @@ const $i = (i, t, e) => {
2878
2878
  }
2879
2879
  }
2880
2880
  }), u();
2881
- }, Wi = () => mt("Length exceeded!"), Pi = (i, t, e, n) => {
2881
+ }, Pi = () => mt("Length exceeded!"), Wi = (i, t, e, n) => {
2882
2882
  if (e > t._length)
2883
- throw Wi();
2883
+ throw Pi();
2884
2884
  if (e === 0)
2885
2885
  return t._searchMarker && Nt(t._searchMarker, e, n.length), zt(i, t, null, n);
2886
2886
  const s = e, r = ie(t, e);
@@ -2910,7 +2910,7 @@ const $i = (i, t, e) => {
2910
2910
  for (; n > 0 && c !== null; )
2911
2911
  c.deleted || (n < c.length && nt(i, k(c.id.client, c.id.clock + n)), c.delete(i), n -= c.length), c = c.right;
2912
2912
  if (n > 0)
2913
- throw Wi();
2913
+ throw Pi();
2914
2914
  t._searchMarker && Nt(
2915
2915
  t._searchMarker,
2916
2916
  s,
@@ -3071,7 +3071,7 @@ class Rt extends M {
3071
3071
  */
3072
3072
  insert(t, e) {
3073
3073
  this.doc !== null ? E(this.doc, (n) => {
3074
- Pi(
3074
+ Wi(
3075
3075
  n,
3076
3076
  this,
3077
3077
  t,
@@ -4326,7 +4326,7 @@ class wt extends M {
4326
4326
  */
4327
4327
  insert(t, e) {
4328
4328
  this.doc !== null ? E(this.doc, (n) => {
4329
- Pi(n, this, t, e);
4329
+ Wi(n, this, t, e);
4330
4330
  }) : this._prelimContent.splice(t, 0, ...e);
4331
4331
  }
4332
4332
  /**
@@ -5830,7 +5830,7 @@ class Ir extends At {
5830
5830
  case ct.RealseeVRWebViewRTC:
5831
5831
  return this._createVRWebViewRTC();
5832
5832
  case ct.RealseeBrowserChimeRTC:
5833
- return new Pe({
5833
+ return new We({
5834
5834
  getVoiceSign: (n = this._options.getVoiceSign) != null ? n : It,
5835
5835
  logLevel: e.__debug__ ? 0 : 1
5836
5836
  });
@@ -5878,7 +5878,7 @@ class Ir extends At {
5878
5878
  a(this, "_createDefaultRTC", (e) => {
5879
5879
  var s;
5880
5880
  const n = (s = this._options.getVoiceSign) != null ? s : It;
5881
- return !this._options.jsBridge || !Ge && !Ke ? e.builtInRTCType === fi.RealseeXChimeRTC ? new Pe({ getVoiceSign: n }) : this._createBrowserRTC() : Ge && (vn || In) || Ke ? this._createVRWebViewRTC() : this._createBrowserRTC();
5881
+ return !this._options.jsBridge || !Ge && !Ke ? e.builtInRTCType === fi.RealseeXChimeRTC ? new We({ getVoiceSign: n }) : this._createBrowserRTC() : Ge && (vn || In) || Ke ? this._createVRWebViewRTC() : this._createBrowserRTC();
5882
5882
  });
5883
5883
  /**
5884
5884
  * 自动连接(内部方法)
@@ -5993,7 +5993,7 @@ class Ir extends At {
5993
5993
  }
5994
5994
  case B.BuiltinMsg: {
5995
5995
  const p = u;
5996
- this.emit("builtinEvent", p), p.event_type === P.UserChange && this.emit("userChange", p), p.event_type === P.RoomChange && this.emit("roomChange", p), p.event_type === P.UserChange && p.action === z.UserMicroStatus && await this.toggleMicro(p.data.status === ot.OPEN), p.event_type === P.RoomChange && p.action === z.RoomClose && await this._exit();
5996
+ this.emit("builtinEvent", p), p.event_type === W.UserChange && this.emit("userChange", p), p.event_type === W.RoomChange && this.emit("roomChange", p), p.event_type === W.UserChange && p.action === z.UserMicroStatus && await this.toggleMicro(p.data.status === ot.OPEN), p.event_type === W.RoomChange && p.action === z.RoomClose && await this._exit();
5997
5997
  break;
5998
5998
  }
5999
5999
  case B.UserKickOut: {
@@ -6135,7 +6135,7 @@ class Ir extends At {
6135
6135
  } catch (n) {
6136
6136
  m.warn(n);
6137
6137
  }
6138
- await this.updateStatus(P.RoomChange, z.RoomClose, {});
6138
+ await this.updateStatus(W.RoomChange, z.RoomClose, {});
6139
6139
  });
6140
6140
  /**
6141
6141
  * 销毁带看实例
@@ -6184,7 +6184,7 @@ class Ir extends At {
6184
6184
  * })
6185
6185
  * ```
6186
6186
  */
6187
- a(this, "setSelfInfo", async (e) => await this.updateStatus(P.UserChange, z.UserInfo, e));
6187
+ a(this, "setSelfInfo", async (e) => await this.updateStatus(W.UserChange, z.UserInfo, e));
6188
6188
  /**
6189
6189
  * 自定义广播消息
6190
6190
  *
@@ -6269,7 +6269,7 @@ class Ir extends At {
6269
6269
  if (!((r = (s = this.selfInfo) == null ? void 0 : s.permission) != null && r.control_own_micro)) return !1;
6270
6270
  const n = await ((o = this.$RTC) == null ? void 0 : o.toggleMicro(e));
6271
6271
  return n && await this.updateStatus(
6272
- P.UserChange,
6272
+ W.UserChange,
6273
6273
  z.UserMicroStatus,
6274
6274
  {
6275
6275
  status: e ? ot.OPEN : ot.CLOSE
@@ -6302,7 +6302,7 @@ class Ir extends At {
6302
6302
  a(this, "forbidMicro", async (e, n) => {
6303
6303
  var s, r;
6304
6304
  return typeof this._options.canForbidUserMicro == "function" && !this._options.canForbidUserMicro(n) || !((r = (s = this.selfInfo) == null ? void 0 : s.permission) != null && r.control_other_micro) ? !1 : await this.updateStatus(
6305
- P.UserChange,
6305
+ W.UserChange,
6306
6306
  z.UserMicroStatus,
6307
6307
  {
6308
6308
  status: e
@@ -6330,7 +6330,7 @@ class Ir extends At {
6330
6330
  a(this, "forbidSync", async (e, n) => {
6331
6331
  var s, r;
6332
6332
  return typeof this._options.canForbidUserSync == "function" && !this._options.canForbidUserSync(n) || !((r = (s = this.selfInfo) == null ? void 0 : s.permission) != null && r.control_other_sync) ? !1 : await this.updateStatus(
6333
- P.UserChange,
6333
+ W.UserChange,
6334
6334
  z.UserPermission,
6335
6335
  { sync_frame: e },
6336
6336
  n
@@ -6360,7 +6360,7 @@ class Ir extends At {
6360
6360
  a(this, "kick", async (e) => {
6361
6361
  var n, s;
6362
6362
  return typeof this._options.canForbidUserKick == "function" && !this._options.canForbidUserKick(e) || !((s = (n = this.selfInfo) == null ? void 0 : n.permission) != null && s.change_other_status) ? !1 : await this.updateStatus(
6363
- P.UserChange,
6363
+ W.UserChange,
6364
6364
  z.UserStatus,
6365
6365
  {
6366
6366
  status: "KICK_OUT"
@@ -6552,52 +6552,52 @@ function Nr(i) {
6552
6552
  return D.useEffect(() => (b.keyframes.on(f, C), T), I), T;
6553
6553
  }
6554
6554
  function d() {
6555
- const f = r(), C = W(
6555
+ const f = r(), C = P(
6556
6556
  async (O) => {
6557
6557
  await f.connect(O);
6558
6558
  },
6559
6559
  [f]
6560
- ), R = W(
6560
+ ), R = P(
6561
6561
  (O) => {
6562
6562
  f.toggleMicro(O);
6563
6563
  },
6564
6564
  [f]
6565
- ), b = W(
6565
+ ), b = P(
6566
6566
  async (O, H, ce = 0) => {
6567
6567
  await f.broadcast(O, H, ce);
6568
6568
  },
6569
6569
  [f]
6570
- ), I = W(async () => {
6570
+ ), I = P(async () => {
6571
6571
  await f.exit();
6572
- }, [f]), T = W(
6572
+ }, [f]), T = P(
6573
6573
  async (O) => {
6574
6574
  await f.kick(O);
6575
6575
  },
6576
6576
  [f]
6577
- ), F = W(
6577
+ ), F = P(
6578
6578
  async (O, H = []) => {
6579
6579
  await f.forbidMicro(O, H);
6580
6580
  },
6581
6581
  [f]
6582
- ), rt = W(
6582
+ ), rt = P(
6583
6583
  (O, H = []) => {
6584
6584
  f.forbidSync(O, H);
6585
6585
  },
6586
6586
  [f]
6587
- ), oe = W(
6587
+ ), oe = P(
6588
6588
  (O) => f.getFramesByKey(O),
6589
6589
  [f]
6590
- ), en = W(
6590
+ ), en = P(
6591
6591
  (O, H) => {
6592
6592
  f.sendKeyframe(O, H);
6593
6593
  },
6594
6594
  [f]
6595
- ), nn = W(
6595
+ ), nn = P(
6596
6596
  (O) => {
6597
6597
  f.setSelfInfo(O);
6598
6598
  },
6599
6599
  [f]
6600
- ), sn = W(
6600
+ ), sn = P(
6601
6601
  (O, H, ce, rn) => {
6602
6602
  f.updateStatus(O, H, ce, rn);
6603
6603
  },
@@ -6695,15 +6695,15 @@ function Nr(i) {
6695
6695
  }
6696
6696
  const ye = globalThis.__REALSEE_LIVE_BADGE_LOG__;
6697
6697
  (ye == null || ye) && console.log(
6698
- "%c@realsee/live@0.7.5 (12/4/2025, 11:37:10 AM)",
6698
+ "%c@realsee/live@0.7.6 (12/4/2025, 12:08:28 PM)",
6699
6699
  "background: linear-gradient(to right, #1890ff, #52c41a); color: white; padding: 3px 6px; border-radius: 4px; font-weight: bold; text-shadow: 0 1px 0 rgba(0,0,0,0.2);"
6700
6700
  );
6701
6701
  export {
6702
6702
  mn as BrowserRTC,
6703
- Pe as BrowserRTC4Chime,
6703
+ We as BrowserRTC4Chime,
6704
6704
  fi as BuiltInRTCType,
6705
6705
  z as BuiltinActionType,
6706
- P as BuiltinEventType,
6706
+ W as BuiltinEventType,
6707
6707
  B as Command,
6708
6708
  Re as CoreRTC,
6709
6709
  Ir as Live,
package/docs/index.html CHANGED
@@ -1,5 +1,5 @@
1
1
  <!DOCTYPE html><html class="default" lang="en"><head><meta charset="utf-8"/><meta http-equiv="x-ua-compatible" content="IE=edge"/><title>如视 Live SDK</title><meta name="description" content="Documentation for 如视 Live SDK"/><meta name="viewport" content="width=device-width, initial-scale=1"/><link rel="stylesheet" href="assets/style.css"/><link rel="stylesheet" href="assets/highlight.css"/><link rel="stylesheet" href="assets/custom.css"/><script defer src="assets/main.js"></script><script async src="assets/icons.js" id="tsd-icons-script"></script><script async src="assets/search.js" id="tsd-search-script"></script><script async src="assets/navigation.js" id="tsd-nav-script"></script></head><body><script>document.documentElement.dataset.theme = localStorage.getItem("tsd-theme") || "os";document.body.style.display="none";setTimeout(() => app?app.showPage():document.body.style.removeProperty("display"),500)</script><header class="tsd-page-toolbar"><div class="tsd-toolbar-contents container"><div class="table-cell" id="tsd-search" data-base="."><div class="field"><label for="tsd-search-field" class="tsd-widget tsd-toolbar-icon search no-caption"><svg width="16" height="16" viewBox="0 0 16 16" fill="none"><use href="assets/icons.svg#icon-search"></use></svg></label><input type="text" id="tsd-search-field" aria-label="Search"/></div><div class="field"><div id="tsd-toolbar-links"></div></div><ul class="results"><li class="state loading">Preparing search index...</li><li class="state failure">The search index is not available</li></ul><a href="index.html" class="title">如视 Live SDK</a></div><div class="table-cell" id="tsd-widgets"><a href="#" class="tsd-widget tsd-toolbar-icon menu no-caption" data-toggle="menu" aria-label="Menu"><svg width="16" height="16" viewBox="0 0 16 16" fill="none"><use href="assets/icons.svg#icon-menu"></use></svg></a></div></div></header><div class="container container-main"><div class="col-content"><div class="tsd-page-title"><h1>如视 Live SDK</h1></div><div class="tsd-panel tsd-typography"><a id="md:livejs" class="tsd-anchor"></a><h1 class="tsd-anchor-link">Live.js<a href="#md:livejs" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h1><p><a href="https://www.npmjs.com/package/@realsee/live" target="_blank" class="external"><img src="https://img.shields.io/npm/v/@realsee/live.svg?style=flat-square&amp;logo=npm&amp;label=npm%20install%20@realsee/live" alt="npm version"></a></p>
2
- <a id="md:功能说明" class="tsd-anchor"></a><h2 class="tsd-anchor-link">功能说明<a href="#md:功能说明" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h2><p><strong>Live</strong> 是 <a href="https://developers.realsee.com/docs/#/docs/live/README" target="_blank" class="external">如视开发者中心 VRTC 服务</a> 的核心客户端 Web SDK,搭配 Live Container
2
+ <a id="md:功能说明" class="tsd-anchor"></a><h2 class="tsd-anchor-link">功能说明<a href="#md:功能说明" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h2><p><strong>Live</strong> 是 <a href="https://open-platform.realsee.com/developer/docs/live/intro/" target="_blank" class="external">如视开放平台线上带看</a> 的核心客户端 Web SDK,搭配 Live Container
3
3
  SDKs(iOS/Android/微信小程序)和 Live API 可以快速实现实时同屏、实时语音、IM 等功能。</p>
4
4
  <a id="md:名词释义" class="tsd-anchor"></a><h3 class="tsd-anchor-link">名词释义<a href="#md:名词释义" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h3><ul>
5
5
  <li><strong>帧数据(Keyframe)</strong>: 指用户界面需同屏交互信息的状态数据的集合。</li>
@@ -31,9 +31,12 @@ SDKs(iOS/Android/微信小程序)和 Live API 可以快速实现实时同屏
31
31
  <p>在创建 <code>live</code> 实例时配置了两个参数:</p>
32
32
  <ul>
33
33
  <li><code>url</code>:连接 WebSocket 服务的 URL(可选),如果在创建 <code>live</code> 实例阶段并不知道 URL,您可以在合适的时机通过 <code>live.connect({ url })</code> 方法进行 WebSocket 连接。</li>
34
- <li><code>getTicket()</code>:是一个异步回调函数(可选),其返回值是连接 WebSocket 服务的 <strong>&quot;门票&quot;</strong>,关于如何获取 <code>ticket</code> 请查阅 <a href="https://developers.realsee.com/docs/#/docs/live/server/README" target="_blank" class="external">VR 带看 API</a>。也可以在 <code>connect</code> 时提供。</li>
34
+ <li><code>getTicket()</code>:是一个异步回调函数(可选),其返回值是连接 WebSocket 服务的 <strong>&quot;门票&quot;</strong>,关于如何获取 <code>ticket</code> 请查阅 <a href="https://open-platform.realsee.com/developer/docs/live/intro/" target="_blank" class="external">如视开放平台带看文档</a>。也可以在 <code>connect</code> 时提供。</li>
35
35
  </ul>
36
36
  <blockquote>
37
+ <p><strong>提示</strong>:如果在创建实例时同时提供了 <code>url</code> 和 <code>getTicket</code>,Live 会自动尝试连接,无需手动调用 <code>connect()</code> 方法。</p>
38
+ </blockquote>
39
+ <blockquote>
37
40
  <p>关于 <code>createLive()</code> 函数的更多参数配置请参考 <a href="https://unpkg.com/@realsee/live/docs/interfaces/live.LiveOptions.html" target="_blank" class="external">LiveOptions</a> 文档。</p>
38
41
  </blockquote>
39
42
  <p>获取实例 <code>live</code> 之后,可以做很多有趣的事情。但在讲述详细用途之前,先简单介绍下 <strong>Live</strong> 中的 <strong>消息系统</strong>。</p>
@@ -135,8 +138,36 @@ SDKs(iOS/Android/微信小程序)和 Live API 可以快速实现实时同屏
135
138
  <p><code>error(liveMsg: LiveMsg): void</code> - 服务端推送出现异常</p>
136
139
  </li>
137
140
  </ul>
138
- <p><code>live</code> 实例提供了很多诸如<code>live.connect()</code>、<code>live.broadcast()</code>、<code>live.sendKeyframe()</code>等方法,这些方法都是异步反馈且可能会影响房间内的其他用户。
141
+ <p><code>live</code> 实例提供了很多诸如<code>live.connect()</code>、<code>live.broadcast()</code>、<code>live.sendKeyframe()</code>、<code>live.exit()</code>、<code>live.close()</code>、<code>live.dispose()</code>等方法,这些方法都是异步反馈且可能会影响房间内的其他用户。
139
142
  您可以通过监听以上事件来获知这些影响。</p>
143
+ <a id="md:主要方法说明" class="tsd-anchor"></a><h3 class="tsd-anchor-link">主要方法说明<a href="#md:主要方法说明" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h3><ul>
144
+ <li><code>connect(options?)</code> - 连接带看房间,建立 WebSocket 连接</li>
145
+ <li><code>exit()</code> - 退出带看房间(不发送房间关闭消息)</li>
146
+ <li><code>close()</code> - 关闭带看房间(会发送房间关闭消息,通知服务器)</li>
147
+ <li><code>dispose()</code> - 销毁带看实例,清理所有资源(事件监听、Yjs 文档等)</li>
148
+ <li><code>sendKeyframe(key, frame)</code> - 发送帧数据</li>
149
+ <li><code>getFramesByKey(key)</code> - 根据键获取对应的帧数据</li>
150
+ <li><code>broadcast(data, toUserIds, timeout?)</code> - 向指定用户广播消息</li>
151
+ <li><code>setSelfInfo(userInfo)</code> - 更新本地用户信息</li>
152
+ <li><code>toggleMicro(status)</code> - 切换麦克风状态</li>
153
+ <li><code>kick(toUserIds)</code> - 踢出指定用户</li>
154
+ <li><code>forbidMicro(status, toUserIds?)</code> - 禁止/允许指定用户的麦克风</li>
155
+ <li><code>forbidSync(sync, toUserIds?)</code> - 禁止/允许指定用户的帧数据同步</li>
156
+ <li><code>updateStatus(evtType, atnType, status, toUserIds?)</code> - 更新带看状态(用户或房间状态)</li>
157
+ </ul>
158
+ <a id="md:主要属性说明" class="tsd-anchor"></a><h3 class="tsd-anchor-link">主要属性说明<a href="#md:主要属性说明" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h3><ul>
159
+ <li><code>state</code> - 当前带看连接状态(LiveState)</li>
160
+ <li><code>readyState</code> - WebSocket 就绪状态</li>
161
+ <li><code>url</code> - WebSocket 连接 URL</li>
162
+ <li><code>options</code> - 配置选项(只读)</li>
163
+ <li><code>snapshot</code> - 当前所有帧数据的快照</li>
164
+ <li><code>selfInfo</code> - 本地用户信息</li>
165
+ <li><code>userList</code> - 房间内所有用户列表</li>
166
+ <li><code>roomInfo</code> - 房间信息</li>
167
+ <li><code>$RTC</code> - RTC 实例(用于语音通信)</li>
168
+ <li><code>jsBridge</code> - JSBridge 实例(用于 App/WebView 环境)</li>
169
+ <li><code>keyframes</code> - 帧数据监听器(Subscribe 实例)</li>
170
+ </ul>
140
171
  <a id="md:rtc-事件" class="tsd-anchor"></a><h3 class="tsd-anchor-link">RTC 事件<a href="#md:rtc-事件" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h3><p>RTC 相关事件通过 <code>live.$RTC.on('/*事件名*/', /*事件回调*/)</code> 方式来监听。</p>
141
172
  <ul>
142
173
  <li>
@@ -186,7 +217,7 @@ SDKs(iOS/Android/微信小程序)和 Live API 可以快速实现实时同屏
186
217
  <tr>
187
218
  <td>code</td>
188
219
  <td>string</td>
189
- <td>返回码,详情参照<a href="https://developers.realsee.com/docs/#/docs/live/server/README" target="_blank" class="external">服务端 API Code 码表</a></td>
220
+ <td>返回码,详情参照<a href="https://open-platform.realsee.com/developer/docs/live/intro/" target="_blank" class="external">如视开放平台带看文档</a></td>
190
221
  </tr>
191
222
  <tr>
192
223
  <td>command</td>
@@ -233,7 +264,7 @@ SDKs(iOS/Android/微信小程序)和 Live API 可以快速实现实时同屏
233
264
  <p>RTC 语音不同容器或 RTC 解决方案不同,其错误信息内容可能不完全一致。</p>
234
265
  </blockquote>
235
266
  <a id="md:rtc-协议" class="tsd-anchor"></a><h2 class="tsd-anchor-link">RTC 协议<a href="#md:rtc-协议" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h2><p>语音能力需依赖 WebView/Browser 容器,即需要容器端实现 RTC 能力。</p>
236
- <p>为了方便开发者接入,<strong>如视开发者中心 VRTC 服务</strong> 为主流平台提供 <a href="https://developers.realsee.com/docs/#/docs/live/client/container/README" target="_blank" class="external">容器 SDK</a>
267
+ <p>为了方便开发者接入,<strong>如视开放平台</strong> 为主流平台提供 <a href="https://open-platform.realsee.com/developer/docs/live/intro/" target="_blank" class="external">容器 SDK</a>
237
268
  和 <a href="https://www.npmjs.com/package/@realsee/jsbridge-x" target="_blank" class="external">jsbridge-x</a> 。</p>
238
269
  <p><strong>Live</strong> 通过 <strong>jsbridge-x</strong> 与 集成了<strong>容器 SDK</strong> 的客户端应用或微信小程序应用程序桥接,实现原生能力的调用。这个 <code>jsbridge-x</code>
239
270
  实例需作为配置参数提供给<code>createLive()</code>。</p>
@@ -306,6 +337,6 @@ SDKs(iOS/Android/微信小程序)和 Live API 可以快速实现实时同屏
306
337
  <a id="md:相关文档链接" class="tsd-anchor"></a><h2 class="tsd-anchor-link">相关文档链接<a href="#md:相关文档链接" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h2><ul>
307
338
  <li><a href="https://www.npmjs.com/package/@realsee/five" target="_blank" class="external">@realsee/five</a></li>
308
339
  <li><a href="https://www.npmjs.com/package/@realsee/jsbridge-x" target="_blank" class="external">@realsee/jsbridge-x</a></li>
309
- <li><a href="https://developers.realsee.com/docs/#/docs/live/README" target="_blank" class="external">如视开发者中心 VRTC 服务</a></li>
340
+ <li><a href="https://open-platform.realsee.com/developer/docs/live/intro/" target="_blank" class="external">如视开放平台线上带看</a></li>
310
341
  </ul>
311
- </div></div><div class="col-sidebar"><div class="page-menu"><div class="tsd-navigation settings"><details class="tsd-accordion"><summary class="tsd-accordion-summary"><h3><svg width="20" height="20" viewBox="0 0 24 24" fill="none"><use href="assets/icons.svg#icon-chevronDown"></use></svg>Settings</h3></summary><div class="tsd-accordion-details"><div class="tsd-filter-visibility"><span class="settings-label">Member Visibility</span><ul id="tsd-filter-options"><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-inherited" name="inherited" checked/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Inherited</span></label></li></ul></div><div class="tsd-theme-toggle"><label class="settings-label" for="tsd-theme">Theme</label><select id="tsd-theme"><option value="os">OS</option><option value="light">Light</option><option value="dark">Dark</option></select></div></div></details></div><details open class="tsd-accordion tsd-page-navigation"><summary class="tsd-accordion-summary"><h3><svg width="20" height="20" viewBox="0 0 24 24" fill="none"><use href="assets/icons.svg#icon-chevronDown"></use></svg>On This Page</h3></summary><div class="tsd-accordion-details"><a href="#md:livejs"><span>Live.js</span></a><ul><li><a href="#md:功能说明"><span>功能说明</span></a></li><li><ul><li><a href="#md:名词释义"><span>名词释义</span></a></li></ul></li><li><a href="#md:快速上手"><span>快速上手</span></a></li><li><ul><li><a href="#md:安装-sdk"><span>安装 SDK</span></a></li><li><a href="#md:如何使用"><span>如何使用</span></a></li></ul></li><li><a href="#md:消息系统"><span>消息系统</span></a></li><li><ul><li><a href="#md:帧数据同步"><span>帧数据同步</span></a></li><li><a href="#md:房间信息"><span>房间信息</span></a></li><li><a href="#md:广播消息"><span>广播消息</span></a></li></ul></li><li><a href="#md:事件监听"><span>事件监听</span></a></li><li><ul><li><a href="#md:带看连接状态"><span>带看连接状态</span></a></li><li><a href="#md:带看事件"><span>带看事件</span></a></li><li><a href="#md:rtc-事件"><span>RTC 事件</span></a></li><li><a href="#md:异常处理"><span>异常处理</span></a></li></ul></li><li><a href="#md:rtc-协议"><span>RTC 协议</span></a></li><li><a href="#md:浏览器端支持"><span>浏览器端支持</span></a></li><li><ul><li><a href="#md:trtc"><span>TRTC</span></a></li><li><a href="#md:chime"><span>Chime</span></a></li><li><a href="#md:使用内置的-jsbridge-和-rtc-实现"><span>使用内置的 <wbr/>Js<wbr/>Bridge 和 RTC 实现</span></a></li></ul></li><li><a href="#md:typescript--react-支持"><span>Type<wbr/>Script &amp; <wbr/>React 支持</span></a></li><li><ul><li><a href="#md:可用的-react-hooks"><span>可用的 <wbr/>React <wbr/>Hooks</span></a></li></ul></li><li><a href="#md:live-api-文档"><span>Live API 文档</span></a></li><li><a href="#md:相关文档链接"><span>相关文档链接</span></a></li></ul></div></details></div><div class="site-menu"><nav class="tsd-navigation"><a href="modules.html" class="current"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="assets/icons.svg#icon-1"></use></svg><span>如视 Live SDK</span></a><ul class="tsd-small-nested-navigation" id="tsd-nav-container" data-base="."><li>Loading...</li></ul></nav></div></div></div><footer></footer><div class="overlay"></div></body></html>
342
+ </div></div><div class="col-sidebar"><div class="page-menu"><div class="tsd-navigation settings"><details class="tsd-accordion"><summary class="tsd-accordion-summary"><h3><svg width="20" height="20" viewBox="0 0 24 24" fill="none"><use href="assets/icons.svg#icon-chevronDown"></use></svg>Settings</h3></summary><div class="tsd-accordion-details"><div class="tsd-filter-visibility"><span class="settings-label">Member Visibility</span><ul id="tsd-filter-options"><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-inherited" name="inherited" checked/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Inherited</span></label></li></ul></div><div class="tsd-theme-toggle"><label class="settings-label" for="tsd-theme">Theme</label><select id="tsd-theme"><option value="os">OS</option><option value="light">Light</option><option value="dark">Dark</option></select></div></div></details></div><details open class="tsd-accordion tsd-page-navigation"><summary class="tsd-accordion-summary"><h3><svg width="20" height="20" viewBox="0 0 24 24" fill="none"><use href="assets/icons.svg#icon-chevronDown"></use></svg>On This Page</h3></summary><div class="tsd-accordion-details"><a href="#md:livejs"><span>Live.js</span></a><ul><li><a href="#md:功能说明"><span>功能说明</span></a></li><li><ul><li><a href="#md:名词释义"><span>名词释义</span></a></li></ul></li><li><a href="#md:快速上手"><span>快速上手</span></a></li><li><ul><li><a href="#md:安装-sdk"><span>安装 SDK</span></a></li><li><a href="#md:如何使用"><span>如何使用</span></a></li></ul></li><li><a href="#md:消息系统"><span>消息系统</span></a></li><li><ul><li><a href="#md:帧数据同步"><span>帧数据同步</span></a></li><li><a href="#md:房间信息"><span>房间信息</span></a></li><li><a href="#md:广播消息"><span>广播消息</span></a></li></ul></li><li><a href="#md:事件监听"><span>事件监听</span></a></li><li><ul><li><a href="#md:带看连接状态"><span>带看连接状态</span></a></li><li><a href="#md:带看事件"><span>带看事件</span></a></li><li><a href="#md:主要方法说明"><span>主要方法说明</span></a></li><li><a href="#md:主要属性说明"><span>主要属性说明</span></a></li><li><a href="#md:rtc-事件"><span>RTC 事件</span></a></li><li><a href="#md:异常处理"><span>异常处理</span></a></li></ul></li><li><a href="#md:rtc-协议"><span>RTC 协议</span></a></li><li><a href="#md:浏览器端支持"><span>浏览器端支持</span></a></li><li><ul><li><a href="#md:trtc"><span>TRTC</span></a></li><li><a href="#md:chime"><span>Chime</span></a></li><li><a href="#md:使用内置的-jsbridge-和-rtc-实现"><span>使用内置的 <wbr/>Js<wbr/>Bridge 和 RTC 实现</span></a></li></ul></li><li><a href="#md:typescript--react-支持"><span>Type<wbr/>Script &amp; <wbr/>React 支持</span></a></li><li><ul><li><a href="#md:可用的-react-hooks"><span>可用的 <wbr/>React <wbr/>Hooks</span></a></li></ul></li><li><a href="#md:live-api-文档"><span>Live API 文档</span></a></li><li><a href="#md:相关文档链接"><span>相关文档链接</span></a></li></ul></div></details></div><div class="site-menu"><nav class="tsd-navigation"><a href="modules.html" class="current"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="assets/icons.svg#icon-1"></use></svg><span>如视 Live SDK</span></a><ul class="tsd-small-nested-navigation" id="tsd-nav-container" data-base="."><li>Loading...</li></ul></nav></div></div></div><footer></footer><div class="overlay"></div></body></html>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@realsee/live",
3
- "version": "0.7.5",
3
+ "version": "0.7.6",
4
4
  "description": "如视 Live SDK:基于如视 WebSocket 长链双工通信能力的前端封装,借助此 SDK 您可以快捷地实现具备同屏连线、实时语音的 VR 带看业务能力。",
5
5
  "author": "BEIKE REALSEE TECHNOLOGY (HK) LIMITED",
6
6
  "license": "SEE LICENSE IN TERMS.txt",