@realsee/live 0.6.12 → 0.6.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs.js +5 -5
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.es.js +191 -179
- package/dist/index.es.js.map +1 -1
- package/dist/live/createLiveReact.d.ts +1 -1
- package/dist/live/live.d.ts +6 -1
- package/docs/functions/createLiveReact.html +8 -8
- package/package.json +1 -1
package/dist/index.cjs.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var Ft=Object.defineProperty;var qt=(r,s,e)=>s in r?Ft(r,s,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[s]=e;var o=(r,s,e)=>(qt(r,typeof s!="symbol"?s+"":s,e),e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const Kt=require("@realsee/jsbridge-x"),Ae=require("trtc-js-sdk"),X=require("amazon-chime-sdk-js"),D=require("react"),ue=Symbol("$$REALSEE_LIVE_EVENT$$");function Ee(r){return r[ue]||(r[ue]={}),r[ue]}function Gt(r){r[ue]||delete r[ue]}class le{hasListener(s){const e=Ee(this);return e&&e[s]&&e[s].length>0}on(s,e,i){const n=Ee(this);return n[s]||(n[s]=[]),n[s].push([e,i||!1]),()=>this.off(s,e)}once(s,e){return this.on(s,e,!0)}off(s,e){if(s===void 0){Gt(this);return}const i=Ee(this);if(i[s]||(i[s]=[]),e===void 0){i[s].length=0;return}let n=0;for(;n<i[s].length&&i[s][n][0]!==e;n++);n<i[s].length&&i[s].splice(n,1)}emit(s,...e){let i=!1;const c=Ee(this)[s]||[];for(let u of c.slice()){const[d,g=!1]=u,v=d(...e);g&&this.off(s,d),v===!1&&(i=!0)}return i}}class Ce extends le{}var ee=(r=>(r.RealseeBrowserRTC="RealseeBrowserRTC",r.RealseeVRWebViewRTC="RealseeVRWebViewRTC",r.RealseeBrowserChimeRTC="RealseeBrowserChimeRTC",r))(ee||{}),Ue=(r=>(r.RealseeXTRTC="trtc",r.RealseeXChimeRTC="chime",r))(Ue||{});const Yt=()=>{const r=new Date,s=r.getFullYear(),e=(r.getMonth()+1).toString().padStart(2,"0"),i=r.getDate().toString().padStart(2,"0"),n=r.getHours().toString().padStart(2,"0"),c=r.getMinutes().toString().padStart(2,"0"),u=r.getSeconds().toString().padStart(2,"0"),d=r.getMilliseconds();return`[${s}-${e}-${i} ${n}:${c}:${u}.${d}]`},we=(r,s=[])=>{switch(s.unshift(`Realsee Live ${Yt()} <${r}> `),r){case"INFO":return console.info(...s);case"ERROR":return console.error(...s);case"WARN":return console.warn(...s);default:return console.log(...s)}},Ht=(...r)=>we("LOG",r),Jt=(...r)=>we("INFO",r),zt=(...r)=>we("ERROR",r),Xt=(...r)=>we("WARN",r),Zt={log:Ht,info:Jt,error:zt,warn:Xt},O=Zt;function Z(){return((1+Math.random())*65536|0).toString(16).substring(1)}function ye(){return(Z()+Z()+"-"+Z()+"-4"+Z().substr(0,3)+"-"+Z()+"-"+Z()+Z()+Z()).toLowerCase()}class De extends Ce{constructor(e){super();o(this,"type",ee.RealseeBrowserRTC);o(this,"joined",!1);o(this,"micro",!1);o(this,"voiceId","");o(this,"_getVoiceSign",()=>{throw new Error("方法 getVoiceSign 未实现")});o(this,"_autoPlayConfirm");o(this,"checkRequirement",()=>Ae.checkSystemRequirements());o(this,"$dom",document.createElement("div"));o(this,"_trtc",{client:null,stream:null});o(this,"join",async e=>{var c;this.emit("joinWillStart");const i=await this._getVoiceSign({voiceId:e.voiceId,roomId:e.roomId,userId:e.userId});this._trtc.client=Ae.createClient({mode:"rtc",...i,enableAutoPlayDialog:typeof this._autoPlayConfirm!="function"}),(c=this._trtc.client)==null||c.enableAudioVolumeEvaluation(),this._registerRtcEvent();let n=await new Promise(u=>{var d;(d=this._trtc.client)==null||d.join({roomId:Number(e.voiceId)}).then(()=>u(!0)).catch(()=>u(!1))});return this.joined=n,n?(this._trtc.stream=Ae.createStream({userId:i.userId,audio:!0,video:!1}),n=await new Promise(u=>{var d;(d=this._trtc.stream)==null||d.initialize().then(()=>u(!0)).catch(()=>u(!1))}),n=await new Promise(u=>{var d;(d=this._trtc.client)==null||d.publish(this._trtc.stream).then(()=>u(!0)).catch(()=>u(!1))}),this.joined=n,this.joined&&this.emit("joined"),n):!1});o(this,"_handleStreamAdded",e=>{var n;const i=e.stream;console.log("远端流增加: "+i.getId()),(n=this._trtc.client)==null||n.subscribe(i)});o(this,"_handleStreamSubscribed",e=>{const i=e.stream;console.log("远端流订阅成功:"+i.getId());const c=`rs-rtc-remote_stream-${i.getId()}`,u=document.createElement("div");u.id=c,this.$dom.appendChild(u),typeof this._autoPlayConfirm=="function"?(i.play(c).catch(d=>{}),i.on("error",d=>{if(d.getCode()===16451){const v=()=>i.resume();this._autoPlayConfirm({onConfirm:v})}})):i.play(c)});this._getVoiceSign=e.getVoiceSign,this._autoPlayConfirm=e.autoPlayConfirm,this._initParentDom()}_initParentDom(){this.$dom.id=`rs-rtc-${ye()}`,this.$dom.style.display="none",document.body.appendChild(this.$dom)}quit(){return new Promise(async e=>{var i,n;this.joined=!1,this._trtc.stream&&(await((i=this._trtc.client)==null?void 0:i.unpublish(this._trtc.stream)),this._trtc.stream.stop(),this._trtc.stream.close(),this._trtc.stream=null),(n=this._trtc.client)==null||n.leave().then(()=>this._trtc.client=null).then(()=>e(!0)).catch(()=>e(!1)),e(!0)})}detectMicro(){return new Promise(e=>{const i={audio:!0,video:!1};try{navigator.mediaDevices.getUserMedia(i).then(()=>e(!0)).catch(n=>{O.error(n.message),e(!1)})}catch(n){console.error(n),e(!1)}})}toggleMicro(e){var i,n,c,u;return Promise.resolve((e?(n=(i=this._trtc)==null?void 0:i.stream)==null?void 0:n.unmuteAudio():(u=(c=this._trtc)==null?void 0:c.stream)==null?void 0:u.muteAudio())||!1)}shock(){throw new Error("Method not implemented.")}_registerRtcEvent(){var e,i,n,c;(e=this._trtc.client)==null||e.on("stream-added",this._handleStreamAdded),(i=this._trtc.client)==null||i.on("stream-subscribed",this._handleStreamSubscribed),(n=this._trtc.client)==null||n.on("audio-volume",u=>this.emit("userVolumes",u.result.map(({userId:d,audioVolume:g})=>({userId:d,audioVolume:g})))),(c=this._trtc.client)==null||c.on("error",u=>this.emit("error",u))}}class Ve extends Ce{constructor(e){super();o(this,"type",ee.RealseeBrowserChimeRTC);o(this,"joined",!1);o(this,"micro",!1);o(this,"voiceId","");o(this,"userId","");o(this,"logger");o(this,"deviceController");o(this,"meetingSession");o(this,"audioInput");o(this,"audioOutput");o(this,"deviceChangeObserver",{});o(this,"audioVideoObserver",{});o(this,"audioMixObserver");o(this,"_getVoiceSign",()=>{throw new Error("方法 getVoiceSign 未实现")});o(this,"_autoPlayConfirm");o(this,"$dom",document.createElement("div"));o(this,"$audio",document.createElement("audio"));o(this,"_initDom",()=>{this.$audio.id=`rs-rtc-${ye()}`,this.$dom.id=`rs-rtc-${ye()}`,this.$dom.appendChild(this.$audio),document.body.appendChild(this.$dom)});o(this,"initObservers",()=>{this.deviceChangeObserver={audioInputsChanged:e=>{this.logger.info(`audioInputsChanged ${typeof e}`),e==null||e.forEach(i=>{this.logger.info(`Device ID: ${i.deviceId} Microphone: ${i.label}`)})},audioOutputsChanged:e=>{this.logger.info(`audioOutputsChanged ${typeof e}`),e==null||e.forEach(i=>{this.logger.info(`Device ID: ${i.deviceId} Speaker: ${i.label}`)})},audioInputMuteStateChanged:(e,i)=>{this.logger.info(`Device ${e.toString()} ${i?"is muted in hardware":"is not muted"}`)}},this.audioVideoObserver={audioVideoDidStart:()=>{this.logger.info("Started")},audioVideoDidStop:e=>{this.logger.info(`Stopped with a session status code: ${e.statusCode()}`)},audioVideoDidStartConnecting:e=>{e&&this.logger.info("Attempting to reconnect")}},this.audioMixObserver={meetingAudioStreamBecameActive:e=>{if(this.$audio.paused){const i=()=>this.$audio.play().then(()=>{}).catch(n=>{if(O.error("播放远端流失败!",n),typeof this._autoPlayConfirm=="function"){const c=()=>i();this._autoPlayConfirm({onConfirm:c})}});i()}},meetingAudioStreamBecameInactive:e=>{}}});o(this,"_registerRtcEvent",()=>{var i,n,c,u,d,g;const e=((c=(n=(i=this.meetingSession)==null?void 0:i.configuration)==null?void 0:n.credentials)==null?void 0:c.attendeeId)||"";if(e){const v=new Map,E=()=>{const y=[];return v.forEach((I,_)=>{y.push({userId:I.userId,volume:I.muted||I.signalStrength===0||!Boolean(I.volume)?0:I.volume})}),y};(u=this.meetingSession)==null||u.audioVideo.realtimeSubscribeToAttendeeIdPresence((y,I,_)=>{var V;if(!I){v.delete(y),this.emit("userVolumes",E());return}(V=this.meetingSession)==null||V.audioVideo.realtimeSubscribeToVolumeIndicator(y,(C,k,B,P)=>{new X.DefaultModality(C).base()===C&&(v.set(C,{userId:_||C,volume:k,muted:B,signalStrength:P}),this.emit("userVolumes",E()))})}),(d=this.meetingSession)==null||d.audioVideo.realtimeSubscribeToVolumeIndicator(e,(y,I,_,V)=>{new X.DefaultModality(y).base()===y&&V!==null&&V!==1&&this.emit("weakNetwork")}),(g=this.meetingSession)==null||g.audioVideo.realtimeSubscribeToFatalError(y=>this.emit("error",y))}});this._getVoiceSign=e.getVoiceSign,this._autoPlayConfirm=e.autoPlayConfirm,this._initDom(),this.logger=new X.ConsoleLogger("WebRTCLogger",e.logLevel||X.LogLevel.INFO),this.deviceController=new X.DefaultDeviceController(this.logger),this.initObservers()}async join(e){return new Promise(async(i,n)=>{var c,u;this.emit("joinWillStart");try{const{sdkAppId:d,userId:g,roomId:v,userSig:E}=await this._getVoiceSign({...e,roomId:e.roomId||0});this.userId=g;const{attendence:y,vendor_wrapper:I}=JSON.parse(decodeURIComponent(E)),_=new X.MeetingSessionConfiguration({Meeting:I},{Attendee:{ExternalUserId:y.external_user_id,AttendeeId:y.attendee_id,JoinToken:y.join_token}});this.meetingSession=new X.DefaultMeetingSession(_,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 V={audioVideoDidStart:()=>{var C;(C=this.meetingSession)==null||C.audioVideo.realtimeMuteLocalAudio(),this.joined=!0,this.emit("joined"),i(!0)},audioVideoDidStop:()=>{this.joined=!1,i(!1)}};this.meetingSession.audioVideo.addObserver(V),this.audioMixObserver&&this.meetingSession.audioVideo.addAudioMixObserver(this.audioMixObserver),this.meetingSession.audioVideo.setDeviceLabelTrigger(async()=>await navigator.mediaDevices.getUserMedia({audio:!0,video:!1}));try{const C=await this.meetingSession.audioVideo.listAudioInputDevices();O.info("audioInputDevices ===>",C);const k=((c=C[0])==null?void 0:c.deviceId)||"default";await this.meetingSession.audioVideo.startAudioInput(k)}catch(C){O.error(`设置语音输入设备失败:${C.message}`)}try{const C=await this.meetingSession.audioVideo.listAudioOutputDevices();O.info("audioOutputDevices ===>",C);const k=((u=C[0])==null?void 0:u.deviceId)||"default";await this.meetingSession.audioVideo.chooseAudioOutput(k)}catch(C){O.error(`设置语音输出设备失败:${C.message}`)}this.meetingSession.audioVideo.start()}catch(d){this.emit("error",d),this.logger.error(d.message),i(!1)}})}quit(){return this.joined?new Promise((e,i)=>{var c,u;this.joined=!1;const n={audioVideoDidStop:async d=>{var v;const g=d.statusCode();(v=this.meetingSession)==null||v.deviceController.destroy(),g===X.MeetingSessionStatusCode.Left?(this.logger.info("You left the session"),e(!0)):(this.logger.info(`Stopped with a session status code: ${g}`),e(!0))}};(c=this.meetingSession)==null||c.audioVideo.addObserver(n),(u=this.meetingSession)==null||u.audioVideo.stop()}):Promise.resolve(!0)}async detectMicro(){return new Promise(e=>{const i={audio:!0,video:!1};try{navigator.mediaDevices.getUserMedia(i).then(()=>e(!0)).catch(()=>e(!1))}catch(n){this.logger.error(n.message),e(!1)}})}async toggleMicro(e){var n,c,u;e?(n=this.meetingSession)==null||n.audioVideo.realtimeUnmuteLocalAudio():(c=this.meetingSession)==null||c.audioVideo.realtimeMuteLocalAudio();const i=(u=this.meetingSession)==null?void 0:u.audioVideo.realtimeIsLocalAudioMuted();return i!==void 0?e!==i:!1}shock(){throw new Error("Method not implemented.")}}var Be=(r=>(r[r.Success=0]="Success",r[r.Failure=1]="Failure",r[r.ReJoin=2]="ReJoin",r[r.NoMicroPermission=3]="NoMicroPermission",r))(Be||{});class $e extends Ce{constructor({jsBridge:e,getVoiceSign:i}){super();o(this,"type",ee.RealseeVRWebViewRTC);o(this,"joined",!1);o(this,"micro",!1);o(this,"voiceId","");o(this,"options");this.options={jsBridge:e,getVoiceSign:i},this.jsBridge.webViewType!=="WxMiniProgramWebView"&&this.jsBridge.callAndListen("live/userVolumes",n=>{this.emit("userVolumes",n)}),this.jsBridge.callAndListen("live/weakNetwork",n=>{n&&this.emit("weakNetwork")})}get jsBridge(){return this.options.jsBridge}async join(e){try{this.emit("joinWillStart");const{sdkAppId:i,userId:n,userSig:c}=await this.options.getVoiceSign(e);if(!(Boolean(i)&&Boolean(n)&&Boolean(c)))return this.emit("error",new Error("加入房间失败:rtc 签名请求异常")),this.joined=!1,this.joined;this.type=e.type;const[u,d]=await this.jsBridge.callAndBackfeed(`live/join?sdkAppID=${i}&userID=${n}&roomID=${Number(e.voiceId)}&userSig=${c}`);return u===!0?(this.emit("joined"),this.joined=!0):u?u.code===Be.Success?(this.emit("joined"),this.joined=!0):(this.emit("error",u),this.joined=!1):(this.emit("error",d||new Error("加入房间失败:未知异常。")),this.joined=!1),this.joined}catch(i){return this.emit("error",new Error("加入房间失败:"+i.message)),this.joined=!1,this.joined}}async quit(){const[e,i]=await this.jsBridge.callAndBackfeed("live/quit");return e===null&&this.emit("error",i||new Error("退出房间失败:未知异常。")),this.joined=!1,!!e}async detectMicro(){const[e,i]=await this.jsBridge.detectMicro();return e===null?(this.emit("error",i||new Error("麦克风监测异常!")),!1):e}async toggleMicro(e){const[i,n]=await this.jsBridge.callAndBackfeed(`live/toggleMicro?flag=${e?1:0}`);return i===null?(this.emit("error",n||new Error("麦克风监测异常!")),!1):(this.micro=i,i)}shock(){this.jsBridge.shock(1)}}var U=(r=>(r.SelfUserInfo="SELF_USER_INFO",r.RoomInfo="ROOM_INFO",r.RTCInfo="RTC_INFO",r.UserList="USER_LIST",r.BuiltinMsg="BUILTIN_MSG",r.CustomEvent="CUSTOM_EVENT",r.KeyframeSync="KEYFRAME_SYNC",r.UserKickOut="USER_KICK_OUT",r))(U||{}),K=(r=>(r.UserChange="user_change",r.RoomChange="room_change",r))(K||{}),Y=(r=>(r.UserMicroStatus="change_micro_status",r.UserMicroStatusSync="sync_micro_status",r.UserPermission="change_permission",r.UserStatus="change_status",r.UserInfo="change_info",r.RoomClose="close",r))(Y||{}),Q=(r=>(r.OPEN="OPEN",r.CLOSE="CLOSE",r))(Q||{});function Qt(r){try{const s=JSON.parse(r),e={code:s.code,message:s.message,command:s.command,roomCode:s.room_code,appID:s.app_id,requestId:s.request_id,frontRequestId:s.front_request_id,triggerUserID:s.trigger_user_id,data:s.data||{}},i=Object.keys(e).filter(n=>e[n]===void 0);return i.length>0&&console.warn(`推送数据格式异常:${i.join(" ")} 值不存在!`),e}catch(s){return!1}}var $=(r=>(r[r.NOTINITIALIZED=-1]="NOTINITIALIZED",r[r.CONNECTING=0]="CONNECTING",r[r.OPEN=1]="OPEN",r[r.CLOSED=3]="CLOSED",r))($||{}),ft=(r=>(r[r.Normal=0]="Normal",r[r.Removed=1]="Removed",r[r.Replaced=2]="Replaced",r))(ft||{}),dt=(r=>(r.WAIT_ENTER="WAIT_ENTER",r.ONLINE="ONLINE",r.LEAVE="LEAVE",r.KICK_OUT="KICK_OUT",r.BE_REPLACE="BE_REPLACE",r.EXCEPTION="EXCEPTION",r))(dt||{}),be=(r=>(r[r.NOTINITIALIZED=-1]="NOTINITIALIZED",r[r.CONNECTING=0]="CONNECTING",r[r.OPEN=1]="OPEN",r[r.CLOSING=2]="CLOSING",r[r.CLOSED=3]="CLOSED",r))(be||{}),ht=(r=>(r.Error="Error",r.Close="Close",r.MicroAuth="MicroAuth",r.DuplicateConnect="DuplicateConnect",r.IllegalURL="IllegalURL",r.Unknown="Unknown",r.IllegalArgs="IllegalArgs",r))(ht||{}),_t=(r=>(r.Err_1000="CLOSE_NORMAL",r.Err_1001="CLOSE_GOING_AWAY",r.Err_1002="CLOSE_PROTOCOL_ERROR",r.Err_1003="CLOSE_UNSUPPORTED",r.Err_1006="CLOSE_ABNORMAL",r.Err_1007="Unsupported Data",r.Err_1008="Policy Violation",r.Err_1009="CLOSE_TOO_LARGE",r.Err_unknown="unknown",r))(_t||{});function gt(r){switch(r){case 1e3:return"CLOSE_NORMAL";case 1001:return"CLOSE_GOING_AWAY";case 1002:return"CLOSE_PROTOCOL_ERROR";case 1003:return"CLOSE_UNSUPPORTED";case 1006:return"CLOSE_ABNORMAL";case 1007:return"Unsupported Data";case 1008:return"Policy Violation";case 1009:return"CLOSE_TOO_LARGE"}return"unknown"}function er(r){return r&&r.__esModule&&Object.prototype.hasOwnProperty.call(r,"default")?r.default:r}var mt={};(function(r){Object.defineProperty(r,"__esModule",{value:!0}),r.LogLevel=void 0;var s;(function(e){e[e.DEBUG=0]="DEBUG",e[e.INFO=1]="INFO",e[e.WARN=2]="WARN",e[e.ERROR=3]="ERROR",e[e.OFF=4]="OFF"})(s=r.LogLevel||(r.LogLevel={})),r.default=s})(mt);const at=er(mt);function tr(r,s={}){const e=r.indexOf("?")!==-1,i=Object.keys(s).reduce((n,c,u)=>`${n}${u===0&&!e?"?":"&"}${c}=${s[c]}`,"");return r+i}const fe=globalThis.navigator.userAgent,rr=/android/gi.test(fe),ir=/iPhone|iPad\s+OS/gi.test(fe),nr=/MicroMessenger/gi.test(fe)&&/miniProgram/gi.test(fe),sr=/realsee/gi.test(fe);function Se(r){return Object.prototype.toString.call(r)==="[object Object]"}function Re(r,s){return r===s?!0:typeof r!=typeof s?!1:!!(Number.isNaN(r)&&Number.isNaN(s))}function or(r,s){const e=Object.getOwnPropertyNames(r),i=Object.getOwnPropertyNames(s);if(e.length!==i.length)return!1;for(let n=0,c=e.length;n<c;n++){const u=e[n];if(!Re(r[u],s[u]))return!1}return!0}function ar(r,s){if(r.length!==s.length)return!1;for(let e=0,i=r.length;e<i;e++)if(!Re(r[e],s[e]))return!1;return!0}function cr(r,s){return Re(r,s)?!0:Se(r)&&Se(s)?or(r,s):Array.isArray(r)&&Array.isArray(s)?ar(r,s):!1}function We(r,s){return Re(r,s)?!0:Se(r)&&Se(s)?lr(r,s):Array.isArray(r)&&Array.isArray(s)?ur(r,s):!1}function ur(r,s){if(r.length!==s.length)return!1;for(let e=0,i=r.length;e<i;e++)if(!We(r[e],s[e]))return!1;return!0}function lr(r,s){const e=Object.getOwnPropertyNames(r),i=Object.getOwnPropertyNames(s);if(e.length!==i.length)return!1;for(let n=0,c=e.length;n<c;n++){const u=e[n];if(!We(r[u],s[u]))return!1}return!0}function ct(r,s,e={deep:!1}){return e.deep?We(r,s):cr(r,s)}class fr extends le{constructor(e){super();o(this,"_realWebSocket");o(this,"_url");o(this,"_protocols");o(this,"_readyState",be.NOTINITIALIZED);o(this,"_options",{timeout:1e4,shouldReconnect:(e,i)=>{if(!(e.code===1008||e.code===1011))return[0,1e3,2e3][i.attempts%3]},should1000Reconnect:!1,ignoreConnectivityEvents:!1,automaticOpen:!1});o(this,"_connectTimeout");o(this,"_attempts",0);o(this,"_reconnects",-1);o(this,"_reconnectWhenOnlineAgain",!1);o(this,"_explicitlyClosed",!1);o(this,"_pendingReconnect");o(this,"_connectivityEventsAttached",!1);o(this,"_heathCheckTimer");o(this,"_healthCheck",async()=>{this._realWebSocket&&this._realWebSocket.readyState!==this._readyState&&(this._readyState=this._realWebSocket.readyState,this._readyState===be.CLOSING&&this.emit("closing")),await new Promise(e=>setTimeout(e,2e3)),this._heathCheckTimer=requestAnimationFrame(this._healthCheck)});o(this,"_clearConnectTimeoutIfNeed",()=>{this._connectTimeout&&(clearTimeout(this._connectTimeout),this._connectTimeout=void 0)});o(this,"_clearHeathCheckIfNeed",()=>{this._heathCheckTimer&&(cancelAnimationFrame(this._heathCheckTimer),this._heathCheckTimer=void 0)});o(this,"_startHealthCheck",()=>{this._clearHeathCheckIfNeed(),this._heathCheckTimer=requestAnimationFrame(this._healthCheck)});o(this,"_stopHealthCheck",()=>{this._clearHeathCheckIfNeed()});o(this,"_clearPendingReconnectIfNeeded",()=>{this._pendingReconnect&&(clearTimeout(this._pendingReconnect),this._pendingReconnect=void 0)});o(this,"_online",e=>{this._reconnectWhenOnlineAgain&&(this._clearPendingReconnectIfNeeded(),this._reconnect(e))});o(this,"_offline",()=>{var e;this._reconnectWhenOnlineAgain=!0,(e=this._realWebSocket)==null||e.close(1e3,"offline")});o(this,"_detachConnectivityEvents",()=>{this._connectivityEventsAttached&&(globalThis==null||globalThis.removeEventListener("online",this._online),globalThis==null||globalThis.removeEventListener("offline",this._offline),this._connectivityEventsAttached=!1)});o(this,"_attachConnectivityEvents",()=>{this._connectivityEventsAttached||(globalThis==null||globalThis.addEventListener("online",this._online),globalThis==null||globalThis.addEventListener("offline",this._offline),this._connectivityEventsAttached=!0)});o(this,"send",e=>{var i,n,c;((i=this._realWebSocket)==null?void 0:i.readyState)===((n=this._realWebSocket)==null?void 0:n.OPEN)&&((c=this._realWebSocket)==null||c.send(e))});o(this,"close",(e,i)=>{var n;return typeof e!="number"&&(i=e,e=1e3),this._clearPendingReconnectIfNeeded(),this._reconnectWhenOnlineAgain=!1,this._explicitlyClosed=!0,this._detachConnectivityEvents(),(n=this._realWebSocket)==null?void 0:n.close(e,i)});o(this,"open",e=>{var i,n;e&&(this._url=e),((i=this._realWebSocket)==null?void 0:i.readyState)!==WebSocket.OPEN&&((n=this._realWebSocket)==null?void 0:n.readyState)!==WebSocket.CONNECTING&&(this._clearPendingReconnectIfNeeded(),this._reconnectWhenOnlineAgain=!1,this._explicitlyClosed=!1,this._createWebSocket())});o(this,"_createWebSocket",()=>{var n,c,u;const e=typeof this._url=="string"?this._url:(n=this._url)==null?void 0:n.call(this,this);if(!e)return;this._clearConnectTimeoutIfNeed(),this._clearPendingReconnectIfNeeded(),this._removeWebSocketEvent(),this._realWebSocket=new WebSocket(e,this._protocols||void 0),this._attempts=this._attempts+1,this.emit("connecting",new CustomEvent("connecting",{detail:{attempts:this._attempts,reconnects:this._reconnects}}));const i=()=>{this._connectTimeout=void 0,this._detachConnectivityEvents(),this.emit("timeout",new CustomEvent("timeout",{detail:{attempts:this._attempts,reconnects:this._reconnects}}))};this._connectTimeout=setTimeout(i,(c=this._options)==null?void 0:c.timeout),this._dispatchWebSocketEvent(),(u=this._options)!=null&&u.ignoreConnectivityEvents||this._attachConnectivityEvents()});o(this,"_removeWebSocketEvent",()=>{var e,i,n,c;(e=this._realWebSocket)==null||e.removeEventListener("open",this._webSocketOpenHandler),(i=this._realWebSocket)==null||i.removeEventListener("close",this._webSocketCloseHandler),(n=this._realWebSocket)==null||n.removeEventListener("error",this._webSocketErrorHandler),(c=this._realWebSocket)==null||c.removeEventListener("message",this._webSocketMessageHandler)});o(this,"_dispatchWebSocketEvent",()=>{var e,i,n,c;(e=this._realWebSocket)==null||e.addEventListener("open",this._webSocketOpenHandler),(i=this._realWebSocket)==null||i.addEventListener("close",this._webSocketCloseHandler),(n=this._realWebSocket)==null||n.addEventListener("error",this._webSocketErrorHandler),(c=this._realWebSocket)==null||c.addEventListener("message",this._webSocketMessageHandler)});o(this,"_webSocketOpenHandler",e=>{this._connectTimeout&&(clearTimeout(this._connectTimeout),this._connectTimeout=void 0);const i=++this._reconnects,n=this._attempts;return this._attempts=0,this._reconnectWhenOnlineAgain=!1,this._startHealthCheck(),this.emit("open",Object.assign(e,{detail:{reconnects:i,attempts:n}}))});o(this,"_webSocketCloseHandler",e=>(this._reconnect(e),this._stopHealthCheck(),this.emit("close",e)));o(this,"_webSocketErrorHandler",e=>this.emit("error",new CustomEvent("error",{detail:{error:e}})));o(this,"_webSocketMessageHandler",e=>this.emit("message",e));e&&this.setOptions(e),this._startHealthCheck()}get attempts(){return this._attempts}setOptions(e){if(!e)return;this._url=e.url,this._protocols=e.protocols;const i=Object.assign(this._options,e.robustOptions||{});if(typeof(i==null?void 0:i.timeout)!="number")throw new Error("timeout must be the number of milliseconds to timeout a connection attempt");if(typeof(i==null?void 0:i.shouldReconnect)!="function")throw new Error("shouldReconnect must be a function that returns the number of milliseconds to wait for a reconnect attempt, or null or undefined to not reconnect.");this._options=i,this._options.automaticOpen&&this._createWebSocket()}_reconnect(e){var n,c,u,d;if(!((n=this._options)!=null&&n.should1000Reconnect)&&e.code===1e3||this._explicitlyClosed){this._attempts=0;return}if(this._connectivityEventsAttached&&((c=globalThis==null?void 0:globalThis.navigator)==null?void 0:c.onLine)===!1){this._reconnectWhenOnlineAgain=!0;return}const i=(d=(u=this._options)==null?void 0:u.shouldReconnect)==null?void 0:d.call(u,e,this);typeof i=="number"&&(this._pendingReconnect=setTimeout(this._createWebSocket,i))}}class dr extends le{constructor(){super();o(this,"_ws",new fr({url:"",robustOptions:{should1000Reconnect:!0,ignoreConnectivityEvents:!0}}));o(this,"_state",$.NOTINITIALIZED);o(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)});o(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)});o(this,"_handleCloseEvent",e=>{O.info(`live room closed bacause of ${e.code}-${e.reason||gt(e.code)}`),this.state=$.CLOSED});o(this,"_handleClosingEvent",()=>{var e;O.info("live room is closing, onLine:",(e=globalThis==null?void 0:globalThis.navigator)==null?void 0:e.onLine),this.state=$.CLOSED});o(this,"_handleConnectingEvent",()=>{O.info("live room is connecting"),this.state=$.CONNECTING});o(this,"_handleErrorEvent",e=>{O.error("live room error",e),this.state=$.CLOSED});o(this,"_handleMessageEvent",e=>{let i=(()=>{try{return JSON.parse(e.data)}catch(n){return e.data}})();this.emit("message",i)});o(this,"_handleOpenEvent",e=>{O.info("live room open",e.detail),this.state=$.OPEN,e.detail.reconnects>0&&this.emit("reconnected",e.detail)});o(this,"_handleTimeoutEvent",e=>{O.error("live room connect timeout!",e.detail),this.state=$.CLOSED});o(this,"dispose",async()=>(this._removeWebSocketEventListeners(),await this.close("live room close by controller disposed!")));o(this,"open",e=>this._ws.open(e));o(this,"close",(e,i)=>new Promise(n=>{this._ws.once("close",()=>n(!0)),this._ws.close(e,i)}));this._addWebSocketEventListeners()}set state(e){const i=JSON.parse(JSON.stringify(this._state));this._state=e,this.emit("stateChange",this.state,i)}get state(){return this._state}sendMessage(e=""){if(e==null||e==="")throw new Error("live message is empty!");if(this.state===$.OPEN)return this._ws.send(JSON.stringify(e));throw new Error("live has not yet been initialized!")}readyClose(){this._ws&&(this._ws._explicitlyClosed=!0)}}const hr=r=>Promise.reject("unimplemented method GetVoiceSign"),Me=(r,s={},e=[])=>({command:r,front_request_id:ye(),data:{...s,to_user_ids:Array.isArray(e)?e:[e]}}),_r=()=>{var r,s;window!=null&&window.__Realsee_Live__&&((s=(r=window==null?void 0:window.__Realsee_Live__)==null?void 0:r.dispose)==null||s.call(r),window.__Realsee_Live__=null)};class gr extends le{constructor(e){var i;super();o(this,"_options",{});o(this,"keyframes",new le);o(this,"_buildInData",{keyframes:{}});o(this,"getFramesByKey",e=>this.snapshot[e]);o(this,"sendKeyframe",(e,i)=>{if(this.state!==$.OPEN)return!1;this._buildInData.keyframes={...this._buildInData.keyframes,[e]:i};const n=Me(U.KeyframeSync,this.snapshot);try{return this._controller.sendMessage(n),!0}catch(c){return O.error(c),!1}});o(this,"_controller",new dr);o(this,"_addLiveControllerEventListeners",()=>{this._controller.on("stateChange",this._handleStateChange),this._controller.on("message",this._handleMessage)});o(this,"_removeLiveControllerEventListeners",()=>{this._controller.off("stateChange",this._handleStateChange),this._controller.off("message",this._handleMessage)});o(this,"_handleStateChange",(e,i)=>this.emit("stateChange",e,i));o(this,"_handleMessage",async e=>{var i,n,c,u,d;if(typeof e=="object"){const{command:g,data:v={},frontRequestId:E,code:y,message:I}=e;if(y==="SUCCESS")switch(g){case U.SelfUserInfo:{const _=v;ct(this.selfInfo,_,{deep:!0})||(this._buildInData.selfInfo=_,this.emit("selfInfoUpdate",this._buildInData.selfInfo,E));break}case U.RoomInfo:{const _=v;this._buildInData.roomInfo=Object.assign({},_),this.emit("readyKeyframeSync",_.last_frame||{});break}case U.RTCInfo:{const{voice_id:_,type:V}=v;if(this._buildInData.rtcInfo={voiceId:_,type:V},(i=this.$RTC)!=null&&i.joined)O.warn("已加入语音房间,无需重复加入!");else if(await((u=this.$RTC)==null?void 0:u.join({voiceId:_,userId:((n=this.selfInfo)==null?void 0:n.id)||"",roomId:(c=this.roomInfo)==null?void 0:c.info.room_code,type:V}))){const k=(d=this._options.initialMicroStatus)!=null?d:Q.OPEN;await this.toggleMicro(k===Q.OPEN)}else O.error("加入语音房间失败");break}case U.UserList:{const _=v;this._buildInData.userList=_,this.emit("userListUpdate",this.userList,E);break}case U.CustomEvent:{const _=v;this.emit("broadcast",_,E);break}case U.KeyframeSync:{const _=v,V=Object.keys(_).reduce((C,k)=>{if(ct(_[k],this._buildInData.keyframes[k],{deep:!0}))return C;const B=[_[k],this._buildInData.keyframes[k],E],P=k;return this.keyframes.emit(P,...B),this._buildInData.keyframes[k]=_[k],C[k]=_[k],C},{});this.emit("keyframes",V,E);break}case U.BuiltinMsg:{const _=v;this.emit("builtinEvent",_),_.event_type===K.UserChange&&this.emit("userChange",_),_.event_type===K.RoomChange&&this.emit("roomChange",_),_.event_type===K.UserChange&&_.action===Y.UserMicroStatus&&await this.toggleMicro(_.data.status===Q.OPEN),_.event_type===K.RoomChange&&_.action===Y.RoomClose&&await this.exit();break}case U.UserKickOut:{this.emit("kickOut");break}default:console.warn("unknown command: ",g)}else this.emit("error",e)}});o(this,"_clearLiveData",()=>{this._buildInData={keyframes:{}}});o(this,"connect",async(e={})=>{var u,d,g,v;if(this._options.url=(d=(u=e.url)!=null?u:this._options.url)!=null?d:"",this._options.getTicket=(g=e.getTicket)!=null?g:this._options.getTicket,this._options.initialMicroStatus=(v=e.rtcMicStatus)!=null?v:this._options.initialMicroStatus,!/^ws(s):\/\//.test(this._options.url)||typeof this._options.getTicket!="function")return/^ws(s):\/\//.test(this._options.url)?typeof this._options.getTicket!="function"?new Error("getTicket muse be function"):!1:new Error("Illegal realsee live room link");const{force:i=!1}=e;if(this._options.rtc&&!await this._options.rtc.detectMicro())return new Error("Failed to obtain microphone authorization");const n=this.state;if(n===$.CONNECTING||n===$.OPEN)if(i)try{await this._controller.close("force close by connect")}catch(E){console.warn(E)}else return new Error("已有Live实例正在连接中,请勿重复连接!");this._clearLiveData();const c=tr(this._options.url,{ticket:await this._options.getTicket(),force:Number(!!i)});return this._controller.open(c),!0});o(this,"exit",async()=>{var e;this._clearLiveData();try{await((e=this.$RTC)==null?void 0:e.quit())}catch(i){O.warn(i)}return this.state!==$.OPEN?!0:await this._controller.close()});o(this,"close",async()=>{await this._controller.readyClose(),await this.updateStatus(K.RoomChange,Y.RoomClose,{})});o(this,"dispose",async()=>(this._removeLiveControllerEventListeners(),this._clearLiveData(),await this._controller.dispose()));o(this,"setSelfInfo",async e=>await this.updateStatus(K.UserChange,Y.UserInfo,e));o(this,"toggleMicro",async e=>{var n,c,u;if(!((c=(n=this.selfInfo)==null?void 0:n.permission)!=null&&c.control_own_micro))return!1;const i=await((u=this.$RTC)==null?void 0:u.toggleMicro(e));return i&&await this.updateStatus(K.UserChange,Y.UserMicroStatus,{status:e?Q.OPEN:Q.CLOSE},[]),i});o(this,"forbidMicro",async(e,i)=>{var n,c;return typeof this._options.canForbidUserMicro=="function"&&!this._options.canForbidUserMicro(i)||!((c=(n=this.selfInfo)==null?void 0:n.permission)!=null&&c.control_other_micro)?!1:await this.updateStatus(K.UserChange,Y.UserMicroStatus,{status:e},i)});o(this,"forbidSync",async(e,i)=>{var n,c;return typeof this._options.canForbidUserSync=="function"&&!this._options.canForbidUserSync(i)||!((c=(n=this.selfInfo)==null?void 0:n.permission)!=null&&c.control_other_sync)?!1:await this.updateStatus(K.UserChange,Y.UserPermission,{sync_frame:e},i)});o(this,"kick",async e=>{var i,n;return typeof this._options.canForbidUserKick=="function"&&!this._options.canForbidUserKick(e)||!((n=(i=this.selfInfo)==null?void 0:i.permission)!=null&&n.change_other_status)?!1:await this.updateStatus(K.UserChange,Y.UserStatus,{status:"KICK_OUT"},e)});this._addLiveControllerEventListeners(),this._options=Object.assign({initialMicroStatus:Q.OPEN},e),this._options.jsBridge=(()=>{if(e.jsBridge)return e.jsBridge;if(e.useBuiltInJsBridge)return new Kt})(),this._options.getVoiceSign=(i=e.getVoiceSign)!=null?i:hr,this._options.autoPlayConfirm=e.autoPlayConfirm,this._options.rtc=(()=>{if(e.rtc)return e.rtc;if(e.rtcType)switch(e.getVoiceSign||O.error("GetVoiceSign method must be passed when using built-in RTC instances"),e.rtcType){case ee.RealseeVRWebViewRTC:{if(this._options.jsBridge)return new $e({jsBridge:this._options.jsBridge,getVoiceSign:this._options.getVoiceSign});O.error("JsBridge instance must be passed when using built-in VRWebViewRTC instances");return}case ee.RealseeBrowserChimeRTC:return new Ve({getVoiceSign:this._options.getVoiceSign,logLevel:e.__debug__?at.DEBUG:at.INFO});case ee.RealseeBrowserRTC:return this._options.autoPlayConfirm||O.error("autoPlayConfirm method must be passed when using built-in RealseeBrowserRTC instances"),new De({getVoiceSign:this._options.getVoiceSign,autoPlayConfirm:this._options.autoPlayConfirm});default:{O.error("unknown built-in RTC type");return}}if(e.useBuiltInRTC){if(e.getVoiceSign||O.error("GetVoiceSign method must be passed when using built-in RTC instances"),this._options.jsBridge)return sr&&(rr||ir)||nr?new $e({jsBridge:this._options.jsBridge,getVoiceSign:this._options.getVoiceSign}):e.builtInRTCType===Ue.RealseeXChimeRTC?new Ve({getVoiceSign:this._options.getVoiceSign}):new De({getVoiceSign:this._options.getVoiceSign,autoPlayConfirm:this._options.autoPlayConfirm});O.error("jsBridge instance must be passed when using built-in RTC instances");return}})(),this._options.rtc||O.warn("unused rtc"),this._options.url&&this._options.getTicket&&this.connect(),this._options.__debug__&&Object.assign(window,{$liveController:this._controller,$live:this})}get options(){return Object.freeze(this._options||{})}get state(){return this._controller.state}get readyState(){return this._controller.state}get url(){return this.options.url}get $RTC(){return this._options.rtc}get jsBridge(){return this._options.jsBridge}get snapshot(){return this._buildInData.keyframes}get selfInfo(){return this._buildInData.selfInfo}get userList(){return this._buildInData.userList||[]}get roomInfo(){return this._buildInData.roomInfo}async updateStatus(e,i,n,c){if(this.state!==$.OPEN)return!1;const u=Object.assign({event_type:e,action:i},{data:n}),d=Me(U.BuiltinMsg,u,c);try{return this._controller.sendMessage(d),!0}catch(g){return O.error(g),!1}}broadcast(e,i,n){return this.state!==$.OPEN?!1:new Promise((c,u)=>{const d=Me(U.CustomEvent,e,i),g=d.front_request_id,v=n?setTimeout(()=>{u(new Error("RESPONSE TIMEOUT")),this.off("broadcast",E)},n):void 0,E=(y,I)=>{I===g&&(v&&clearTimeout(v),this.off("broadcast",E),c(y))};this.on("broadcast",E);try{this._controller.sendMessage(d)}catch(y){u(y)}})}}const vt=r=>(_r(),new gr(r));var xe={},mr={get exports(){return xe},set exports(r){xe=r}},ae={};/**
|
|
1
|
+
"use strict";var Ft=Object.defineProperty;var qt=(r,o,e)=>o in r?Ft(r,o,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[o]=e;var s=(r,o,e)=>(qt(r,typeof o!="symbol"?o+"":o,e),e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const Kt=require("@realsee/jsbridge-x"),Ae=require("trtc-js-sdk"),X=require("amazon-chime-sdk-js"),D=require("react"),ue=Symbol("$$REALSEE_LIVE_EVENT$$");function Ee(r){return r[ue]||(r[ue]={}),r[ue]}function Gt(r){r[ue]||delete r[ue]}class le{hasListener(o){const e=Ee(this);return e&&e[o]&&e[o].length>0}on(o,e,i){const n=Ee(this);return n[o]||(n[o]=[]),n[o].push([e,i||!1]),()=>this.off(o,e)}once(o,e){return this.on(o,e,!0)}off(o,e){if(o===void 0){Gt(this);return}const i=Ee(this);if(i[o]||(i[o]=[]),e===void 0){i[o].length=0;return}let n=0;for(;n<i[o].length&&i[o][n][0]!==e;n++);n<i[o].length&&i[o].splice(n,1)}emit(o,...e){let i=!1;const c=Ee(this)[o]||[];for(let u of c.slice()){const[d,g=!1]=u,v=d(...e);g&&this.off(o,d),v===!1&&(i=!0)}return i}}class Ce extends le{}var ee=(r=>(r.RealseeBrowserRTC="RealseeBrowserRTC",r.RealseeVRWebViewRTC="RealseeVRWebViewRTC",r.RealseeBrowserChimeRTC="RealseeBrowserChimeRTC",r))(ee||{}),Ue=(r=>(r.RealseeXTRTC="trtc",r.RealseeXChimeRTC="chime",r))(Ue||{});const Yt=()=>{const r=new Date,o=r.getFullYear(),e=(r.getMonth()+1).toString().padStart(2,"0"),i=r.getDate().toString().padStart(2,"0"),n=r.getHours().toString().padStart(2,"0"),c=r.getMinutes().toString().padStart(2,"0"),u=r.getSeconds().toString().padStart(2,"0"),d=r.getMilliseconds();return`[${o}-${e}-${i} ${n}:${c}:${u}.${d}]`},we=(r,o=[])=>{switch(o.unshift(`Realsee Live ${Yt()} <${r}> `),r){case"INFO":return console.info(...o);case"ERROR":return console.error(...o);case"WARN":return console.warn(...o);default:return console.log(...o)}},Ht=(...r)=>we("LOG",r),Jt=(...r)=>we("INFO",r),zt=(...r)=>we("ERROR",r),Xt=(...r)=>we("WARN",r),Zt={log:Ht,info:Jt,error:zt,warn:Xt},O=Zt;function Z(){return((1+Math.random())*65536|0).toString(16).substring(1)}function ye(){return(Z()+Z()+"-"+Z()+"-4"+Z().substr(0,3)+"-"+Z()+"-"+Z()+Z()+Z()).toLowerCase()}class De extends Ce{constructor(e){super();s(this,"type",ee.RealseeBrowserRTC);s(this,"joined",!1);s(this,"micro",!1);s(this,"voiceId","");s(this,"_getVoiceSign",()=>{throw new Error("方法 getVoiceSign 未实现")});s(this,"_autoPlayConfirm");s(this,"checkRequirement",()=>Ae.checkSystemRequirements());s(this,"$dom",document.createElement("div"));s(this,"_trtc",{client:null,stream:null});s(this,"join",async e=>{var c;this.emit("joinWillStart");const i=await this._getVoiceSign({voiceId:e.voiceId,roomId:e.roomId,userId:e.userId});this._trtc.client=Ae.createClient({mode:"rtc",...i,enableAutoPlayDialog:typeof this._autoPlayConfirm!="function"}),(c=this._trtc.client)==null||c.enableAudioVolumeEvaluation(),this._registerRtcEvent();let n=await new Promise(u=>{var d;(d=this._trtc.client)==null||d.join({roomId:Number(e.voiceId)}).then(()=>u(!0)).catch(()=>u(!1))});return this.joined=n,n?(this._trtc.stream=Ae.createStream({userId:i.userId,audio:!0,video:!1}),n=await new Promise(u=>{var d;(d=this._trtc.stream)==null||d.initialize().then(()=>u(!0)).catch(()=>u(!1))}),n=await new Promise(u=>{var d;(d=this._trtc.client)==null||d.publish(this._trtc.stream).then(()=>u(!0)).catch(()=>u(!1))}),this.joined=n,this.joined&&this.emit("joined"),n):!1});s(this,"_handleStreamAdded",e=>{var n;const i=e.stream;console.log("远端流增加: "+i.getId()),(n=this._trtc.client)==null||n.subscribe(i)});s(this,"_handleStreamSubscribed",e=>{const i=e.stream;console.log("远端流订阅成功:"+i.getId());const c=`rs-rtc-remote_stream-${i.getId()}`,u=document.createElement("div");u.id=c,this.$dom.appendChild(u),typeof this._autoPlayConfirm=="function"?(i.play(c).catch(d=>{}),i.on("error",d=>{if(d.getCode()===16451){const v=()=>i.resume();this._autoPlayConfirm({onConfirm:v})}})):i.play(c)});this._getVoiceSign=e.getVoiceSign,this._autoPlayConfirm=e.autoPlayConfirm,this._initParentDom()}_initParentDom(){this.$dom.id=`rs-rtc-${ye()}`,this.$dom.style.display="none",document.body.appendChild(this.$dom)}quit(){return new Promise(async e=>{var i,n;this.joined=!1,this._trtc.stream&&(await((i=this._trtc.client)==null?void 0:i.unpublish(this._trtc.stream)),this._trtc.stream.stop(),this._trtc.stream.close(),this._trtc.stream=null),(n=this._trtc.client)==null||n.leave().then(()=>this._trtc.client=null).then(()=>e(!0)).catch(()=>e(!1)),e(!0)})}detectMicro(){return new Promise(e=>{const i={audio:!0,video:!1};try{navigator.mediaDevices.getUserMedia(i).then(()=>e(!0)).catch(n=>{O.error(n.message),e(!1)})}catch(n){console.error(n),e(!1)}})}toggleMicro(e){var i,n,c,u;return Promise.resolve((e?(n=(i=this._trtc)==null?void 0:i.stream)==null?void 0:n.unmuteAudio():(u=(c=this._trtc)==null?void 0:c.stream)==null?void 0:u.muteAudio())||!1)}shock(){throw new Error("Method not implemented.")}_registerRtcEvent(){var e,i,n,c;(e=this._trtc.client)==null||e.on("stream-added",this._handleStreamAdded),(i=this._trtc.client)==null||i.on("stream-subscribed",this._handleStreamSubscribed),(n=this._trtc.client)==null||n.on("audio-volume",u=>this.emit("userVolumes",u.result.map(({userId:d,audioVolume:g})=>({userId:d,audioVolume:g})))),(c=this._trtc.client)==null||c.on("error",u=>this.emit("error",u))}}class Ve extends Ce{constructor(e){super();s(this,"type",ee.RealseeBrowserChimeRTC);s(this,"joined",!1);s(this,"micro",!1);s(this,"voiceId","");s(this,"userId","");s(this,"logger");s(this,"deviceController");s(this,"meetingSession");s(this,"audioInput");s(this,"audioOutput");s(this,"deviceChangeObserver",{});s(this,"audioVideoObserver",{});s(this,"audioMixObserver");s(this,"_getVoiceSign",()=>{throw new Error("方法 getVoiceSign 未实现")});s(this,"_autoPlayConfirm");s(this,"$dom",document.createElement("div"));s(this,"$audio",document.createElement("audio"));s(this,"_initDom",()=>{this.$audio.id=`rs-rtc-${ye()}`,this.$dom.id=`rs-rtc-${ye()}`,this.$dom.appendChild(this.$audio),document.body.appendChild(this.$dom)});s(this,"initObservers",()=>{this.deviceChangeObserver={audioInputsChanged:e=>{this.logger.info(`audioInputsChanged ${typeof e}`),e==null||e.forEach(i=>{this.logger.info(`Device ID: ${i.deviceId} Microphone: ${i.label}`)})},audioOutputsChanged:e=>{this.logger.info(`audioOutputsChanged ${typeof e}`),e==null||e.forEach(i=>{this.logger.info(`Device ID: ${i.deviceId} Speaker: ${i.label}`)})},audioInputMuteStateChanged:(e,i)=>{this.logger.info(`Device ${e.toString()} ${i?"is muted in hardware":"is not muted"}`)}},this.audioVideoObserver={audioVideoDidStart:()=>{this.logger.info("Started")},audioVideoDidStop:e=>{this.logger.info(`Stopped with a session status code: ${e.statusCode()}`)},audioVideoDidStartConnecting:e=>{e&&this.logger.info("Attempting to reconnect")}},this.audioMixObserver={meetingAudioStreamBecameActive:e=>{if(this.$audio.paused){const i=()=>this.$audio.play().then(()=>{}).catch(n=>{if(O.error("播放远端流失败!",n),typeof this._autoPlayConfirm=="function"){const c=()=>i();this._autoPlayConfirm({onConfirm:c})}});i()}},meetingAudioStreamBecameInactive:e=>{}}});s(this,"_registerRtcEvent",()=>{var i,n,c,u,d,g;const e=((c=(n=(i=this.meetingSession)==null?void 0:i.configuration)==null?void 0:n.credentials)==null?void 0:c.attendeeId)||"";if(e){const v=new Map,E=()=>{const y=[];return v.forEach((I,_)=>{y.push({userId:I.userId,volume:I.muted||I.signalStrength===0||!Boolean(I.volume)?0:I.volume})}),y};(u=this.meetingSession)==null||u.audioVideo.realtimeSubscribeToAttendeeIdPresence((y,I,_)=>{var V;if(!I){v.delete(y),this.emit("userVolumes",E());return}(V=this.meetingSession)==null||V.audioVideo.realtimeSubscribeToVolumeIndicator(y,(C,k,B,P)=>{new X.DefaultModality(C).base()===C&&(v.set(C,{userId:_||C,volume:k,muted:B,signalStrength:P}),this.emit("userVolumes",E()))})}),(d=this.meetingSession)==null||d.audioVideo.realtimeSubscribeToVolumeIndicator(e,(y,I,_,V)=>{new X.DefaultModality(y).base()===y&&V!==null&&V!==1&&this.emit("weakNetwork")}),(g=this.meetingSession)==null||g.audioVideo.realtimeSubscribeToFatalError(y=>this.emit("error",y))}});this._getVoiceSign=e.getVoiceSign,this._autoPlayConfirm=e.autoPlayConfirm,this._initDom(),this.logger=new X.ConsoleLogger("WebRTCLogger",e.logLevel||X.LogLevel.INFO),this.deviceController=new X.DefaultDeviceController(this.logger),this.initObservers()}async join(e){return new Promise(async(i,n)=>{var c,u;this.emit("joinWillStart");try{const{sdkAppId:d,userId:g,roomId:v,userSig:E}=await this._getVoiceSign({...e,roomId:e.roomId||0});this.userId=g;const{attendence:y,vendor_wrapper:I}=JSON.parse(decodeURIComponent(E)),_=new X.MeetingSessionConfiguration({Meeting:I},{Attendee:{ExternalUserId:y.external_user_id,AttendeeId:y.attendee_id,JoinToken:y.join_token}});this.meetingSession=new X.DefaultMeetingSession(_,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 V={audioVideoDidStart:()=>{var C;(C=this.meetingSession)==null||C.audioVideo.realtimeMuteLocalAudio(),this.joined=!0,this.emit("joined"),i(!0)},audioVideoDidStop:()=>{this.joined=!1,i(!1)}};this.meetingSession.audioVideo.addObserver(V),this.audioMixObserver&&this.meetingSession.audioVideo.addAudioMixObserver(this.audioMixObserver),this.meetingSession.audioVideo.setDeviceLabelTrigger(async()=>await navigator.mediaDevices.getUserMedia({audio:!0,video:!1}));try{const C=await this.meetingSession.audioVideo.listAudioInputDevices();O.info("audioInputDevices ===>",C);const k=((c=C[0])==null?void 0:c.deviceId)||"default";await this.meetingSession.audioVideo.startAudioInput(k)}catch(C){O.error(`设置语音输入设备失败:${C.message}`)}try{const C=await this.meetingSession.audioVideo.listAudioOutputDevices();O.info("audioOutputDevices ===>",C);const k=((u=C[0])==null?void 0:u.deviceId)||"default";await this.meetingSession.audioVideo.chooseAudioOutput(k)}catch(C){O.error(`设置语音输出设备失败:${C.message}`)}this.meetingSession.audioVideo.start()}catch(d){this.emit("error",d),this.logger.error(d.message),i(!1)}})}quit(){return this.joined?new Promise((e,i)=>{var c,u;this.joined=!1;const n={audioVideoDidStop:async d=>{var v;const g=d.statusCode();(v=this.meetingSession)==null||v.deviceController.destroy(),g===X.MeetingSessionStatusCode.Left?(this.logger.info("You left the session"),e(!0)):(this.logger.info(`Stopped with a session status code: ${g}`),e(!0))}};(c=this.meetingSession)==null||c.audioVideo.addObserver(n),(u=this.meetingSession)==null||u.audioVideo.stop()}):Promise.resolve(!0)}async detectMicro(){return new Promise(e=>{const i={audio:!0,video:!1};try{navigator.mediaDevices.getUserMedia(i).then(()=>e(!0)).catch(()=>e(!1))}catch(n){this.logger.error(n.message),e(!1)}})}async toggleMicro(e){var n,c,u;e?(n=this.meetingSession)==null||n.audioVideo.realtimeUnmuteLocalAudio():(c=this.meetingSession)==null||c.audioVideo.realtimeMuteLocalAudio();const i=(u=this.meetingSession)==null?void 0:u.audioVideo.realtimeIsLocalAudioMuted();return i!==void 0?e!==i:!1}shock(){throw new Error("Method not implemented.")}}var Be=(r=>(r[r.Success=0]="Success",r[r.Failure=1]="Failure",r[r.ReJoin=2]="ReJoin",r[r.NoMicroPermission=3]="NoMicroPermission",r))(Be||{});class $e extends Ce{constructor({jsBridge:e,getVoiceSign:i}){super();s(this,"type",ee.RealseeVRWebViewRTC);s(this,"joined",!1);s(this,"micro",!1);s(this,"voiceId","");s(this,"options");this.options={jsBridge:e,getVoiceSign:i},this.jsBridge.webViewType!=="WxMiniProgramWebView"&&this.jsBridge.callAndListen("live/userVolumes",n=>{this.emit("userVolumes",n)}),this.jsBridge.callAndListen("live/weakNetwork",n=>{n&&this.emit("weakNetwork")})}get jsBridge(){return this.options.jsBridge}async join(e){try{this.emit("joinWillStart");const{sdkAppId:i,userId:n,userSig:c}=await this.options.getVoiceSign(e);if(!(Boolean(i)&&Boolean(n)&&Boolean(c)))return this.emit("error",new Error("加入房间失败:rtc 签名请求异常")),this.joined=!1,this.joined;this.type=e.type;const[u,d]=await this.jsBridge.callAndBackfeed(`live/join?sdkAppID=${i}&userID=${n}&roomID=${Number(e.voiceId)}&userSig=${c}`);return u===!0?(this.emit("joined"),this.joined=!0):u?u.code===Be.Success?(this.emit("joined"),this.joined=!0):(this.emit("error",u),this.joined=!1):(this.emit("error",d||new Error("加入房间失败:未知异常。")),this.joined=!1),this.joined}catch(i){return this.emit("error",new Error("加入房间失败:"+i.message)),this.joined=!1,this.joined}}async quit(){const[e,i]=await this.jsBridge.callAndBackfeed("live/quit");return e===null&&this.emit("error",i||new Error("退出房间失败:未知异常。")),this.joined=!1,!!e}async detectMicro(){const[e,i]=await this.jsBridge.detectMicro();return e===null?(this.emit("error",i||new Error("麦克风监测异常!")),!1):e}async toggleMicro(e){const[i,n]=await this.jsBridge.callAndBackfeed(`live/toggleMicro?flag=${e?1:0}`);return i===null?(this.emit("error",n||new Error("麦克风监测异常!")),!1):(this.micro=i,i)}shock(){this.jsBridge.shock(1)}}var U=(r=>(r.SelfUserInfo="SELF_USER_INFO",r.RoomInfo="ROOM_INFO",r.RTCInfo="RTC_INFO",r.UserList="USER_LIST",r.BuiltinMsg="BUILTIN_MSG",r.CustomEvent="CUSTOM_EVENT",r.KeyframeSync="KEYFRAME_SYNC",r.UserKickOut="USER_KICK_OUT",r))(U||{}),K=(r=>(r.UserChange="user_change",r.RoomChange="room_change",r))(K||{}),Y=(r=>(r.UserMicroStatus="change_micro_status",r.UserMicroStatusSync="sync_micro_status",r.UserPermission="change_permission",r.UserStatus="change_status",r.UserInfo="change_info",r.RoomClose="close",r))(Y||{}),Q=(r=>(r.OPEN="OPEN",r.CLOSE="CLOSE",r))(Q||{});function Qt(r){try{const o=JSON.parse(r),e={code:o.code,message:o.message,command:o.command,roomCode:o.room_code,appID:o.app_id,requestId:o.request_id,frontRequestId:o.front_request_id,triggerUserID:o.trigger_user_id,data:o.data||{}},i=Object.keys(e).filter(n=>e[n]===void 0);return i.length>0&&console.warn(`推送数据格式异常:${i.join(" ")} 值不存在!`),e}catch(o){return!1}}var $=(r=>(r[r.NOTINITIALIZED=-1]="NOTINITIALIZED",r[r.CONNECTING=0]="CONNECTING",r[r.OPEN=1]="OPEN",r[r.CLOSED=3]="CLOSED",r))($||{}),ft=(r=>(r[r.Normal=0]="Normal",r[r.Removed=1]="Removed",r[r.Replaced=2]="Replaced",r))(ft||{}),dt=(r=>(r.WAIT_ENTER="WAIT_ENTER",r.ONLINE="ONLINE",r.LEAVE="LEAVE",r.KICK_OUT="KICK_OUT",r.BE_REPLACE="BE_REPLACE",r.EXCEPTION="EXCEPTION",r))(dt||{}),be=(r=>(r[r.NOTINITIALIZED=-1]="NOTINITIALIZED",r[r.CONNECTING=0]="CONNECTING",r[r.OPEN=1]="OPEN",r[r.CLOSING=2]="CLOSING",r[r.CLOSED=3]="CLOSED",r))(be||{}),ht=(r=>(r.Error="Error",r.Close="Close",r.MicroAuth="MicroAuth",r.DuplicateConnect="DuplicateConnect",r.IllegalURL="IllegalURL",r.Unknown="Unknown",r.IllegalArgs="IllegalArgs",r))(ht||{}),_t=(r=>(r.Err_1000="CLOSE_NORMAL",r.Err_1001="CLOSE_GOING_AWAY",r.Err_1002="CLOSE_PROTOCOL_ERROR",r.Err_1003="CLOSE_UNSUPPORTED",r.Err_1006="CLOSE_ABNORMAL",r.Err_1007="Unsupported Data",r.Err_1008="Policy Violation",r.Err_1009="CLOSE_TOO_LARGE",r.Err_unknown="unknown",r))(_t||{});function gt(r){switch(r){case 1e3:return"CLOSE_NORMAL";case 1001:return"CLOSE_GOING_AWAY";case 1002:return"CLOSE_PROTOCOL_ERROR";case 1003:return"CLOSE_UNSUPPORTED";case 1006:return"CLOSE_ABNORMAL";case 1007:return"Unsupported Data";case 1008:return"Policy Violation";case 1009:return"CLOSE_TOO_LARGE"}return"unknown"}function er(r){return r&&r.__esModule&&Object.prototype.hasOwnProperty.call(r,"default")?r.default:r}var mt={};(function(r){Object.defineProperty(r,"__esModule",{value:!0}),r.LogLevel=void 0;var o;(function(e){e[e.DEBUG=0]="DEBUG",e[e.INFO=1]="INFO",e[e.WARN=2]="WARN",e[e.ERROR=3]="ERROR",e[e.OFF=4]="OFF"})(o=r.LogLevel||(r.LogLevel={})),r.default=o})(mt);const at=er(mt);function tr(r,o={}){const e=r.indexOf("?")!==-1,i=Object.keys(o).reduce((n,c,u)=>`${n}${u===0&&!e?"?":"&"}${c}=${o[c]}`,"");return r+i}const fe=globalThis.navigator.userAgent,rr=/android/gi.test(fe),ir=/iPhone|iPad\s+OS/gi.test(fe),nr=/MicroMessenger/gi.test(fe)&&/miniProgram/gi.test(fe),sr=/realsee/gi.test(fe);function Se(r){return Object.prototype.toString.call(r)==="[object Object]"}function Re(r,o){return r===o?!0:typeof r!=typeof o?!1:!!(Number.isNaN(r)&&Number.isNaN(o))}function or(r,o){const e=Object.getOwnPropertyNames(r),i=Object.getOwnPropertyNames(o);if(e.length!==i.length)return!1;for(let n=0,c=e.length;n<c;n++){const u=e[n];if(!Re(r[u],o[u]))return!1}return!0}function ar(r,o){if(r.length!==o.length)return!1;for(let e=0,i=r.length;e<i;e++)if(!Re(r[e],o[e]))return!1;return!0}function cr(r,o){return Re(r,o)?!0:Se(r)&&Se(o)?or(r,o):Array.isArray(r)&&Array.isArray(o)?ar(r,o):!1}function We(r,o){return Re(r,o)?!0:Se(r)&&Se(o)?lr(r,o):Array.isArray(r)&&Array.isArray(o)?ur(r,o):!1}function ur(r,o){if(r.length!==o.length)return!1;for(let e=0,i=r.length;e<i;e++)if(!We(r[e],o[e]))return!1;return!0}function lr(r,o){const e=Object.getOwnPropertyNames(r),i=Object.getOwnPropertyNames(o);if(e.length!==i.length)return!1;for(let n=0,c=e.length;n<c;n++){const u=e[n];if(!We(r[u],o[u]))return!1}return!0}function ct(r,o,e={deep:!1}){return e.deep?We(r,o):cr(r,o)}class fr extends le{constructor(e){super();s(this,"_realWebSocket");s(this,"_url");s(this,"_protocols");s(this,"_readyState",be.NOTINITIALIZED);s(this,"_options",{timeout:1e4,shouldReconnect:(e,i)=>{if(!(e.code===1008||e.code===1011))return[0,1e3,2e3][i.attempts%3]},should1000Reconnect:!1,ignoreConnectivityEvents:!1,automaticOpen:!1});s(this,"_connectTimeout");s(this,"_attempts",0);s(this,"_reconnects",-1);s(this,"_reconnectWhenOnlineAgain",!1);s(this,"_explicitlyClosed",!1);s(this,"_pendingReconnect");s(this,"_connectivityEventsAttached",!1);s(this,"_heathCheckTimer");s(this,"_healthCheck",async()=>{this._realWebSocket&&this._realWebSocket.readyState!==this._readyState&&(this._readyState=this._realWebSocket.readyState,this._readyState===be.CLOSING&&this.emit("closing")),await new Promise(e=>setTimeout(e,2e3)),this._heathCheckTimer=requestAnimationFrame(this._healthCheck)});s(this,"_clearConnectTimeoutIfNeed",()=>{this._connectTimeout&&(clearTimeout(this._connectTimeout),this._connectTimeout=void 0)});s(this,"_clearHeathCheckIfNeed",()=>{this._heathCheckTimer&&(cancelAnimationFrame(this._heathCheckTimer),this._heathCheckTimer=void 0)});s(this,"_startHealthCheck",()=>{this._clearHeathCheckIfNeed(),this._heathCheckTimer=requestAnimationFrame(this._healthCheck)});s(this,"_stopHealthCheck",()=>{this._clearHeathCheckIfNeed()});s(this,"_clearPendingReconnectIfNeeded",()=>{this._pendingReconnect&&(clearTimeout(this._pendingReconnect),this._pendingReconnect=void 0)});s(this,"_online",e=>{this._reconnectWhenOnlineAgain&&(this._clearPendingReconnectIfNeeded(),this._reconnect(e))});s(this,"_offline",()=>{var e;this._reconnectWhenOnlineAgain=!0,(e=this._realWebSocket)==null||e.close(1e3,"offline")});s(this,"_detachConnectivityEvents",()=>{this._connectivityEventsAttached&&(globalThis==null||globalThis.removeEventListener("online",this._online),globalThis==null||globalThis.removeEventListener("offline",this._offline),this._connectivityEventsAttached=!1)});s(this,"_attachConnectivityEvents",()=>{this._connectivityEventsAttached||(globalThis==null||globalThis.addEventListener("online",this._online),globalThis==null||globalThis.addEventListener("offline",this._offline),this._connectivityEventsAttached=!0)});s(this,"send",e=>{var i,n,c;((i=this._realWebSocket)==null?void 0:i.readyState)===((n=this._realWebSocket)==null?void 0:n.OPEN)&&((c=this._realWebSocket)==null||c.send(e))});s(this,"close",(e,i)=>{var n;return typeof e!="number"&&(i=e,e=1e3),this._clearPendingReconnectIfNeeded(),this._reconnectWhenOnlineAgain=!1,this._explicitlyClosed=!0,this._detachConnectivityEvents(),(n=this._realWebSocket)==null?void 0:n.close(e,i)});s(this,"open",e=>{var i,n;e&&(this._url=e),((i=this._realWebSocket)==null?void 0:i.readyState)!==WebSocket.OPEN&&((n=this._realWebSocket)==null?void 0:n.readyState)!==WebSocket.CONNECTING&&(this._clearPendingReconnectIfNeeded(),this._reconnectWhenOnlineAgain=!1,this._explicitlyClosed=!1,this._createWebSocket())});s(this,"_createWebSocket",()=>{var n,c,u;const e=typeof this._url=="string"?this._url:(n=this._url)==null?void 0:n.call(this,this);if(!e)return;this._clearConnectTimeoutIfNeed(),this._clearPendingReconnectIfNeeded(),this._removeWebSocketEvent(),this._realWebSocket=new WebSocket(e,this._protocols||void 0),this._attempts=this._attempts+1,this.emit("connecting",new CustomEvent("connecting",{detail:{attempts:this._attempts,reconnects:this._reconnects}}));const i=()=>{this._connectTimeout=void 0,this._detachConnectivityEvents(),this.emit("timeout",new CustomEvent("timeout",{detail:{attempts:this._attempts,reconnects:this._reconnects}}))};this._connectTimeout=setTimeout(i,(c=this._options)==null?void 0:c.timeout),this._dispatchWebSocketEvent(),(u=this._options)!=null&&u.ignoreConnectivityEvents||this._attachConnectivityEvents()});s(this,"_removeWebSocketEvent",()=>{var e,i,n,c;(e=this._realWebSocket)==null||e.removeEventListener("open",this._webSocketOpenHandler),(i=this._realWebSocket)==null||i.removeEventListener("close",this._webSocketCloseHandler),(n=this._realWebSocket)==null||n.removeEventListener("error",this._webSocketErrorHandler),(c=this._realWebSocket)==null||c.removeEventListener("message",this._webSocketMessageHandler)});s(this,"_dispatchWebSocketEvent",()=>{var e,i,n,c;(e=this._realWebSocket)==null||e.addEventListener("open",this._webSocketOpenHandler),(i=this._realWebSocket)==null||i.addEventListener("close",this._webSocketCloseHandler),(n=this._realWebSocket)==null||n.addEventListener("error",this._webSocketErrorHandler),(c=this._realWebSocket)==null||c.addEventListener("message",this._webSocketMessageHandler)});s(this,"_webSocketOpenHandler",e=>{this._connectTimeout&&(clearTimeout(this._connectTimeout),this._connectTimeout=void 0);const i=++this._reconnects,n=this._attempts;return this._attempts=0,this._reconnectWhenOnlineAgain=!1,this._startHealthCheck(),this.emit("open",Object.assign(e,{detail:{reconnects:i,attempts:n}}))});s(this,"_webSocketCloseHandler",e=>(this._reconnect(e),this._stopHealthCheck(),this.emit("close",e)));s(this,"_webSocketErrorHandler",e=>this.emit("error",new CustomEvent("error",{detail:{error:e}})));s(this,"_webSocketMessageHandler",e=>this.emit("message",e));e&&this.setOptions(e),this._startHealthCheck()}get attempts(){return this._attempts}setOptions(e){if(!e)return;this._url=e.url,this._protocols=e.protocols;const i=Object.assign(this._options,e.robustOptions||{});if(typeof(i==null?void 0:i.timeout)!="number")throw new Error("timeout must be the number of milliseconds to timeout a connection attempt");if(typeof(i==null?void 0:i.shouldReconnect)!="function")throw new Error("shouldReconnect must be a function that returns the number of milliseconds to wait for a reconnect attempt, or null or undefined to not reconnect.");this._options=i,this._options.automaticOpen&&this._createWebSocket()}_reconnect(e){var n,c,u,d;if(!((n=this._options)!=null&&n.should1000Reconnect)&&e.code===1e3||this._explicitlyClosed){this._attempts=0;return}if(this._connectivityEventsAttached&&((c=globalThis==null?void 0:globalThis.navigator)==null?void 0:c.onLine)===!1){this._reconnectWhenOnlineAgain=!0;return}const i=(d=(u=this._options)==null?void 0:u.shouldReconnect)==null?void 0:d.call(u,e,this);typeof i=="number"&&(this._pendingReconnect=setTimeout(this._createWebSocket,i))}}class dr extends le{constructor(){super();s(this,"_ws",new fr({url:"",robustOptions:{should1000Reconnect:!0,ignoreConnectivityEvents:!0}}));s(this,"_state",$.NOTINITIALIZED);s(this,"_addWebSocketEventListeners",()=>{this._ws.on("close",this._handleCloseEvent),this._ws.on("closing",this._handleClosingEvent),this._ws.on("connecting",this._handleConnectingEvent),this._ws.on("error",this._handleErrorEvent),this._ws.on("message",this._handleMessageEvent),this._ws.on("open",this._handleOpenEvent),this._ws.on("timeout",this._handleTimeoutEvent)});s(this,"_removeWebSocketEventListeners",()=>{this._ws.off("close",this._handleCloseEvent),this._ws.off("closing",this._handleClosingEvent),this._ws.off("connecting",this._handleConnectingEvent),this._ws.off("error",this._handleErrorEvent),this._ws.off("message",this._handleMessageEvent),this._ws.off("open",this._handleOpenEvent),this._ws.off("timeout",this._handleTimeoutEvent)});s(this,"_handleCloseEvent",e=>{O.info(`live room closed bacause of ${e.code}-${e.reason||gt(e.code)}`),this.state=$.CLOSED});s(this,"_handleClosingEvent",()=>{var e;O.info("live room is closing, onLine:",(e=globalThis==null?void 0:globalThis.navigator)==null?void 0:e.onLine),this.state=$.CLOSED});s(this,"_handleConnectingEvent",()=>{O.info("live room is connecting"),this.state=$.CONNECTING});s(this,"_handleErrorEvent",e=>{O.error("live room error",e),this.state=$.CLOSED});s(this,"_handleMessageEvent",e=>{let i=(()=>{try{return JSON.parse(e.data)}catch(n){return e.data}})();this.emit("message",i)});s(this,"_handleOpenEvent",e=>{O.info("live room open",e.detail),this.state=$.OPEN,e.detail.reconnects>0&&this.emit("reconnected",e.detail)});s(this,"_handleTimeoutEvent",e=>{O.error("live room connect timeout!",e.detail),this.state=$.CLOSED});s(this,"dispose",async()=>(this._removeWebSocketEventListeners(),await this.close("live room close by controller disposed!")));s(this,"open",e=>this._ws.open(e));s(this,"close",(e,i)=>new Promise(n=>{this._ws.once("close",()=>n(!0)),this._ws.close(e,i)}));this._addWebSocketEventListeners()}set state(e){const i=JSON.parse(JSON.stringify(this._state));this._state=e,this.emit("stateChange",this.state,i)}get state(){return this._state}sendMessage(e=""){if(e==null||e==="")throw new Error("live message is empty!");if(this.state===$.OPEN)return this._ws.send(JSON.stringify(e));throw new Error("live has not yet been initialized!")}readyClose(){this._ws&&(this._ws._explicitlyClosed=!0)}}const hr=r=>Promise.reject("unimplemented method GetVoiceSign"),Me=(r,o={},e=[])=>({command:r,front_request_id:ye(),data:{...o,to_user_ids:Array.isArray(e)?e:[e]}}),_r=()=>{var r,o;window!=null&&window.__Realsee_Live__&&((o=(r=window==null?void 0:window.__Realsee_Live__)==null?void 0:r.dispose)==null||o.call(r),window.__Realsee_Live__=null)};class gr extends le{constructor(e){var i;super();s(this,"_options",{});s(this,"keyframes",new le);s(this,"_buildInData",{keyframes:{}});s(this,"getFramesByKey",e=>this.snapshot[e]);s(this,"sendKeyframe",(e,i)=>{if(this.state!==$.OPEN)return!1;this._buildInData.keyframes={...this._buildInData.keyframes,[e]:i};const n=Me(U.KeyframeSync,this.snapshot);try{return this._controller.sendMessage(n),!0}catch(c){return O.error(c),!1}});s(this,"_controller",new dr);s(this,"_addLiveControllerEventListeners",()=>{this._controller.on("stateChange",this._handleStateChange),this._controller.on("message",this._handleMessage)});s(this,"_removeLiveControllerEventListeners",()=>{this._controller.off("stateChange",this._handleStateChange),this._controller.off("message",this._handleMessage)});s(this,"_handleStateChange",(e,i)=>this.emit("stateChange",e,i));s(this,"_handleMessage",async e=>{var i,n,c,u,d;if(typeof e=="object"){const{command:g,data:v={},frontRequestId:E,code:y,message:I}=e;if(y==="SUCCESS")switch(g){case U.SelfUserInfo:{const _=v;ct(this.selfInfo,_,{deep:!0})||(this._buildInData.selfInfo=_,this.emit("selfInfoUpdate",this._buildInData.selfInfo,E));break}case U.RoomInfo:{const _=v;this._buildInData.roomInfo=Object.assign({},_),this.emit("readyKeyframeSync",_.last_frame||{});break}case U.RTCInfo:{const{voice_id:_,type:V}=v;if(this._buildInData.rtcInfo={voiceId:_,type:V},(i=this.$RTC)!=null&&i.joined)O.warn("已加入语音房间,无需重复加入!");else if(await((u=this.$RTC)==null?void 0:u.join({voiceId:_,userId:((n=this.selfInfo)==null?void 0:n.id)||"",roomId:(c=this.roomInfo)==null?void 0:c.info.room_code,type:V}))){const k=(d=this._options.initialMicroStatus)!=null?d:Q.OPEN;await this.toggleMicro(k===Q.OPEN)}else O.error("加入语音房间失败");break}case U.UserList:{const _=v;this._buildInData.userList=_,this.emit("userListUpdate",this.userList,E);break}case U.CustomEvent:{const _=v;this.emit("broadcast",_,E);break}case U.KeyframeSync:{const _=v,V=Object.keys(_).reduce((C,k)=>{if(ct(_[k],this._buildInData.keyframes[k],{deep:!0}))return C;const B=[_[k],this._buildInData.keyframes[k],E],P=k;return this.keyframes.emit(P,...B),this._buildInData.keyframes[k]=_[k],C[k]=_[k],C},{});this.emit("keyframes",V,E);break}case U.BuiltinMsg:{const _=v;this.emit("builtinEvent",_),_.event_type===K.UserChange&&this.emit("userChange",_),_.event_type===K.RoomChange&&this.emit("roomChange",_),_.event_type===K.UserChange&&_.action===Y.UserMicroStatus&&await this.toggleMicro(_.data.status===Q.OPEN),_.event_type===K.RoomChange&&_.action===Y.RoomClose&&await this._exit();break}case U.UserKickOut:{this.emit("kickOut");break}default:console.warn("unknown command: ",g)}else this.emit("error",e)}});s(this,"_clearLiveData",()=>{this._buildInData={keyframes:{}}});s(this,"connect",async(e={})=>{var u,d,g,v;if(this._options.url=(d=(u=e.url)!=null?u:this._options.url)!=null?d:"",this._options.getTicket=(g=e.getTicket)!=null?g:this._options.getTicket,this._options.initialMicroStatus=(v=e.rtcMicStatus)!=null?v:this._options.initialMicroStatus,!/^ws(s):\/\//.test(this._options.url)||typeof this._options.getTicket!="function")return/^ws(s):\/\//.test(this._options.url)?typeof this._options.getTicket!="function"?new Error("getTicket muse be function"):!1:new Error("Illegal realsee live room link");const{force:i=!1}=e;if(this._options.rtc&&!await this._options.rtc.detectMicro())return new Error("Failed to obtain microphone authorization");const n=this.state;if(n===$.CONNECTING||n===$.OPEN)if(i)try{await this._controller.close("force close by connect")}catch(E){console.warn(E)}else return new Error("已有Live实例正在连接中,请勿重复连接!");this._clearLiveData();const c=tr(this._options.url,{ticket:await this._options.getTicket(),force:Number(!!i)});return this._controller.open(c),!0});s(this,"_exit",async()=>{var e;this._clearLiveData();try{await((e=this.$RTC)==null?void 0:e.quit())}catch(i){O.warn(i)}return this.state!==$.OPEN?!0:await this._controller.close()});s(this,"exit",async()=>this.close());s(this,"close",async()=>{var e;await this._controller.readyClose();try{await((e=this.$RTC)==null?void 0:e.quit())}catch(i){O.warn(i)}await this.updateStatus(K.RoomChange,Y.RoomClose,{})});s(this,"dispose",async()=>(this._removeLiveControllerEventListeners(),this._clearLiveData(),await this._controller.dispose()));s(this,"setSelfInfo",async e=>await this.updateStatus(K.UserChange,Y.UserInfo,e));s(this,"toggleMicro",async e=>{var n,c,u;if(!((c=(n=this.selfInfo)==null?void 0:n.permission)!=null&&c.control_own_micro))return!1;const i=await((u=this.$RTC)==null?void 0:u.toggleMicro(e));return i&&await this.updateStatus(K.UserChange,Y.UserMicroStatus,{status:e?Q.OPEN:Q.CLOSE},[]),i});s(this,"forbidMicro",async(e,i)=>{var n,c;return typeof this._options.canForbidUserMicro=="function"&&!this._options.canForbidUserMicro(i)||!((c=(n=this.selfInfo)==null?void 0:n.permission)!=null&&c.control_other_micro)?!1:await this.updateStatus(K.UserChange,Y.UserMicroStatus,{status:e},i)});s(this,"forbidSync",async(e,i)=>{var n,c;return typeof this._options.canForbidUserSync=="function"&&!this._options.canForbidUserSync(i)||!((c=(n=this.selfInfo)==null?void 0:n.permission)!=null&&c.control_other_sync)?!1:await this.updateStatus(K.UserChange,Y.UserPermission,{sync_frame:e},i)});s(this,"kick",async e=>{var i,n;return typeof this._options.canForbidUserKick=="function"&&!this._options.canForbidUserKick(e)||!((n=(i=this.selfInfo)==null?void 0:i.permission)!=null&&n.change_other_status)?!1:await this.updateStatus(K.UserChange,Y.UserStatus,{status:"KICK_OUT"},e)});this._addLiveControllerEventListeners(),this._options=Object.assign({initialMicroStatus:Q.OPEN},e),this._options.jsBridge=(()=>{if(e.jsBridge)return e.jsBridge;if(e.useBuiltInJsBridge)return new Kt})(),this._options.getVoiceSign=(i=e.getVoiceSign)!=null?i:hr,this._options.autoPlayConfirm=e.autoPlayConfirm,this._options.rtc=(()=>{if(e.rtc)return e.rtc;if(e.rtcType)switch(e.getVoiceSign||O.error("GetVoiceSign method must be passed when using built-in RTC instances"),e.rtcType){case ee.RealseeVRWebViewRTC:{if(this._options.jsBridge)return new $e({jsBridge:this._options.jsBridge,getVoiceSign:this._options.getVoiceSign});O.error("JsBridge instance must be passed when using built-in VRWebViewRTC instances");return}case ee.RealseeBrowserChimeRTC:return new Ve({getVoiceSign:this._options.getVoiceSign,logLevel:e.__debug__?at.DEBUG:at.INFO});case ee.RealseeBrowserRTC:return this._options.autoPlayConfirm||O.error("autoPlayConfirm method must be passed when using built-in RealseeBrowserRTC instances"),new De({getVoiceSign:this._options.getVoiceSign,autoPlayConfirm:this._options.autoPlayConfirm});default:{O.error("unknown built-in RTC type");return}}if(e.useBuiltInRTC){if(e.getVoiceSign||O.error("GetVoiceSign method must be passed when using built-in RTC instances"),this._options.jsBridge)return sr&&(rr||ir)||nr?new $e({jsBridge:this._options.jsBridge,getVoiceSign:this._options.getVoiceSign}):e.builtInRTCType===Ue.RealseeXChimeRTC?new Ve({getVoiceSign:this._options.getVoiceSign}):new De({getVoiceSign:this._options.getVoiceSign,autoPlayConfirm:this._options.autoPlayConfirm});O.error("jsBridge instance must be passed when using built-in RTC instances");return}})(),this._options.rtc||O.warn("unused rtc"),this._options.url&&this._options.getTicket&&this.connect(),this._options.__debug__&&Object.assign(window,{$liveController:this._controller,$live:this})}get options(){return Object.freeze(this._options||{})}get state(){return this._controller.state}get readyState(){return this._controller.state}get url(){return this.options.url}get $RTC(){return this._options.rtc}get jsBridge(){return this._options.jsBridge}get snapshot(){return this._buildInData.keyframes}get selfInfo(){return this._buildInData.selfInfo}get userList(){return this._buildInData.userList||[]}get roomInfo(){return this._buildInData.roomInfo}async updateStatus(e,i,n,c){if(this.state!==$.OPEN)return!1;const u=Object.assign({event_type:e,action:i},{data:n}),d=Me(U.BuiltinMsg,u,c);try{return this._controller.sendMessage(d),!0}catch(g){return O.error(g),!1}}broadcast(e,i,n){return this.state!==$.OPEN?!1:new Promise((c,u)=>{const d=Me(U.CustomEvent,e,i),g=d.front_request_id,v=n?setTimeout(()=>{u(new Error("RESPONSE TIMEOUT")),this.off("broadcast",E)},n):void 0,E=(y,I)=>{I===g&&(v&&clearTimeout(v),this.off("broadcast",E),c(y))};this.on("broadcast",E);try{this._controller.sendMessage(d)}catch(y){u(y)}})}}const vt=r=>(_r(),new gr(r));var xe={},mr={get exports(){return xe},set exports(r){xe=r}},ae={};/**
|
|
2
2
|
* @license React
|
|
3
3
|
* react-jsx-runtime.production.min.js
|
|
4
4
|
*
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*
|
|
7
7
|
* This source code is licensed under the MIT license found in the
|
|
8
8
|
* LICENSE file in the root directory of this source tree.
|
|
9
|
-
*/var ut;function vr(){if(ut)return ae;ut=1;var r=D,
|
|
9
|
+
*/var ut;function vr(){if(ut)return ae;ut=1;var r=D,o=Symbol.for("react.element"),e=Symbol.for("react.fragment"),i=Object.prototype.hasOwnProperty,n=r.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,c={key:!0,ref:!0,__self:!0,__source:!0};function u(d,g,v){var E,y={},I=null,_=null;v!==void 0&&(I=""+v),g.key!==void 0&&(I=""+g.key),g.ref!==void 0&&(_=g.ref);for(E in g)i.call(g,E)&&!c.hasOwnProperty(E)&&(y[E]=g[E]);if(d&&d.defaultProps)for(E in g=d.defaultProps,g)y[E]===void 0&&(y[E]=g[E]);return{$$typeof:o,type:d,key:I,ref:_,props:y,_owner:n.current}}return ae.Fragment=e,ae.jsx=u,ae.jsxs=u,ae}var ce={};/**
|
|
10
10
|
* @license React
|
|
11
11
|
* react-jsx-runtime.development.js
|
|
12
12
|
*
|
|
@@ -14,14 +14,14 @@
|
|
|
14
14
|
*
|
|
15
15
|
* This source code is licensed under the MIT license found in the
|
|
16
16
|
* LICENSE file in the root directory of this source tree.
|
|
17
|
-
*/var lt;function pr(){return lt||(lt=1,process.env.NODE_ENV!=="production"&&function(){var r=D,
|
|
17
|
+
*/var lt;function pr(){return lt||(lt=1,process.env.NODE_ENV!=="production"&&function(){var r=D,o=Symbol.for("react.element"),e=Symbol.for("react.portal"),i=Symbol.for("react.fragment"),n=Symbol.for("react.strict_mode"),c=Symbol.for("react.profiler"),u=Symbol.for("react.provider"),d=Symbol.for("react.context"),g=Symbol.for("react.forward_ref"),v=Symbol.for("react.suspense"),E=Symbol.for("react.suspense_list"),y=Symbol.for("react.memo"),I=Symbol.for("react.lazy"),_=Symbol.for("react.offscreen"),V=Symbol.iterator,C="@@iterator";function k(t){if(t===null||typeof t!="object")return null;var a=V&&t[V]||t[C];return typeof a=="function"?a:null}var B=r.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function P(t){{for(var a=arguments.length,l=new Array(a>1?a-1:0),h=1;h<a;h++)l[h-1]=arguments[h];de("error",t,l)}}function de(t,a,l){{var h=B.ReactDebugCurrentFrame,b=h.getStackAddendum();b!==""&&(a+="%s",l=l.concat([b]));var R=l.map(function(p){return String(p)});R.unshift("Warning: "+a),Function.prototype.apply.call(console[t],console,R)}}var f=!1,w=!1,A=!1,S=!1,N=!1,M;M=Symbol.for("react.module.reference");function W(t){return!!(typeof t=="string"||typeof t=="function"||t===i||t===c||N||t===n||t===v||t===E||S||t===_||f||w||A||typeof t=="object"&&t!==null&&(t.$$typeof===I||t.$$typeof===y||t.$$typeof===u||t.$$typeof===d||t.$$typeof===g||t.$$typeof===M||t.getModuleId!==void 0))}function J(t,a,l){var h=t.displayName;if(h)return h;var b=a.displayName||a.name||"";return b!==""?l+"("+b+")":l}function se(t){return t.displayName||"Context"}function G(t){if(t==null)return null;if(typeof t.tag=="number"&&P("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),typeof t=="function")return t.displayName||t.name||null;if(typeof t=="string")return t;switch(t){case i:return"Fragment";case e:return"Portal";case c:return"Profiler";case n:return"StrictMode";case v:return"Suspense";case E:return"SuspenseList"}if(typeof t=="object")switch(t.$$typeof){case d:var a=t;return se(a)+".Consumer";case u:var l=t;return se(l._context)+".Provider";case g:return J(t,t.render,"ForwardRef");case y:var h=t.displayName||null;return h!==null?h:G(t.type)||"Memo";case I:{var b=t,R=b._payload,p=b._init;try{return G(p(R))}catch(m){return null}}}return null}var z=Object.assign,te=0,T,F,re,he,Fe,qe,Ke;function Ge(){}Ge.__reactDisabledLog=!0;function pt(){{if(te===0){T=console.log,F=console.info,re=console.warn,he=console.error,Fe=console.group,qe=console.groupCollapsed,Ke=console.groupEnd;var t={configurable:!0,enumerable:!0,value:Ge,writable:!0};Object.defineProperties(console,{info:t,log:t,warn:t,error:t,group:t,groupCollapsed:t,groupEnd:t})}te++}}function Et(){{if(te--,te===0){var t={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:z({},t,{value:T}),info:z({},t,{value:F}),warn:z({},t,{value:re}),error:z({},t,{value:he}),group:z({},t,{value:Fe}),groupCollapsed:z({},t,{value:qe}),groupEnd:z({},t,{value:Ke})})}te<0&&P("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var Oe=B.ReactCurrentDispatcher,Ie;function _e(t,a,l){{if(Ie===void 0)try{throw Error()}catch(b){var h=b.stack.trim().match(/\n( *(at )?)/);Ie=h&&h[1]||""}return`
|
|
18
18
|
`+Ie+t}}var Te=!1,ge;{var yt=typeof WeakMap=="function"?WeakMap:Map;ge=new yt}function Ye(t,a){if(!t||Te)return"";{var l=ge.get(t);if(l!==void 0)return l}var h;Te=!0;var b=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var R;R=Oe.current,Oe.current=null,pt();try{if(a){var p=function(){throw Error()};if(Object.defineProperty(p.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(p,[])}catch(H){h=H}Reflect.construct(t,[],p)}else{try{p.call()}catch(H){h=H}t.call(p.prototype)}}else{try{throw Error()}catch(H){h=H}t()}}catch(H){if(H&&h&&typeof H.stack=="string"){for(var m=H.stack.split(`
|
|
19
19
|
`),x=h.stack.split(`
|
|
20
20
|
`),j=m.length-1,L=x.length-1;j>=1&&L>=0&&m[j]!==x[L];)L--;for(;j>=1&&L>=0;j--,L--)if(m[j]!==x[L]){if(j!==1||L!==1)do if(j--,L--,L<0||m[j]!==x[L]){var q=`
|
|
21
|
-
`+m[j].replace(" at new "," at ");return t.displayName&&q.includes("<anonymous>")&&(q=q.replace("<anonymous>",t.displayName)),typeof t=="function"&&ge.set(t,q),q}while(j>=1&&L>=0);break}}}finally{Te=!1,Oe.current=R,Et(),Error.prepareStackTrace=b}var ne=t?t.displayName||t.name:"",ot=ne?_e(ne):"";return typeof t=="function"&&ge.set(t,ot),ot}function bt(t,a,l){return Ye(t,!1)}function St(t){var a=t.prototype;return!!(a&&a.isReactComponent)}function me(t,a,l){if(t==null)return"";if(typeof t=="function")return Ye(t,St(t));if(typeof t=="string")return _e(t);switch(t){case v:return _e("Suspense");case E:return _e("SuspenseList")}if(typeof t=="object")switch(t.$$typeof){case g:return bt(t.render);case y:return me(t.type,a,l);case I:{var h=t,b=h._payload,R=h._init;try{return me(R(b),a,l)}catch(p){}}}return""}var ve=Object.prototype.hasOwnProperty,He={},Je=B.ReactDebugCurrentFrame;function pe(t){if(t){var a=t._owner,l=me(t.type,t._source,a?a.type:null);Je.setExtraStackFrame(l)}else Je.setExtraStackFrame(null)}function Ct(t,a,l,h,b){{var R=Function.call.bind(ve);for(var p in t)if(R(t,p)){var m=void 0;try{if(typeof t[p]!="function"){var x=Error((h||"React class")+": "+l+" type `"+p+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof t[p]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw x.name="Invariant Violation",x}m=t[p](a,p,h,l,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(j){m=j}m&&!(m instanceof Error)&&(pe(b),P("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).",h||"React class",l,p,typeof m),pe(null)),m instanceof Error&&!(m.message in He)&&(He[m.message]=!0,pe(b),P("Failed %s type: %s",l,m.message),pe(null))}}}var wt=Array.isArray;function ke(t){return wt(t)}function Rt(t){{var a=typeof Symbol=="function"&&Symbol.toStringTag,l=a&&t[Symbol.toStringTag]||t.constructor.name||"Object";return l}}function Ot(t){try{return ze(t),!1}catch(a){return!0}}function ze(t){return""+t}function Xe(t){if(Ot(t))return P("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",Rt(t)),ze(t)}var oe=B.ReactCurrentOwner,It={key:!0,ref:!0,__self:!0,__source:!0},Ze,Qe,Pe;Pe={};function Tt(t){if(ve.call(t,"ref")){var a=Object.getOwnPropertyDescriptor(t,"ref").get;if(a&&a.isReactWarning)return!1}return t.ref!==void 0}function kt(t){if(ve.call(t,"key")){var a=Object.getOwnPropertyDescriptor(t,"key").get;if(a&&a.isReactWarning)return!1}return t.key!==void 0}function Pt(t,a){if(typeof t.ref=="string"&&oe.current&&a&&oe.current.stateNode!==a){var l=G(oe.current.type);Pe[l]||(P('Component "%s" contains the string ref "%s". Support for string refs will be removed in a future major release. This case cannot be automatically converted to an arrow function. We ask you to manually fix this case by using useRef() or createRef() instead. Learn more about using refs safely here: https://reactjs.org/link/strict-mode-string-ref',G(oe.current.type),t.ref),Pe[l]=!0)}}function Nt(t,a){{var l=function(){Ze||(Ze=!0,P("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",a))};l.isReactWarning=!0,Object.defineProperty(t,"key",{get:l,configurable:!0})}}function jt(t,a){{var l=function(){Qe||(Qe=!0,P("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",a))};l.isReactWarning=!0,Object.defineProperty(t,"ref",{get:l,configurable:!0})}}var Lt=function(t,a,l,h,b,R,p){var m={$$typeof:
|
|
21
|
+
`+m[j].replace(" at new "," at ");return t.displayName&&q.includes("<anonymous>")&&(q=q.replace("<anonymous>",t.displayName)),typeof t=="function"&&ge.set(t,q),q}while(j>=1&&L>=0);break}}}finally{Te=!1,Oe.current=R,Et(),Error.prepareStackTrace=b}var ne=t?t.displayName||t.name:"",ot=ne?_e(ne):"";return typeof t=="function"&&ge.set(t,ot),ot}function bt(t,a,l){return Ye(t,!1)}function St(t){var a=t.prototype;return!!(a&&a.isReactComponent)}function me(t,a,l){if(t==null)return"";if(typeof t=="function")return Ye(t,St(t));if(typeof t=="string")return _e(t);switch(t){case v:return _e("Suspense");case E:return _e("SuspenseList")}if(typeof t=="object")switch(t.$$typeof){case g:return bt(t.render);case y:return me(t.type,a,l);case I:{var h=t,b=h._payload,R=h._init;try{return me(R(b),a,l)}catch(p){}}}return""}var ve=Object.prototype.hasOwnProperty,He={},Je=B.ReactDebugCurrentFrame;function pe(t){if(t){var a=t._owner,l=me(t.type,t._source,a?a.type:null);Je.setExtraStackFrame(l)}else Je.setExtraStackFrame(null)}function Ct(t,a,l,h,b){{var R=Function.call.bind(ve);for(var p in t)if(R(t,p)){var m=void 0;try{if(typeof t[p]!="function"){var x=Error((h||"React class")+": "+l+" type `"+p+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof t[p]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw x.name="Invariant Violation",x}m=t[p](a,p,h,l,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(j){m=j}m&&!(m instanceof Error)&&(pe(b),P("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).",h||"React class",l,p,typeof m),pe(null)),m instanceof Error&&!(m.message in He)&&(He[m.message]=!0,pe(b),P("Failed %s type: %s",l,m.message),pe(null))}}}var wt=Array.isArray;function ke(t){return wt(t)}function Rt(t){{var a=typeof Symbol=="function"&&Symbol.toStringTag,l=a&&t[Symbol.toStringTag]||t.constructor.name||"Object";return l}}function Ot(t){try{return ze(t),!1}catch(a){return!0}}function ze(t){return""+t}function Xe(t){if(Ot(t))return P("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",Rt(t)),ze(t)}var oe=B.ReactCurrentOwner,It={key:!0,ref:!0,__self:!0,__source:!0},Ze,Qe,Pe;Pe={};function Tt(t){if(ve.call(t,"ref")){var a=Object.getOwnPropertyDescriptor(t,"ref").get;if(a&&a.isReactWarning)return!1}return t.ref!==void 0}function kt(t){if(ve.call(t,"key")){var a=Object.getOwnPropertyDescriptor(t,"key").get;if(a&&a.isReactWarning)return!1}return t.key!==void 0}function Pt(t,a){if(typeof t.ref=="string"&&oe.current&&a&&oe.current.stateNode!==a){var l=G(oe.current.type);Pe[l]||(P('Component "%s" contains the string ref "%s". Support for string refs will be removed in a future major release. This case cannot be automatically converted to an arrow function. We ask you to manually fix this case by using useRef() or createRef() instead. Learn more about using refs safely here: https://reactjs.org/link/strict-mode-string-ref',G(oe.current.type),t.ref),Pe[l]=!0)}}function Nt(t,a){{var l=function(){Ze||(Ze=!0,P("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",a))};l.isReactWarning=!0,Object.defineProperty(t,"key",{get:l,configurable:!0})}}function jt(t,a){{var l=function(){Qe||(Qe=!0,P("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",a))};l.isReactWarning=!0,Object.defineProperty(t,"ref",{get:l,configurable:!0})}}var Lt=function(t,a,l,h,b,R,p){var m={$$typeof:o,type:t,key:a,ref:l,props:p,_owner:R};return m._store={},Object.defineProperty(m._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(m,"_self",{configurable:!1,enumerable:!1,writable:!1,value:h}),Object.defineProperty(m,"_source",{configurable:!1,enumerable:!1,writable:!1,value:b}),Object.freeze&&(Object.freeze(m.props),Object.freeze(m)),m};function At(t,a,l,h,b){{var R,p={},m=null,x=null;l!==void 0&&(Xe(l),m=""+l),kt(a)&&(Xe(a.key),m=""+a.key),Tt(a)&&(x=a.ref,Pt(a,b));for(R in a)ve.call(a,R)&&!It.hasOwnProperty(R)&&(p[R]=a[R]);if(t&&t.defaultProps){var j=t.defaultProps;for(R in j)p[R]===void 0&&(p[R]=j[R])}if(m||x){var L=typeof t=="function"?t.displayName||t.name||"Unknown":t;m&&Nt(p,L),x&&jt(p,L)}return Lt(t,m,x,b,h,oe.current,p)}}var Ne=B.ReactCurrentOwner,et=B.ReactDebugCurrentFrame;function ie(t){if(t){var a=t._owner,l=me(t.type,t._source,a?a.type:null);et.setExtraStackFrame(l)}else et.setExtraStackFrame(null)}var je;je=!1;function Le(t){return typeof t=="object"&&t!==null&&t.$$typeof===o}function tt(){{if(Ne.current){var t=G(Ne.current.type);if(t)return`
|
|
22
22
|
|
|
23
23
|
Check the render method of \``+t+"`."}return""}}function Mt(t){{if(t!==void 0){var a=t.fileName.replace(/^.*[\\\/]/,""),l=t.lineNumber;return`
|
|
24
24
|
|
|
25
25
|
Check your code at `+a+":"+l+"."}return""}}var rt={};function Dt(t){{var a=tt();if(!a){var l=typeof t=="string"?t:t.displayName||t.name;l&&(a=`
|
|
26
26
|
|
|
27
|
-
Check the top-level render call using <`+l+">.")}return a}}function it(t,a){{if(!t._store||t._store.validated||t.key!=null)return;t._store.validated=!0;var l=Dt(a);if(rt[l])return;rt[l]=!0;var h="";t&&t._owner&&t._owner!==Ne.current&&(h=" It was passed a child from "+G(t._owner.type)+"."),ie(t),P('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',l,h),ie(null)}}function nt(t,a){{if(typeof t!="object")return;if(ke(t))for(var l=0;l<t.length;l++){var h=t[l];Le(h)&&it(h,a)}else if(Le(t))t._store&&(t._store.validated=!0);else if(t){var b=k(t);if(typeof b=="function"&&b!==t.entries)for(var R=b.call(t),p;!(p=R.next()).done;)Le(p.value)&&it(p.value,a)}}}function Vt(t){{var a=t.type;if(a==null||typeof a=="string")return;var l;if(typeof a=="function")l=a.propTypes;else if(typeof a=="object"&&(a.$$typeof===g||a.$$typeof===y))l=a.propTypes;else return;if(l){var h=G(a);Ct(l,t.props,"prop",h,t)}else if(a.PropTypes!==void 0&&!je){je=!0;var b=G(a);P("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",b||"Unknown")}typeof a.getDefaultProps=="function"&&!a.getDefaultProps.isReactClassApproved&&P("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function $t(t){{for(var a=Object.keys(t.props),l=0;l<a.length;l++){var h=a[l];if(h!=="children"&&h!=="key"){ie(t),P("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",h),ie(null);break}}t.ref!==null&&(ie(t),P("Invalid attribute `ref` supplied to `React.Fragment`."),ie(null))}}function st(t,a,l,h,b,R){{var p=W(t);if(!p){var m="";(t===void 0||typeof t=="object"&&t!==null&&Object.keys(t).length===0)&&(m+=" You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");var x=Mt(b);x?m+=x:m+=tt();var j;t===null?j="null":ke(t)?j="array":t!==void 0&&t.$$typeof===
|
|
27
|
+
Check the top-level render call using <`+l+">.")}return a}}function it(t,a){{if(!t._store||t._store.validated||t.key!=null)return;t._store.validated=!0;var l=Dt(a);if(rt[l])return;rt[l]=!0;var h="";t&&t._owner&&t._owner!==Ne.current&&(h=" It was passed a child from "+G(t._owner.type)+"."),ie(t),P('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',l,h),ie(null)}}function nt(t,a){{if(typeof t!="object")return;if(ke(t))for(var l=0;l<t.length;l++){var h=t[l];Le(h)&&it(h,a)}else if(Le(t))t._store&&(t._store.validated=!0);else if(t){var b=k(t);if(typeof b=="function"&&b!==t.entries)for(var R=b.call(t),p;!(p=R.next()).done;)Le(p.value)&&it(p.value,a)}}}function Vt(t){{var a=t.type;if(a==null||typeof a=="string")return;var l;if(typeof a=="function")l=a.propTypes;else if(typeof a=="object"&&(a.$$typeof===g||a.$$typeof===y))l=a.propTypes;else return;if(l){var h=G(a);Ct(l,t.props,"prop",h,t)}else if(a.PropTypes!==void 0&&!je){je=!0;var b=G(a);P("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",b||"Unknown")}typeof a.getDefaultProps=="function"&&!a.getDefaultProps.isReactClassApproved&&P("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function $t(t){{for(var a=Object.keys(t.props),l=0;l<a.length;l++){var h=a[l];if(h!=="children"&&h!=="key"){ie(t),P("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",h),ie(null);break}}t.ref!==null&&(ie(t),P("Invalid attribute `ref` supplied to `React.Fragment`."),ie(null))}}function st(t,a,l,h,b,R){{var p=W(t);if(!p){var m="";(t===void 0||typeof t=="object"&&t!==null&&Object.keys(t).length===0)&&(m+=" You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");var x=Mt(b);x?m+=x:m+=tt();var j;t===null?j="null":ke(t)?j="array":t!==void 0&&t.$$typeof===o?(j="<"+(G(t.type)||"Unknown")+" />",m=" Did you accidentally export a JSX literal instead of a component?"):j=typeof t,P("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",j,m)}var L=At(t,a,l,b,R);if(L==null)return L;if(p){var q=a.children;if(q!==void 0)if(h)if(ke(q)){for(var ne=0;ne<q.length;ne++)nt(q[ne],t);Object.freeze&&Object.freeze(q)}else P("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else nt(q,t)}return t===i?$t(L):Vt(L),L}}function xt(t,a,l){return st(t,a,l,!0)}function Ut(t,a,l){return st(t,a,l,!1)}var Bt=Ut,Wt=xt;ce.Fragment=i,ce.jsx=Bt,ce.jsxs=Wt}()),ce}(function(r){process.env.NODE_ENV==="production"?r.exports=vr():r.exports=pr()})(mr);const Er=xe.jsx;function yr(r){const o=D.createContext(null),e=vt(r),i=e.jsBridge,n=f=>Er(o.Provider,{value:e,children:f.children}),c=()=>{const f=D.useContext(o);if(!f)throw new Error("LiveProvider never found.");return f},u=()=>e,d=()=>e.$RTC,g=()=>d(),v=()=>async f=>await e.connect(f);function E(f,w,A=[]){const S=c(),N=[S,name,...A],M=()=>S.keyframes.off(f,w);return D.useEffect(()=>(S.keyframes.on(f,w),M),N),M}function y(){const f=c();return{connect:async T=>await f.connect(T),broadcast:async(T,F,re=0)=>await f.broadcast(T,F,re),exit:async()=>await f.exit(),kick:async T=>await f.kick(T),toggleMicro:T=>f.toggleMicro(T),forbidMicro:async(T,F=[])=>await f.forbidMicro(T,F),forbidSync:(T,F=[])=>f.forbidSync(T,F),sendKeyframe:(T,F)=>f.sendKeyframe(T,F),getFramesByKey:T=>f.getFramesByKey(T),setSelfInfo:T=>f.setSelfInfo(T),updateStatus:(T,F,re,he)=>f.updateStatus(T,F,re,he)}}function I(f){const w=c(),[A,S]=D.useState(w.getFramesByKey(f));D.useEffect(()=>{const M=se=>S(se),W=f,J=M;return w.keyframes.on(W,J),()=>w.keyframes.off(W,J)},[w]);const N=D.useCallback(M=>w.sendKeyframe(f,M),[w]);return[A,N]}function _(f,w,A=[]){const S=c(),N=()=>S.off(f,w),M=[S,f,...A];return D.useEffect(()=>(S.on(f,w),N),M),N}function V(){const f=c(),[w,A]=D.useState(f.state);return D.useEffect(()=>{const S=N=>A(N);return f.on("stateChange",S),()=>f.off("stateChange",S)},[f]),w}function C(){const f=c();return{join:W=>f.$RTC.join(W),quit:()=>f.$RTC.quit(),shock:()=>{var W,J;return(J=(W=f.$RTC).shock)==null?void 0:J.call(W)},toggleMicro:W=>f.$RTC.toggleMicro(W),detectMicro:()=>f.$RTC.detectMicro()}}function k(f,w,A=[]){const S=c(),N=()=>S.$RTC.off(f,w),M=[S,f,...A];return D.useEffect(()=>(S.$RTC.on(f,w),N),M),N}function B(){const f=c(),[w,A]=D.useState(f.selfInfo||{}),S=M=>A(M);D.useEffect(()=>(f.on("selfInfoUpdate",S),()=>f.off("selfInfoUpdate",S)),[f]);const N=D.useCallback(async M=>await f.setSelfInfo(M),[f]);return[w,N]}function P(){const f=c(),[w,A]=D.useState(f.snapshot);return D.useEffect(()=>{const S=N=>A(N);return f.on("keyframes",S),()=>f.off("keyframes",S)}),w}function de(){const f=c(),[w,A]=D.useState(f.userList),S=N=>A(N);return D.useEffect(()=>(f.on("userListUpdate",S),()=>f.off("userListUpdate",S)),[f]),w}return{live:e,jsBridge:i,LiveProvider:n,unsafe__useLiveInstance:u,unsafe__useRTCInstance:g,useConnect:v,useKeyframe:I,useKeyframeUpdateCallback:E,useLiveAction:y,useLiveEventCallback:_,useLiveState:V,useRTCAction:C,useRTCEventCallback:k,useSelfInfo:B,useKeyframesSnapshot:P,useUserList:de}}exports.BrowserRTC=De;exports.BrowserRTC4Chime=Ve;exports.BuiltInRTCType=Ue;exports.BuiltinActionType=Y;exports.BuiltinEventType=K;exports.Command=U;exports.CoreRTC=Ce;exports.LiveState=$;exports.MemUserStatus=dt;exports.MicroStatus=Q;exports.RTCJoinedInfoCodeEnum=Be;exports.RTCType=ee;exports.UserStatus=ft;exports.VRWebViewRTC=$e;exports.WebSocketCloseError=_t;exports.WebSocketErrorType=ht;exports.WebSocketState=be;exports.createLive=vt;exports.createLiveReact=yr;exports.parseLiveMsg=Qt;exports.parseWSClsErr=gt;
|