@realsee/live 0.5.2-dev.8 → 0.5.4-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("trtc-js-sdk"),t=require("amazon-chime-sdk-js"),i=require("react");function o(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var n=o(e),s=o(i);const r=Symbol("$$REALSEE_LIVE_EVENT$$");function c(e){return e[r]||(e[r]={}),e[r]}class a{hasListener(e){const t=c(this);return t&&t[e]&&t[e].length>0}on(e,t,i){const o=c(this);return o[e]||(o[e]=[]),o[e].push([t,i||!1]),()=>this.off(e,t)}once(e,t){return this.on(e,t,!0)}off(e,t){if(void 0===e)return void((i=this)[r]||delete i[r]);var i;const o=c(this);if(o[e]||(o[e]=[]),void 0===t)return void(o[e].length=0);let n=0;for(;n<o[e].length&&o[e][n][0]!==t;n++);n<o[e].length&&o[e].splice(n,1)}emit(e,...t){let i=!1;const o=c(this)[e]||[];for(let n of o.slice()){const[o,s=!1]=n,r=o(...t);s&&this.off(e,o),!1===r&&(i=!0)}return i}}class l extends a{}function d(e,t,i,o){return new(i||(i=Promise))((function(n,s){function r(e){try{a(o.next(e))}catch(e){s(e)}}function c(e){try{a(o.throw(e))}catch(e){s(e)}}function a(e){var t;e.done?n(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(r,c)}a((o=o.apply(e,t||[])).next())}))}var h,u;exports.RTCType=void 0,(h=exports.RTCType||(exports.RTCType={})).RealseeBrowserRTC="RealseeBrowserRTC",h.RealseeVRWebViewRTC="RealseeVRWebViewRTC",h.RealseeBrowserChimeRTC="RealseeBrowserChimeRTC",exports.BuiltInRTCType=void 0,(u=exports.BuiltInRTCType||(exports.BuiltInRTCType={})).RealseeXTRTC="trtc",u.RealseeXChimeRTC="chime";var v;!function(e){e.info="INFO",e.log="LOG",e.error="ERROR",e.warn="WARN"}(v||(v={}));const m=(e,t=[])=>{switch(t.unshift(`Realsee Live ${(()=>{const e=new Date;return`[${e.getFullYear()}-${(e.getMonth()+1).toString().padStart(2,"0")}-${e.getDate().toString().padStart(2,"0")} ${e.getHours().toString().padStart(2,"0")}:${e.getMinutes().toString().padStart(2,"0")}:${e.getSeconds().toString().padStart(2,"0")}.${e.getMilliseconds()}]`})()} <${e}> `),e){case v.info:return console.info(...t);case v.error:return console.error(...t);case v.warn:return console.warn(...t);default:return console.log(...t)}};var g,f,p,_,y,b,S,w,k,E,C,T={log:(...e)=>m(v.log,e),info:(...e)=>m(v.info,e),error:(...e)=>m(v.error,e),warn:(...e)=>m(v.warn,e)};function I(){return(65536*(1+Math.random())|0).toString(16).substring(1)}function R(){return(I()+I()+"-"+I()+"-4"+I().substr(0,3)+"-"+I()+"-"+I()+I()+I()).toLowerCase()}class O extends l{constructor(e){super(),this.type=exports.RTCType.RealseeBrowserRTC,this.joined=!1,this.micro=!1,this.voiceId="",this._getVoiceSign=()=>{throw new Error("方法 getVoiceSign 未实现")},this.checkRequirement=()=>n.default.checkSystemRequirements(),this.$dom=document.createElement("div"),this._trtc={client:null,stream:null},this.join=e=>d(this,void 0,void 0,(function*(){var t;this.emit("joinWillStart");const i=yield this._getVoiceSign({voiceId:e.voiceId,roomId:e.roomId,userId:e.userId});this._trtc.client=n.default.createClient(Object.assign(Object.assign({mode:"rtc"},i),{enableAutoPlayDialog:"function"!=typeof this._autoPlayConfirm})),null===(t=this._trtc.client)||void 0===t||t.enableAudioVolumeEvaluation(),this._registerRtcEvent();let o=yield new Promise((t=>{var i;null===(i=this._trtc.client)||void 0===i||i.join({roomId:Number(e.voiceId)}).then((()=>t(!0))).catch((()=>t(!1)))}));return this.joined=o,!!o&&(this._trtc.stream=n.default.createStream({userId:i.userId,audio:!0,video:!1}),o=yield new Promise((e=>{var t;null===(t=this._trtc.stream)||void 0===t||t.initialize().then((()=>e(!0))).catch((()=>e(!1)))})),o=yield new Promise((e=>{var t;null===(t=this._trtc.client)||void 0===t||t.publish(this._trtc.stream).then((()=>e(!0))).catch((()=>e(!1)))})),this.joined=o,this.joined&&this.emit("joined"),o)})),this._handleStreamAdded=e=>{var t;const i=e.stream;console.log("远端流增加: "+i.getId()),null===(t=this._trtc.client)||void 0===t||t.subscribe(i)},this._handleStreamSubscribed=e=>{const t=e.stream;console.log("远端流订阅成功:"+t.getId());const i=`rs-rtc-remote_stream-${t.getId()}`,o=document.createElement("div");o.id=i,this.$dom.appendChild(o),"function"==typeof this._autoPlayConfirm?(t.play(i).catch((e=>{})),t.on("error",(e=>{if(16451===e.getCode()){const e=()=>t.resume();this._autoPlayConfirm({onConfirm:e})}}))):t.play(i)},this._getVoiceSign=e.getVoiceSign,this._autoPlayConfirm=e.autoPlayConfirm,this._initParentDom()}_initParentDom(){this.$dom.id=`rs-rtc-${R()}`,this.$dom.style.display="none",document.body.appendChild(this.$dom)}quit(){return new Promise((e=>d(this,void 0,void 0,(function*(){var t,i;this.joined=!1,this._trtc.stream&&(yield null===(t=this._trtc.client)||void 0===t?void 0:t.unpublish(this._trtc.stream),this._trtc.stream.stop(),this._trtc.stream.close(),this._trtc.stream=null),null===(i=this._trtc.client)||void 0===i||i.leave().then((()=>this._trtc.client=null)).then((()=>e(!0))).catch((()=>e(!1))),e(!0)}))))}detectMicro(){return new Promise((e=>{const t={audio:!0,video:!1};try{navigator.mediaDevices.getUserMedia(t).then((()=>e(!0))).catch((t=>{T.error(t.message),e(!1)}))}catch(t){console.error(t),e(!1)}}))}toggleMicro(e){var t,i,o,n;return Promise.resolve((e?null===(i=null===(t=this._trtc)||void 0===t?void 0:t.stream)||void 0===i?void 0:i.unmuteAudio():null===(n=null===(o=this._trtc)||void 0===o?void 0:o.stream)||void 0===n?void 0:n.muteAudio())||!1)}shock(){throw new Error("Method not implemented.")}_registerRtcEvent(){var e,t,i,o;null===(e=this._trtc.client)||void 0===e||e.on("stream-added",this._handleStreamAdded),null===(t=this._trtc.client)||void 0===t||t.on("stream-subscribed",this._handleStreamSubscribed),null===(i=this._trtc.client)||void 0===i||i.on("audio-volume",(e=>this.emit("userVolumes",e.result.map((({userId:e,audioVolume:t})=>({userId:e,audioVolume:t})))))),null===(o=this._trtc.client)||void 0===o||o.on("error",(e=>this.emit("error",e)))}}class B extends l{constructor(e){super(),this.type=exports.RTCType.RealseeBrowserChimeRTC,this.joined=!1,this.micro=!1,this.voiceId="",this.userId="",this.deviceChangeObserver={},this.audioVideoObserver={},this._getVoiceSign=()=>{throw new Error("方法 getVoiceSign 未实现")},this.$dom=document.createElement("div"),this.$audio=document.createElement("audio"),this._initDom=()=>{this.$audio.id=`rs-rtc-${R()}`,this.$dom.id=`rs-rtc-${R()}`,this.$dom.appendChild(this.$audio),document.body.appendChild(this.$dom)},this.initObservers=()=>{this.deviceChangeObserver={audioInputsChanged:e=>{null==e||e.forEach((e=>{this.logger.info(`Device ID: ${e.deviceId} Microphone: ${e.label}`)}))},audioOutputsChanged:e=>{this.logger.info(`Audio outputs updated: ${e}`)},videoInputsChanged:e=>{this.logger.info(`Video inputs updated: ${e}`)},audioInputMuteStateChanged:(e,t)=>{this.logger.info(`Device ${e.toString()} ${t?"is muted in hardware":"is not muted"}`)}},this.audioVideoObserver={audioVideoDidStart:()=>{this.logger.info("Started")},audioVideoDidStop:e=>{this.logger.info(`Stopped with a session status code: ${e.statusCode()}`)},audioVideoDidStartConnecting:e=>{e&&this.logger.info("Attempting to reconnect")}}},this._registerRtcEvent=()=>{var e,i,o,n,s,r;const c=(null===(o=null===(i=null===(e=this.meetingSession)||void 0===e?void 0:e.configuration)||void 0===i?void 0:i.credentials)||void 0===o?void 0:o.attendeeId)||"";if(c){const e=new Map,i=()=>{const t=[];return e.forEach(((e,i)=>{t.push({userId:e.userId,volume:e.muted||0===e.signalStrength||!Boolean(e.volume)?0:e.volume})})),t};null===(n=this.meetingSession)||void 0===n||n.audioVideo.realtimeSubscribeToAttendeeIdPresence(((o,n,s)=>{var r;if(!n)return e.delete(o),void this.emit("userVolumes",i());null===(r=this.meetingSession)||void 0===r||r.audioVideo.realtimeSubscribeToVolumeIndicator(o,((o,n,r,c)=>{new t.DefaultModality(o).base()===o&&(e.set(o,{userId:s||o,volume:n,muted:r,signalStrength:c}),this.emit("userVolumes",i()))}))})),null===(s=this.meetingSession)||void 0===s||s.audioVideo.realtimeSubscribeToVolumeIndicator(c,((e,i,o,n)=>{new t.DefaultModality(e).base()===e&&null!==n&&1!==n&&this.emit("weakNetwork")})),null===(r=this.meetingSession)||void 0===r||r.audioVideo.realtimeSubscribeToFatalError((e=>this.emit("error",e)))}},this._getVoiceSign=e.getVoiceSign,this._initDom(),this.logger=new t.ConsoleLogger("WebRTCLogger",e.logLevel||t.LogLevel.OFF),this.deviceController=new t.DefaultDeviceController(this.logger),this.initObservers()}join(e){return d(this,void 0,void 0,(function*(){return new Promise(((i,o)=>d(this,void 0,void 0,(function*(){var o;this.emit("joinWillStart");try{const{sdkAppId:n,userId:s,roomId:r,userSig:c}=yield this._getVoiceSign(Object.assign(Object.assign({},e),{roomId:e.roomId||0}));this.userId=s;const{attendence:a,vendor_wrapper:l}=JSON.parse(decodeURIComponent(c)),d=new t.MeetingSessionConfiguration({Meeting:l},{Attendee:{ExternalUserId:a.external_user_id,AttendeeId:a.attendee_id,JoinToken:a.join_token}});this.meetingSession=new t.DefaultMeetingSession(d,this.logger,this.deviceController),this._registerRtcEvent(),this.meetingSession.audioVideo.addDeviceChangeObserver(this.deviceChangeObserver),this.meetingSession.audioVideo.addObserver(this.audioVideoObserver),this.meetingSession.audioVideo.bindAudioElement(this.$audio);const h={audioVideoDidStart:()=>{var e;null===(e=this.meetingSession)||void 0===e||e.audioVideo.realtimeMuteLocalAudio(),this.joined=!0,this.emit("joined"),i(!0)},audioVideoDidStop:()=>{this.joined=!1,i(!1)}};this.meetingSession.audioVideo.addObserver(h);const u=yield this.deviceController.listAudioInputDevices(!0),v=u.find((e=>"default"===e.deviceId)),m=u.find((e=>""!==e.deviceId));this.audioInput=v||m,yield this.meetingSession.audioVideo.chooseVideoInputDevice(null),yield this.meetingSession.audioVideo.chooseAudioInputDevice((null===(o=this.audioInput)||void 0===o?void 0:o.deviceId)||"default"),this.meetingSession.audioVideo.start()}catch(e){this.emit("error",e),this.logger.error(e.message),i(!1)}}))))}))}quit(){return this.joined?new Promise(((e,i)=>{var o,n;this.joined=!1;const s={audioVideoDidStop:i=>{const o=i.statusCode();o===t.MeetingSessionStatusCode.Left?(this.logger.info("You left the session"),e(!0)):(this.logger.info(`Stopped with a session status code: ${o}`),e(!0))}};null===(o=this.meetingSession)||void 0===o||o.audioVideo.addObserver(s),null===(n=this.meetingSession)||void 0===n||n.audioVideo.stop()})):Promise.resolve(!0)}detectMicro(){return d(this,void 0,void 0,(function*(){return new Promise((e=>{const t={audio:!0,video:!1};try{navigator.mediaDevices.getUserMedia(t).then((()=>e(!0))).catch((()=>e(!1)))}catch(t){this.logger.error(t.message),e(!1)}}))}))}toggleMicro(e){var t,i,o;return d(this,void 0,void 0,(function*(){e?null===(t=this.meetingSession)||void 0===t||t.audioVideo.realtimeUnmuteLocalAudio():null===(i=this.meetingSession)||void 0===i||i.audioVideo.realtimeMuteLocalAudio();const n=null===(o=this.meetingSession)||void 0===o?void 0:o.audioVideo.realtimeIsLocalAudioMuted();return void 0!==n&&e!==n}))}shock(){throw new Error("Method not implemented.")}}exports.RTCJoinedInfoCodeEnum=void 0,(g=exports.RTCJoinedInfoCodeEnum||(exports.RTCJoinedInfoCodeEnum={}))[g.Success=0]="Success",g[g.Failure=1]="Failure",g[g.ReJoin=2]="ReJoin",g[g.NoMicroPermission=3]="NoMicroPermission";class A extends l{get jsBridge(){return this.options.jsBridge}constructor({jsBridge:e,getVoiceSign:t}){super(),this.type=exports.RTCType.RealseeVRWebViewRTC,this.joined=!1,this.micro=!1,this.voiceId="",this.options={jsBridge:e,getVoiceSign:t},"WxMiniProgramWebView"!==this.jsBridge.webViewType&&this.jsBridge.callAndListen("live/userVolumes",(e=>{this.emit("userVolumes",e)})),this.jsBridge.callAndListen("live/weakNetwork",(e=>{e&&this.emit("weakNetwork")}))}join(e){return d(this,void 0,void 0,(function*(){try{this.emit("joinWillStart");const{sdkAppId:t,userId:i,userSig:o}=yield this.options.getVoiceSign(e);if(!(Boolean(t)&&Boolean(i)&&Boolean(o)))return this.emit("error",new Error("加入房间失败:rtc 签名请求异常")),this.joined=!1,this.joined;this.type=e.type;const[n,s]=yield this.jsBridge.callAndBackfeed(`live/join?sdkAppID=${t}&userID=${i}&roomID=${Number(e.voiceId)}&userSig=${o}`);return n?n.code===exports.RTCJoinedInfoCodeEnum.Success?(this.emit("joined"),this.joined=!0):(this.emit("error",n),this.joined=!1):(this.emit("error",s||new Error("加入房间失败:未知异常。")),this.joined=!1),this.joined}catch(e){return this.emit("error",new Error("加入房间失败:"+e.message)),this.joined=!1,this.joined}}))}quit(){return d(this,void 0,void 0,(function*(){const[e,t]=yield this.jsBridge.callAndBackfeed("live/quit");return null===e&&this.emit("error",t||new Error("退出房间失败:未知异常。")),this.joined=!1,!!e}))}detectMicro(){return d(this,void 0,void 0,(function*(){const[e,t]=yield this.jsBridge.detectMicro();return null===e?(this.emit("error",t||new Error("麦克风监测异常!")),!1):e}))}toggleMicro(e){return d(this,void 0,void 0,(function*(){const[t,i]=yield this.jsBridge.callAndBackfeed("live/toggleMicro?flag="+(e?1:0));return null===t?(this.emit("error",i||new Error("麦克风监测异常!")),!1):(this.micro=t,t)}))}shock(){this.jsBridge.shock(1)}}function L(e){switch(e){case 1e3:return exports.WebSocketCloseError.Err_1000;case 1001:return exports.WebSocketCloseError.Err_1001;case 1002:return exports.WebSocketCloseError.Err_1002;case 1003:return exports.WebSocketCloseError.Err_1003;case 1006:return exports.WebSocketCloseError.Err_1006;case 1007:return exports.WebSocketCloseError.Err_1007;case 1008:return exports.WebSocketCloseError.Err_1008;case 1009:return exports.WebSocketCloseError.Err_1009}return exports.WebSocketCloseError.Err_unknown}function x(e,t,i,o){return new(i||(i=Promise))((function(n,s){function r(e){try{a(o.next(e))}catch(e){s(e)}}function c(e){try{a(o.throw(e))}catch(e){s(e)}}function a(e){var t;e.done?n(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(r,c)}a((o=o.apply(e,t||[])).next())}))}exports.Command=void 0,(f=exports.Command||(exports.Command={})).SelfUserInfo="SELF_USER_INFO",f.RoomInfo="ROOM_INFO",f.RTCInfo="RTC_INFO",f.UserList="USER_LIST",f.BuiltinMsg="BUILTIN_MSG",f.CustomEvent="CUSTOM_EVENT",f.KeyframeSync="KEYFRAME_SYNC",f.UserKickOut="USER_KICK_OUT",exports.BuiltinEventType=void 0,(p=exports.BuiltinEventType||(exports.BuiltinEventType={})).UserChange="user_change",p.RoomChange="room_change",exports.BuiltinActionType=void 0,(_=exports.BuiltinActionType||(exports.BuiltinActionType={})).UserMicroStatus="change_micro_status",_.UserMicroStatusSync="sync_micro_status",_.UserPermission="change_permission",_.UserStatus="change_status",_.UserInfo="change_info",_.RoomClose="close",exports.MicroStatus=void 0,(y=exports.MicroStatus||(exports.MicroStatus={})).OPEN="OPEN",y.CLOSE="CLOSE",exports.LiveState=void 0,(b=exports.LiveState||(exports.LiveState={}))[b.NOTINITIALIZED=-1]="NOTINITIALIZED",b[b.CONNECTING=0]="CONNECTING",b[b.OPEN=1]="OPEN",b[b.CLOSED=3]="CLOSED",exports.UserStatus=void 0,(S=exports.UserStatus||(exports.UserStatus={}))[S.Normal=0]="Normal",S[S.Removed=1]="Removed",S[S.Replaced=2]="Replaced",exports.MemUserStatus=void 0,(w=exports.MemUserStatus||(exports.MemUserStatus={})).WAIT_ENTER="WAIT_ENTER",w.ONLINE="ONLINE",w.LEAVE="LEAVE",w.KICK_OUT="KICK_OUT",w.BE_REPLACE="BE_REPLACE",w.EXCEPTION="EXCEPTION",exports.WebSocketState=void 0,(k=exports.WebSocketState||(exports.WebSocketState={}))[k.NOTINITIALIZED=-1]="NOTINITIALIZED",k[k.CONNECTING=0]="CONNECTING",k[k.OPEN=1]="OPEN",k[k.CLOSING=2]="CLOSING",k[k.CLOSED=3]="CLOSED",exports.WebSocketErrorType=void 0,(E=exports.WebSocketErrorType||(exports.WebSocketErrorType={})).Error="Error",E.Close="Close",E.MicroAuth="MicroAuth",E.DuplicateConnect="DuplicateConnect",E.IllegalURL="IllegalURL",E.Unknown="Unknown",E.IllegalArgs="IllegalArgs",exports.WebSocketCloseError=void 0,(C=exports.WebSocketCloseError||(exports.WebSocketCloseError={})).Err_1000="CLOSE_NORMAL",C.Err_1001="CLOSE_GOING_AWAY",C.Err_1002="CLOSE_PROTOCOL_ERROR",C.Err_1003="CLOSE_UNSUPPORTED",C.Err_1006="CLOSE_ABNORMAL",C.Err_1007="Unsupported Data",C.Err_1008="Policy Violation",C.Err_1009="CLOSE_TOO_LARGE",C.Err_unknown="unknown";const N={};function W(e,t,i=!0){if(N[e])N[e].queue.push({once:i,callback:t});else{const o="$jsBridgeFn_"+Date.now().toString(16).toUpperCase()+"_"+Math.ceil(1e4*Math.random()).toString(16).toUpperCase();N[e]={uuid:o,queue:[{once:i,callback:t}]}}return Object.assign(window,{[N[e].uuid]:t=>{N[e].queue=N[e].queue.reduce(((e,i)=>{const{once:o,callback:n}=i;return o||e.push(i),n(t),e}),[])}}),N[e].uuid}class M{checkReady(e){return Promise.resolve([!1,null])}callAndBackfeed(e){return Promise.resolve([!1,null])}callAndListen(e,t){return Promise.resolve([!1,null])}}const P=window;class V extends M{constructor(){super(),Promise.resolve().then((()=>x(this,void 0,void 0,(function*(){try{yield this.checkBridgeReady()}catch(e){console.warn(e)}}))))}checkBridgeReady(e=6e3){if(this.hybridBridge)return!0;const t=performance.now();return new Promise(((i,o)=>{const n=()=>{if(this.hybridBridge)return i(!0);if(P.HybridBridgeLJ){const e=P.HybridBridgeLJ;null==e||e.getStaticData(W("HYBRID_BRIDGE_NAME",(t=>(this.deviceInfo=JSON.parse(t),this.hybridBridge=e,i(!0)))))}if(performance.now()-t>(e||6e3))return o(new Error("HybridBridge 初始化超时~"));requestAnimationFrame(n)};n()}))}checkReady(e=6e3){return x(this,void 0,void 0,(function*(){const t=[null,null];if(this.hybridBridge)return t[0]=!0,t;try{t[0]=yield this.checkBridgeReady(e)}catch(e){t[0]=!1,t[1]=e}return t}))}get ready(){return!!this.hybridBridge}get scheme(){var e;return(null===(e=this.deviceInfo)||void 0===e?void 0:e.scheme)||""}createSchemeLink(e){return e.startsWith(this.scheme)?e:this.scheme+"://"+e}callAndBackfeed(e){return x(this,void 0,void 0,(function*(){const t=[!1,null],[i,o]=yield this.checkReady();return i?yield new Promise((i=>x(this,void 0,void 0,(function*(){const o=this.createSchemeLink(e),n=JSON.stringify({actionUrl:o,functionName:W(this.createSchemeLink(e),(e=>{const o=(()=>{try{return JSON.parse(e)}catch(t){return e}})();t[0]=1===o||0!==o&&o,i(t)}))});this.hybridBridge.callAndBackfeed(n)})))):(t[0]=!1,t[1]=o,t)}))}callAndListen(e,t){return x(this,void 0,void 0,(function*(){const i=[!1,null],[o,n]=yield this.checkReady();return o?yield new Promise((o=>x(this,void 0,void 0,(function*(){const n=this.createSchemeLink(e),s=e=>{const r=(()=>{try{return JSON.parse(e)}catch(t){return e}})();t(1===r||0!==r&&r),i[0]=()=>{const e=N[n];if(!e)return;const t=e.queue.findIndex((e=>e.callback===s));-1!==t&&e.queue.splice(t,1)},o(i)},r=JSON.stringify({actionUrl:n,functionName:W(n,s,!1)});this.hybridBridge.callAndListen(r)})))):(i[0]=!1,i[1]=n,i)}))}}var j;!function(e){e.callAndBackfeed="callAndBack",e.callAndListen="callAndListen"}(j||(j={}));const U=window;class D{constructor(){this.checkBridgeReady()}checkBridgeReady(e=6e3){if(this.worker)return!0;const t=performance.now();return new Promise(((i,o)=>{const n=()=>{if(this.worker)return i(!0);if(U.webkit&&U.webkit.messageHandlers&&U.webkit.messageHandlers.realsee){const e=U.webkit.messageHandlers.realsee;e.postMessage(JSON.stringify({type:"getStaticData",param:JSON.stringify({functionName:W("HYBRID_BRIDGE_NAME",(t=>(this.deviceInfo=JSON.parse(t),this.worker=e,i(!0))))})}))}else{if(performance.now()-t>(e||6e3))return o(new Error("HybridBridge 初始化超时~"));requestAnimationFrame(n)}};n()}))}checkReady(e=6e3){return x(this,void 0,void 0,(function*(){const t=[null,null];if(this.worker)return t[0]=!0,t;try{t[0]=yield this.checkBridgeReady(e)}catch(e){t[0]=!1,t[1]=e}return t}))}get ready(){return!!this.worker}get scheme(){var e;return(null===(e=this.deviceInfo)||void 0===e?void 0:e.scheme)||""}createSchemeLink(e){return e.startsWith(this.scheme)?e:this.scheme+"://"+e}callAndBackfeed(e){return x(this,void 0,void 0,(function*(){const t=[!1,null],[i,o]=yield this.checkReady();return i?yield new Promise((i=>x(this,void 0,void 0,(function*(){const o=this.createSchemeLink(e),n=JSON.stringify({actionUrl:o,functionName:W(this.createSchemeLink(e),(e=>{const o=(()=>{try{return JSON.parse(e)}catch(t){return e}})();t[0]=1===o||0!==o&&o,i(t)}))});this.worker.postMessage(JSON.stringify({type:"callAndBackfeed",param:n}))})))):(t[0]=!1,t[1]=o,t)}))}callAndListen(e,t){return x(this,void 0,void 0,(function*(){const i=[!1,null],[o,n]=yield this.checkReady();return o?yield new Promise((o=>x(this,void 0,void 0,(function*(){const n=this.createSchemeLink(e),s=e=>{const r=(()=>{try{return JSON.parse(e)}catch(t){return e}})();t(1===r||0!==r&&r),i[0]=()=>{const e=N[n];if(!e)return;const t=e.queue.findIndex((e=>e.callback===s));-1!==t&&e.queue.splice(t,1)},o(i)},r=JSON.stringify({actionUrl:n,functionName:W(n,s,!1)});this.worker.postMessage(JSON.stringify({type:"callAndListen",param:r}))})))):(i[0]=!1,i[1]=n,i)}))}}function $(){return(65536*(1+Math.random())|0).toString(16).substring(1)}function H(){return($()+$()+"-"+$()+"-4"+$().substr(0,3)+"-"+$()+"-"+$()+$()+$()).toLowerCase()}var J;!function(e){e.isReady="Are You OK?",e.ready="I`m OK!",e.ping="ping",e.pong="pong",e.alive="I`m alive!"}(J||(J={}));var q="wss://ws.realsee.com";var F=(e,t)=>{const i=Object.keys(t).reduce(((e,i)=>e.replace(`{{${i}}}`,`${t[i]}`)),e);return encodeURI(i)};var K=(e,t)=>e in t;var G=(e="")=>e.replace("?","").split("&").map((e=>{const[t,i]=e.split("=");return{[t]:decodeURIComponent(i)}})).reduce(((e,t)=>Object.assign(Object.assign({},e),t)),{});const z="$$REALSEE_JSBRIDGE_EVENT$$";function Y(e){return e[z]||(e[z]={}),e[z]}class Z{hasListener(e){const t=Y(this);return t&&t[e]&&t[e].length>0}on(e,t,i){const o=Y(this);return o[e]||(o[e]=[]),o[e].push([t,i||!1]),()=>this.off(e,t)}once(e,t){return this.on(e,t,!0)}off(e,t){if(void 0===e)return void((i=this)[z]||delete i[z]);var i;const o=Y(this);if(o[e]||(o[e]=[]),void 0===t)return void(o[e].length=0);let n=0;for(;n<o[e].length&&o[e][n][0]!==t;n++);n<o[e].length&&o[e].splice(n,1)}emit(e,...t){let i=!1;const o=Y(this)[e]||[];for(const n of o.slice()){const[o,s=!1]=n,r=o(...t);s&&this.off(e,o),!1===r&&(i=!0)}return i}}class X extends Z{get attempts(){return this._attempts}constructor(e){super(),this._options={timeout:1e4,shouldReconnect:(e,t)=>{if(1008!==e.code&&1011!==e.code)return[0,3e3,1e4][t.attempts]},should1000Reconnect:!1,ignoreConnectivityEvents:!1,automaticOpen:!1},this._attempts=0,this._reconnects=-1,this._reconnectWhenOnlineAgain=!1,this._explicitlyClosed=!1,this._connectivityEventsAttached=!1,this._clearPendingReconnectIfNeeded=()=>{this._pendingReconnect&&(clearTimeout(this._pendingReconnect),this._pendingReconnect=void 0)},this._online=e=>{this._reconnectWhenOnlineAgain&&(this._clearPendingReconnectIfNeeded(),this._reconnect(e))},this._offline=()=>{var e;this._reconnectWhenOnlineAgain=!0,null===(e=this._realWebSocket)||void 0===e||e.close(1e3)},this._detachConnectivityEvents=()=>{this._connectivityEventsAttached&&(null===globalThis||void 0===globalThis||globalThis.removeEventListener("online",this._online),null===globalThis||void 0===globalThis||globalThis.removeEventListener("offline",this._offline),this._connectivityEventsAttached=!1)},this._attachConnectivityEvents=()=>{this._connectivityEventsAttached||(null===globalThis||void 0===globalThis||globalThis.addEventListener("online",this._online),null===globalThis||void 0===globalThis||globalThis.addEventListener("offline",this._offline),this._connectivityEventsAttached=!0)},this.send=e=>{var t,i,o;(null===(t=this._realWebSocket)||void 0===t?void 0:t.readyState)===(null===(i=this._realWebSocket)||void 0===i?void 0:i.OPEN)&&(null===(o=this._realWebSocket)||void 0===o||o.send(e))},this.close=(e,t)=>{var i;return"number"!=typeof e&&(t=e,e=1e3),this._clearPendingReconnectIfNeeded(),this._reconnectWhenOnlineAgain=!1,this._explicitlyClosed=!0,this._detachConnectivityEvents(),null===(i=this._realWebSocket)||void 0===i?void 0:i.close(e,t)},this.open=e=>{var t,i;e&&(this._url=e),(null===(t=this._realWebSocket)||void 0===t?void 0:t.readyState)!==WebSocket.OPEN&&(null===(i=this._realWebSocket)||void 0===i?void 0:i.readyState)!==WebSocket.CONNECTING&&(this._clearPendingReconnectIfNeeded(),this._reconnectWhenOnlineAgain=!1,this._explicitlyClosed=!1,this._createWebSocket())},this._createWebSocket=()=>{var e,t,i;const o="string"==typeof this._url?this._url:null===(e=this._url)||void 0===e?void 0:e.call(this,this);if(!o)return;this._pendingReconnect=void 0,this._removeWebSocketEvent(),this._realWebSocket=new WebSocket(o,this._protocols||void 0),this._attempts=this._attempts+1,this.emit("connecting",new CustomEvent("connecting",{detail:{attempts:this._attempts,reconnects:this._reconnects}}));this._connectTimeout=setTimeout((()=>{this._connectTimeout=void 0,this._detachConnectivityEvents(),this.emit("timeout",new CustomEvent("connecting",{detail:{attempts:this._attempts,reconnects:this._reconnects}}))}),null===(t=this._options)||void 0===t?void 0:t.timeout),this._dispatchWebSocketEvent(),(null===(i=this._options)||void 0===i?void 0:i.ignoreConnectivityEvents)||this._attachConnectivityEvents()},this._removeWebSocketEvent=()=>{var e,t,i,o;null===(e=this._realWebSocket)||void 0===e||e.removeEventListener("open",this._webSocketOpenHandler),null===(t=this._realWebSocket)||void 0===t||t.removeEventListener("close",this._webSocketCloseHandler),null===(i=this._realWebSocket)||void 0===i||i.removeEventListener("error",this._webSocketErrorHandler),null===(o=this._realWebSocket)||void 0===o||o.removeEventListener("message",this._webSocketMessageHandler)},this._dispatchWebSocketEvent=()=>{var e,t,i,o;null===(e=this._realWebSocket)||void 0===e||e.addEventListener("open",this._webSocketOpenHandler),null===(t=this._realWebSocket)||void 0===t||t.addEventListener("close",this._webSocketCloseHandler),null===(i=this._realWebSocket)||void 0===i||i.addEventListener("error",this._webSocketErrorHandler),null===(o=this._realWebSocket)||void 0===o||o.addEventListener("message",this._webSocketMessageHandler)},this._webSocketOpenHandler=e=>{this._connectTimeout&&(clearTimeout(this._connectTimeout),this._connectTimeout=void 0);const t=++this._reconnects,i=this._attempts;return this._attempts=0,this._reconnectWhenOnlineAgain=!1,this.emit("open",Object.assign(e,{detail:{reconnects:t,attempts:i}}))},this._webSocketCloseHandler=e=>(this._reconnect(e),this.emit("close",e)),this._webSocketErrorHandler=e=>this.emit("error",new CustomEvent("error",{detail:{error:e}})),this._webSocketMessageHandler=e=>this.emit("message",e),e&&this.setOptions(e)}setOptions(e){if(!e)return;this._url=e.url,this._protocols=e.protocols;const t=Object.assign(this._options,e.robustOptions||{});if("number"!=typeof(null==t?void 0:t.timeout))throw new Error("timeout must be the number of milliseconds to timeout a connection attempt");if("function"!=typeof(null==t?void 0:t.shouldReconnect))throw new Error("shouldReconnect must be a function that returns the number of milliseconds to wait for a reconnect attempt, or null or undefined to not reconnect.");this._options=t,this._options.automaticOpen&&this._createWebSocket()}_reconnect(e){var t,i,o,n;if(!(null===(t=this._options)||void 0===t?void 0:t.should1000Reconnect)&&1e3===e.code||this._explicitlyClosed)return void(this._attempts=0);if(!1===(null===(i=null===globalThis||void 0===globalThis?void 0:globalThis.navigator)||void 0===i?void 0:i.onLine))return void(this._reconnectWhenOnlineAgain=!0);const s=null===(n=null===(o=this._options)||void 0===o?void 0:o.shouldReconnect)||void 0===n?void 0:n.call(o,e,this);"number"==typeof s&&(this._pendingReconnect=setTimeout(this._createWebSocket,s))}}class Q{get isReady(){return"open"===this._readyState}constructor(){var e,t;if(this._rsWeappBridgeMethodAdapter={},this._ws=new X,this._readyState="close",this.initialize=(e=6e3)=>x(this,void 0,void 0,(function*(){const t=[!1,null],{wssid:i,wstsp:o,wssig:n,wsmnt:s=q}=G(globalThis.location.search);if(!(i&&o&&n&&s))return t[1]=new Error("HybridBridge 参数缺失,初始化失败~"),t;const r=F("{{origin}}/{{endpoint}}/{{uuid}}/{{member}}/{{ak}}/{{ts}}/{{sign}}",{origin:s,endpoint:"proxy",uuid:i,member:"webview",ak:"vr_live_miniapp",ts:o,sign:n});try{(yield this._open(r))?(this.initBuiltInHandlers(),t[0]=yield this.waitReady(e)):t[1]=new Error("HybridBridge ws未连接,初始化失败~")}catch(e){t[1]=e}return t})),this.initBuiltInHandlers=()=>{this._registerLifecycleHandler(),this._registerHeartbeatHandler(),this._registerMessageHandler(),this._registerBridgeRequestHandler(),this._registerReadyHandler()},this._open=e=>new Promise((t=>{this._ws.once("open",(()=>{this._receivedMessage(J.ready,(()=>t(!0)),!0),this._ws.once("timeout",(()=>t(!1))),this.send(J.isReady)})),this._ws.open(e)})),this._registerLifecycleHandler=()=>{this._ws.on("connecting",(()=>{console.log("RsWeappBridge connecting"),this._readyState="connecting"})),this._ws.on("open",(()=>{console.log("RsWeappBridge open"),this._readyState="open"})),this._ws.on("close",(()=>{this._readyState="close"})),this._ws.on("error",(()=>{console.log("RsWeappBridge error"),this._readyState="close"})),this._ws.on("timeout",(()=>{console.log("RsWeappBridge timeout"),this._readyState="close"}))},this._registerHeartbeatHandler=()=>{this._receivedMessage(J.ping,(()=>setTimeout((()=>this._ws.send(J.pong)),500))),this._receivedMessage(J.pong,(()=>setTimeout((()=>this._ws.send(J.ping)),1e3)))},this._receivedMessage=(e,t,i)=>{const o=n=>{n.data===e&&(t(),i&&this._ws.off("message",o))};this._ws.on("message",o)},this._registerReadyHandler=()=>{this._receivedMessage(J.isReady,(()=>this._ws.send(J.ready)))},this.send=e=>{this._ws.send(e)},this.waitReady=(e=6e3)=>new Promise(((t,i)=>{this._receivedMessage(J.ready,(()=>t(!0))),this.send(J.isReady),setTimeout((()=>i("HybridBridge 初始化超时~")),e)})),this._parseMessage=e=>{try{return JSON.parse(e.data)}catch(t){return e.data}},this._registerMessageHandler=()=>{this._ws.on("message",(e=>{const t=this._parseMessage(e);if("object"==typeof t){const{id:e,command:i,data:o}=t;"message"===i&&"function"==typeof this._rsWeappBridgeMethodAdapter.bindMessage&&this._rsWeappBridgeMethodAdapter.bindMessage({id:e,data:o})}}))},this.getStaticData=e=>{this.callAndBackfeed(JSON.stringify({actionUrl:"common/staticData",functionName:e}))},this.callAndBackfeed=e=>{const{actionUrl:t="",functionName:i=""}=JSON.parse(e);if(!t)throw new Error("callAndBackfeed actionUrl is empty!");if(!i)throw new Error("callAndBackfeed functionName is empty!");this._callAndBackfeed(t,(e=>{"function"==typeof globalThis[i]&&globalThis[i](e)}))},this.callAndListen=e=>{const{actionUrl:t,functionName:i}=JSON.parse(e);if(!t)throw new Error("callAndListen actionUrl is empty!");if(!i)throw new Error("callAndListen functionName is empty!");const o=e=>{"function"==typeof globalThis[i]&&globalThis[i](e)};try{this._callAndListen(t,o)}catch(e){console.warn(e),o(!1)}},this.execute=(e,t)=>x(this,void 0,void 0,(function*(){return yield this._invokeBridgeMethod(e,t)})),this._invokeBridgeMethod=(e,t)=>new Promise(((i,o)=>{const n=H(),s=t=>{const r=this._parseMessage(t);"object"==typeof r&&r.method===e&&r.id===n&&(this._ws.off("message",s),r.error?o(r.error):i(r.data))};this._ws.on("message",s),this.send(JSON.stringify({method:e,args:t,id:n}))})),(null===(e=null===globalThis||void 0===globalThis?void 0:globalThis.window)||void 0===e?void 0:e.__Realsee_WxMini_HybridBridge__)instanceof Q)return null===(t=null===globalThis||void 0===globalThis?void 0:globalThis.window)||void 0===t?void 0:t.__Realsee_WxMini_HybridBridge__;(null===globalThis||void 0===globalThis?void 0:globalThis.window)&&(globalThis.window.__Realsee_WxMini_HybridBridge__=this,this.initBuiltInHandlers())}_registerBridgeRequestHandler(){this._ws.on("message",(e=>x(this,void 0,void 0,(function*(){const t=this._parseMessage(e);if("object"==typeof t){const{id:e,method:i,args:o,command:n}=t;if("request"===n&&i){let t=null,n=null,s=null;if("function"==typeof this._rsWeappBridgeMethodAdapter[i]?s=this._rsWeappBridgeMethodAdapter[i]:globalThis&&K(i,globalThis)&&(s=globalThis[i]),"function"==typeof s)try{t=yield s(o)}catch(e){n=e.message||e}else n="Method not implemented.";this.send(JSON.stringify({id:e,method:i,result:t,error:n,command:"response"}))}}}))))}_callAndBackfeed(e,t){const i=H(),o=JSON.stringify({id:i,actionUrl:e,command:"rsSchemeRequest",type:"callAndBackfeed"});let n=null;const s=e=>{const o=this._parseMessage(e);if("object"==typeof o){const{id:e,result:r,errmsg:c,command:a}=o;"rsSchemeResponse"===a&&e===i&&(this._ws.off("message",s),n&&clearTimeout(n),c?(console.warn(c),t(0)):t(r))}};this._ws.on("message",s),this.send(o),n=globalThis.setTimeout((()=>{console.warn("callAndBackfeed timeout"),t(0)}),3e4)}_callAndListen(e,t){const i=H(),o=JSON.stringify({id:i,actionUrl:e,command:"rsSchemeRequest",type:"callAndListen"});this._ws.on("message",(e=>{const o=this._parseMessage(e);if("object"==typeof o){const{id:e,result:n,errmsg:s,command:r}=o;"rsSchemeResponse"===r&&e===i&&(s?(console.warn(s),t(!1)):t(n))}})),this.send(o)}invoke(e,t){return x(this,void 0,void 0,(function*(){return new Promise(((i,o)=>{const n=H(),s=JSON.stringify({id:n,method:e,args:t,command:"request"});let r=null;const c=t=>{const s=this._parseMessage(t);if("object"==typeof s){const{id:t,result:a,error:l,command:d}=s;"response"===d&&t===n&&s.method===e&&(this._ws.off("message",c),r&&clearTimeout(r),l?o(l):i(a))}};this._ws.on("message",c),this.send(s),r=setTimeout((()=>o("method invoke timeout")),3e4)}))}))}}class ee extends M{constructor(){super(...arguments),this._hybridBridge=new Q,this.initializing=!1}get hybridBridge(){return this._hybridBridge}checkBridgeReady(e=6e4){return!!this.ready||new Promise(((t,i)=>x(this,void 0,void 0,(function*(){if(this.ready)return t(!0);if(!this.initializing){this.initializing=!0;const[i,o]=yield this._hybridBridge.initialize(e);if(!i||o)throw o||new Error("HybridBridge 初始化失败~");return this._hybridBridge.getStaticData(W("HYBRID_BRIDGE_NAME",(e=>{this.deviceInfo=(()=>{try{return JSON.parse(e)}catch(t){return e}})()}))),this.initializing=!1,t(!0)}{const e=()=>{if(this.ready)return t(!0);requestAnimationFrame(e)};e()}}))))}checkReady(e=6e4){return x(this,void 0,void 0,(function*(){const t=[null,null];if(this.ready)return t[0]=!0,t;try{t[0]=yield this.checkBridgeReady(e)}catch(e){t[0]=!1,t[1]=e}return t}))}get ready(){return!!this._hybridBridge.isReady}get scheme(){var e;return(null===(e=this.deviceInfo)||void 0===e?void 0:e.scheme)||""}createSchemeLink(e){return e.startsWith(this.scheme)?e:this.scheme+"://"+e}callAndBackfeed(e){return x(this,void 0,void 0,(function*(){const t=[!1,null],[i,o]=yield this.checkReady();return i?yield new Promise((i=>x(this,void 0,void 0,(function*(){const o=this.createSchemeLink(e),n=JSON.stringify({actionUrl:o,functionName:W(this.createSchemeLink(e),(e=>{let o=e;try{o=JSON.parse(e)}catch(e){}t[0]=1===o||0!==o&&o,i(t)}))});this._hybridBridge.callAndBackfeed(n)})))):(t[0]=!1,t[1]=o,t)}))}callAndListen(e,t){return x(this,void 0,void 0,(function*(){const i=[!1,null],[o,n]=yield this.checkReady();return o?yield new Promise((o=>x(this,void 0,void 0,(function*(){const n=this.createSchemeLink(e),s=e=>{let r=e;try{r=JSON.parse(e)}catch(e){}t(1===r||0!==r&&r),i[0]=()=>{const e=N[n];if(!e)return;const t=e.queue.findIndex((e=>e.callback===s));-1!==t&&e.queue.splice(t,1)},o(i)},r=JSON.stringify({actionUrl:n,functionName:W(n,s,!1)});this._hybridBridge.callAndListen(r)})))):(i[0]=!1,i[1]=n,i)}))}invoke(e,t){var i,o;return x(this,void 0,void 0,(function*(){const[n,s]=yield this.checkReady();if(n)return yield null===(o=(i=this._hybridBridge).invoke)||void 0===o?void 0:o.call(i,e,t);throw s}))}}var te;!function(e){e.WebView="WebKit",e.WKWebview="WKWebview",e.UIWebview="UIWebview",e.Browser="Browser",e.WeChatMPWebView="WxMiniProgramWebView",e.Unsupported="Unsupported"}(te||(te={}));class ie extends Z{constructor(){super(...arguments),this.webViewType=te.Unsupported}}const oe=globalThis.navigator.userAgent,ne=/android/gi.test(oe),se=/iPhone|iPad\s+OS/gi.test(oe),re=/MicroMessenger/gi.test(oe)&&/miniProgram/gi.test(oe),ce=/realsee/gi.test(oe),ae={timeout:6e3};class le extends ie{constructor(e={}){super(),this.options=Object.assign(ae,e),ce||console.warn("未知容器:此版本 `jsBridge` 不支持当前 WebView 容器 ... "),this.webViewType=ne?te.WebView:se?te.WKWebview:te.Browser,this._controller=ne?new V:se?new D:new M,this.callAndListen("common/webViewState",(e=>{this.emit("webViewStateChange",e)})),this.callAndListen("common/webViewError",(e=>{this.emit("error",e)}))}ready(){return x(this,void 0,void 0,(function*(){return yield this._controller.checkReady(this.options.timeout)}))}callAndBackfeed(e){return x(this,void 0,void 0,(function*(){return yield this._controller.callAndBackfeed(e)}))}callAndListen(e,t){var i;return x(this,void 0,void 0,(function*(){return yield null===(i=this._controller)||void 0===i?void 0:i.callAndListen(e,t)}))}setLeftTopBackButton(e){return x(this,void 0,void 0,(function*(){return this.webViewType===te.WebView?[!0,null]:yield this.callAndBackfeed("common/setLeftTopBackButton?enable="+(e?1:0))}))}getBangsHeight(){return x(this,void 0,void 0,(function*(){return yield this.callAndBackfeed("common/getBangsHeight")}))}shock(e=4){return x(this,void 0,void 0,(function*(){return yield this.callAndBackfeed(`common/shock?duration=${e}`)}))}minimize(){return x(this,void 0,void 0,(function*(){return yield this.callAndBackfeed("common/minimize")}))}loadProgress(e){return x(this,void 0,void 0,(function*(){return e=e<0?0:e>100?100:e,yield this.callAndBackfeed(`common/loadProgress?progress=${e}`)}))}closeLoading(){return x(this,void 0,void 0,(function*(){return yield this.callAndBackfeed("common/closeLoading")}))}setOrientation(e){return x(this,void 0,void 0,(function*(){return yield this.callAndBackfeed(`common/setOrientation?orientation=${e}`)}))}keepScreenLight(e){return x(this,void 0,void 0,(function*(){return yield this.callAndBackfeed("common/keepScreenLight?enable="+(e?1:0))}))}closeWebView(){return x(this,void 0,void 0,(function*(){return yield this.callAndBackfeed("common/closeWebView")}))}openWebView(e,t){return x(this,void 0,void 0,(function*(){return yield this.callAndBackfeed(`common/openWebView?way=${t}&url=${encodeURIComponent(e)}`)}))}saveImage2Album(e){return x(this,void 0,void 0,(function*(){return yield this.callAndBackfeed(`common/saveImage2Album?base64=${e}`)}))}actionShare(e){return x(this,void 0,void 0,(function*(){return yield this.callAndBackfeed(`common/actionShare?json=${JSON.stringify(e)}`)}))}getDeviceInfo(){return x(this,void 0,void 0,(function*(){return yield this.callAndBackfeed("common/getDeviceInfo")}))}getUserInfo(){return x(this,void 0,void 0,(function*(){return yield this.callAndBackfeed("common/getUserInfo")}))}getWebViewState(){return x(this,void 0,void 0,(function*(){return yield this.callAndBackfeed("common/getWebViewState")}))}login(){return x(this,void 0,void 0,(function*(){const e=yield this.callAndBackfeed("common/login");return e[0]?yield this.getUserInfo():e}))}logout(){return x(this,void 0,void 0,(function*(){return yield this.callAndBackfeed("common/logout")}))}detectMicro(){return x(this,void 0,void 0,(function*(){return yield this.callAndBackfeed("common/detectMicro")}))}preload(e){return x(this,void 0,void 0,(function*(){return e=e.map((e=>e.startsWith("//")?"https:"+e:e)),yield this.callAndBackfeed(`common/preload?urls=${JSON.stringify(e)}`)}))}createCacheProxyUrl(e){e=Array.isArray(e)?e:[e];const t=window.navigator.userAgent;if(!/supportCache/i.test(t))return e;return e.map((e=>this.webViewType===te.WKWebview?e.replace(/https*:/,"").replace(/\/\//,"realseeproxycache://"):this.webViewType===te.WebView?e+(-1!==e.indexOf("?")?"&":"?")+"realseeproxycache=1":e))}}var de;!function(e){e.Append="Append",e.Replace="Replace",e.Single="Single"}(de||(de={}));class he extends ie{constructor(){super(...arguments),this.webViewType=te.Browser}ready(){return Promise.resolve([!0,null])}callAndBackfeed(e){return Promise.resolve([!1,null])}callAndListen(e,t){return Promise.resolve([()=>{},null])}loadProgress(e){return Promise.resolve([!0,null])}closeLoading(){return Promise.resolve([!0,null])}getDeviceInfo(){return Promise.resolve([!1,null])}getWebViewState(){return Promise.resolve([!1,null])}setLeftTopBackButton(e){return Promise.resolve([!1,null])}login(){return Promise.resolve([!1,null])}logout(){return Promise.resolve([!1,null])}getUserInfo(){return Promise.resolve([!1,null])}openWebView(e,t){switch(t){case de.Replace:case de.Single:setTimeout((()=>globalThis.location.replace(e)),200);break;case de.Append:default:setTimeout((()=>globalThis.location.href=e),200)}return Promise.resolve([!0,null])}closeWebView(){return globalThis.close(),Promise.resolve([!0,null])}getBangsHeight(){return Promise.resolve([0,null])}setOrientation(e){return Promise.resolve([!1,null])}keepScreenLight(e){return Promise.resolve([!1,null])}shock(e){return Promise.resolve([!1,null])}minimize(){return Promise.resolve([!1,null])}saveImage2Album(e){return Promise.resolve([!1,null])}detectMicro(){return new Promise((e=>{const t={audio:!0,video:!1};try{globalThis.navigator.mediaDevices.getUserMedia(t).then((()=>e([!0,null]))).catch((t=>e([!1,t])))}catch(t){console.error(t),e([!1,t])}}))}actionShare(e){return Promise.resolve([!1,null])}preload(e){return Promise.resolve([!1,null])}createCacheProxyUrl(e){return[]}}const ue={timeout:6e4};class ve extends ie{constructor(e={}){super(),this._controller=new ee,this.options=Object.assign(ue,e),re||console.warn("未知容器:此版本 `jsBridge` 不支持当前 WebView 容器 ... "),this.webViewType=te.WeChatMPWebView,this.callAndListen("common/webViewState",(e=>{this.emit("webViewStateChange",e)})),this.callAndListen("common/webViewError",(e=>{this.emit("error",e)}))}ready(){return x(this,void 0,void 0,(function*(){return yield this._controller.checkReady(this.options.timeout)}))}callAndBackfeed(e){return x(this,void 0,void 0,(function*(){return yield this._controller.callAndBackfeed(e)}))}callAndListen(e,t){return x(this,void 0,void 0,(function*(){return yield this._controller.callAndListen(e,t)}))}setLeftTopBackButton(e){return x(this,void 0,void 0,(function*(){return this.webViewType===te.WebView?[!0,null]:yield this.callAndBackfeed("common/setLeftTopBackButton?enable="+(e?1:0))}))}getBangsHeight(){return x(this,void 0,void 0,(function*(){return yield this.callAndBackfeed("common/getBangsHeight")}))}shock(e=4){return x(this,void 0,void 0,(function*(){return yield this.callAndBackfeed(`common/shock?duration=${e}`)}))}minimize(){return x(this,void 0,void 0,(function*(){return yield this.callAndBackfeed("common/minimize")}))}loadProgress(e){return x(this,void 0,void 0,(function*(){return e=e<0?0:e>100?100:e,yield this.callAndBackfeed(`common/loadProgress?progress=${e}`)}))}closeLoading(){return x(this,void 0,void 0,(function*(){return yield this.callAndBackfeed("common/closeLoading")}))}setOrientation(e){return x(this,void 0,void 0,(function*(){return yield this.callAndBackfeed(`common/setOrientation?orientation=${e}`)}))}keepScreenLight(e){return x(this,void 0,void 0,(function*(){return yield this.callAndBackfeed("common/keepScreenLight?enable="+(e?1:0))}))}closeWebView(){return x(this,void 0,void 0,(function*(){return yield this.callAndBackfeed("common/closeWebView")}))}openWebView(e,t){return x(this,void 0,void 0,(function*(){return yield this.callAndBackfeed(`common/openWebView?way=${t}&url=${encodeURIComponent(e)}`)}))}saveImage2Album(e){return x(this,void 0,void 0,(function*(){return yield this.callAndBackfeed(`common/saveImage2Album?base64=${e}`)}))}actionShare(e){var t,i,o;return x(this,void 0,void 0,(function*(){const n={path:null===(t=e.miniprogram)||void 0===t?void 0:t[0].path,title:null===(i=e.miniprogram)||void 0===i?void 0:i[0].title,imageUrl:null===(o=e.miniprogram)||void 0===o?void 0:o[0].hdImageData};return yield this.callAndBackfeed(`common/actionShare?json=${JSON.stringify(n)}`)}))}getDeviceInfo(){return x(this,void 0,void 0,(function*(){return yield this.callAndBackfeed("common/getDeviceInfo")}))}getUserInfo(){return x(this,void 0,void 0,(function*(){return yield this.callAndBackfeed("common/getUserInfo")}))}getWebViewState(){return x(this,void 0,void 0,(function*(){return yield this.callAndBackfeed("common/getWebViewState")}))}login(){return x(this,void 0,void 0,(function*(){const e=yield this.callAndBackfeed("common/login");return e[0]?yield this.getUserInfo():e}))}logout(){return x(this,void 0,void 0,(function*(){return yield this.callAndBackfeed("common/logout")}))}detectMicro(){return x(this,void 0,void 0,(function*(){return yield this.callAndBackfeed("common/detectMicro")}))}preload(e){return x(this,void 0,void 0,(function*(){return e=e.map((e=>e.startsWith("//")?"https:"+e:e)),yield this.callAndBackfeed(`common/preload?urls=${JSON.stringify(e)}`)}))}createCacheProxyUrl(e){e=Array.isArray(e)?e:[e];const t=window.navigator.userAgent;if(!/supportCache/i.test(t))return e;return e.map((e=>this.webViewType===te.WKWebview?e.replace(/https*:/,"").replace(/\/\//,"realseeproxycache://"):this.webViewType===te.WebView?e+(-1!==e.indexOf("?")?"&":"?")+"realseeproxycache=1":e))}invokeNativeApi(e,t){return x(this,void 0,void 0,(function*(){return yield this._controller.invoke(e,t)}))}execute(e,t){var i,o,n;return x(this,void 0,void 0,(function*(){return yield null===(n=null===(o=null===(i=this._controller)||void 0===i?void 0:i.hybridBridge)||void 0===o?void 0:o.execute)||void 0===n?void 0:n.call(o,e,t)}))}}class me extends ie{constructor(e={}){return super(),ce&&(ne||se)?new le(e):re?new ve(e):new he}}function ge(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var fe,pe,_e=(fe=function(e,t){var i;Object.defineProperty(t,"__esModule",{value:!0}),t.LogLevel=void 0,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"}(i=t.LogLevel||(t.LogLevel={})),t.default=i},fe(pe={exports:{}},pe.exports),pe.exports),ye=ge(_e);const be=globalThis.navigator.userAgent,Se=/android/gi.test(be),we=/iPhone|iPad\s+OS/gi.test(be),ke=/MicroMessenger/gi.test(be)&&/miniProgram/gi.test(be),Ee=/realsee/gi.test(be);function Ce(e){return"[object Object]"===Object.prototype.toString.call(e)}function Te(e,t){return e===t||typeof e==typeof t&&!(!Number.isNaN(e)||!Number.isNaN(t))}function Ie(e,t){return!!Te(e,t)||(Ce(e)&&Ce(t)?function(e,t){const i=Object.getOwnPropertyNames(e),o=Object.getOwnPropertyNames(t);if(i.length!==o.length)return!1;for(let o=0,n=i.length;o<n;o++){const n=i[o];if(!Te(e[n],t[n]))return!1}return!0}(e,t):!(!Array.isArray(e)||!Array.isArray(t))&&function(e,t){if(e.length!==t.length)return!1;for(let i=0,o=e.length;i<o;i++)if(!Te(e[i],t[i]))return!1;return!0}(e,t))}function Re(e,t){return!!Te(e,t)||(Ce(e)&&Ce(t)?function(e,t){const i=Object.getOwnPropertyNames(e),o=Object.getOwnPropertyNames(t);if(i.length!==o.length)return!1;for(let o=0,n=i.length;o<n;o++){const n=i[o];if(!Re(e[n],t[n]))return!1}return!0}(e,t):!(!Array.isArray(e)||!Array.isArray(t))&&function(e,t){if(e.length!==t.length)return!1;for(let i=0,o=e.length;i<o;i++)if(!Re(e[i],t[i]))return!1;return!0}(e,t))}function Oe(e,t,i={deep:!1}){return i.deep?Re(e,t):Ie(e,t)}class Be extends a{get attempts(){return this._attempts}constructor(e){super(),this._readyState=exports.WebSocketState.NOTINITIALIZED,this._options={timeout:1e4,shouldReconnect:(e,t)=>{if(1008!==e.code&&1011!==e.code)return[0,3e3,1e4][t.attempts]},should1000Reconnect:!1,ignoreConnectivityEvents:!1,automaticOpen:!1},this._attempts=0,this._reconnects=-1,this._reconnectWhenOnlineAgain=!1,this._explicitlyClosed=!1,this._connectivityEventsAttached=!1,this._healthCheck=()=>d(this,void 0,void 0,(function*(){this._realWebSocket&&this._realWebSocket.readyState!==this._readyState&&(this._readyState=this._realWebSocket.readyState,this._readyState===exports.WebSocketState.CLOSING&&this.emit("closing")),yield new Promise((e=>setTimeout(e,2e3))),this._heathCheckTimer=requestAnimationFrame(this._healthCheck)})),this._clearHeathCheckIfNeed=()=>{this._heathCheckTimer&&(cancelAnimationFrame(this._heathCheckTimer),this._heathCheckTimer=void 0)},this._startHealthCheck=()=>{this._clearHeathCheckIfNeed(),this._heathCheckTimer=requestAnimationFrame(this._healthCheck)},this._stopHealthCheck=()=>{this._clearHeathCheckIfNeed()},this._clearPendingReconnectIfNeeded=()=>{this._pendingReconnect&&(clearTimeout(this._pendingReconnect),this._pendingReconnect=void 0)},this._online=e=>{this._reconnectWhenOnlineAgain&&(this._clearPendingReconnectIfNeeded(),this._reconnect(e))},this._offline=()=>{var e;this._reconnectWhenOnlineAgain=!0,null===(e=this._realWebSocket)||void 0===e||e.close(1e3,"offline")},this._detachConnectivityEvents=()=>{this._connectivityEventsAttached&&(null===globalThis||void 0===globalThis||globalThis.removeEventListener("online",this._online),null===globalThis||void 0===globalThis||globalThis.removeEventListener("offline",this._offline),this._connectivityEventsAttached=!1)},this._attachConnectivityEvents=()=>{this._connectivityEventsAttached||(null===globalThis||void 0===globalThis||globalThis.addEventListener("online",this._online),null===globalThis||void 0===globalThis||globalThis.addEventListener("offline",this._offline),this._connectivityEventsAttached=!0)},this.send=e=>{var t,i,o;(null===(t=this._realWebSocket)||void 0===t?void 0:t.readyState)===(null===(i=this._realWebSocket)||void 0===i?void 0:i.OPEN)&&(null===(o=this._realWebSocket)||void 0===o||o.send(e))},this.close=(e,t)=>{var i;return"number"!=typeof e&&(t=e,e=1e3),this._clearPendingReconnectIfNeeded(),this._reconnectWhenOnlineAgain=!1,this._explicitlyClosed=!0,this._detachConnectivityEvents(),null===(i=this._realWebSocket)||void 0===i?void 0:i.close(e,t)},this.open=e=>{var t,i;e&&(this._url=e),(null===(t=this._realWebSocket)||void 0===t?void 0:t.readyState)!==WebSocket.OPEN&&(null===(i=this._realWebSocket)||void 0===i?void 0:i.readyState)!==WebSocket.CONNECTING&&(this._clearPendingReconnectIfNeeded(),this._reconnectWhenOnlineAgain=!1,this._explicitlyClosed=!1,this._createWebSocket())},this._createWebSocket=()=>{var e,t,i;const o="string"==typeof this._url?this._url:null===(e=this._url)||void 0===e?void 0:e.call(this,this);if(!o)return;this._pendingReconnect=void 0,this._removeWebSocketEvent(),this._realWebSocket=new WebSocket(o,this._protocols||void 0),this._attempts=this._attempts+1,this.emit("connecting",new CustomEvent("connecting",{detail:{attempts:this._attempts,reconnects:this._reconnects}}));this._connectTimeout=setTimeout((()=>{this._connectTimeout=void 0,this._detachConnectivityEvents(),this.emit("timeout",new CustomEvent("connecting",{detail:{attempts:this._attempts,reconnects:this._reconnects}}))}),null===(t=this._options)||void 0===t?void 0:t.timeout),this._dispatchWebSocketEvent(),(null===(i=this._options)||void 0===i?void 0:i.ignoreConnectivityEvents)||this._attachConnectivityEvents()},this._removeWebSocketEvent=()=>{var e,t,i,o;null===(e=this._realWebSocket)||void 0===e||e.removeEventListener("open",this._webSocketOpenHandler),null===(t=this._realWebSocket)||void 0===t||t.removeEventListener("close",this._webSocketCloseHandler),null===(i=this._realWebSocket)||void 0===i||i.removeEventListener("error",this._webSocketErrorHandler),null===(o=this._realWebSocket)||void 0===o||o.removeEventListener("message",this._webSocketMessageHandler)},this._dispatchWebSocketEvent=()=>{var e,t,i,o;null===(e=this._realWebSocket)||void 0===e||e.addEventListener("open",this._webSocketOpenHandler),null===(t=this._realWebSocket)||void 0===t||t.addEventListener("close",this._webSocketCloseHandler),null===(i=this._realWebSocket)||void 0===i||i.addEventListener("error",this._webSocketErrorHandler),null===(o=this._realWebSocket)||void 0===o||o.addEventListener("message",this._webSocketMessageHandler)},this._webSocketOpenHandler=e=>{this._connectTimeout&&(clearTimeout(this._connectTimeout),this._connectTimeout=void 0);const t=++this._reconnects,i=this._attempts;return this._attempts=0,this._reconnectWhenOnlineAgain=!1,this._startHealthCheck(),this.emit("open",Object.assign(e,{detail:{reconnects:t,attempts:i}}))},this._webSocketCloseHandler=e=>(this._reconnect(e),this._stopHealthCheck(),this.emit("close",e)),this._webSocketErrorHandler=e=>this.emit("error",new CustomEvent("error",{detail:{error:e}})),this._webSocketMessageHandler=e=>this.emit("message",e),e&&this.setOptions(e),this._startHealthCheck()}setOptions(e){if(!e)return;this._url=e.url,this._protocols=e.protocols;const t=Object.assign(this._options,e.robustOptions||{});if("number"!=typeof(null==t?void 0:t.timeout))throw new Error("timeout must be the number of milliseconds to timeout a connection attempt");if("function"!=typeof(null==t?void 0:t.shouldReconnect))throw new Error("shouldReconnect must be a function that returns the number of milliseconds to wait for a reconnect attempt, or null or undefined to not reconnect.");this._options=t,this._options.automaticOpen&&this._createWebSocket()}_reconnect(e){var t,i,o,n;if(!(null===(t=this._options)||void 0===t?void 0:t.should1000Reconnect)&&1e3===e.code||this._explicitlyClosed)return void(this._attempts=0);if(!1===(null===(i=null===globalThis||void 0===globalThis?void 0:globalThis.navigator)||void 0===i?void 0:i.onLine))return void(this._reconnectWhenOnlineAgain=!0);const s=null===(n=null===(o=this._options)||void 0===o?void 0:o.shouldReconnect)||void 0===n?void 0:n.call(o,e,this);"number"==typeof s&&(this._pendingReconnect=setTimeout(this._createWebSocket,s))}}class Ae extends a{set state(e){const t=JSON.parse(JSON.stringify(this._state));this._state=e,this.emit("stateChange",this.state,t)}get state(){return this._state}constructor(){super(),this._ws=new Be({url:"",robustOptions:{timeout:18e4}}),this._state=exports.LiveState.NOTINITIALIZED,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)},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)},this._handleCloseEvent=e=>{T.info(`live room closed bacause of ${e.code}-${e.reason||L(e.code)}`),this.state=exports.LiveState.CLOSED},this._handleClosingEvent=()=>{var e;T.info("live room is closing, onLine:",null===(e=null===globalThis||void 0===globalThis?void 0:globalThis.navigator)||void 0===e?void 0:e.onLine),this.state=exports.LiveState.CLOSED},this._handleConnectingEvent=()=>{T.info("live room is connecting"),this.state=exports.LiveState.CONNECTING},this._handleErrorEvent=e=>{T.error("live room error",e),this.state=exports.LiveState.CLOSED},this._handleMessageEvent=e=>{let t=(()=>{try{return JSON.parse(e.data)}catch(t){return e.data}})();this.emit("message",t)},this._handleOpenEvent=e=>{T.info("live room open",e.detail),this.state=exports.LiveState.OPEN,e.detail.reconnects>0&&this.emit("reconnected",e.detail)},this._handleTimeoutEvent=e=>{T.error("live room connect timeout!",e.detail),this.state=exports.LiveState.CLOSED},this.dispose=()=>d(this,void 0,void 0,(function*(){return this._removeWebSocketEventListeners(),yield this.close("live room close by controller disposed!")})),this.open=e=>this._ws.open(e),this.close=(e,t)=>new Promise((i=>{this._ws.once("close",(()=>i(!0))),this._ws.close(e,t)})),this._addWebSocketEventListeners()}sendMessage(e=""){if(null==e||""===e)throw new Error("live message is empty!");if(this.state===exports.LiveState.OPEN)return this._ws.send(JSON.stringify(e));throw new Error("live has not yet been initialized!")}}const Le=e=>Promise.reject("unimplemented method GetVoiceSign"),xe=(e,t={},i=[])=>({command:e,front_request_id:R(),data:Object.assign(Object.assign({},t),{to_user_ids:Array.isArray(i)?i:[i]})});class Ne extends a{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}constructor(e){var t;super(),this._options={},this.keyframes=new a,this._buildInData={keyframes:{}},this.getFramesByKey=e=>this.snapshot[e],this.sendKeyframe=(e,t)=>{if(this.state!==exports.LiveState.OPEN)return!1;this._buildInData.keyframes=Object.assign(Object.assign({},this._buildInData.keyframes),{[e]:t});const i=xe(exports.Command.KeyframeSync,this.snapshot);try{return this._controller.sendMessage(i),!0}catch(e){return T.error(e),!1}},this._controller=new Ae,this._addLiveControllerEventListeners=()=>{this._controller.on("stateChange",this._handleStateChange),this._controller.on("message",this._handleMessage)},this._removeLiveControllerEventListeners=()=>{this._controller.off("stateChange",this._handleStateChange),this._controller.off("message",this._handleMessage)},this._handleStateChange=(e,t)=>this.emit("stateChange",e,t),this._handleMessage=e=>d(this,void 0,void 0,(function*(){var t,i,o,n,s;if("object"==typeof e){const{command:r,data:c={},frontRequestId:a,code:l,message:d}=e;if("SUCCESS"===l)switch(r){case exports.Command.SelfUserInfo:{const e=c;Oe(this.selfInfo,e,{deep:!0})||(this._buildInData.selfInfo=e,this.emit("selfInfoUpdate",this._buildInData.selfInfo,a));break}case exports.Command.RoomInfo:{const e=c;this._buildInData.roomInfo=Object.assign({},e),this.emit("readyKeyframeSync",e.last_frame||{});break}case exports.Command.RTCInfo:{const{voice_id:e,type:r}=c;if(this._buildInData.rtcInfo={voiceId:e,type:r},null===(t=this.$RTC)||void 0===t?void 0:t.joined)T.warn("已加入语音房间,无需重复加入!");else{if(yield null===(i=this.$RTC)||void 0===i?void 0:i.join({voiceId:e,userId:(null===(o=this.selfInfo)||void 0===o?void 0:o.id)||"",roomId:null===(n=this.roomInfo)||void 0===n?void 0:n.info.room_code,type:r})){const e=null!==(s=this._options.initialMicroStatus)&&void 0!==s?s:exports.MicroStatus.OPEN;yield this.toggleMicro(e===exports.MicroStatus.OPEN)}else T.error("加入语音房间失败")}break}case exports.Command.UserList:{const e=c;this._buildInData.userList=e,this.emit("userListUpdate",this.userList,a);break}case exports.Command.CustomEvent:{const e=c;this.emit("broadcast",e,a);break}case exports.Command.KeyframeSync:{const e=c,t=Object.keys(e).reduce(((t,i)=>{if(Oe(e[i],this._buildInData.keyframes[i],{deep:!0}))return t;const o=[e[i],this._buildInData.keyframes[i],a],n=i;return this.keyframes.emit(n,...o),this._buildInData.keyframes[i]=e[i],t[i]=e[i],t}),{});this.emit("keyframes",t,a);break}case exports.Command.BuiltinMsg:{const e=c;this.emit("builtinEvent",e),e.event_type===exports.BuiltinEventType.UserChange&&this.emit("userChange",e),e.event_type===exports.BuiltinEventType.RoomChange&&this.emit("roomChange",e),e.event_type===exports.BuiltinEventType.UserChange&&e.action===exports.BuiltinActionType.UserMicroStatus&&(yield this.toggleMicro(e.data.status===exports.MicroStatus.OPEN)),e.event_type===exports.BuiltinEventType.RoomChange&&e.action===exports.BuiltinActionType.RoomClose&&(yield this.exit());break}case exports.Command.UserKickOut:this.emit("kickOut");break;default:console.warn("unknown command: ",r)}else this.emit("error",e)}})),this._clearLiveData=()=>{this._buildInData={keyframes:{}}},this.connect=(e={})=>d(this,void 0,void 0,(function*(){var t,i,o,n;if(this._options.url=null!==(i=null!==(t=e.url)&&void 0!==t?t:this._options.url)&&void 0!==i?i:"",this._options.getTicket=null!==(o=e.getTicket)&&void 0!==o?o:this._options.getTicket,this._options.initialMicroStatus=null!==(n=e.rtcMicStatus)&&void 0!==n?n:this._options.initialMicroStatus,!/^ws(s):\/\//.test(this._options.url)||"function"!=typeof this._options.getTicket)return/^ws(s):\/\//.test(this._options.url)?"function"!=typeof this._options.getTicket&&new Error("getTicket muse be function"):new Error("Illegal realsee live room link");const{force:s=!1}=e;if(this._options.rtc){if(!(yield this._options.rtc.detectMicro()))return new Error("Failed to obtain microphone authorization")}const r=this.state;if(r===exports.LiveState.CONNECTING||r===exports.LiveState.OPEN){if(!s)return new Error("已有Live实例正在连接中,请勿重复连接!");try{yield this._controller.close("force close by connect")}catch(e){console.warn(e)}}this._clearLiveData();const c=function(e,t={}){const i=-1!==e.indexOf("?");return e+Object.keys(t).reduce(((e,o,n)=>`${e}${0!==n||i?"&":"?"}${o}=${t[o]}`),"")}(this._options.url,{ticket:yield this._options.getTicket(),force:Number(!!s)});return this._controller.open(c),!0})),this.exit=()=>d(this,void 0,void 0,(function*(){var e;if(this._clearLiveData(),this.state!==exports.LiveState.OPEN)return!0;try{yield null===(e=this.$RTC)||void 0===e?void 0:e.quit()}catch(e){T.warn(e)}return yield this._controller.close()})),this.close=()=>d(this,void 0,void 0,(function*(){var e,t;return(null===(t=null===(e=this.selfInfo)||void 0===e?void 0:e.permission)||void 0===t?void 0:t.close_live_room)?yield this.updateStatus(exports.BuiltinEventType.RoomChange,exports.BuiltinActionType.RoomClose,{}):void 0})),this.dispose=()=>d(this,void 0,void 0,(function*(){return this._removeLiveControllerEventListeners(),this._clearLiveData(),yield this._controller.dispose()})),this.setSelfInfo=e=>d(this,void 0,void 0,(function*(){return yield this.updateStatus(exports.BuiltinEventType.UserChange,exports.BuiltinActionType.UserInfo,e)})),this.toggleMicro=e=>d(this,void 0,void 0,(function*(){var t,i,o;if(!(null===(i=null===(t=this.selfInfo)||void 0===t?void 0:t.permission)||void 0===i?void 0:i.control_own_micro))return!1;const n=yield null===(o=this.$RTC)||void 0===o?void 0:o.toggleMicro(e);return n&&(yield this.updateStatus(exports.BuiltinEventType.UserChange,exports.BuiltinActionType.UserMicroStatus,{status:e?exports.MicroStatus.OPEN:exports.MicroStatus.CLOSE},[])),n})),this.forbidMicro=(e,t)=>d(this,void 0,void 0,(function*(){var i,o;return!("function"==typeof this._options.canForbidUserMicro&&!this._options.canForbidUserMicro(t))&&(!!(null===(o=null===(i=this.selfInfo)||void 0===i?void 0:i.permission)||void 0===o?void 0:o.control_other_micro)&&(yield this.updateStatus(exports.BuiltinEventType.UserChange,exports.BuiltinActionType.UserMicroStatus,{status:e},t)))})),this.forbidSync=(e,t)=>d(this,void 0,void 0,(function*(){var i,o;return!("function"==typeof this._options.canForbidUserSync&&!this._options.canForbidUserSync(t))&&(!!(null===(o=null===(i=this.selfInfo)||void 0===i?void 0:i.permission)||void 0===o?void 0:o.control_other_sync)&&(yield this.updateStatus(exports.BuiltinEventType.UserChange,exports.BuiltinActionType.UserPermission,{sync_frame:e},t)))})),this.kick=e=>d(this,void 0,void 0,(function*(){var t,i;return!("function"==typeof this._options.canForbidUserKick&&!this._options.canForbidUserKick(e))&&(!!(null===(i=null===(t=this.selfInfo)||void 0===t?void 0:t.permission)||void 0===i?void 0:i.change_other_status)&&(yield this.updateStatus(exports.BuiltinEventType.UserChange,exports.BuiltinActionType.UserStatus,{status:"KICK_OUT"},e)))})),this._addLiveControllerEventListeners(),this._options=Object.assign({initialMicroStatus:exports.MicroStatus.OPEN},e),this._options.jsBridge=e.jsBridge?e.jsBridge:e.useBuiltInJsBridge?new me:void 0,this._options.getVoiceSign=null!==(t=e.getVoiceSign)&&void 0!==t?t:Le,this._options.autoPlayConfirm=e.autoPlayConfirm,this._options.rtc=(()=>{if(e.rtc)return e.rtc;if(e.rtcType)switch(e.getVoiceSign||T.error("GetVoiceSign method must be passed when using built-in RTC instances"),e.rtcType){case exports.RTCType.RealseeVRWebViewRTC:return this._options.jsBridge?new A({jsBridge:this._options.jsBridge,getVoiceSign:this._options.getVoiceSign}):void T.error("JsBridge instance must be passed when using built-in VRWebViewRTC instances");case exports.RTCType.RealseeBrowserChimeRTC:return new B({getVoiceSign:this._options.getVoiceSign,logLevel:e.__debug__?ye.DEBUG:ye.ERROR});case exports.RTCType.RealseeBrowserRTC:return this._options.autoPlayConfirm||T.error("autoPlayConfirm method must be passed when using built-in RealseeBrowserRTC instances"),new O({getVoiceSign:this._options.getVoiceSign,autoPlayConfirm:this._options.autoPlayConfirm});default:return void T.error("unknown built-in RTC type")}return e.useBuiltInRTC?(e.getVoiceSign||T.error("GetVoiceSign method must be passed when using built-in RTC instances"),this._options.jsBridge?Ee&&(Se||we)||ke?new A({jsBridge:this._options.jsBridge,getVoiceSign:this._options.getVoiceSign}):e.builtInRTCType===exports.BuiltInRTCType.RealseeXChimeRTC?new B({getVoiceSign:this._options.getVoiceSign}):new O({getVoiceSign:this._options.getVoiceSign,autoPlayConfirm:this._options.autoPlayConfirm}):void T.error("jsBridge instance must be passed when using built-in RTC instances")):void 0})(),this._options.rtc||T.warn("unused rtc"),this._options.url&&this._options.getTicket&&this.connect(),this._options.__debug__&&Object.assign(window,{$liveController:this._controller,$live:this})}updateStatus(e,t,i,o){return d(this,void 0,void 0,(function*(){if(this.state!==exports.LiveState.OPEN)return!1;const n=Object.assign({event_type:e,action:t},{data:i}),s=xe(exports.Command.BuiltinMsg,n,o);try{return this._controller.sendMessage(s),!0}catch(e){return T.error(e),!1}}))}broadcast(e,t,i){return this.state===exports.LiveState.OPEN&&new Promise(((o,n)=>{const s=xe(exports.Command.CustomEvent,e,t),r=s.front_request_id,c=i?setTimeout((()=>{n(new Error("RESPONSE TIMEOUT")),this.off("broadcast",a)}),i):void 0,a=(e,t)=>{t===r&&(c&&clearTimeout(c),this.off("broadcast",a),o(e))};this.on("broadcast",a);try{this._controller.sendMessage(s)}catch(e){n(e)}}))}}const We=e=>{var t,i;return(null===window||void 0===window?void 0:window.__Realsee_Live__)&&(null===(i=null===(t=null===window||void 0===window?void 0:window.__Realsee_Live__)||void 0===t?void 0:t.dispose)||void 0===i||i.call(t),window.__Realsee_Live__=null),new Ne(e)};exports.BrowserRTC=O,exports.BrowserRTC4Chime=B,exports.CoreRTC=l,exports.VRWebViewRTC=A,exports.createLive=We,exports.createLiveReact=function(e){const t=i.createContext(null),o=We(e),n=o.jsBridge,r=()=>{const e=s.default.useContext(t);if(!e)throw new Error("LiveProvider never found.");return e};return{live:o,jsBridge:n,LiveProvider:e=>s.default.createElement(t.Provider,{value:o},e.children),unsafe__useLiveInstance:()=>o,unsafe__useRTCInstance:()=>o.$RTC,useConnect:()=>e=>d(this,void 0,void 0,(function*(){return yield o.connect(e)})),useKeyframe:function(e){const t=r(),[i,o]=s.default.useState(t.getFramesByKey(e));return s.default.useEffect((()=>{const i=e,n=e=>o(e);return t.keyframes.on(i,n),()=>t.keyframes.off(i,n)}),[t]),[i,s.default.useCallback((i=>t.sendKeyframe(e,i)),[t])]},useKeyframeUpdateCallback:function(e,t,i=[]){const o=r(),n=[o,name,...i],c=()=>o.keyframes.off(e,t);return s.default.useEffect((()=>(o.keyframes.on(e,t),c)),n),c},useLiveAction:function(){const e=r();return{connect:t=>d(this,void 0,void 0,(function*(){return yield e.connect(t)})),broadcast:(t,i,o=0)=>d(this,void 0,void 0,(function*(){return yield e.broadcast(t,i,o)})),exit:()=>d(this,void 0,void 0,(function*(){return yield e.exit()})),kick:t=>d(this,void 0,void 0,(function*(){return yield e.kick(t)})),toggleMicro:t=>e.toggleMicro(t),forbidMicro:(t,i=[])=>d(this,void 0,void 0,(function*(){return yield e.forbidMicro(t,i)})),forbidSync:(t,i=[])=>e.forbidSync(t,i),sendKeyframe:(t,i)=>e.sendKeyframe(t,i),getFramesByKey:t=>e.getFramesByKey(t),setSelfInfo:t=>e.setSelfInfo(t),updateStatus:(t,i,o,n)=>e.updateStatus(t,i,o,n)}},useLiveEventCallback:function(e,t,i=[]){const o=r(),n=()=>o.off(e,t),c=[o,e,...i];return s.default.useEffect((()=>(o.on(e,t),n)),c),n},useLiveState:function(){const e=r(),[t,i]=s.default.useState(e.state);return s.default.useEffect((()=>{const t=e=>i(e);return e.on("stateChange",t),()=>e.off("stateChange",t)}),[e]),t},useRTCAction:function(){const e=r();return{join:t=>e.$RTC.join(t),quit:()=>e.$RTC.quit(),shock:()=>{var t,i;return null===(i=(t=e.$RTC).shock)||void 0===i?void 0:i.call(t)},toggleMicro:t=>e.$RTC.toggleMicro(t),detectMicro:()=>e.$RTC.detectMicro()}},useRTCEventCallback:function(e,t,i=[]){const o=r(),n=()=>o.$RTC.off(e,t),c=[o,e,...i];return s.default.useEffect((()=>(o.$RTC.on(e,t),n)),c),n},useSelfInfo:function(){const e=r(),[t,i]=s.default.useState(e.selfInfo||{}),o=e=>i(e);return s.default.useEffect((()=>(e.on("selfInfoUpdate",o),()=>e.off("selfInfoUpdate",o))),[e]),[t,s.default.useCallback((t=>d(this,void 0,void 0,(function*(){return yield e.setSelfInfo(t)}))),[e])]},useKeyframesSnapshot:function(){const e=r(),[t,i]=s.default.useState(e.snapshot);return s.default.useEffect((()=>{const t=e=>i(e);return e.on("keyframes",t),()=>e.off("keyframes",t)})),t},useUserList:function(){const e=r(),[t,i]=s.default.useState(e.userList),o=e=>i(e);return s.default.useEffect((()=>(e.on("userListUpdate",o),()=>e.off("userListUpdate",o))),[e]),t}}},exports.parseLiveMsg=function(e){try{const t=JSON.parse(e),i={code:t.code,message:t.message,command:t.command,roomCode:t.room_code,appID:t.app_id,requestId:t.request_id,frontRequestId:t.front_request_id,triggerUserID:t.trigger_user_id,data:t.data||{}},o=Object.keys(i).filter((e=>void 0===i[e]));return o.length>0&&console.warn(`推送数据格式异常:${o.join(" ")} 值不存在!`),i}catch(e){return!1}},exports.parseWSClsErr=L;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("trtc-js-sdk"),t=require("amazon-chime-sdk-js"),n=require("react");function r(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var o=r(e),i=r(n),s=function(e,t){return s=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},s(e,t)};function c(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function n(){this.constructor=e}s(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}var a=function(){return a=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},a.apply(this,arguments)};function u(e,t,n,r){return new(n||(n=Promise))((function(o,i){function s(e){try{a(r.next(e))}catch(e){i(e)}}function c(e){try{a(r.throw(e))}catch(e){i(e)}}function a(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,c)}a((r=r.apply(e,t||[])).next())}))}function l(e,t){var n,r,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function c(i){return function(c){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return s.label++,{value:i[1],done:!1};case 5:s.label++,r=i[1],i=[0];continue;case 7:i=s.ops.pop(),s.trys.pop();continue;default:if(!(o=s.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){s.label=i[1];break}if(6===i[0]&&s.label<o[1]){s.label=o[1],o=i;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(i);break}o[2]&&s.ops.pop(),s.trys.pop();continue}i=t.call(e,s)}catch(e){i=[6,e],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,c])}}}function d(e,t,n){if(n||2===arguments.length)for(var r,o=0,i=t.length;o<i;o++)!r&&o in t||(r||(r=Array.prototype.slice.call(t,0,o)),r[o]=t[o]);return e.concat(r||Array.prototype.slice.call(t))}var f=Symbol("$$REALSEE_LIVE_EVENT$$");function h(e){return e[f]||(e[f]={}),e[f]}var p,v,m=function(){function e(){}return e.prototype.hasListener=function(e){var t=h(this);return t&&t[e]&&t[e].length>0},e.prototype.on=function(e,t,n){var r=this,o=h(this);return o[e]||(o[e]=[]),o[e].push([t,n||!1]),function(){return r.off(e,t)}},e.prototype.once=function(e,t){return this.on(e,t,!0)},e.prototype.off=function(e,t){if(void 0!==e){var n,r=h(this);if(r[e]||(r[e]=[]),void 0!==t){for(var o=0;o<r[e].length&&r[e][o][0]!==t;o++);o<r[e].length&&r[e].splice(o,1)}else r[e].length=0}else(n=this)[f]||delete n[f]},e.prototype.emit=function(e){for(var t=[],n=1;n<arguments.length;n++)t[n-1]=arguments[n];for(var r=!1,o=h(this),i=o[e]||[],s=0,c=i.slice();s<c.length;s++){var a=c[s],u=a[0],l=a[1],d=void 0!==l&&l,f=u.apply(void 0,t);d&&this.off(e,u),!1===f&&(r=!0)}return r},e}(),g=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return c(t,e),t}(m);exports.RTCType=void 0,(p=exports.RTCType||(exports.RTCType={})).RealseeBrowserRTC="RealseeBrowserRTC",p.RealseeVRWebViewRTC="RealseeVRWebViewRTC",p.RealseeBrowserChimeRTC="RealseeBrowserChimeRTC",exports.BuiltInRTCType=void 0,(v=exports.BuiltInRTCType||(exports.BuiltInRTCType={})).RealseeXTRTC="trtc",v.RealseeXChimeRTC="chime";var _;!function(e){e.info="INFO",e.log="LOG",e.error="ERROR",e.warn="WARN"}(_||(_={}));var b=function(e,t){var n,r,o,i,s,c,a,u;switch(void 0===t&&(t=[]),t.unshift("Realsee Live ".concat((n=new Date,r=n.getFullYear(),o=(n.getMonth()+1).toString().padStart(2,"0"),i=n.getDate().toString().padStart(2,"0"),s=n.getHours().toString().padStart(2,"0"),c=n.getMinutes().toString().padStart(2,"0"),a=n.getSeconds().toString().padStart(2,"0"),u=n.getMilliseconds(),"[".concat(r,"-").concat(o,"-").concat(i," ").concat(s,":").concat(c,":").concat(a,".").concat(u,"]"))," <").concat(e,"> ")),e){case _.info:return console.info.apply(console,t);case _.error:return console.error.apply(console,t);case _.warn:return console.warn.apply(console,t);default:return console.log.apply(console,t)}},y={log:function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return b(_.log,e)},info:function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return b(_.info,e)},error:function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return b(_.error,e)},warn:function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return b(_.warn,e)}};function w(){return(65536*(1+Math.random())|0).toString(16).substring(1)}function S(){return(w()+w()+"-"+w()+"-4"+w().substr(0,3)+"-"+w()+"-"+w()+w()+w()).toLowerCase()}var k,E=function(e){function t(t){var n=e.call(this)||this;return n.type=exports.RTCType.RealseeBrowserRTC,n.joined=!1,n.micro=!1,n.voiceId="",n._getVoiceSign=function(){throw new Error("方法 getVoiceSign 未实现")},n.checkRequirement=function(){return o.default.checkSystemRequirements()},n.$dom=document.createElement("div"),n._trtc={client:null,stream:null},n.join=function(e){return u(n,void 0,void 0,(function(){var t,n,r,i=this;return l(this,(function(s){switch(s.label){case 0:return this.emit("joinWillStart"),[4,this._getVoiceSign({voiceId:e.voiceId,roomId:e.roomId,userId:e.userId})];case 1:return t=s.sent(),this._trtc.client=o.default.createClient(a(a({mode:"rtc"},t),{enableAutoPlayDialog:"function"!=typeof this._autoPlayConfirm})),null===(r=this._trtc.client)||void 0===r||r.enableAudioVolumeEvaluation(),this._registerRtcEvent(),[4,new Promise((function(t){var n;null===(n=i._trtc.client)||void 0===n||n.join({roomId:Number(e.voiceId)}).then((function(){return t(!0)})).catch((function(){return t(!1)}))}))];case 2:return n=s.sent(),this.joined=n,n?(this._trtc.stream=o.default.createStream({userId:t.userId,audio:!0,video:!1}),[4,new Promise((function(e){var t;null===(t=i._trtc.stream)||void 0===t||t.initialize().then((function(){return e(!0)})).catch((function(){return e(!1)}))}))]):[2,!1];case 3:return n=s.sent(),[4,new Promise((function(e){var t;null===(t=i._trtc.client)||void 0===t||t.publish(i._trtc.stream).then((function(){return e(!0)})).catch((function(){return e(!1)}))}))];case 4:return n=s.sent(),this.joined=n,this.joined&&this.emit("joined"),[2,n]}}))}))},n._handleStreamAdded=function(e){var t,r=e.stream;console.log("远端流增加: "+r.getId()),null===(t=n._trtc.client)||void 0===t||t.subscribe(r)},n._handleStreamSubscribed=function(e){var t=e.stream;console.log("远端流订阅成功:"+t.getId());var r=t.getId(),o="rs-rtc-remote_stream-".concat(r),i=document.createElement("div");i.id=o,n.$dom.appendChild(i),"function"==typeof n._autoPlayConfirm?(t.play(o).catch((function(e){})),t.on("error",(function(e){if(16451===e.getCode()){n._autoPlayConfirm({onConfirm:function(){return t.resume()}})}}))):t.play(o)},n._getVoiceSign=t.getVoiceSign,n._autoPlayConfirm=t.autoPlayConfirm,n._initParentDom(),n}return c(t,e),t.prototype._initParentDom=function(){this.$dom.id="rs-rtc-".concat(S()),this.$dom.style.display="none",document.body.appendChild(this.$dom)},t.prototype.quit=function(){var e=this;return new Promise((function(t){return u(e,void 0,void 0,(function(){var e,n,r=this;return l(this,(function(o){switch(o.label){case 0:return this.joined=!1,this._trtc.stream?[4,null===(e=this._trtc.client)||void 0===e?void 0:e.unpublish(this._trtc.stream)]:[3,2];case 1:o.sent(),this._trtc.stream.stop(),this._trtc.stream.close(),this._trtc.stream=null,o.label=2;case 2:return null===(n=this._trtc.client)||void 0===n||n.leave().then((function(){return r._trtc.client=null})).then((function(){return t(!0)})).catch((function(){return t(!1)})),t(!0),[2]}}))}))}))},t.prototype.detectMicro=function(){return new Promise((function(e){try{navigator.mediaDevices.getUserMedia({audio:!0,video:!1}).then((function(){return e(!0)})).catch((function(t){y.error(t.message),e(!1)}))}catch(t){console.error(t),e(!1)}}))},t.prototype.toggleMicro=function(e){var t,n,r,o;return Promise.resolve((e?null===(n=null===(t=this._trtc)||void 0===t?void 0:t.stream)||void 0===n?void 0:n.unmuteAudio():null===(o=null===(r=this._trtc)||void 0===r?void 0:r.stream)||void 0===o?void 0:o.muteAudio())||!1)},t.prototype.shock=function(){throw new Error("Method not implemented.")},t.prototype._registerRtcEvent=function(){var e,t,n,r,o=this;null===(e=this._trtc.client)||void 0===e||e.on("stream-added",this._handleStreamAdded),null===(t=this._trtc.client)||void 0===t||t.on("stream-subscribed",this._handleStreamSubscribed),null===(n=this._trtc.client)||void 0===n||n.on("audio-volume",(function(e){return o.emit("userVolumes",e.result.map((function(e){return{userId:e.userId,audioVolume:e.audioVolume}})))})),null===(r=this._trtc.client)||void 0===r||r.on("error",(function(e){return o.emit("error",e)}))},t}(g),C=function(e){function n(n){var r=e.call(this)||this;return r.type=exports.RTCType.RealseeBrowserChimeRTC,r.joined=!1,r.micro=!1,r.voiceId="",r.userId="",r.deviceChangeObserver={},r.audioVideoObserver={},r._getVoiceSign=function(){throw new Error("方法 getVoiceSign 未实现")},r.$dom=document.createElement("div"),r.$audio=document.createElement("audio"),r._initDom=function(){r.$audio.id="rs-rtc-".concat(S()),r.$dom.id="rs-rtc-".concat(S()),r.$dom.appendChild(r.$audio),document.body.appendChild(r.$dom)},r.initObservers=function(){r.deviceChangeObserver={audioInputsChanged:function(e){null==e||e.forEach((function(e){r.logger.info("Device ID: ".concat(e.deviceId," Microphone: ").concat(e.label))}))},audioOutputsChanged:function(e){r.logger.info("Audio outputs updated: ".concat(e))},videoInputsChanged:function(e){r.logger.info("Video inputs updated: ".concat(e))},audioInputMuteStateChanged:function(e,t){r.logger.info("Device ".concat(e.toString()," ").concat(t?"is muted in hardware":"is not muted"))}},r.audioVideoObserver={audioVideoDidStart:function(){r.logger.info("Started")},audioVideoDidStop:function(e){r.logger.info("Stopped with a session status code: ".concat(e.statusCode()))},audioVideoDidStartConnecting:function(e){e&&r.logger.info("Attempting to reconnect")}}},r._registerRtcEvent=function(){var e,n,o,i,s,c,a=(null===(o=null===(n=null===(e=r.meetingSession)||void 0===e?void 0:e.configuration)||void 0===n?void 0:n.credentials)||void 0===o?void 0:o.attendeeId)||"";if(a){var u=new Map,l=function(){var e=[];return u.forEach((function(t,n){e.push({userId:t.userId,volume:t.muted||0===t.signalStrength||!Boolean(t.volume)?0:t.volume})})),e};null===(i=r.meetingSession)||void 0===i||i.audioVideo.realtimeSubscribeToAttendeeIdPresence((function(e,n,o){var i;if(!n)return u.delete(e),void r.emit("userVolumes",l());null===(i=r.meetingSession)||void 0===i||i.audioVideo.realtimeSubscribeToVolumeIndicator(e,(function(e,n,i,s){new t.DefaultModality(e).base()===e&&(u.set(e,{userId:o||e,volume:n,muted:i,signalStrength:s}),r.emit("userVolumes",l()))}))})),null===(s=r.meetingSession)||void 0===s||s.audioVideo.realtimeSubscribeToVolumeIndicator(a,(function(e,n,o,i){new t.DefaultModality(e).base()===e&&null!==i&&1!==i&&r.emit("weakNetwork")})),null===(c=r.meetingSession)||void 0===c||c.audioVideo.realtimeSubscribeToFatalError((function(e){return r.emit("error",e)}))}},r._getVoiceSign=n.getVoiceSign,r._initDom(),r.logger=new t.ConsoleLogger("WebRTCLogger",n.logLevel||t.LogLevel.INFO),r.deviceController=new t.DefaultDeviceController(r.logger),r.initObservers(),r}return c(n,e),n.prototype.join=function(e){return u(this,void 0,void 0,(function(){var n=this;return l(this,(function(r){return[2,new Promise((function(r,o){return u(n,void 0,void 0,(function(){var n,o,i,s,c,u,d,f,h,p,v,m,g,_=this;return l(this,(function(l){switch(l.label){case 0:this.emit("joinWillStart"),l.label=1;case 1:return l.trys.push([1,5,,6]),[4,this._getVoiceSign(a(a({},e),{roomId:e.roomId||0}))];case 2:return n=l.sent(),o=n.userId,i=n.userSig,this.userId=o,s=JSON.parse(decodeURIComponent(i)),c=s.attendence,u=s.vendor_wrapper,d=new t.MeetingSessionConfiguration({Meeting:u},{Attendee:{ExternalUserId:c.external_user_id,AttendeeId:c.attendee_id,JoinToken:c.join_token}}),this.meetingSession=new t.DefaultMeetingSession(d,this.logger,this.deviceController),this._registerRtcEvent(),this.meetingSession.audioVideo.addDeviceChangeObserver(this.deviceChangeObserver),this.meetingSession.audioVideo.addObserver(this.audioVideoObserver),this.meetingSession.audioVideo.bindAudioElement(this.$audio),f={audioVideoDidStart:function(){var e;null===(e=_.meetingSession)||void 0===e||e.audioVideo.realtimeMuteLocalAudio(),_.joined=!0,_.emit("joined"),r(!0)},audioVideoDidStop:function(){_.joined=!1,r(!1)}},this.meetingSession.audioVideo.addObserver(f),[4,this.deviceController.listAudioInputDevices(!0)];case 3:return h=l.sent(),p=h.find((function(e){return"default"===e.deviceId})),v=h.find((function(e){return""!==e.deviceId})),this.audioInput=p||v,[4,this.meetingSession.audioVideo.startAudioInput((null===(g=this.audioInput)||void 0===g?void 0:g.deviceId)||"default")];case 4:return l.sent(),this.meetingSession.audioVideo.start(),[3,6];case 5:return m=l.sent(),this.emit("error",m),this.logger.error(m.message),r(!1),[3,6];case 6:return[2]}}))}))}))]}))}))},n.prototype.quit=function(){var e=this;return this.joined?new Promise((function(n,r){var o,i;e.joined=!1;var s={audioVideoDidStop:function(r){return u(e,void 0,void 0,(function(){var e,o;return l(this,(function(i){return e=r.statusCode(),null===(o=this.meetingSession)||void 0===o||o.deviceController.destroy(),e===t.MeetingSessionStatusCode.Left?(this.logger.info("You left the session"),n(!0)):(this.logger.info("Stopped with a session status code: ".concat(e)),n(!0)),[2]}))}))}};null===(o=e.meetingSession)||void 0===o||o.audioVideo.addObserver(s),null===(i=e.meetingSession)||void 0===i||i.audioVideo.stop()})):Promise.resolve(!0)},n.prototype.detectMicro=function(){return u(this,void 0,void 0,(function(){var e=this;return l(this,(function(t){return[2,new Promise((function(t){try{navigator.mediaDevices.getUserMedia({audio:!0,video:!1}).then((function(){return t(!0)})).catch((function(){return t(!1)}))}catch(n){e.logger.error(n.message),t(!1)}}))]}))}))},n.prototype.toggleMicro=function(e){var t,n,r;return u(this,void 0,void 0,(function(){var o;return l(this,(function(i){return e?null===(t=this.meetingSession)||void 0===t||t.audioVideo.realtimeUnmuteLocalAudio():null===(n=this.meetingSession)||void 0===n||n.audioVideo.realtimeMuteLocalAudio(),void 0!==(o=null===(r=this.meetingSession)||void 0===r?void 0:r.audioVideo.realtimeIsLocalAudioMuted())?[2,e!==o]:[2,!1]}))}))},n.prototype.shock=function(){throw new Error("Method not implemented.")},n}(g);exports.RTCJoinedInfoCodeEnum=void 0,(k=exports.RTCJoinedInfoCodeEnum||(exports.RTCJoinedInfoCodeEnum={}))[k.Success=0]="Success",k[k.Failure=1]="Failure",k[k.ReJoin=2]="ReJoin",k[k.NoMicroPermission=3]="NoMicroPermission";var T,O,I,R,B,A,L,N,W,P,x=function(e){function t(t){var n=t.jsBridge,r=t.getVoiceSign,o=e.call(this)||this;return o.type=exports.RTCType.RealseeVRWebViewRTC,o.joined=!1,o.micro=!1,o.voiceId="",o.options={jsBridge:n,getVoiceSign:r},"WxMiniProgramWebView"!==o.jsBridge.webViewType&&o.jsBridge.callAndListen("live/userVolumes",(function(e){o.emit("userVolumes",e)})),o.jsBridge.callAndListen("live/weakNetwork",(function(e){e&&o.emit("weakNetwork")})),o}return c(t,e),Object.defineProperty(t.prototype,"jsBridge",{get:function(){return this.options.jsBridge},enumerable:!1,configurable:!0}),t.prototype.join=function(e){return u(this,void 0,void 0,(function(){var t,n,r,o,i,s,c,a;return l(this,(function(u){switch(u.label){case 0:return u.trys.push([0,3,,4]),this.emit("joinWillStart"),[4,this.options.getVoiceSign(e)];case 1:return t=u.sent(),n=t.sdkAppId,r=t.userId,o=t.userSig,Boolean(n)&&Boolean(r)&&Boolean(o)?(this.type=e.type,[4,this.jsBridge.callAndBackfeed("live/join?sdkAppID=".concat(n,"&userID=").concat(r,"&roomID=").concat(Number(e.voiceId),"&userSig=").concat(o))]):(this.emit("error",new Error("加入房间失败:rtc 签名请求异常")),this.joined=!1,[2,this.joined]);case 2:return i=u.sent(),s=i[0],c=i[1],s?s.code===exports.RTCJoinedInfoCodeEnum.Success?(this.emit("joined"),this.joined=!0):(this.emit("error",s),this.joined=!1):(this.emit("error",c||new Error("加入房间失败:未知异常。")),this.joined=!1),[2,this.joined];case 3:return a=u.sent(),this.emit("error",new Error("加入房间失败:"+a.message)),this.joined=!1,[2,this.joined];case 4:return[2]}}))}))},t.prototype.quit=function(){return u(this,void 0,void 0,(function(){var e,t,n;return l(this,(function(r){switch(r.label){case 0:return[4,this.jsBridge.callAndBackfeed("live/quit")];case 1:return e=r.sent(),t=e[0],n=e[1],null===t&&this.emit("error",n||new Error("退出房间失败:未知异常。")),this.joined=!1,[2,!!t]}}))}))},t.prototype.detectMicro=function(){return u(this,void 0,void 0,(function(){var e,t,n;return l(this,(function(r){switch(r.label){case 0:return[4,this.jsBridge.detectMicro()];case 1:return e=r.sent(),t=e[0],n=e[1],null===t?(this.emit("error",n||new Error("麦克风监测异常!")),[2,!1]):[2,t]}}))}))},t.prototype.toggleMicro=function(e){return u(this,void 0,void 0,(function(){var t,n,r;return l(this,(function(o){switch(o.label){case 0:return[4,this.jsBridge.callAndBackfeed("live/toggleMicro?flag=".concat(e?1:0))];case 1:return t=o.sent(),n=t[0],r=t[1],null===n?(this.emit("error",r||new Error("麦克风监测异常!")),[2,!1]):(this.micro=n,[2,n])}}))}))},t.prototype.shock=function(){this.jsBridge.shock(1)},t}(g);function M(e){switch(e){case 1e3:return exports.WebSocketCloseError.Err_1000;case 1001:return exports.WebSocketCloseError.Err_1001;case 1002:return exports.WebSocketCloseError.Err_1002;case 1003:return exports.WebSocketCloseError.Err_1003;case 1006:return exports.WebSocketCloseError.Err_1006;case 1007:return exports.WebSocketCloseError.Err_1007;case 1008:return exports.WebSocketCloseError.Err_1008;case 1009:return exports.WebSocketCloseError.Err_1009}return exports.WebSocketCloseError.Err_unknown}exports.Command=void 0,(T=exports.Command||(exports.Command={})).SelfUserInfo="SELF_USER_INFO",T.RoomInfo="ROOM_INFO",T.RTCInfo="RTC_INFO",T.UserList="USER_LIST",T.BuiltinMsg="BUILTIN_MSG",T.CustomEvent="CUSTOM_EVENT",T.KeyframeSync="KEYFRAME_SYNC",T.UserKickOut="USER_KICK_OUT",exports.BuiltinEventType=void 0,(O=exports.BuiltinEventType||(exports.BuiltinEventType={})).UserChange="user_change",O.RoomChange="room_change",exports.BuiltinActionType=void 0,(I=exports.BuiltinActionType||(exports.BuiltinActionType={})).UserMicroStatus="change_micro_status",I.UserMicroStatusSync="sync_micro_status",I.UserPermission="change_permission",I.UserStatus="change_status",I.UserInfo="change_info",I.RoomClose="close",exports.MicroStatus=void 0,(R=exports.MicroStatus||(exports.MicroStatus={})).OPEN="OPEN",R.CLOSE="CLOSE",exports.LiveState=void 0,(B=exports.LiveState||(exports.LiveState={}))[B.NOTINITIALIZED=-1]="NOTINITIALIZED",B[B.CONNECTING=0]="CONNECTING",B[B.OPEN=1]="OPEN",B[B.CLOSED=3]="CLOSED",exports.UserStatus=void 0,(A=exports.UserStatus||(exports.UserStatus={}))[A.Normal=0]="Normal",A[A.Removed=1]="Removed",A[A.Replaced=2]="Replaced",exports.MemUserStatus=void 0,(L=exports.MemUserStatus||(exports.MemUserStatus={})).WAIT_ENTER="WAIT_ENTER",L.ONLINE="ONLINE",L.LEAVE="LEAVE",L.KICK_OUT="KICK_OUT",L.BE_REPLACE="BE_REPLACE",L.EXCEPTION="EXCEPTION",exports.WebSocketState=void 0,(N=exports.WebSocketState||(exports.WebSocketState={}))[N.NOTINITIALIZED=-1]="NOTINITIALIZED",N[N.CONNECTING=0]="CONNECTING",N[N.OPEN=1]="OPEN",N[N.CLOSING=2]="CLOSING",N[N.CLOSED=3]="CLOSED",exports.WebSocketErrorType=void 0,(W=exports.WebSocketErrorType||(exports.WebSocketErrorType={})).Error="Error",W.Close="Close",W.MicroAuth="MicroAuth",W.DuplicateConnect="DuplicateConnect",W.IllegalURL="IllegalURL",W.Unknown="Unknown",W.IllegalArgs="IllegalArgs",exports.WebSocketCloseError=void 0,(P=exports.WebSocketCloseError||(exports.WebSocketCloseError={})).Err_1000="CLOSE_NORMAL",P.Err_1001="CLOSE_GOING_AWAY",P.Err_1002="CLOSE_PROTOCOL_ERROR",P.Err_1003="CLOSE_UNSUPPORTED",P.Err_1006="CLOSE_ABNORMAL",P.Err_1007="Unsupported Data",P.Err_1008="Policy Violation",P.Err_1009="CLOSE_TOO_LARGE",P.Err_unknown="unknown";var j=function(e,t){return j=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},j(e,t)};function V(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function n(){this.constructor=e}j(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}var U=function(){return U=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},U.apply(this,arguments)};function D(e,t,n,r){return new(n||(n=Promise))((function(o,i){function s(e){try{a(r.next(e))}catch(e){i(e)}}function c(e){try{a(r.throw(e))}catch(e){i(e)}}function a(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,c)}a((r=r.apply(e,t||[])).next())}))}function H(e,t){var n,r,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function c(c){return function(a){return function(c){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,c[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&c[0]?r.return:c[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,c[1])).done)return o;switch(r=0,o&&(c=[2&c[0],o.value]),c[0]){case 0:case 1:o=c;break;case 4:return s.label++,{value:c[1],done:!1};case 5:s.label++,r=c[1],c=[0];continue;case 7:c=s.ops.pop(),s.trys.pop();continue;default:if(!(o=s.trys,(o=o.length>0&&o[o.length-1])||6!==c[0]&&2!==c[0])){s=0;continue}if(3===c[0]&&(!o||c[1]>o[0]&&c[1]<o[3])){s.label=c[1];break}if(6===c[0]&&s.label<o[1]){s.label=o[1],o=c;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(c);break}o[2]&&s.ops.pop(),s.trys.pop();continue}c=t.call(e,s)}catch(e){c=[6,e],r=0}finally{n=o=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}([c,a])}}}var J={};function q(e,t,n){var r;if(void 0===n&&(n=!0),J[e])J[e].queue.push({once:n,callback:t});else{var o="$jsBridgeFn_"+Date.now().toString(16).toUpperCase()+"_"+Math.ceil(1e4*Math.random()).toString(16).toUpperCase();J[e]={uuid:o,queue:[{once:n,callback:t}]}}return Object.assign(window,((r={})[J[e].uuid]=function(t){J[e].queue=J[e].queue.reduce((function(e,n){var r=n.once,o=n.callback;return r||e.push(n),o(t),e}),[])},r)),J[e].uuid}var $,K=function(){function e(){}return e.prototype.checkReady=function(e){return Promise.resolve([!1,null])},e.prototype.callAndBackfeed=function(e){return Promise.resolve([!1,null])},e.prototype.callAndListen=function(e,t){return Promise.resolve([!1,null])},e}(),F=window,G=function(e){function t(){var t=e.call(this)||this;return Promise.resolve().then((function(){return D(t,void 0,void 0,(function(){var e;return H(this,(function(t){switch(t.label){case 0:return t.trys.push([0,2,,3]),[4,this.checkBridgeReady()];case 1:return t.sent(),[3,3];case 2:return e=t.sent(),console.warn(e),[3,3];case 3:return[2]}}))}))})),t}return V(t,e),t.prototype.checkBridgeReady=function(e){var t=this;if(void 0===e&&(e=6e3),this.hybridBridge)return!0;var n=performance.now();return new Promise((function(r,o){var i=function(){if(t.hybridBridge)return r(!0);if(F.HybridBridgeLJ){var s=F.HybridBridgeLJ;null==s||s.getStaticData(q("HYBRID_BRIDGE_NAME",(function(e){return t.deviceInfo=JSON.parse(e),t.hybridBridge=s,r(!0)})))}if(performance.now()-n>(e||6e3))return o(new Error("HybridBridge 初始化超时~"));requestAnimationFrame(i)};i()}))},t.prototype.checkReady=function(e){return void 0===e&&(e=6e3),D(this,void 0,void 0,(function(){var t,n,r,o;return H(this,(function(i){switch(i.label){case 0:if(t=[null,null],this.hybridBridge)return t[0]=!0,[2,t];i.label=1;case 1:return i.trys.push([1,3,,4]),n=t,r=0,[4,this.checkBridgeReady(e)];case 2:return n[r]=i.sent(),[3,4];case 3:return o=i.sent(),t[0]=!1,t[1]=o,[3,4];case 4:return[2,t]}}))}))},Object.defineProperty(t.prototype,"ready",{get:function(){return!!this.hybridBridge},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"scheme",{get:function(){var e;return(null===(e=this.deviceInfo)||void 0===e?void 0:e.scheme)||""},enumerable:!1,configurable:!0}),t.prototype.createSchemeLink=function(e){return e.startsWith(this.scheme)?e:this.scheme+"://"+e},t.prototype.callAndBackfeed=function(e){return D(this,void 0,void 0,(function(){var t,n,r,o,i=this;return H(this,(function(s){switch(s.label){case 0:return t=[!1,null],[4,this.checkReady()];case 1:return n=s.sent(),r=n[0],o=n[1],r?[4,new Promise((function(n){return D(i,void 0,void 0,(function(){var r,o;return H(this,(function(i){return r=this.createSchemeLink(e),o=JSON.stringify({actionUrl:r,functionName:q(this.createSchemeLink(e),(function(e){var r=function(){try{return JSON.parse(e)}catch(t){return e}}();t[0]=1===r||0!==r&&r,n(t)}))}),this.hybridBridge.callAndBackfeed(o),[2]}))}))}))]:(t[0]=!1,t[1]=o,[2,t]);case 2:return[2,s.sent()]}}))}))},t.prototype.callAndListen=function(e,t){return D(this,void 0,void 0,(function(){var n,r,o,i,s=this;return H(this,(function(c){switch(c.label){case 0:return n=[!1,null],[4,this.checkReady()];case 1:return r=c.sent(),o=r[0],i=r[1],o?[4,new Promise((function(r){return D(s,void 0,void 0,(function(){var o,i,s;return H(this,(function(c){return o=this.createSchemeLink(e),i=function(e){var s=function(){try{return JSON.parse(e)}catch(t){return e}}();t(1===s||0!==s&&s),n[0]=function(){var e=J[o];if(e){var t=e.queue.findIndex((function(e){return e.callback===i}));-1!==t&&e.queue.splice(t,1)}},r(n)},s=JSON.stringify({actionUrl:o,functionName:q(o,i,!1)}),this.hybridBridge.callAndListen(s),[2]}))}))}))]:(n[0]=!1,n[1]=i,[2,n]);case 2:return[2,c.sent()]}}))}))},t}(K);!function(e){e.callAndBackfeed="callAndBack",e.callAndListen="callAndListen"}($||($={}));var z,Y=window,Z=function(){function e(){this.checkBridgeReady()}return e.prototype.checkBridgeReady=function(e){var t=this;if(void 0===e&&(e=6e3),this.worker)return!0;var n=performance.now();return new Promise((function(r,o){var i=function(){if(t.worker)return r(!0);if(Y.webkit&&Y.webkit.messageHandlers&&Y.webkit.messageHandlers.realsee){var s=Y.webkit.messageHandlers.realsee;s.postMessage(JSON.stringify({type:"getStaticData",param:JSON.stringify({functionName:q("HYBRID_BRIDGE_NAME",(function(e){return t.deviceInfo=JSON.parse(e),t.worker=s,r(!0)}))})}))}else{if(performance.now()-n>(e||6e3))return o(new Error("HybridBridge 初始化超时~"));requestAnimationFrame(i)}};i()}))},e.prototype.checkReady=function(e){return void 0===e&&(e=6e3),D(this,void 0,void 0,(function(){var t,n,r,o;return H(this,(function(i){switch(i.label){case 0:if(t=[null,null],this.worker)return t[0]=!0,[2,t];i.label=1;case 1:return i.trys.push([1,3,,4]),n=t,r=0,[4,this.checkBridgeReady(e)];case 2:return n[r]=i.sent(),[3,4];case 3:return o=i.sent(),t[0]=!1,t[1]=o,[3,4];case 4:return[2,t]}}))}))},Object.defineProperty(e.prototype,"ready",{get:function(){return!!this.worker},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"scheme",{get:function(){var e;return(null===(e=this.deviceInfo)||void 0===e?void 0:e.scheme)||""},enumerable:!1,configurable:!0}),e.prototype.createSchemeLink=function(e){return e.startsWith(this.scheme)?e:this.scheme+"://"+e},e.prototype.callAndBackfeed=function(e){return D(this,void 0,void 0,(function(){var t,n,r,o,i=this;return H(this,(function(s){switch(s.label){case 0:return t=[!1,null],[4,this.checkReady()];case 1:return n=s.sent(),r=n[0],o=n[1],r?[4,new Promise((function(n){return D(i,void 0,void 0,(function(){var r,o;return H(this,(function(i){return r=this.createSchemeLink(e),o=JSON.stringify({actionUrl:r,functionName:q(this.createSchemeLink(e),(function(e){var r=function(){try{return JSON.parse(e)}catch(t){return e}}();t[0]=1===r||0!==r&&r,n(t)}))}),this.worker.postMessage(JSON.stringify({type:"callAndBackfeed",param:o})),[2]}))}))}))]:(t[0]=!1,t[1]=o,[2,t]);case 2:return[2,s.sent()]}}))}))},e.prototype.callAndListen=function(e,t){return D(this,void 0,void 0,(function(){var n,r,o,i,s=this;return H(this,(function(c){switch(c.label){case 0:return n=[!1,null],[4,this.checkReady()];case 1:return r=c.sent(),o=r[0],i=r[1],o?[4,new Promise((function(r){return D(s,void 0,void 0,(function(){var o,i,s;return H(this,(function(c){return o=this.createSchemeLink(e),i=function(e){var s=function(){try{return JSON.parse(e)}catch(t){return e}}();t(1===s||0!==s&&s),n[0]=function(){var e=J[o];if(e){var t=e.queue.findIndex((function(e){return e.callback===i}));-1!==t&&e.queue.splice(t,1)}},r(n)},s=JSON.stringify({actionUrl:o,functionName:q(o,i,!1)}),this.worker.postMessage(JSON.stringify({type:"callAndListen",param:s})),[2]}))}))}))]:(n[0]=!1,n[1]=i,[2,n]);case 2:return[2,c.sent()]}}))}))},e}();function X(){return(65536*(1+Math.random())|0).toString(16).substring(1)}function Q(){return(X()+X()+"-"+X()+"-4"+X().substr(0,3)+"-"+X()+"-"+X()+X()+X()).toLowerCase()}!function(e){e.isReady="Are You OK?",e.ready="I`m OK!",e.ping="ping",e.pong="pong",e.alive="I`m alive!"}(z||(z={}));var ee=function(e,t){var n=Object.keys(t).reduce((function(e,n){return e.replace("{{".concat(n,"}}"),"".concat(t[n]))}),e);return encodeURI(n)},te=function(e,t){return e in t},ne=function(e){return void 0===e&&(e=""),e.replace("?","").split("&").map((function(e){var t,n=e.split("="),r=n[0],o=n[1];return(t={})[r]=decodeURIComponent(o),t})).reduce((function(e,t){return U(U({},e),t)}),{})},re="$$REALSEE_JSBRIDGE_EVENT$$";function oe(e){return e[re]||(e[re]={}),e[re]}var ie,se=function(){function e(){}return e.prototype.hasListener=function(e){var t=oe(this);return t&&t[e]&&t[e].length>0},e.prototype.on=function(e,t,n){var r=this,o=oe(this);return o[e]||(o[e]=[]),o[e].push([t,n||!1]),function(){return r.off(e,t)}},e.prototype.once=function(e,t){return this.on(e,t,!0)},e.prototype.off=function(e,t){if(void 0!==e){var n,r=oe(this);if(r[e]||(r[e]=[]),void 0!==t){for(var o=0;o<r[e].length&&r[e][o][0]!==t;o++);o<r[e].length&&r[e].splice(o,1)}else r[e].length=0}else(n=this)[re]||delete n[re]},e.prototype.emit=function(e){for(var t=[],n=1;n<arguments.length;n++)t[n-1]=arguments[n];for(var r=!1,o=oe(this),i=o[e]||[],s=0,c=i.slice();s<c.length;s++){var a=c[s],u=a[0],l=a[1],d=void 0!==l&&l,f=u.apply(void 0,t);d&&this.off(e,u),!1===f&&(r=!0)}return r},e}(),ce=function(e){function t(t){var n=e.call(this)||this;return n._options={timeout:1e4,shouldReconnect:function(e,t){if(1008!==e.code&&1011!==e.code)return[0,3e3,1e4][t.attempts]},should1000Reconnect:!1,ignoreConnectivityEvents:!1,automaticOpen:!1},n._attempts=0,n._reconnects=-1,n._reconnectWhenOnlineAgain=!1,n._explicitlyClosed=!1,n._connectivityEventsAttached=!1,n._clearPendingReconnectIfNeeded=function(){n._pendingReconnect&&(clearTimeout(n._pendingReconnect),n._pendingReconnect=void 0)},n._online=function(e){n._reconnectWhenOnlineAgain&&(n._clearPendingReconnectIfNeeded(),n._reconnect(e))},n._offline=function(){var e;n._reconnectWhenOnlineAgain=!0,null===(e=n._realWebSocket)||void 0===e||e.close(1e3)},n._detachConnectivityEvents=function(){n._connectivityEventsAttached&&(null===globalThis||void 0===globalThis||globalThis.removeEventListener("online",n._online),null===globalThis||void 0===globalThis||globalThis.removeEventListener("offline",n._offline),n._connectivityEventsAttached=!1)},n._attachConnectivityEvents=function(){n._connectivityEventsAttached||(null===globalThis||void 0===globalThis||globalThis.addEventListener("online",n._online),null===globalThis||void 0===globalThis||globalThis.addEventListener("offline",n._offline),n._connectivityEventsAttached=!0)},n.send=function(e){var t,r,o;(null===(t=n._realWebSocket)||void 0===t?void 0:t.readyState)===(null===(r=n._realWebSocket)||void 0===r?void 0:r.OPEN)&&(null===(o=n._realWebSocket)||void 0===o||o.send(e))},n.close=function(e,t){var r;return"number"!=typeof e&&(t=e,e=1e3),n._clearPendingReconnectIfNeeded(),n._reconnectWhenOnlineAgain=!1,n._explicitlyClosed=!0,n._detachConnectivityEvents(),null===(r=n._realWebSocket)||void 0===r?void 0:r.close(e,t)},n.open=function(e){var t,r;e&&(n._url=e),(null===(t=n._realWebSocket)||void 0===t?void 0:t.readyState)!==WebSocket.OPEN&&(null===(r=n._realWebSocket)||void 0===r?void 0:r.readyState)!==WebSocket.CONNECTING&&(n._clearPendingReconnectIfNeeded(),n._reconnectWhenOnlineAgain=!1,n._explicitlyClosed=!1,n._createWebSocket())},n._createWebSocket=function(){var e,t,r,o="string"==typeof n._url?n._url:null===(e=n._url)||void 0===e?void 0:e.call(n,n);if(o){n._pendingReconnect=void 0,n._removeWebSocketEvent(),n._realWebSocket=new WebSocket(o,n._protocols||void 0),n._attempts=n._attempts+1,n.emit("connecting",new CustomEvent("connecting",{detail:{attempts:n._attempts,reconnects:n._reconnects}}));n._connectTimeout=setTimeout((function(){n._connectTimeout=void 0,n._detachConnectivityEvents(),n.emit("timeout",new CustomEvent("connecting",{detail:{attempts:n._attempts,reconnects:n._reconnects}}))}),null===(t=n._options)||void 0===t?void 0:t.timeout),n._dispatchWebSocketEvent(),(null===(r=n._options)||void 0===r?void 0:r.ignoreConnectivityEvents)||n._attachConnectivityEvents()}},n._removeWebSocketEvent=function(){var e,t,r,o;null===(e=n._realWebSocket)||void 0===e||e.removeEventListener("open",n._webSocketOpenHandler),null===(t=n._realWebSocket)||void 0===t||t.removeEventListener("close",n._webSocketCloseHandler),null===(r=n._realWebSocket)||void 0===r||r.removeEventListener("error",n._webSocketErrorHandler),null===(o=n._realWebSocket)||void 0===o||o.removeEventListener("message",n._webSocketMessageHandler)},n._dispatchWebSocketEvent=function(){var e,t,r,o;null===(e=n._realWebSocket)||void 0===e||e.addEventListener("open",n._webSocketOpenHandler),null===(t=n._realWebSocket)||void 0===t||t.addEventListener("close",n._webSocketCloseHandler),null===(r=n._realWebSocket)||void 0===r||r.addEventListener("error",n._webSocketErrorHandler),null===(o=n._realWebSocket)||void 0===o||o.addEventListener("message",n._webSocketMessageHandler)},n._webSocketOpenHandler=function(e){n._connectTimeout&&(clearTimeout(n._connectTimeout),n._connectTimeout=void 0);var t=++n._reconnects,r=n._attempts;return n._attempts=0,n._reconnectWhenOnlineAgain=!1,n.emit("open",Object.assign(e,{detail:{reconnects:t,attempts:r}}))},n._webSocketCloseHandler=function(e){return n._reconnect(e),n.emit("close",e)},n._webSocketErrorHandler=function(e){return n.emit("error",new CustomEvent("error",{detail:{error:e}}))},n._webSocketMessageHandler=function(e){return n.emit("message",e)},t&&n.setOptions(t),n}return V(t,e),Object.defineProperty(t.prototype,"attempts",{get:function(){return this._attempts},enumerable:!1,configurable:!0}),t.prototype.setOptions=function(e){if(e){this._url=e.url,this._protocols=e.protocols;var t=Object.assign(this._options,e.robustOptions||{});if("number"!=typeof(null==t?void 0:t.timeout))throw new Error("timeout must be the number of milliseconds to timeout a connection attempt");if("function"!=typeof(null==t?void 0:t.shouldReconnect))throw new Error("shouldReconnect must be a function that returns the number of milliseconds to wait for a reconnect attempt, or null or undefined to not reconnect.");this._options=t,this._options.automaticOpen&&this._createWebSocket()}},t.prototype._reconnect=function(e){var t,n,r,o;if(!(null===(t=this._options)||void 0===t?void 0:t.should1000Reconnect)&&1e3===e.code||this._explicitlyClosed)this._attempts=0;else if(!1!==(null===(n=null===globalThis||void 0===globalThis?void 0:globalThis.navigator)||void 0===n?void 0:n.onLine)){var i=null===(o=null===(r=this._options)||void 0===r?void 0:r.shouldReconnect)||void 0===o?void 0:o.call(r,e,this);"number"==typeof i&&(this._pendingReconnect=setTimeout(this._createWebSocket,i))}else this._reconnectWhenOnlineAgain=!0},t}(se),ae=function(){function e(){var t,n,r=this;if(this._rsWeappBridgeMethodAdapter={},this._ws=new ce,this._readyState="close",this.initialize=function(e){return void 0===e&&(e=6e3),D(r,void 0,void 0,(function(){var t,n,r,o,i,s,c,a,u,l,d;return H(this,(function(f){switch(f.label){case 0:if(t=[!1,null],n=ne(globalThis.location.search),r=n.wssid,o=n.wstsp,i=n.wssig,s=n.wsmnt,c=void 0===s?"wss://ws.realsee.com":s,!(r&&o&&i&&c))return t[1]=new Error("HybridBridge 参数缺失,初始化失败~"),[2,t];a=ee("{{origin}}/{{endpoint}}/{{uuid}}/{{member}}/{{ak}}/{{ts}}/{{sign}}",{origin:c,endpoint:"proxy",uuid:r,member:"webview",ak:"vr_live_miniapp",ts:o,sign:i}),f.label=1;case 1:return f.trys.push([1,6,,7]),[4,this._open(a)];case 2:return f.sent()?(this.initBuiltInHandlers(),u=t,l=0,[4,this.waitReady(e)]):[3,4];case 3:return u[l]=f.sent(),[3,5];case 4:t[1]=new Error("HybridBridge ws未连接,初始化失败~"),f.label=5;case 5:return[3,7];case 6:return d=f.sent(),t[1]=d,[3,7];case 7:return[2,t]}}))}))},this.initBuiltInHandlers=function(){r._registerLifecycleHandler(),r._registerHeartbeatHandler(),r._registerMessageHandler(),r._registerBridgeRequestHandler(),r._registerReadyHandler()},this._open=function(e){return new Promise((function(t){r._ws.once("open",(function(){r._receivedMessage(z.ready,(function(){return t(!0)}),!0),r._ws.once("timeout",(function(){return t(!1)})),r.send(z.isReady)})),r._ws.open(e)}))},this._registerLifecycleHandler=function(){r._ws.on("connecting",(function(){console.log("RsWeappBridge connecting"),r._readyState="connecting"})),r._ws.on("open",(function(){console.log("RsWeappBridge open"),r._readyState="open"})),r._ws.on("close",(function(){r._readyState="close"})),r._ws.on("error",(function(){console.log("RsWeappBridge error"),r._readyState="close"})),r._ws.on("timeout",(function(){console.log("RsWeappBridge timeout"),r._readyState="close"}))},this._registerHeartbeatHandler=function(){r._receivedMessage(z.ping,(function(){return setTimeout((function(){return r._ws.send(z.pong)}),500)})),r._receivedMessage(z.pong,(function(){return setTimeout((function(){return r._ws.send(z.ping)}),1e3)}))},this._receivedMessage=function(e,t,n){var o=function(i){i.data===e&&(t(),n&&r._ws.off("message",o))};r._ws.on("message",o)},this._registerReadyHandler=function(){r._receivedMessage(z.isReady,(function(){return r._ws.send(z.ready)}))},this.send=function(e){r._ws.send(e)},this.waitReady=function(e){return void 0===e&&(e=6e3),new Promise((function(t,n){r._receivedMessage(z.ready,(function(){return t(!0)})),r.send(z.isReady),setTimeout((function(){return n("HybridBridge 初始化超时~")}),e)}))},this._parseMessage=function(e){try{return JSON.parse(e.data)}catch(t){return e.data}},this._registerMessageHandler=function(){r._ws.on("message",(function(e){var t=r._parseMessage(e);if("object"==typeof t){var n=t.id,o=t.command,i=t.data;"message"===o&&"function"==typeof r._rsWeappBridgeMethodAdapter.bindMessage&&r._rsWeappBridgeMethodAdapter.bindMessage({id:n,data:i})}}))},this.getStaticData=function(e){r.callAndBackfeed(JSON.stringify({actionUrl:"common/staticData",functionName:e}))},this.callAndBackfeed=function(e){var t=JSON.parse(e),n=t.actionUrl,o=void 0===n?"":n,i=t.functionName,s=void 0===i?"":i;if(!o)throw new Error("callAndBackfeed actionUrl is empty!");if(!s)throw new Error("callAndBackfeed functionName is empty!");r._callAndBackfeed(o,(function(e){"function"==typeof globalThis[s]&&globalThis[s](e)}))},this.callAndListen=function(e){var t=JSON.parse(e),n=t.actionUrl,o=t.functionName;if(!n)throw new Error("callAndListen actionUrl is empty!");if(!o)throw new Error("callAndListen functionName is empty!");var i=function(e){"function"==typeof globalThis[o]&&globalThis[o](e)};try{r._callAndListen(n,i)}catch(e){console.warn(e),i(!1)}},this.execute=function(e,t){return D(r,void 0,void 0,(function(){return H(this,(function(n){switch(n.label){case 0:return[4,this._invokeBridgeMethod(e,t)];case 1:return[2,n.sent()]}}))}))},this._invokeBridgeMethod=function(e,t){return new Promise((function(n,o){var i=Q(),s=function(t){var c=r._parseMessage(t);"object"==typeof c&&c.method===e&&c.id===i&&(r._ws.off("message",s),c.error?o(c.error):n(c.data))};r._ws.on("message",s),r.send(JSON.stringify({method:e,args:t,id:i}))}))},(null===(t=null===globalThis||void 0===globalThis?void 0:globalThis.window)||void 0===t?void 0:t.__Realsee_WxMini_HybridBridge__)instanceof e)return null===(n=null===globalThis||void 0===globalThis?void 0:globalThis.window)||void 0===n?void 0:n.__Realsee_WxMini_HybridBridge__;(null===globalThis||void 0===globalThis?void 0:globalThis.window)&&(globalThis.window.__Realsee_WxMini_HybridBridge__=this,this.initBuiltInHandlers())}return Object.defineProperty(e.prototype,"isReady",{get:function(){return"open"===this._readyState},enumerable:!1,configurable:!0}),e.prototype._registerBridgeRequestHandler=function(){var e=this;this._ws.on("message",(function(t){return D(e,void 0,void 0,(function(){var e,n,r,o,i,s,c,a;return H(this,(function(u){switch(u.label){case 0:if("object"!=typeof(e=this._parseMessage(t)))return[3,7];if(n=e.id,r=e.method,o=e.args,"request"!==e.command)return[3,7];if(!r)return[3,7];if(i=null,s=null,c=null,"function"==typeof this._rsWeappBridgeMethodAdapter[r]?c=this._rsWeappBridgeMethodAdapter[r]:globalThis&&te(r,globalThis)&&(c=globalThis[r]),"function"!=typeof c)return[3,5];u.label=1;case 1:return u.trys.push([1,3,,4]),[4,c(o)];case 2:return i=u.sent(),[3,4];case 3:return a=u.sent(),s=a.message||a,[3,4];case 4:return[3,6];case 5:s="Method not implemented.",u.label=6;case 6:this.send(JSON.stringify({id:n,method:r,result:i,error:s,command:"response"})),u.label=7;case 7:return[2]}}))}))}))},e.prototype._callAndBackfeed=function(e,t){var n=this,r=Q(),o=JSON.stringify({id:r,actionUrl:e,command:"rsSchemeRequest",type:"callAndBackfeed"}),i=null,s=function(e){var o=n._parseMessage(e);if("object"==typeof o){var c=o.id,a=o.result,u=o.errmsg;"rsSchemeResponse"===o.command&&c===r&&(n._ws.off("message",s),i&&clearTimeout(i),u?(console.warn(u),t(0)):t(a))}};this._ws.on("message",s),this.send(o),i=globalThis.setTimeout((function(){console.warn("callAndBackfeed timeout"),t(0)}),3e4)},e.prototype._callAndListen=function(e,t){var n=this,r=Q(),o=JSON.stringify({id:r,actionUrl:e,command:"rsSchemeRequest",type:"callAndListen"});this._ws.on("message",(function(e){var o=n._parseMessage(e);if("object"==typeof o){var i=o.id,s=o.result,c=o.errmsg;"rsSchemeResponse"===o.command&&i===r&&(c?(console.warn(c),t(!1)):t(s))}})),this.send(o)},e.prototype.invoke=function(e,t){return D(this,void 0,void 0,(function(){var n=this;return H(this,(function(r){return[2,new Promise((function(r,o){var i=Q(),s=JSON.stringify({id:i,method:e,args:t,command:"request"}),c=null,a=function(t){var s=n._parseMessage(t);if("object"==typeof s){var u=s.id,l=s.result,d=s.error;"response"===s.command&&u===i&&s.method===e&&(n._ws.off("message",a),c&&clearTimeout(c),d?o(d):r(l))}};n._ws.on("message",a),n.send(s),c=setTimeout((function(){return o("method invoke timeout")}),3e4)}))]}))}))},e}(),ue=ae,le=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t._hybridBridge=new ue,t.initializing=!1,t}return V(t,e),Object.defineProperty(t.prototype,"hybridBridge",{get:function(){return this._hybridBridge},enumerable:!1,configurable:!0}),t.prototype.checkBridgeReady=function(e){var t=this;return void 0===e&&(e=6e4),!!this.ready||new Promise((function(n,r){return D(t,void 0,void 0,(function(){var t,r,o,i,s=this;return H(this,(function(c){switch(c.label){case 0:return this.ready?[2,n(!0)]:this.initializing?((t=function(){if(s.ready)return n(!0);requestAnimationFrame(t)})(),[3,3]):[3,1];case 1:return this.initializing=!0,[4,this._hybridBridge.initialize(e)];case 2:if(r=c.sent(),o=r[0],i=r[1],!o||i)throw i||new Error("HybridBridge 初始化失败~");return this._hybridBridge.getStaticData(q("HYBRID_BRIDGE_NAME",(function(e){s.deviceInfo=function(){try{return JSON.parse(e)}catch(t){return e}}()}))),this.initializing=!1,[2,n(!0)];case 3:return[2]}}))}))}))},t.prototype.checkReady=function(e){return void 0===e&&(e=6e4),D(this,void 0,void 0,(function(){var t,n,r,o;return H(this,(function(i){switch(i.label){case 0:if(t=[null,null],this.ready)return t[0]=!0,[2,t];i.label=1;case 1:return i.trys.push([1,3,,4]),n=t,r=0,[4,this.checkBridgeReady(e)];case 2:return n[r]=i.sent(),[3,4];case 3:return o=i.sent(),t[0]=!1,t[1]=o,[3,4];case 4:return[2,t]}}))}))},Object.defineProperty(t.prototype,"ready",{get:function(){return!!this._hybridBridge.isReady},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"scheme",{get:function(){var e;return(null===(e=this.deviceInfo)||void 0===e?void 0:e.scheme)||""},enumerable:!1,configurable:!0}),t.prototype.createSchemeLink=function(e){return e.startsWith(this.scheme)?e:this.scheme+"://"+e},t.prototype.callAndBackfeed=function(e){return D(this,void 0,void 0,(function(){var t,n,r,o,i=this;return H(this,(function(s){switch(s.label){case 0:return t=[!1,null],[4,this.checkReady()];case 1:return n=s.sent(),r=n[0],o=n[1],r?[4,new Promise((function(n){return D(i,void 0,void 0,(function(){var r,o;return H(this,(function(i){return r=this.createSchemeLink(e),o=JSON.stringify({actionUrl:r,functionName:q(this.createSchemeLink(e),(function(e){var r=e;try{r=JSON.parse(e)}catch(e){}t[0]=1===r||0!==r&&r,n(t)}))}),this._hybridBridge.callAndBackfeed(o),[2]}))}))}))]:(t[0]=!1,t[1]=o,[2,t]);case 2:return[2,s.sent()]}}))}))},t.prototype.callAndListen=function(e,t){return D(this,void 0,void 0,(function(){var n,r,o,i,s=this;return H(this,(function(c){switch(c.label){case 0:return n=[!1,null],[4,this.checkReady()];case 1:return r=c.sent(),o=r[0],i=r[1],o?[4,new Promise((function(r){return D(s,void 0,void 0,(function(){var o,i,s;return H(this,(function(c){return o=this.createSchemeLink(e),i=function(e){var s=e;try{s=JSON.parse(e)}catch(e){}t(1===s||0!==s&&s),n[0]=function(){var e=J[o];if(e){var t=e.queue.findIndex((function(e){return e.callback===i}));-1!==t&&e.queue.splice(t,1)}},r(n)},s=JSON.stringify({actionUrl:o,functionName:q(o,i,!1)}),this._hybridBridge.callAndListen(s),[2]}))}))}))]:(n[0]=!1,n[1]=i,[2,n]);case 2:return[2,c.sent()]}}))}))},t.prototype.invoke=function(e,t){var n,r;return D(this,void 0,void 0,(function(){var o,i,s,c;return H(this,(function(a){switch(a.label){case 0:return o=[!1,null],[4,this.checkReady()];case 1:if(i=a.sent(),s=i[0],c=i[1],s)return[3,2];throw o[0]=!1,o[1]=c,c;case 2:return[4,null===(r=(n=this._hybridBridge).invoke)||void 0===r?void 0:r.call(n,e,t)];case 3:return[2,a.sent()]}}))}))},t}(K);!function(e){e.WebView="WebKit",e.WKWebview="WKWebview",e.UIWebview="UIWebview",e.Browser="Browser",e.WeChatMPWebView="WxMiniProgramWebView",e.Unsupported="Unsupported"}(ie||(ie={}));var de,fe=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.webViewType=ie.Unsupported,t}return V(t,e),t}(se),he=globalThis.navigator.userAgent,pe=/android/gi.test(he),ve=/iPhone|iPad\s+OS/gi.test(he),me=/MicroMessenger/gi.test(he)&&/miniProgram/gi.test(he),ge=/realsee/gi.test(he),_e={timeout:6e3},be=function(e){function t(t){void 0===t&&(t={});var n=e.call(this)||this;return n.options=Object.assign(_e,t),ge||console.warn("未知容器:此版本 `jsBridge` 不支持当前 WebView 容器 ... "),n.webViewType=pe?ie.WebView:ve?ie.WKWebview:ie.Browser,n._controller=pe?new G:ve?new Z:new K,n.callAndListen("common/webViewState",(function(e){n.emit("webViewStateChange",e)})),n.callAndListen("common/webViewError",(function(e){n.emit("error",e)})),n}return V(t,e),t.prototype.ready=function(){return D(this,void 0,void 0,(function(){return H(this,(function(e){switch(e.label){case 0:return[4,this._controller.checkReady(this.options.timeout)];case 1:return[2,e.sent()]}}))}))},t.prototype.callAndBackfeed=function(e){return D(this,void 0,void 0,(function(){return H(this,(function(t){switch(t.label){case 0:return[4,this._controller.callAndBackfeed(e)];case 1:return[2,t.sent()]}}))}))},t.prototype.callAndListen=function(e,t){var n;return D(this,void 0,void 0,(function(){return H(this,(function(r){switch(r.label){case 0:return[4,null===(n=this._controller)||void 0===n?void 0:n.callAndListen(e,t)];case 1:return[2,r.sent()]}}))}))},t.prototype.setLeftTopBackButton=function(e){return D(this,void 0,void 0,(function(){return H(this,(function(t){switch(t.label){case 0:return this.webViewType===ie.WebView?[2,[!0,null]]:[4,this.callAndBackfeed("common/setLeftTopBackButton?enable=".concat(e?1:0))];case 1:return[2,t.sent()]}}))}))},t.prototype.getBangsHeight=function(){return D(this,void 0,void 0,(function(){return H(this,(function(e){switch(e.label){case 0:return[4,this.callAndBackfeed("common/getBangsHeight")];case 1:return[2,e.sent()]}}))}))},t.prototype.shock=function(e){return void 0===e&&(e=4),D(this,void 0,void 0,(function(){return H(this,(function(t){switch(t.label){case 0:return[4,this.callAndBackfeed("common/shock?duration=".concat(e))];case 1:return[2,t.sent()]}}))}))},t.prototype.minimize=function(){return D(this,void 0,void 0,(function(){return H(this,(function(e){switch(e.label){case 0:return[4,this.callAndBackfeed("common/minimize")];case 1:return[2,e.sent()]}}))}))},t.prototype.loadProgress=function(e){return D(this,void 0,void 0,(function(){return H(this,(function(t){switch(t.label){case 0:return e=e<0?0:e>100?100:e,[4,this.callAndBackfeed("common/loadProgress?progress=".concat(e))];case 1:return[2,t.sent()]}}))}))},t.prototype.closeLoading=function(){return D(this,void 0,void 0,(function(){return H(this,(function(e){switch(e.label){case 0:return[4,this.callAndBackfeed("common/closeLoading")];case 1:return[2,e.sent()]}}))}))},t.prototype.setOrientation=function(e){return D(this,void 0,void 0,(function(){return H(this,(function(t){switch(t.label){case 0:return[4,this.callAndBackfeed("common/setOrientation?orientation=".concat(e))];case 1:return[2,t.sent()]}}))}))},t.prototype.keepScreenLight=function(e){return D(this,void 0,void 0,(function(){return H(this,(function(t){switch(t.label){case 0:return[4,this.callAndBackfeed("common/keepScreenLight?enable=".concat(e?1:0))];case 1:return[2,t.sent()]}}))}))},t.prototype.closeWebView=function(){return D(this,void 0,void 0,(function(){return H(this,(function(e){switch(e.label){case 0:return[4,this.callAndBackfeed("common/closeWebView")];case 1:return[2,e.sent()]}}))}))},t.prototype.openWebView=function(e,t){return D(this,void 0,void 0,(function(){return H(this,(function(n){switch(n.label){case 0:return[4,this.callAndBackfeed("common/openWebView?way=".concat(t,"&url=").concat(encodeURIComponent(e)))];case 1:return[2,n.sent()]}}))}))},t.prototype.saveImage2Album=function(e){return D(this,void 0,void 0,(function(){return H(this,(function(t){switch(t.label){case 0:return[4,this.callAndBackfeed("common/saveImage2Album?base64=".concat(e))];case 1:return[2,t.sent()]}}))}))},t.prototype.actionShare=function(e){return D(this,void 0,void 0,(function(){return H(this,(function(t){switch(t.label){case 0:return[4,this.callAndBackfeed("common/actionShare?json=".concat(JSON.stringify(e)))];case 1:return[2,t.sent()]}}))}))},t.prototype.getDeviceInfo=function(){return D(this,void 0,void 0,(function(){return H(this,(function(e){switch(e.label){case 0:return[4,this.callAndBackfeed("common/getDeviceInfo")];case 1:return[2,e.sent()]}}))}))},t.prototype.getUserInfo=function(){return D(this,void 0,void 0,(function(){return H(this,(function(e){switch(e.label){case 0:return[4,this.callAndBackfeed("common/getUserInfo")];case 1:return[2,e.sent()]}}))}))},t.prototype.getWebViewState=function(){return D(this,void 0,void 0,(function(){return H(this,(function(e){switch(e.label){case 0:return[4,this.callAndBackfeed("common/getWebViewState")];case 1:return[2,e.sent()]}}))}))},t.prototype.login=function(){return D(this,void 0,void 0,(function(){var e;return H(this,(function(t){switch(t.label){case 0:return[4,this.callAndBackfeed("common/login")];case 1:return(e=t.sent())[0]?[4,this.getUserInfo()]:[3,3];case 2:return[2,t.sent()];case 3:return[2,e]}}))}))},t.prototype.logout=function(){return D(this,void 0,void 0,(function(){return H(this,(function(e){switch(e.label){case 0:return[4,this.callAndBackfeed("common/logout")];case 1:return[2,e.sent()]}}))}))},t.prototype.detectMicro=function(){return D(this,void 0,void 0,(function(){return H(this,(function(e){switch(e.label){case 0:return[4,this.callAndBackfeed("common/detectMicro")];case 1:return[2,e.sent()]}}))}))},t.prototype.preload=function(e){return D(this,void 0,void 0,(function(){return H(this,(function(t){switch(t.label){case 0:return e=e.map((function(e){return e.startsWith("//")?"https:"+e:e})),[4,this.callAndBackfeed("common/preload?urls=".concat(JSON.stringify(e)))];case 1:return[2,t.sent()]}}))}))},t.prototype.createCacheProxyUrl=function(e){var t=this;e=Array.isArray(e)?e:[e];var n=window.navigator.userAgent;if(!/supportCache/i.test(n))return e;return e.map((function(e){return t.webViewType===ie.WKWebview?e.replace(/https*:/,"").replace(/\/\//,"realseeproxycache://"):t.webViewType===ie.WebView?e+(-1!==e.indexOf("?")?"&":"?")+"realseeproxycache=1":e}))},t}(fe);!function(e){e.Append="Append",e.Replace="Replace",e.Single="Single"}(de||(de={}));var ye=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.webViewType=ie.Browser,t}return V(t,e),t.prototype.ready=function(){return Promise.resolve([!0,null])},t.prototype.callAndBackfeed=function(e){return Promise.resolve([!1,null])},t.prototype.callAndListen=function(e,t){return Promise.resolve([function(){},null])},t.prototype.loadProgress=function(e){return Promise.resolve([!0,null])},t.prototype.closeLoading=function(){return Promise.resolve([!0,null])},t.prototype.getDeviceInfo=function(){return Promise.resolve([!1,null])},t.prototype.getWebViewState=function(){return Promise.resolve([!1,null])},t.prototype.setLeftTopBackButton=function(e){return Promise.resolve([!1,null])},t.prototype.login=function(){return Promise.resolve([!1,null])},t.prototype.logout=function(){return Promise.resolve([!1,null])},t.prototype.getUserInfo=function(){return Promise.resolve([!1,null])},t.prototype.openWebView=function(e,t){switch(t){case de.Replace:case de.Single:setTimeout((function(){return globalThis.location.replace(e)}),200);break;case de.Append:default:setTimeout((function(){return globalThis.location.href=e}),200)}return Promise.resolve([!0,null])},t.prototype.closeWebView=function(){return globalThis.close(),Promise.resolve([!0,null])},t.prototype.getBangsHeight=function(){return Promise.resolve([0,null])},t.prototype.setOrientation=function(e){return Promise.resolve([!1,null])},t.prototype.keepScreenLight=function(e){return Promise.resolve([!1,null])},t.prototype.shock=function(e){return Promise.resolve([!1,null])},t.prototype.minimize=function(){return Promise.resolve([!1,null])},t.prototype.saveImage2Album=function(e){return Promise.resolve([!1,null])},t.prototype.detectMicro=function(){return new Promise((function(e){try{globalThis.navigator.mediaDevices.getUserMedia({audio:!0,video:!1}).then((function(){return e([!0,null])})).catch((function(t){return e([!1,t])}))}catch(t){console.error(t),e([!1,t])}}))},t.prototype.actionShare=function(e){return Promise.resolve([!1,null])},t.prototype.preload=function(e){return Promise.resolve([!1,null])},t.prototype.createCacheProxyUrl=function(e){return[]},t}(fe),we={timeout:6e4},Se=function(e){function t(t){void 0===t&&(t={});var n=e.call(this)||this;return n._controller=new le,n.options=Object.assign(we,t),me||console.warn("未知容器:此版本 `jsBridge` 不支持当前 WebView 容器 ... "),n.webViewType=ie.WeChatMPWebView,n.callAndListen("common/webViewState",(function(e){n.emit("webViewStateChange",e)})),n.callAndListen("common/webViewError",(function(e){n.emit("error",e)})),n}return V(t,e),t.prototype.ready=function(){return D(this,void 0,void 0,(function(){return H(this,(function(e){switch(e.label){case 0:return[4,this._controller.checkReady(this.options.timeout)];case 1:return[2,e.sent()]}}))}))},t.prototype.callAndBackfeed=function(e){return D(this,void 0,void 0,(function(){return H(this,(function(t){switch(t.label){case 0:return[4,this._controller.callAndBackfeed(e)];case 1:return[2,t.sent()]}}))}))},t.prototype.callAndListen=function(e,t){return D(this,void 0,void 0,(function(){return H(this,(function(n){switch(n.label){case 0:return[4,this._controller.callAndListen(e,t)];case 1:return[2,n.sent()]}}))}))},t.prototype.setLeftTopBackButton=function(e){return D(this,void 0,void 0,(function(){return H(this,(function(t){switch(t.label){case 0:return this.webViewType===ie.WebView?[2,[!0,null]]:[4,this.callAndBackfeed("common/setLeftTopBackButton?enable=".concat(e?1:0))];case 1:return[2,t.sent()]}}))}))},t.prototype.getBangsHeight=function(){return D(this,void 0,void 0,(function(){return H(this,(function(e){switch(e.label){case 0:return[4,this.callAndBackfeed("common/getBangsHeight")];case 1:return[2,e.sent()]}}))}))},t.prototype.shock=function(e){return void 0===e&&(e=4),D(this,void 0,void 0,(function(){return H(this,(function(t){switch(t.label){case 0:return[4,this.callAndBackfeed("common/shock?duration=".concat(e))];case 1:return[2,t.sent()]}}))}))},t.prototype.minimize=function(){return D(this,void 0,void 0,(function(){return H(this,(function(e){switch(e.label){case 0:return[4,this.callAndBackfeed("common/minimize")];case 1:return[2,e.sent()]}}))}))},t.prototype.loadProgress=function(e){return D(this,void 0,void 0,(function(){return H(this,(function(t){switch(t.label){case 0:return e=e<0?0:e>100?100:e,[4,this.callAndBackfeed("common/loadProgress?progress=".concat(e))];case 1:return[2,t.sent()]}}))}))},t.prototype.closeLoading=function(){return D(this,void 0,void 0,(function(){return H(this,(function(e){switch(e.label){case 0:return[4,this.callAndBackfeed("common/closeLoading")];case 1:return[2,e.sent()]}}))}))},t.prototype.setOrientation=function(e){return D(this,void 0,void 0,(function(){return H(this,(function(t){switch(t.label){case 0:return[4,this.callAndBackfeed("common/setOrientation?orientation=".concat(e))];case 1:return[2,t.sent()]}}))}))},t.prototype.keepScreenLight=function(e){return D(this,void 0,void 0,(function(){return H(this,(function(t){switch(t.label){case 0:return[4,this.callAndBackfeed("common/keepScreenLight?enable=".concat(e?1:0))];case 1:return[2,t.sent()]}}))}))},t.prototype.closeWebView=function(){return D(this,void 0,void 0,(function(){return H(this,(function(e){switch(e.label){case 0:return[4,this.callAndBackfeed("common/closeWebView")];case 1:return[2,e.sent()]}}))}))},t.prototype.openWebView=function(e,t){return D(this,void 0,void 0,(function(){return H(this,(function(n){switch(n.label){case 0:return[4,this.callAndBackfeed("common/openWebView?way=".concat(t,"&url=").concat(encodeURIComponent(e)))];case 1:return[2,n.sent()]}}))}))},t.prototype.saveImage2Album=function(e){return D(this,void 0,void 0,(function(){return H(this,(function(t){switch(t.label){case 0:return[4,this.callAndBackfeed("common/saveImage2Album?base64=".concat(e))];case 1:return[2,t.sent()]}}))}))},t.prototype.actionShare=function(e){var t,n,r;return D(this,void 0,void 0,(function(){var o;return H(this,(function(i){switch(i.label){case 0:return o={path:null===(t=e.miniprogram)||void 0===t?void 0:t[0].path,title:null===(n=e.miniprogram)||void 0===n?void 0:n[0].title,imageUrl:null===(r=e.miniprogram)||void 0===r?void 0:r[0].hdImageData},[4,this.callAndBackfeed("common/actionShare?json=".concat(JSON.stringify(o)))];case 1:return[2,i.sent()]}}))}))},t.prototype.getDeviceInfo=function(){return D(this,void 0,void 0,(function(){return H(this,(function(e){switch(e.label){case 0:return[4,this.callAndBackfeed("common/getDeviceInfo")];case 1:return[2,e.sent()]}}))}))},t.prototype.getUserInfo=function(){return D(this,void 0,void 0,(function(){return H(this,(function(e){switch(e.label){case 0:return[4,this.callAndBackfeed("common/getUserInfo")];case 1:return[2,e.sent()]}}))}))},t.prototype.getWebViewState=function(){return D(this,void 0,void 0,(function(){return H(this,(function(e){switch(e.label){case 0:return[4,this.callAndBackfeed("common/getWebViewState")];case 1:return[2,e.sent()]}}))}))},t.prototype.login=function(){return D(this,void 0,void 0,(function(){var e;return H(this,(function(t){switch(t.label){case 0:return[4,this.callAndBackfeed("common/login")];case 1:return(e=t.sent())[0]?[4,this.getUserInfo()]:[3,3];case 2:return[2,t.sent()];case 3:return[2,e]}}))}))},t.prototype.logout=function(){return D(this,void 0,void 0,(function(){return H(this,(function(e){switch(e.label){case 0:return[4,this.callAndBackfeed("common/logout")];case 1:return[2,e.sent()]}}))}))},t.prototype.detectMicro=function(){return D(this,void 0,void 0,(function(){return H(this,(function(e){switch(e.label){case 0:return[4,this.callAndBackfeed("common/detectMicro")];case 1:return[2,e.sent()]}}))}))},t.prototype.preload=function(e){return D(this,void 0,void 0,(function(){return H(this,(function(t){switch(t.label){case 0:return e=e.map((function(e){return e.startsWith("//")?"https:"+e:e})),[4,this.callAndBackfeed("common/preload?urls=".concat(JSON.stringify(e)))];case 1:return[2,t.sent()]}}))}))},t.prototype.createCacheProxyUrl=function(e){var t=this;e=Array.isArray(e)?e:[e];var n=window.navigator.userAgent;if(!/supportCache/i.test(n))return e;return e.map((function(e){return t.webViewType===ie.WKWebview?e.replace(/https*:/,"").replace(/\/\//,"realseeproxycache://"):t.webViewType===ie.WebView?e+(-1!==e.indexOf("?")?"&":"?")+"realseeproxycache=1":e}))},t.prototype.invokeNativeApi=function(e,t){return D(this,void 0,void 0,(function(){return H(this,(function(n){switch(n.label){case 0:return[4,this._controller.invoke(e,t)];case 1:return[2,n.sent()]}}))}))},t.prototype.execute=function(e,t){var n,r,o;return D(this,void 0,void 0,(function(){return H(this,(function(i){switch(i.label){case 0:return[4,null===(o=null===(r=null===(n=this._controller)||void 0===n?void 0:n.hybridBridge)||void 0===r?void 0:r.execute)||void 0===o?void 0:o.call(r,e,t)];case 1:return[2,i.sent()]}}))}))},t}(fe),ke=function(e){function t(t){return void 0===t&&(t={}),e.call(this),ge&&(pe||ve)?new be(t):me?new Se(t):new ye}return V(t,e),t}(fe);function Ee(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var Ce,Te,Oe=(Ce=function(e,t){var n;Object.defineProperty(t,"__esModule",{value:!0}),t.LogLevel=void 0,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"}(n=t.LogLevel||(t.LogLevel={})),t.default=n},Ce(Te={exports:{}},Te.exports),Te.exports),Ie=Ee(Oe);function Re(e,t){void 0===t&&(t={});var n=-1!==e.indexOf("?");return e+Object.keys(t).reduce((function(e,r,o){return"".concat(e).concat(0!==o||n?"&":"?").concat(r,"=").concat(t[r])}),"")}var Be=globalThis.navigator.userAgent,Ae=/android/gi.test(Be),Le=/iPhone|iPad\s+OS/gi.test(Be),Ne=/MicroMessenger/gi.test(Be)&&/miniProgram/gi.test(Be),We=/realsee/gi.test(Be);function Pe(e){return"[object Object]"===Object.prototype.toString.call(e)}function xe(e,t){return e===t||typeof e==typeof t&&!(!Number.isNaN(e)||!Number.isNaN(t))}function Me(e,t){return!!xe(e,t)||(Pe(e)&&Pe(t)?function(e,t){var n=Object.getOwnPropertyNames(e),r=Object.getOwnPropertyNames(t);if(n.length!==r.length)return!1;for(var o=0,i=n.length;o<i;o++){var s=n[o];if(!xe(e[s],t[s]))return!1}return!0}(e,t):!(!Array.isArray(e)||!Array.isArray(t))&&function(e,t){if(e.length!==t.length)return!1;for(var n=0,r=e.length;n<r;n++)if(!xe(e[n],t[n]))return!1;return!0}(e,t))}function je(e,t){return!!xe(e,t)||(Pe(e)&&Pe(t)?function(e,t){var n=Object.getOwnPropertyNames(e),r=Object.getOwnPropertyNames(t);if(n.length!==r.length)return!1;for(var o=0,i=n.length;o<i;o++){var s=n[o];if(!je(e[s],t[s]))return!1}return!0}(e,t):!(!Array.isArray(e)||!Array.isArray(t))&&function(e,t){if(e.length!==t.length)return!1;for(var n=0,r=e.length;n<r;n++)if(!je(e[n],t[n]))return!1;return!0}(e,t))}function Ve(e,t,n){return void 0===n&&(n={deep:!1}),n.deep?je(e,t):Me(e,t)}var Ue=function(e){function t(t){var n=e.call(this)||this;return n._readyState=exports.WebSocketState.NOTINITIALIZED,n._options={timeout:1e4,shouldReconnect:function(e,t){if(1008!==e.code&&1011!==e.code)return[0,3e3,1e4][t.attempts]},should1000Reconnect:!1,ignoreConnectivityEvents:!1,automaticOpen:!1},n._attempts=0,n._reconnects=-1,n._reconnectWhenOnlineAgain=!1,n._explicitlyClosed=!1,n._connectivityEventsAttached=!1,n._healthCheck=function(){return u(n,void 0,void 0,(function(){return l(this,(function(e){switch(e.label){case 0:return this._realWebSocket&&this._realWebSocket.readyState!==this._readyState&&(this._readyState=this._realWebSocket.readyState,this._readyState===exports.WebSocketState.CLOSING&&this.emit("closing")),[4,new Promise((function(e){return setTimeout(e,2e3)}))];case 1:return e.sent(),this._heathCheckTimer=requestAnimationFrame(this._healthCheck),[2]}}))}))},n._clearHeathCheckIfNeed=function(){n._heathCheckTimer&&(cancelAnimationFrame(n._heathCheckTimer),n._heathCheckTimer=void 0)},n._startHealthCheck=function(){n._clearHeathCheckIfNeed(),n._heathCheckTimer=requestAnimationFrame(n._healthCheck)},n._stopHealthCheck=function(){n._clearHeathCheckIfNeed()},n._clearPendingReconnectIfNeeded=function(){n._pendingReconnect&&(clearTimeout(n._pendingReconnect),n._pendingReconnect=void 0)},n._online=function(e){n._reconnectWhenOnlineAgain&&(n._clearPendingReconnectIfNeeded(),n._reconnect(e))},n._offline=function(){var e;n._reconnectWhenOnlineAgain=!0,null===(e=n._realWebSocket)||void 0===e||e.close(1e3,"offline")},n._detachConnectivityEvents=function(){n._connectivityEventsAttached&&(null===globalThis||void 0===globalThis||globalThis.removeEventListener("online",n._online),null===globalThis||void 0===globalThis||globalThis.removeEventListener("offline",n._offline),n._connectivityEventsAttached=!1)},n._attachConnectivityEvents=function(){n._connectivityEventsAttached||(null===globalThis||void 0===globalThis||globalThis.addEventListener("online",n._online),null===globalThis||void 0===globalThis||globalThis.addEventListener("offline",n._offline),n._connectivityEventsAttached=!0)},n.send=function(e){var t,r,o;(null===(t=n._realWebSocket)||void 0===t?void 0:t.readyState)===(null===(r=n._realWebSocket)||void 0===r?void 0:r.OPEN)&&(null===(o=n._realWebSocket)||void 0===o||o.send(e))},n.close=function(e,t){var r;return"number"!=typeof e&&(t=e,e=1e3),n._clearPendingReconnectIfNeeded(),n._reconnectWhenOnlineAgain=!1,n._explicitlyClosed=!0,n._detachConnectivityEvents(),null===(r=n._realWebSocket)||void 0===r?void 0:r.close(e,t)},n.open=function(e){var t,r;e&&(n._url=e),(null===(t=n._realWebSocket)||void 0===t?void 0:t.readyState)!==WebSocket.OPEN&&(null===(r=n._realWebSocket)||void 0===r?void 0:r.readyState)!==WebSocket.CONNECTING&&(n._clearPendingReconnectIfNeeded(),n._reconnectWhenOnlineAgain=!1,n._explicitlyClosed=!1,n._createWebSocket())},n._createWebSocket=function(){var e,t,r,o="string"==typeof n._url?n._url:null===(e=n._url)||void 0===e?void 0:e.call(n,n);if(o){n._pendingReconnect=void 0,n._removeWebSocketEvent(),n._realWebSocket=new WebSocket(o,n._protocols||void 0),n._attempts=n._attempts+1,n.emit("connecting",new CustomEvent("connecting",{detail:{attempts:n._attempts,reconnects:n._reconnects}}));n._connectTimeout=setTimeout((function(){n._connectTimeout=void 0,n._detachConnectivityEvents(),n.emit("timeout",new CustomEvent("connecting",{detail:{attempts:n._attempts,reconnects:n._reconnects}}))}),null===(t=n._options)||void 0===t?void 0:t.timeout),n._dispatchWebSocketEvent(),(null===(r=n._options)||void 0===r?void 0:r.ignoreConnectivityEvents)||n._attachConnectivityEvents()}},n._removeWebSocketEvent=function(){var e,t,r,o;null===(e=n._realWebSocket)||void 0===e||e.removeEventListener("open",n._webSocketOpenHandler),null===(t=n._realWebSocket)||void 0===t||t.removeEventListener("close",n._webSocketCloseHandler),null===(r=n._realWebSocket)||void 0===r||r.removeEventListener("error",n._webSocketErrorHandler),null===(o=n._realWebSocket)||void 0===o||o.removeEventListener("message",n._webSocketMessageHandler)},n._dispatchWebSocketEvent=function(){var e,t,r,o;null===(e=n._realWebSocket)||void 0===e||e.addEventListener("open",n._webSocketOpenHandler),null===(t=n._realWebSocket)||void 0===t||t.addEventListener("close",n._webSocketCloseHandler),null===(r=n._realWebSocket)||void 0===r||r.addEventListener("error",n._webSocketErrorHandler),null===(o=n._realWebSocket)||void 0===o||o.addEventListener("message",n._webSocketMessageHandler)},n._webSocketOpenHandler=function(e){n._connectTimeout&&(clearTimeout(n._connectTimeout),n._connectTimeout=void 0);var t=++n._reconnects,r=n._attempts;return n._attempts=0,n._reconnectWhenOnlineAgain=!1,n._startHealthCheck(),n.emit("open",Object.assign(e,{detail:{reconnects:t,attempts:r}}))},n._webSocketCloseHandler=function(e){return n._reconnect(e),n._stopHealthCheck(),n.emit("close",e)},n._webSocketErrorHandler=function(e){return n.emit("error",new CustomEvent("error",{detail:{error:e}}))},n._webSocketMessageHandler=function(e){return n.emit("message",e)},t&&n.setOptions(t),n._startHealthCheck(),n}return c(t,e),Object.defineProperty(t.prototype,"attempts",{get:function(){return this._attempts},enumerable:!1,configurable:!0}),t.prototype.setOptions=function(e){if(e){this._url=e.url,this._protocols=e.protocols;var t=Object.assign(this._options,e.robustOptions||{});if("number"!=typeof(null==t?void 0:t.timeout))throw new Error("timeout must be the number of milliseconds to timeout a connection attempt");if("function"!=typeof(null==t?void 0:t.shouldReconnect))throw new Error("shouldReconnect must be a function that returns the number of milliseconds to wait for a reconnect attempt, or null or undefined to not reconnect.");this._options=t,this._options.automaticOpen&&this._createWebSocket()}},t.prototype._reconnect=function(e){var t,n,r,o;if(!(null===(t=this._options)||void 0===t?void 0:t.should1000Reconnect)&&1e3===e.code||this._explicitlyClosed)this._attempts=0;else if(!1!==(null===(n=null===globalThis||void 0===globalThis?void 0:globalThis.navigator)||void 0===n?void 0:n.onLine)){var i=null===(o=null===(r=this._options)||void 0===r?void 0:r.shouldReconnect)||void 0===o?void 0:o.call(r,e,this);"number"==typeof i&&(this._pendingReconnect=setTimeout(this._createWebSocket,i))}else this._reconnectWhenOnlineAgain=!0},t}(m),De=function(e){function t(){var t=e.call(this)||this;return t._ws=new Ue({url:"",robustOptions:{timeout:18e4}}),t._state=exports.LiveState.NOTINITIALIZED,t._addWebSocketEventListeners=function(){t._ws.on("close",t._handleCloseEvent),t._ws.on("closing",t._handleClosingEvent),t._ws.on("connecting",t._handleConnectingEvent),t._ws.on("error",t._handleErrorEvent),t._ws.on("message",t._handleMessageEvent),t._ws.on("open",t._handleOpenEvent),t._ws.on("timeout",t._handleTimeoutEvent)},t._removeWebSocketEventListeners=function(){t._ws.off("close",t._handleCloseEvent),t._ws.off("closing",t._handleClosingEvent),t._ws.off("connecting",t._handleConnectingEvent),t._ws.off("error",t._handleErrorEvent),t._ws.off("message",t._handleMessageEvent),t._ws.off("open",t._handleOpenEvent),t._ws.off("timeout",t._handleTimeoutEvent)},t._handleCloseEvent=function(e){y.info("live room closed bacause of ".concat(e.code,"-").concat(e.reason||M(e.code))),t.state=exports.LiveState.CLOSED},t._handleClosingEvent=function(){var e;y.info("live room is closing, onLine:",null===(e=null===globalThis||void 0===globalThis?void 0:globalThis.navigator)||void 0===e?void 0:e.onLine),t.state=exports.LiveState.CLOSED},t._handleConnectingEvent=function(){y.info("live room is connecting"),t.state=exports.LiveState.CONNECTING},t._handleErrorEvent=function(e){y.error("live room error",e),t.state=exports.LiveState.CLOSED},t._handleMessageEvent=function(e){var n=function(){try{return JSON.parse(e.data)}catch(t){return e.data}}();t.emit("message",n)},t._handleOpenEvent=function(e){y.info("live room open",e.detail),t.state=exports.LiveState.OPEN,e.detail.reconnects>0&&t.emit("reconnected",e.detail)},t._handleTimeoutEvent=function(e){y.error("live room connect timeout!",e.detail),t.state=exports.LiveState.CLOSED},t.dispose=function(){return u(t,void 0,void 0,(function(){return l(this,(function(e){switch(e.label){case 0:return this._removeWebSocketEventListeners(),[4,this.close("live room close by controller disposed!")];case 1:return[2,e.sent()]}}))}))},t.open=function(e){return t._ws.open(e)},t.close=function(e,n){return new Promise((function(r){t._ws.once("close",(function(){return r(!0)})),t._ws.close(e,n)}))},t._addWebSocketEventListeners(),t}return c(t,e),Object.defineProperty(t.prototype,"state",{get:function(){return this._state},set:function(e){var t=JSON.parse(JSON.stringify(this._state));this._state=e,this.emit("stateChange",this.state,t)},enumerable:!1,configurable:!0}),t.prototype.sendMessage=function(e){if(void 0===e&&(e=""),null==e||""===e)throw new Error("live message is empty!");if(this.state===exports.LiveState.OPEN)return this._ws.send(JSON.stringify(e));throw new Error("live has not yet been initialized!")},t}(m),He=function(e){return Promise.reject("unimplemented method GetVoiceSign")},Je=function(e,t,n){return void 0===t&&(t={}),void 0===n&&(n=[]),{command:e,front_request_id:S(),data:a(a({},t),{to_user_ids:Array.isArray(n)?n:[n]})}},qe=function(e){function t(t){var n,r=this;return(r=e.call(this)||this)._options={},r.keyframes=new m,r._buildInData={keyframes:{}},r.getFramesByKey=function(e){return r.snapshot[e]},r.sendKeyframe=function(e,t){var n;if(r.state!==exports.LiveState.OPEN)return!1;r._buildInData.keyframes=a(a({},r._buildInData.keyframes),((n={})[e]=t,n));var o=Je(exports.Command.KeyframeSync,r.snapshot);try{return r._controller.sendMessage(o),!0}catch(e){return y.error(e),!1}},r._controller=new De,r._addLiveControllerEventListeners=function(){r._controller.on("stateChange",r._handleStateChange),r._controller.on("message",r._handleMessage)},r._removeLiveControllerEventListeners=function(){r._controller.off("stateChange",r._handleStateChange),r._controller.off("message",r._handleMessage)},r._handleStateChange=function(e,t){return r.emit("stateChange",e,t)},r._handleMessage=function(e){return u(r,void 0,void 0,(function(){var t,n,r,o,i,s,c,a,u,f,h,p,v,m,g,_,b,w,S,k,E=this;return l(this,(function(l){switch(l.label){case 0:if("object"!=typeof e)return[3,22];if(t=e.command,n=e.data,r=void 0===n?{}:n,o=e.frontRequestId,"SUCCESS"!==e.code)return[3,21];switch(t){case exports.Command.SelfUserInfo:return[3,1];case exports.Command.RoomInfo:return[3,2];case exports.Command.RTCInfo:return[3,3];case exports.Command.UserList:return[3,10];case exports.Command.CustomEvent:return[3,11];case exports.Command.KeyframeSync:return[3,12];case exports.Command.BuiltinMsg:return[3,13];case exports.Command.UserKickOut:return[3,18]}return[3,19];case 1:return i=r,Ve(this.selfInfo,i,{deep:!0})||(this._buildInData.selfInfo=i,this.emit("selfInfoUpdate",this._buildInData.selfInfo,o)),[3,20];case 2:return s=r,this._buildInData.roomInfo=Object.assign({},s),this.emit("readyKeyframeSync",s.last_frame||{}),[3,20];case 3:return a=(c=r).voice_id,u=c.type,this._buildInData.rtcInfo={voiceId:a,type:u},(null===(_=this.$RTC)||void 0===_?void 0:_.joined)?[3,8]:[4,null===(b=this.$RTC)||void 0===b?void 0:b.join({voiceId:a,userId:(null===(w=this.selfInfo)||void 0===w?void 0:w.id)||"",roomId:null===(S=this.roomInfo)||void 0===S?void 0:S.info.room_code,type:u})];case 4:return l.sent()?(f=null!==(k=this._options.initialMicroStatus)&&void 0!==k?k:exports.MicroStatus.OPEN,[4,this.toggleMicro(f===exports.MicroStatus.OPEN)]):[3,6];case 5:return l.sent(),[3,7];case 6:y.error("加入语音房间失败"),l.label=7;case 7:return[3,9];case 8:y.warn("已加入语音房间,无需重复加入!"),l.label=9;case 9:return[3,20];case 10:return h=r,this._buildInData.userList=h,this.emit("userListUpdate",this.userList,o),[3,20];case 11:return p=r,this.emit("broadcast",p,o),[3,20];case 12:return v=r,m=Object.keys(v).reduce((function(e,t){var n;if(Ve(v[t],E._buildInData.keyframes[t],{deep:!0}))return e;var r=[v[t],E._buildInData.keyframes[t],o],i=t;return(n=E.keyframes).emit.apply(n,d([i],r,!1)),E._buildInData.keyframes[t]=v[t],e[t]=v[t],e}),{}),this.emit("keyframes",m,o),[3,20];case 13:return g=r,this.emit("builtinEvent",g),g.event_type===exports.BuiltinEventType.UserChange&&this.emit("userChange",g),g.event_type===exports.BuiltinEventType.RoomChange&&this.emit("roomChange",g),g.event_type!==exports.BuiltinEventType.UserChange||g.action!==exports.BuiltinActionType.UserMicroStatus?[3,15]:[4,this.toggleMicro(g.data.status===exports.MicroStatus.OPEN)];case 14:l.sent(),l.label=15;case 15:return g.event_type!==exports.BuiltinEventType.RoomChange||g.action!==exports.BuiltinActionType.RoomClose?[3,17]:[4,this.exit()];case 16:l.sent(),l.label=17;case 17:return[3,20];case 18:return this.emit("kickOut"),[3,20];case 19:console.warn("unknown command: ",t),l.label=20;case 20:return[3,22];case 21:this.emit("error",e),l.label=22;case 22:return[2]}}))}))},r._clearLiveData=function(){r._buildInData={keyframes:{}}},r.connect=function(e){return void 0===e&&(e={}),u(r,void 0,void 0,(function(){var t,n,r,o,i,s,c,a,u,d,f,h;return l(this,(function(l){switch(l.label){case 0:return this._options.url=null!==(d=null!==(u=e.url)&&void 0!==u?u:this._options.url)&&void 0!==d?d:"",this._options.getTicket=null!==(f=e.getTicket)&&void 0!==f?f:this._options.getTicket,this._options.initialMicroStatus=null!==(h=e.rtcMicStatus)&&void 0!==h?h:this._options.initialMicroStatus,/^ws(s):\/\//.test(this._options.url)&&"function"==typeof this._options.getTicket?(t=e.force,n=void 0!==t&&t,this._options.rtc?[4,this._options.rtc.detectMicro()]:[3,2]):/^ws(s):\/\//.test(this._options.url)?"function"!=typeof this._options.getTicket?[2,new Error("getTicket muse be function")]:[2,!1]:[2,new Error("Illegal realsee live room link")];case 1:if(!l.sent())return[2,new Error("Failed to obtain microphone authorization")];l.label=2;case 2:if((r=this.state)!==exports.LiveState.CONNECTING&&r!==exports.LiveState.OPEN)return[3,8];if(!n)return[3,7];l.label=3;case 3:return l.trys.push([3,5,,6]),[4,this._controller.close("force close by connect")];case 4:return l.sent(),[3,6];case 5:return o=l.sent(),console.warn(o),[3,6];case 6:return[3,8];case 7:return[2,new Error("已有Live实例正在连接中,请勿重复连接!")];case 8:return this._clearLiveData(),s=Re,c=[this._options.url],a={},[4,this._options.getTicket()];case 9:return i=s.apply(void 0,c.concat([(a.ticket=l.sent(),a.force=Number(!!n),a)])),this._controller.open(i),[2,!0]}}))}))},r.exit=function(){return u(r,void 0,void 0,(function(){var e,t;return l(this,(function(n){switch(n.label){case 0:if(this._clearLiveData(),this.state!==exports.LiveState.OPEN)return[2,!0];n.label=1;case 1:return n.trys.push([1,3,,4]),[4,null===(t=this.$RTC)||void 0===t?void 0:t.quit()];case 2:return n.sent(),[3,4];case 3:return e=n.sent(),y.warn(e),[3,4];case 4:return[4,this._controller.close()];case 5:return[2,n.sent()]}}))}))},r.close=function(){return u(r,void 0,void 0,(function(){var e,t;return l(this,(function(n){switch(n.label){case 0:return(null===(t=null===(e=this.selfInfo)||void 0===e?void 0:e.permission)||void 0===t?void 0:t.close_live_room)?[4,this.updateStatus(exports.BuiltinEventType.RoomChange,exports.BuiltinActionType.RoomClose,{})]:[3,2];case 1:return[2,n.sent()];case 2:return[2]}}))}))},r.dispose=function(){return u(r,void 0,void 0,(function(){return l(this,(function(e){switch(e.label){case 0:return this._removeLiveControllerEventListeners(),this._clearLiveData(),[4,this._controller.dispose()];case 1:return[2,e.sent()]}}))}))},r.setSelfInfo=function(e){return u(r,void 0,void 0,(function(){return l(this,(function(t){switch(t.label){case 0:return[4,this.updateStatus(exports.BuiltinEventType.UserChange,exports.BuiltinActionType.UserInfo,e)];case 1:return[2,t.sent()]}}))}))},r.toggleMicro=function(e){return u(r,void 0,void 0,(function(){var t,n,r,o;return l(this,(function(i){switch(i.label){case 0:return(null===(r=null===(n=this.selfInfo)||void 0===n?void 0:n.permission)||void 0===r?void 0:r.control_own_micro)?[4,null===(o=this.$RTC)||void 0===o?void 0:o.toggleMicro(e)]:[2,!1];case 1:return(t=i.sent())?[4,this.updateStatus(exports.BuiltinEventType.UserChange,exports.BuiltinActionType.UserMicroStatus,{status:e?exports.MicroStatus.OPEN:exports.MicroStatus.CLOSE},[])]:[3,3];case 2:i.sent(),i.label=3;case 3:return[2,t]}}))}))},r.forbidMicro=function(e,t){return u(r,void 0,void 0,(function(){var n,r;return l(this,(function(o){switch(o.label){case 0:return("function"!=typeof this._options.canForbidUserMicro||this._options.canForbidUserMicro(t))&&(null===(r=null===(n=this.selfInfo)||void 0===n?void 0:n.permission)||void 0===r?void 0:r.control_other_micro)?[4,this.updateStatus(exports.BuiltinEventType.UserChange,exports.BuiltinActionType.UserMicroStatus,{status:e},t)]:[2,!1];case 1:return[2,o.sent()]}}))}))},r.forbidSync=function(e,t){return u(r,void 0,void 0,(function(){var n,r;return l(this,(function(o){switch(o.label){case 0:return("function"!=typeof this._options.canForbidUserSync||this._options.canForbidUserSync(t))&&(null===(r=null===(n=this.selfInfo)||void 0===n?void 0:n.permission)||void 0===r?void 0:r.control_other_sync)?[4,this.updateStatus(exports.BuiltinEventType.UserChange,exports.BuiltinActionType.UserPermission,{sync_frame:e},t)]:[2,!1];case 1:return[2,o.sent()]}}))}))},r.kick=function(e){return u(r,void 0,void 0,(function(){var t,n;return l(this,(function(r){switch(r.label){case 0:return("function"!=typeof this._options.canForbidUserKick||this._options.canForbidUserKick(e))&&(null===(n=null===(t=this.selfInfo)||void 0===t?void 0:t.permission)||void 0===n?void 0:n.change_other_status)?[4,this.updateStatus(exports.BuiltinEventType.UserChange,exports.BuiltinActionType.UserStatus,{status:"KICK_OUT"},e)]:[2,!1];case 1:return[2,r.sent()]}}))}))},r._addLiveControllerEventListeners(),r._options=Object.assign({initialMicroStatus:exports.MicroStatus.OPEN},t),r._options.jsBridge=t.jsBridge?t.jsBridge:t.useBuiltInJsBridge?new ke:void 0,r._options.getVoiceSign=null!==(n=t.getVoiceSign)&&void 0!==n?n:He,r._options.autoPlayConfirm=t.autoPlayConfirm,r._options.rtc=function(){if(t.rtc)return t.rtc;if(t.rtcType)switch(t.getVoiceSign||y.error("GetVoiceSign method must be passed when using built-in RTC instances"),t.rtcType){case exports.RTCType.RealseeVRWebViewRTC:return r._options.jsBridge?new x({jsBridge:r._options.jsBridge,getVoiceSign:r._options.getVoiceSign}):void y.error("JsBridge instance must be passed when using built-in VRWebViewRTC instances");case exports.RTCType.RealseeBrowserChimeRTC:return new C({getVoiceSign:r._options.getVoiceSign,logLevel:t.__debug__?Ie.DEBUG:Ie.ERROR});case exports.RTCType.RealseeBrowserRTC:return r._options.autoPlayConfirm||y.error("autoPlayConfirm method must be passed when using built-in RealseeBrowserRTC instances"),new E({getVoiceSign:r._options.getVoiceSign,autoPlayConfirm:r._options.autoPlayConfirm});default:return void y.error("unknown built-in RTC type")}return t.useBuiltInRTC?(t.getVoiceSign||y.error("GetVoiceSign method must be passed when using built-in RTC instances"),r._options.jsBridge?We&&(Ae||Le)||Ne?new x({jsBridge:r._options.jsBridge,getVoiceSign:r._options.getVoiceSign}):t.builtInRTCType===exports.BuiltInRTCType.RealseeXChimeRTC?new C({getVoiceSign:r._options.getVoiceSign}):new E({getVoiceSign:r._options.getVoiceSign,autoPlayConfirm:r._options.autoPlayConfirm}):void y.error("jsBridge instance must be passed when using built-in RTC instances")):void 0}(),r._options.rtc||y.warn("unused rtc"),r._options.url&&r._options.getTicket&&r.connect(),r._options.__debug__&&Object.assign(window,{$liveController:r._controller,$live:r}),r}return c(t,e),Object.defineProperty(t.prototype,"options",{get:function(){return Object.freeze(this._options||{})},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"state",{get:function(){return this._controller.state},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"readyState",{get:function(){return this._controller.state},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"url",{get:function(){return this.options.url},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"$RTC",{get:function(){return this._options.rtc},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"jsBridge",{get:function(){return this._options.jsBridge},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"snapshot",{get:function(){return this._buildInData.keyframes},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"selfInfo",{get:function(){return this._buildInData.selfInfo},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"userList",{get:function(){return this._buildInData.userList||[]},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"roomInfo",{get:function(){return this._buildInData.roomInfo},enumerable:!1,configurable:!0}),t.prototype.updateStatus=function(e,t,n,r){return u(this,void 0,void 0,(function(){var o,i;return l(this,(function(s){if(this.state!==exports.LiveState.OPEN)return[2,!1];o=Object.assign({event_type:e,action:t},{data:n}),i=Je(exports.Command.BuiltinMsg,o,r);try{return this._controller.sendMessage(i),[2,!0]}catch(e){return y.error(e),[2,!1]}return[2]}))}))},t.prototype.broadcast=function(e,t,n){var r=this;return this.state===exports.LiveState.OPEN&&new Promise((function(o,i){var s=Je(exports.Command.CustomEvent,e,t),c=s.front_request_id,a=n?setTimeout((function(){i(new Error("RESPONSE TIMEOUT")),r.off("broadcast",u)}),n):void 0,u=function(e,t){t===c&&(a&&clearTimeout(a),r.off("broadcast",u),o(e))};r.on("broadcast",u);try{r._controller.sendMessage(s)}catch(e){i(e)}}))},t}(m),$e=function(e){var t,n;return(null===window||void 0===window?void 0:window.__Realsee_Live__)&&(null===(n=null===(t=null===window||void 0===window?void 0:window.__Realsee_Live__)||void 0===t?void 0:t.dispose)||void 0===n||n.call(t),window.__Realsee_Live__=null),new qe(e)};exports.BrowserRTC=E,exports.BrowserRTC4Chime=C,exports.CoreRTC=g,exports.VRWebViewRTC=x,exports.createLive=$e,exports.createLiveReact=function(e){var t=this,r=n.createContext(null),o=$e(e),s=o.jsBridge,c=function(){var e=i.default.useContext(r);if(!e)throw new Error("LiveProvider never found.");return e};return{live:o,jsBridge:s,LiveProvider:function(e){return i.default.createElement(r.Provider,{value:o},e.children)},unsafe__useLiveInstance:function(){return o},unsafe__useRTCInstance:function(){return o.$RTC},useConnect:function(){return function(e){return u(t,void 0,void 0,(function(){return l(this,(function(t){switch(t.label){case 0:return[4,o.connect(e)];case 1:return[2,t.sent()]}}))}))}},useKeyframe:function(e){var t=c(),n=i.default.useState(t.getFramesByKey(e)),r=n[0],o=n[1];return i.default.useEffect((function(){var n=e,r=function(e){return o(e)};return t.keyframes.on(n,r),function(){return t.keyframes.off(n,r)}}),[t]),[r,i.default.useCallback((function(n){return t.sendKeyframe(e,n)}),[t])]},useKeyframeUpdateCallback:function(e,t,n){void 0===n&&(n=[]);var r=c(),o=d([r,name],n,!0),s=function(){return r.keyframes.off(e,t)};return i.default.useEffect((function(){return r.keyframes.on(e,t),s}),o),s},useLiveAction:function(){var e=this,t=c();return{connect:function(n){return u(e,void 0,void 0,(function(){return l(this,(function(e){switch(e.label){case 0:return[4,t.connect(n)];case 1:return[2,e.sent()]}}))}))},broadcast:function(n,r,o){return void 0===o&&(o=0),u(e,void 0,void 0,(function(){return l(this,(function(e){switch(e.label){case 0:return[4,t.broadcast(n,r,o)];case 1:return[2,e.sent()]}}))}))},exit:function(){return u(e,void 0,void 0,(function(){return l(this,(function(e){switch(e.label){case 0:return[4,t.exit()];case 1:return[2,e.sent()]}}))}))},kick:function(n){return u(e,void 0,void 0,(function(){return l(this,(function(e){switch(e.label){case 0:return[4,t.kick(n)];case 1:return[2,e.sent()]}}))}))},toggleMicro:function(e){return t.toggleMicro(e)},forbidMicro:function(n,r){return void 0===r&&(r=[]),u(e,void 0,void 0,(function(){return l(this,(function(e){switch(e.label){case 0:return[4,t.forbidMicro(n,r)];case 1:return[2,e.sent()]}}))}))},forbidSync:function(e,n){return void 0===n&&(n=[]),t.forbidSync(e,n)},sendKeyframe:function(e,n){return t.sendKeyframe(e,n)},getFramesByKey:function(e){return t.getFramesByKey(e)},setSelfInfo:function(e){return t.setSelfInfo(e)},updateStatus:function(e,n,r,o){return t.updateStatus(e,n,r,o)}}},useLiveEventCallback:function(e,t,n){void 0===n&&(n=[]);var r=c(),o=function(){return r.off(e,t)},s=d([r,e],n,!0);return i.default.useEffect((function(){return r.on(e,t),o}),s),o},useLiveState:function(){var e=c(),t=i.default.useState(e.state),n=t[0],r=t[1];return i.default.useEffect((function(){var t=function(e){return r(e)};return e.on("stateChange",t),function(){return e.off("stateChange",t)}}),[e]),n},useRTCAction:function(){var e=c();return{join:function(t){return e.$RTC.join(t)},quit:function(){return e.$RTC.quit()},shock:function(){var t,n;return null===(n=(t=e.$RTC).shock)||void 0===n?void 0:n.call(t)},toggleMicro:function(t){return e.$RTC.toggleMicro(t)},detectMicro:function(){return e.$RTC.detectMicro()}}},useRTCEventCallback:function(e,t,n){void 0===n&&(n=[]);var r=c(),o=function(){return r.$RTC.off(e,t)},s=d([r,e],n,!0);return i.default.useEffect((function(){return r.$RTC.on(e,t),o}),s),o},useSelfInfo:function(){var e=this,t=c(),n=i.default.useState(t.selfInfo||{}),r=n[0],o=n[1],s=function(e){return o(e)};i.default.useEffect((function(){return t.on("selfInfoUpdate",s),function(){return t.off("selfInfoUpdate",s)}}),[t]);var a=i.default.useCallback((function(n){return u(e,void 0,void 0,(function(){return l(this,(function(e){switch(e.label){case 0:return[4,t.setSelfInfo(n)];case 1:return[2,e.sent()]}}))}))}),[t]);return[r,a]},useKeyframesSnapshot:function(){var e=c(),t=i.default.useState(e.snapshot),n=t[0],r=t[1];return i.default.useEffect((function(){var t=function(e){return r(e)};return e.on("keyframes",t),function(){return e.off("keyframes",t)}})),n},useUserList:function(){var e=c(),t=i.default.useState(e.userList),n=t[0],r=t[1],o=function(e){return r(e)};return i.default.useEffect((function(){return e.on("userListUpdate",o),function(){return e.off("userListUpdate",o)}}),[e]),n}}},exports.parseLiveMsg=function(e){try{var t=JSON.parse(e),n={code:t.code,message:t.message,command:t.command,roomCode:t.room_code,appID:t.app_id,requestId:t.request_id,frontRequestId:t.front_request_id,triggerUserID:t.trigger_user_id,data:t.data||{}},r=Object.keys(n).filter((function(e){return void 0===n[e]}));return r.length>0&&console.warn("推送数据格式异常:".concat(r.join(" ")," 值不存在!")),n}catch(e){return!1}},exports.parseWSClsErr=M;
2
2
  //# sourceMappingURL=realsee-live.cjs.production.js.map