@realsee/live 0.2.1 → 0.3.0-alpha.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +60 -2
- package/docs/assets/highlight.css +1 -1
- package/docs/assets/main.js +2 -2
- package/docs/assets/search.js +1 -1
- package/docs/assets/style.css +25 -0
- package/docs/classes/RTCProtocol.BrowserRTC.html +60 -0
- package/docs/classes/RTCProtocol.BrowserRTC4Chime.html +66 -0
- package/docs/classes/RTCProtocol.RTCExample.html +10 -10
- package/docs/classes/RTCProtocol.VRWebViewRTC.html +10 -10
- package/docs/classes/shared_utils.Subscribe.html +5 -5
- package/docs/enums/RTCProtocol.RTCJoinedInfoCodeEnum.html +4 -4
- package/docs/enums/RTCProtocol.RTCType.html +1 -1
- package/docs/enums/live.BuiltinActionType.html +6 -6
- package/docs/enums/live.BuiltinEventType.html +2 -2
- package/docs/enums/live.Command.html +1 -1
- package/docs/enums/live.MemUserStatus.html +1 -1
- package/docs/enums/live.MicroStatus.html +1 -1
- package/docs/enums/live.UserStatus.html +3 -3
- package/docs/enums/live.WebSocketCloseError.html +8 -8
- package/docs/enums/live.WebSocketErrorType.html +1 -1
- package/docs/enums/live.WebSocketState.html +5 -5
- package/docs/index.html +32 -1
- package/docs/interfaces/RTCProtocol.GetVoiceSignReturnType.html +1 -1
- package/docs/interfaces/RTCProtocol.RTCJoinedInfo.html +1 -1
- package/docs/interfaces/RTCProtocol.RTCProtocol-1.html +10 -10
- package/docs/interfaces/RTCProtocol.VRWebViewRTCOptions.html +1 -1
- package/docs/interfaces/live.Live.html +24 -24
- package/docs/interfaces/live.LiveOptions.html +9 -9
- package/docs/interfaces/live.LiveReact.html +15 -15
- package/docs/modules/RTCProtocol.html +3 -3
- package/docs/modules/live.html +10 -10
- package/docs/modules/shared_utils.html +2 -2
- package/lib/RTC/BrowserRTC.js +9 -9
- package/lib/RTC/BrowserRTC.js.map +1 -1
- package/lib/RTC/BrowserRTC4Chime.d.ts +53 -0
- package/lib/RTC/BrowserRTC4Chime.js +299 -0
- package/lib/RTC/BrowserRTC4Chime.js.map +1 -0
- package/lib/RTC/VRWebViewRTC.js +12 -11
- package/lib/RTC/VRWebViewRTC.js.map +1 -1
- package/lib/RTC/index.js +7 -7
- package/lib/RTC/index.js.map +1 -1
- package/lib/createLive.js +22 -21
- package/lib/createLive.js.map +1 -1
- package/lib/createLiveReact.d.ts +1 -1
- package/lib/createLiveReact.js +9 -13
- package/lib/createLiveReact.js.map +1 -1
- package/lib/shared-utils/appendUri.js +1 -1
- package/lib/shared-utils/appendUri.js.map +1 -1
- package/lib/typings/Chime/AttendeeResponse.d.ts +5 -0
- package/lib/typings/Chime/AttendeeResponse.js +3 -0
- package/lib/typings/Chime/AttendeeResponse.js.map +1 -0
- package/lib/typings/Chime/MeetingResponse.d.ts +12 -0
- package/lib/typings/Chime/MeetingResponse.js +3 -0
- package/lib/typings/Chime/MeetingResponse.js.map +1 -0
- package/lib/typings/Chime/MeetingSessionConfigurationOptions.d.ts +16 -0
- package/lib/typings/Chime/MeetingSessionConfigurationOptions.js +3 -0
- package/lib/typings/Chime/MeetingSessionConfigurationOptions.js.map +1 -0
- package/lib/typings/LiveMsg.js +2 -2
- package/lib/typings/LiveMsg.js.map +1 -1
- package/package.json +10 -9
- package/umd/createLive.96395a4c.js +1 -0
- package/umd/createLiveReact.e1836101.js +1 -0
- package/umd/createLive.a6edf473.js +0 -1
- package/umd/createLiveReact.e21b4514.js +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.LiveSDK=t():e.LiveSDK=t()}(self,(function(){return(()=>{"use strict";var e={900:(e,t,r)=>{r.d(t,{RTCExample:()=>o});var n=r(508);let s;!function(e){e.realsee="realsee",e.custom="custom"}(s||(s={}));class o extends n.x{join(e){throw new Error("Method not implemented.")}joined=!1;micro=!1;voiceId="";type=s.realsee;async quit(){return!0}async detectMicro(){return!0}async toggleMicro(e){return!0}shock(){}}},508:(e,t,r)=>{r.d(t,{x:()=>o});const n=Symbol("$$LIVE_EVENT$$");function s(e){return e[n]||(e[n]={}),e[n]}class o{hasListener(e){const t=s(this);return t&&t[e]&&t[e].length>0}on(e,t,r){const n=s(this);return n[e]||(n[e]=[]),n[e].push([t,r||!1]),()=>this.off(e,t)}once(e,t){return this.on(e,t,!0)}off(e,t){if(void 0===e)return void(this[n]||delete this[n]);const r=s(this);if(r[e]||(r[e]=[]),void 0===t)return void(r[e].length=0);let o=0;for(;o<r[e].length&&r[e][o][0]!==t;o++);o<r[e].length&&r[e].splice(o,1)}emit(e,...t){let r=!1;const n=s(this)[e]||[];for(let s of n.slice()){const[n,o=!1]=s,i=n(...t);o&&this.off(e,n),!1===i&&(r=!0)}return r}}let i;i||(i={})}},t={};function r(n){var s=t[n];if(void 0!==s)return s.exports;var o=t[n]={exports:{}};return e[n](o,o.exports,r),o.exports}r.d=(e,t)=>{for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var n={};return(()=>{function e(){return(65536*(1+Math.random())|0).toString(16).substring(1)}function t(e){return"[object Object]"===Object.prototype.toString.call(e)}function s(e,t){return e===t||typeof e==typeof t&&!(!Number.isNaN(e)||!Number.isNaN(t))}function o(e,r){return!!s(e,r)||(t(e)&&t(r)?function(e,t){const r=Object.getOwnPropertyNames(e),n=Object.getOwnPropertyNames(t);if(r.length!==n.length)return!1;for(let n=0,s=r.length;n<s;n++){const s=r[n];if(!o(e[s],t[s]))return!1}return!0}(e,r):!(!Array.isArray(e)||!Array.isArray(r))&&function(e,t){if(e.length!==t.length)return!1;for(let r=0,n=e.length;r<n;r++)if(!o(e[r],t[r]))return!1;return!0}(e,r))}function i(e,r,n={deep:!1}){return n.deep?o(e,r):function(e,r){return!!s(e,r)||(t(e)&&t(r)?function(e,t){const r=Object.getOwnPropertyNames(e),n=Object.getOwnPropertyNames(t);if(r.length!==n.length)return!1;for(let n=0,o=r.length;n<o;n++){const o=r[n];if(!s(e[o],t[o]))return!1}return!0}(e,r):!(!Array.isArray(e)||!Array.isArray(r))&&function(e,t){if(e.length!==t.length)return!1;for(let r=0,n=e.length;r<n;r++)if(!s(e[r],t[r]))return!1;return!0}(e,r))}(e,r)}r.r(n),r.d(n,{createLive:()=>E});var a=r(508);let c,u,h,d,f,l,y;!function(e){e[e.NOTINITIALIZED=-1]="NOTINITIALIZED",e[e.CONNECTING=0]="CONNECTING",e[e.OPEN=1]="OPEN",e[e.CLOSING=2]="CLOSING",e[e.CLOSED=3]="CLOSED"}(c||(c={})),function(e){e.Error="Error",e.Close="Close",e.MicroAuth="MicroAuth",e.DuplicateConnect="DuplicateConnect",e.IllegalURL="IllegalURL",e.Unknown="Unknown",e.IllegalArgs="IllegalArgs"}(u||(u={})),function(e){e.Err_1001="CLOSE_GOING_AWAY",e.Err_1002="CLOSE_PROTOCOL_ERROR",e.Err_1003="CLOSE_UNSUPPORTED",e.Err_1006="CLOSE_ABNORMAL",e.Err_1007="Unsupported Data",e.Err_1008="Policy Violation",e.Err_1009="CLOSE_TOO_LARGE",e.Err_unknown="unknown"}(h||(h={})),function(e){e.SelfUserInfo="SELF_USER_INFO",e.RoomInfo="ROOM_INFO",e.RTCInfo="RTC_INFO",e.UserList="USER_LIST",e.BuiltinMsg="BUILTIN_MSG",e.CustomEvent="CUSTOM_EVENT",e.KeyframeSync="KEYFRAME_SYNC",e.UserKickOut="USER_KICK_OUT"}(d||(d={})),function(e){e.UserChange="user_change",e.RoomChange="room_change"}(f||(f={})),function(e){e.UserMicroStatus="change_micro_status",e.UserMicroStatusSync="sync_micro_status",e.UserPermission="change_permission",e.UserStatus="change_status",e.UserInfo="change_info",e.RoomClose="close"}(l||(l={})),function(e){e.OPEN="OPEN",e.CLOSE="CLOSE"}(y||(y={}));var g=r(900);class m{readyState=c.NOTINITIALIZED;canSync=!0;connecting=!1;keyframes={};constructor(e){this.options=Object.assign({autoConnect:!0,healthCheck:3e3},e)}checkReadyState=e=>{do{if(!this.webSocket){this.readyState!==c.NOTINITIALIZED&&(this.readyState=c.NOTINITIALIZED,e.emit("ws.readyStateUpdate",this.readyState));break}const t=this.webSocket.readyState;t!==this.readyState&&(this.readyState=t,e.emit("ws.readyStateUpdate",this.readyState))}while(0);return this.readyState};dispose=()=>{console.log("dispose"),this.disposeWebSocket(),this.connecting=!1,this.healthCheckId&&(clearInterval(this.healthCheckId),this.healthCheckId=void 0)};disposeWebSocket=()=>{this.webSocket&&(this.onEvtOpnListener&&(this.webSocket.removeEventListener("open",this.onEvtOpnListener),this.onEvtOpnListener=void 0),this.onEvtMsgListener&&(this.webSocket.removeEventListener("message",this.onEvtMsgListener),this.onEvtMsgListener=void 0),this.onEvtErrListener&&(this.webSocket.removeEventListener("error",this.onEvtErrListener),this.onEvtErrListener=void 0),this.onEvtCLEListener&&(this.webSocket.removeEventListener("close",this.onEvtCLEListener),this.onEvtCLEListener=void 0),this.webSocket.close(),this.webSocket=void 0)};handleMessage(e,t){const{command:r,data:n,frontRequestId:s,code:o,message:a}=e;if("SUCCESS"!==o)return t.emit("error",e);switch(r){case d.SelfUserInfo:{const e=n;if(i(this.selfUserInfo,e,{deep:!0}))return;this.selfUserInfo=e,t.emit("selfInfoUpdate",this.selfUserInfo,s);break}case d.RoomInfo:{const e=n;this.roomInfo=Object.assign({},e),t.emit("readyKeyframeSync",e.last_frame||{});break}case d.RTCInfo:{const{voice_id:e,type:r}=n;if(t.$RTC.joined)break;t.$RTC.join({voiceId:e,userId:this.selfUserInfo?.id||"",roomId:this.roomInfo?.info.room_code,type:r}),t.updateStatus(f.UserChange,l.UserMicroStatus,{status:y.OPEN});break}case d.UserList:{const e=n;this.userList=e,t.emit("userListUpdate",this.userList,s);break}case d.CustomEvent:{const e=n;t.emit("broadcast",e,s);break}case d.KeyframeSync:{const e=n,r=Object.keys(e).reduce(((r,n)=>{if(i(e[n],this.keyframes[n],{deep:!0}))return r;const o=[e[n],this.keyframes[n],s];return t.keyframes.emit(n,...o),this.keyframes[n]=e[n],r[n]=e[n],r}),{});t.emit("keyframes",r,s);break}case d.BuiltinMsg:{const e=n;t.emit("builtinEvent",e),e.event_type===f.UserChange&&t.emit("userChange",e),e.event_type===f.RoomChange&&t.emit("roomChange",e),e.event_type===f.UserChange&&e.action===l.UserMicroStatus&&t.toggleMicro(e.data.status===y.OPEN),e.event_type===f.RoomChange&&e.action===l.RoomClose&&(this.options.rtc?.quit(),this.disposeWebSocket());break}case d.UserKickOut:t.emit("kickOut")}}sendMessage(e){return this.webSocket?e?void this.webSocket.send(JSON.stringify(e)):console.warn("WebSocket messages is empty!"):console.warn("WebSocket has not yet been initialized!")}}function E(t){const r=new m(t),n=(t,r={},n)=>((n=n?Array.isArray(n)?n:[n]:[])&&(r.to_user_ids=n),{command:t,front_request_id:(e()+e()+"-"+e()+"-4"+e().substr(0,3)+"-"+e()+"-"+e()+e()+e()).toLowerCase(),data:r});class s extends a.x{get options(){return Object.freeze(Object.assign({},r.options))}get readyState(){return r.checkReadyState(this),r.readyState}get url(){return r.webSocket?.url||""}get selfInfo(){return r.selfUserInfo}get userList(){return r.userList||[]}get snapshot(){return r.keyframes||{}}get $RTC(){return r.options.rtc}keyframes=new a.x;constructor(){super(),t.rtc||(r.options.rtc=new g.RTCExample),r.options.url&&r.options.getTicket&&this.connect();const e=(e=>{if(!e)return 0;if(!0===e)return 3e3;const t=Number(e);return t>0?t:3e3})(r.options.healthCheck);e&&(r.healthCheckId=setInterval((()=>r.checkReadyState(this)),e))}async setSelfInfo(e){if(this.readyState!==c.OPEN)return new Error("The connection is not open and ready to communicate.");try{return await this.updateStatus(f.UserChange,l.UserInfo,e)}catch(e){return e}}getFramesByKey(e){return r.keyframes[e]}sendKeyframe(e,t){if(this.readyState!==c.OPEN)return new Error("The connection is not open and ready to communicate.");r.keyframes[e]=t;const s=n(d.KeyframeSync,this.snapshot);return r.sendMessage(s),!0}broadcast(e,t,s){return this.readyState!==c.OPEN?new Error("The connection is not open and ready to communicate."):new Promise(((o,i)=>{const a=n(d.CustomEvent,e,t),c=a.front_request_id;r.sendMessage(a);const u=s?setTimeout((()=>{i(new Error("RESPONSE TIMEOUT")),this.off("broadcast",h)}),s):void 0,h=(e,t)=>{t===c&&(this.off("broadcast",h),o(e),u&&clearInterval(u))};this.on("broadcast",h)}))}async updateStatus(e,t,s,o){if(this.readyState!==c.OPEN)return!1;const i=Object.assign({event_type:e,action:t},{data:s}),a=n(d.BuiltinMsg,i,o);return r.sendMessage(a),!0}async toggleMicro(e){return!!this.selfInfo?.permission?.control_own_micro&&(await this.$RTC.toggleMicro(e),await this.updateStatus(f.UserChange,l.UserMicroStatus,{status:e?y.OPEN:y.CLOSE},[]))}async forbidMicro(e,t){return!(r.options.canForbidUserMicro&&!r.options.canForbidUserMicro(t))&&!!this.selfInfo?.permission?.control_other_micro&&await this.updateStatus(f.UserChange,l.UserMicroStatus,{status:e},t)}async forbidSync(e,t){return!(r.options.canForbidUserSync&&!r.options.canForbidUserSync(t))&&!!this.selfInfo?.permission?.control_other_sync&&await this.updateStatus(f.UserChange,l.UserPermission,{sync_frame:e},t)}async kick(e){return!(r.options.canForbidUserKick&&!r.options.canForbidUserKick(e))&&!!this.selfInfo?.permission?.change_other_status&&await this.updateStatus(f.UserChange,l.UserStatus,{status:"KICK_OUT"},e)}async exit(){return await this.$RTC.quit(),await this.updateStatus(f.RoomChange,l.RoomClose,{})}async connect(e={}){if(!await this.$RTC.detectMicro()){const e=new Error("系统监测麦克风未授权~");return this.emit("ws.error",{type:u.MicroAuth,error:e}),e}if(r.connecting){const e=new Error("WebSocket 正在连接中,请勿重复连接 ...");return this.emit("ws.error",{type:u.DuplicateConnect,error:e}),e}const{force:t}=e;if(!t&&(this.readyState===c.CONNECTING||this.readyState===c.OPEN))return!0;if(e.url&&(r.options.url=e.url),e.getTicket&&(r.options.getTicket=e.getTicket),!r.options.url||!r.options.url.startsWith("ws")){const e=new Error(`WebSocket URL 未配置或格式不合法:"${r.options.url}"`);return this.emit("ws.error",{type:u.IllegalURL,error:e}),e}if(!r.options.getTicket){const e=new Error("getTicket() 未配置!");return this.emit("ws.error",{type:u.IllegalArgs,error:e}),e}r.connecting=!0,r.disposeWebSocket(),this.emit("ws.beforeConnect");const n=t||e.url||!this.url?function(e,t={}){const r=-1!==e.indexOf("?");return e+Object.keys(t).reduce(((e,n,s)=>`${e}${0!==s||r?"&":"?"}${n}=${t[n]}`),"")}(r.options.url,{ticket:await r.options.getTicket(),force:Number(!!t)}):this.url;return r.webSocket=new WebSocket(n),r.onEvtOpnListener=()=>{r.checkReadyState(this),this.emit("ws.afterConnect")},r.onEvtMsgListener=e=>{r.checkReadyState(this);try{const t=function(e){try{const t=JSON.parse(e),r={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||{}},n=Object.keys(r).filter((e=>void 0===r[e]));return n.length>0&&console.warn(`推送数据格式异常:${n.join(" ")} 值不存在!`),r}catch(e){return!1}}(e.data);if(!1===t)return;r.handleMessage(t,this)}catch(t){this.emit("ws.error",{type:u.Unknown,error:t,target:e})}},r.onEvtErrListener=e=>{o.emit("ws.error",{type:u.Error,target:e}),r.checkReadyState(this)},r.onEvtCLEListener=e=>{r.checkReadyState(this);const t=Number(e.code);if(1e3===t)return;const n=function(e){switch(e){case 1001:return h.Err_1001;case 1002:return h.Err_1002;case 1003:return h.Err_1003;case 1006:return h.Err_1006;case 1007:return h.Err_1007;case 1008:return h.Err_1008;case 1009:return h.Err_1009}return h.Err_unknown}(t);o.emit("ws.error",{target:e,type:u.Close,closeError:n})},r.webSocket.addEventListener("open",r.onEvtOpnListener),r.webSocket.addEventListener("message",r.onEvtMsgListener),r.webSocket.addEventListener("error",r.onEvtErrListener),r.webSocket.addEventListener("close",r.onEvtCLEListener),await new Promise(((e,t)=>{const n=()=>{e(!0),r.connecting=!1,this.off("ws.error",s)},s=e=>{t(e.error?e.error:new Error("WebSocket connection failed!")),r.connecting=!1,this.off("ws.afterConnect",n)};this.once("ws.afterConnect",n),this.once("ws.error",s)}))}async revoke(){return!0}}const o=new s;return t.__debug__&&(Object.assign(o,{__controller__:r}),Object.assign(window,{$live:o})),o}})(),n})()}));
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.LiveSDK=t():e.LiveSDK=t()}(self,(function(){return(()=>{var e={206:e=>{if(!("React"in window))throw new Error('"React" is not available. Please include "react" in your HTML.');e.exports=window.React},900:(e,t,r)=>{"use strict";r.d(t,{RTCExample:()=>o});var n=r(508);let s;!function(e){e.realsee="realsee",e.custom="custom"}(s||(s={}));class o extends n.x{join(e){throw new Error("Method not implemented.")}joined=!1;micro=!1;voiceId="";type=s.realsee;async quit(){return!0}async detectMicro(){return!0}async toggleMicro(e){return!0}shock(){}}},431:(e,t,r)=>{"use strict";function n(){return(65536*(1+Math.random())|0).toString(16).substring(1)}function s(e){return"[object Object]"===Object.prototype.toString.call(e)}function o(e,t){return e===t||typeof e==typeof t&&!(!Number.isNaN(e)||!Number.isNaN(t))}function i(e,t){return!!o(e,t)||(s(e)&&s(t)?function(e,t){const r=Object.getOwnPropertyNames(e),n=Object.getOwnPropertyNames(t);if(r.length!==n.length)return!1;for(let n=0,s=r.length;n<s;n++){const s=r[n];if(!i(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(let r=0,n=e.length;r<n;r++)if(!i(e[r],t[r]))return!1;return!0}(e,t))}function a(e,t,r={deep:!1}){return r.deep?i(e,t):function(e,t){return!!o(e,t)||(s(e)&&s(t)?function(e,t){const r=Object.getOwnPropertyNames(e),n=Object.getOwnPropertyNames(t);if(r.length!==n.length)return!1;for(let n=0,s=r.length;n<s;n++){const s=r[n];if(!o(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(let r=0,n=e.length;r<n;r++)if(!o(e[r],t[r]))return!1;return!0}(e,t))}(e,t)}r.d(t,{createLive:()=>g});var c=r(508);let u,f,l,d,h,y,m;!function(e){e[e.NOTINITIALIZED=-1]="NOTINITIALIZED",e[e.CONNECTING=0]="CONNECTING",e[e.OPEN=1]="OPEN",e[e.CLOSING=2]="CLOSING",e[e.CLOSED=3]="CLOSED"}(u||(u={})),function(e){e.Error="Error",e.Close="Close",e.MicroAuth="MicroAuth",e.DuplicateConnect="DuplicateConnect",e.IllegalURL="IllegalURL",e.Unknown="Unknown",e.IllegalArgs="IllegalArgs"}(f||(f={})),function(e){e.Err_1001="CLOSE_GOING_AWAY",e.Err_1002="CLOSE_PROTOCOL_ERROR",e.Err_1003="CLOSE_UNSUPPORTED",e.Err_1006="CLOSE_ABNORMAL",e.Err_1007="Unsupported Data",e.Err_1008="Policy Violation",e.Err_1009="CLOSE_TOO_LARGE",e.Err_unknown="unknown"}(l||(l={})),function(e){e.SelfUserInfo="SELF_USER_INFO",e.RoomInfo="ROOM_INFO",e.RTCInfo="RTC_INFO",e.UserList="USER_LIST",e.BuiltinMsg="BUILTIN_MSG",e.CustomEvent="CUSTOM_EVENT",e.KeyframeSync="KEYFRAME_SYNC",e.UserKickOut="USER_KICK_OUT"}(d||(d={})),function(e){e.UserChange="user_change",e.RoomChange="room_change"}(h||(h={})),function(e){e.UserMicroStatus="change_micro_status",e.UserMicroStatusSync="sync_micro_status",e.UserPermission="change_permission",e.UserStatus="change_status",e.UserInfo="change_info",e.RoomClose="close"}(y||(y={})),function(e){e.OPEN="OPEN",e.CLOSE="CLOSE"}(m||(m={}));var S=r(900);class E{readyState=u.NOTINITIALIZED;canSync=!0;connecting=!1;keyframes={};constructor(e){this.options=Object.assign({autoConnect:!0,healthCheck:3e3},e)}checkReadyState=e=>{do{if(!this.webSocket){this.readyState!==u.NOTINITIALIZED&&(this.readyState=u.NOTINITIALIZED,e.emit("ws.readyStateUpdate",this.readyState));break}const t=this.webSocket.readyState;t!==this.readyState&&(this.readyState=t,e.emit("ws.readyStateUpdate",this.readyState))}while(0);return this.readyState};dispose=()=>{console.log("dispose"),this.disposeWebSocket(),this.connecting=!1,this.healthCheckId&&(clearInterval(this.healthCheckId),this.healthCheckId=void 0)};disposeWebSocket=()=>{this.webSocket&&(this.onEvtOpnListener&&(this.webSocket.removeEventListener("open",this.onEvtOpnListener),this.onEvtOpnListener=void 0),this.onEvtMsgListener&&(this.webSocket.removeEventListener("message",this.onEvtMsgListener),this.onEvtMsgListener=void 0),this.onEvtErrListener&&(this.webSocket.removeEventListener("error",this.onEvtErrListener),this.onEvtErrListener=void 0),this.onEvtCLEListener&&(this.webSocket.removeEventListener("close",this.onEvtCLEListener),this.onEvtCLEListener=void 0),this.webSocket.close(),this.webSocket=void 0)};handleMessage(e,t){const{command:r,data:n,frontRequestId:s,code:o,message:i}=e;if("SUCCESS"!==o)return t.emit("error",e);switch(r){case d.SelfUserInfo:{const e=n;if(a(this.selfUserInfo,e,{deep:!0}))return;this.selfUserInfo=e,t.emit("selfInfoUpdate",this.selfUserInfo,s);break}case d.RoomInfo:{const e=n;this.roomInfo=Object.assign({},e),t.emit("readyKeyframeSync",e.last_frame||{});break}case d.RTCInfo:{const{voice_id:e,type:r}=n;if(t.$RTC.joined)break;t.$RTC.join({voiceId:e,userId:this.selfUserInfo?.id||"",roomId:this.roomInfo?.info.room_code,type:r}),t.updateStatus(h.UserChange,y.UserMicroStatus,{status:m.OPEN});break}case d.UserList:{const e=n;this.userList=e,t.emit("userListUpdate",this.userList,s);break}case d.CustomEvent:{const e=n;t.emit("broadcast",e,s);break}case d.KeyframeSync:{const e=n,r=Object.keys(e).reduce(((r,n)=>{if(a(e[n],this.keyframes[n],{deep:!0}))return r;const o=[e[n],this.keyframes[n],s];return t.keyframes.emit(n,...o),this.keyframes[n]=e[n],r[n]=e[n],r}),{});t.emit("keyframes",r,s);break}case d.BuiltinMsg:{const e=n;t.emit("builtinEvent",e),e.event_type===h.UserChange&&t.emit("userChange",e),e.event_type===h.RoomChange&&t.emit("roomChange",e),e.event_type===h.UserChange&&e.action===y.UserMicroStatus&&t.toggleMicro(e.data.status===m.OPEN),e.event_type===h.RoomChange&&e.action===y.RoomClose&&(this.options.rtc?.quit(),this.disposeWebSocket());break}case d.UserKickOut:t.emit("kickOut")}}sendMessage(e){return this.webSocket?e?void this.webSocket.send(JSON.stringify(e)):console.warn("WebSocket messages is empty!"):console.warn("WebSocket has not yet been initialized!")}}function g(e){const t=new E(e),r=(e,t={},r)=>((r=r?Array.isArray(r)?r:[r]:[])&&(t.to_user_ids=r),{command:e,front_request_id:(n()+n()+"-"+n()+"-4"+n().substr(0,3)+"-"+n()+"-"+n()+n()+n()).toLowerCase(),data:t});class s extends c.x{get options(){return Object.freeze(Object.assign({},t.options))}get readyState(){return t.checkReadyState(this),t.readyState}get url(){return t.webSocket?.url||""}get selfInfo(){return t.selfUserInfo}get userList(){return t.userList||[]}get snapshot(){return t.keyframes||{}}get $RTC(){return t.options.rtc}keyframes=new c.x;constructor(){super(),e.rtc||(t.options.rtc=new S.RTCExample),t.options.url&&t.options.getTicket&&this.connect();const r=(e=>{if(!e)return 0;if(!0===e)return 3e3;const t=Number(e);return t>0?t:3e3})(t.options.healthCheck);r&&(t.healthCheckId=setInterval((()=>t.checkReadyState(this)),r))}async setSelfInfo(e){if(this.readyState!==u.OPEN)return new Error("The connection is not open and ready to communicate.");try{return await this.updateStatus(h.UserChange,y.UserInfo,e)}catch(e){return e}}getFramesByKey(e){return t.keyframes[e]}sendKeyframe(e,n){if(this.readyState!==u.OPEN)return new Error("The connection is not open and ready to communicate.");t.keyframes[e]=n;const s=r(d.KeyframeSync,this.snapshot);return t.sendMessage(s),!0}broadcast(e,n,s){return this.readyState!==u.OPEN?new Error("The connection is not open and ready to communicate."):new Promise(((o,i)=>{const a=r(d.CustomEvent,e,n),c=a.front_request_id;t.sendMessage(a);const u=s?setTimeout((()=>{i(new Error("RESPONSE TIMEOUT")),this.off("broadcast",f)}),s):void 0,f=(e,t)=>{t===c&&(this.off("broadcast",f),o(e),u&&clearInterval(u))};this.on("broadcast",f)}))}async updateStatus(e,n,s,o){if(this.readyState!==u.OPEN)return!1;const i=Object.assign({event_type:e,action:n},{data:s}),a=r(d.BuiltinMsg,i,o);return t.sendMessage(a),!0}async toggleMicro(e){return!!this.selfInfo?.permission?.control_own_micro&&(await this.$RTC.toggleMicro(e),await this.updateStatus(h.UserChange,y.UserMicroStatus,{status:e?m.OPEN:m.CLOSE},[]))}async forbidMicro(e,r){return!(t.options.canForbidUserMicro&&!t.options.canForbidUserMicro(r))&&!!this.selfInfo?.permission?.control_other_micro&&await this.updateStatus(h.UserChange,y.UserMicroStatus,{status:e},r)}async forbidSync(e,r){return!(t.options.canForbidUserSync&&!t.options.canForbidUserSync(r))&&!!this.selfInfo?.permission?.control_other_sync&&await this.updateStatus(h.UserChange,y.UserPermission,{sync_frame:e},r)}async kick(e){return!(t.options.canForbidUserKick&&!t.options.canForbidUserKick(e))&&!!this.selfInfo?.permission?.change_other_status&&await this.updateStatus(h.UserChange,y.UserStatus,{status:"KICK_OUT"},e)}async exit(){return await this.$RTC.quit(),await this.updateStatus(h.RoomChange,y.RoomClose,{})}async connect(e={}){if(!await this.$RTC.detectMicro()){const e=new Error("系统监测麦克风未授权~");return this.emit("ws.error",{type:f.MicroAuth,error:e}),e}if(t.connecting){const e=new Error("WebSocket 正在连接中,请勿重复连接 ...");return this.emit("ws.error",{type:f.DuplicateConnect,error:e}),e}const{force:r}=e;if(!r&&(this.readyState===u.CONNECTING||this.readyState===u.OPEN))return!0;if(e.url&&(t.options.url=e.url),e.getTicket&&(t.options.getTicket=e.getTicket),!t.options.url||!t.options.url.startsWith("ws")){const e=new Error(`WebSocket URL 未配置或格式不合法:"${t.options.url}"`);return this.emit("ws.error",{type:f.IllegalURL,error:e}),e}if(!t.options.getTicket){const e=new Error("getTicket() 未配置!");return this.emit("ws.error",{type:f.IllegalArgs,error:e}),e}t.connecting=!0,t.disposeWebSocket(),this.emit("ws.beforeConnect");const n=r||e.url||!this.url?function(e,t={}){const r=-1!==e.indexOf("?");return e+Object.keys(t).reduce(((e,n,s)=>`${e}${0!==s||r?"&":"?"}${n}=${t[n]}`),"")}(t.options.url,{ticket:await t.options.getTicket(),force:Number(!!r)}):this.url;return t.webSocket=new WebSocket(n),t.onEvtOpnListener=()=>{t.checkReadyState(this),this.emit("ws.afterConnect")},t.onEvtMsgListener=e=>{t.checkReadyState(this);try{const r=function(e){try{const t=JSON.parse(e),r={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||{}},n=Object.keys(r).filter((e=>void 0===r[e]));return n.length>0&&console.warn(`推送数据格式异常:${n.join(" ")} 值不存在!`),r}catch(e){return!1}}(e.data);if(!1===r)return;t.handleMessage(r,this)}catch(t){this.emit("ws.error",{type:f.Unknown,error:t,target:e})}},t.onEvtErrListener=e=>{o.emit("ws.error",{type:f.Error,target:e}),t.checkReadyState(this)},t.onEvtCLEListener=e=>{t.checkReadyState(this);const r=Number(e.code);if(1e3===r)return;const n=function(e){switch(e){case 1001:return l.Err_1001;case 1002:return l.Err_1002;case 1003:return l.Err_1003;case 1006:return l.Err_1006;case 1007:return l.Err_1007;case 1008:return l.Err_1008;case 1009:return l.Err_1009}return l.Err_unknown}(r);o.emit("ws.error",{target:e,type:f.Close,closeError:n})},t.webSocket.addEventListener("open",t.onEvtOpnListener),t.webSocket.addEventListener("message",t.onEvtMsgListener),t.webSocket.addEventListener("error",t.onEvtErrListener),t.webSocket.addEventListener("close",t.onEvtCLEListener),await new Promise(((e,r)=>{const n=()=>{e(!0),t.connecting=!1,this.off("ws.error",s)},s=e=>{r(e.error?e.error:new Error("WebSocket connection failed!")),t.connecting=!1,this.off("ws.afterConnect",n)};this.once("ws.afterConnect",n),this.once("ws.error",s)}))}async revoke(){return!0}}const o=new s;return e.__debug__&&(Object.assign(o,{__controller__:t}),Object.assign(window,{$live:o})),o}},508:(e,t,r)=>{"use strict";r.d(t,{x:()=>o});const n=Symbol("$$LIVE_EVENT$$");function s(e){return e[n]||(e[n]={}),e[n]}class o{hasListener(e){const t=s(this);return t&&t[e]&&t[e].length>0}on(e,t,r){const n=s(this);return n[e]||(n[e]=[]),n[e].push([t,r||!1]),()=>this.off(e,t)}once(e,t){return this.on(e,t,!0)}off(e,t){if(void 0===e)return void(this[n]||delete this[n]);const r=s(this);if(r[e]||(r[e]=[]),void 0===t)return void(r[e].length=0);let o=0;for(;o<r[e].length&&r[e][o][0]!==t;o++);o<r[e].length&&r[e].splice(o,1)}emit(e,...t){let r=!1;const n=s(this)[e]||[];for(let s of n.slice()){const[n,o=!1]=s,i=n(...t);o&&this.off(e,n),!1===i&&(r=!0)}return r}}let i;i||(i={})}},t={};function r(n){var s=t[n];if(void 0!==s)return s.exports;var o=t[n]={exports:{}};return e[n](o,o.exports,r),o.exports}r.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return r.d(t,{a:t}),t},r.d=(e,t)=>{for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var n={};return(()=>{"use strict";r.r(n),r.d(n,{createLiveReact:()=>s});var e=r(206),t=r(431);function s(r){const n=e.createContext(null),s=(0,t.createLive)(r);function o(){const t=e.useContext(n);if(!t)throw new Error("LiveProvider never found.");return t}return{live:s,LiveProvider:function(t){return e.createElement(n.Provider,{value:t.live||s},t.children)},unsafe__useLiveInstance:function(){return o()},unsafe__useRTCInstance:function(){return o().$RTC},useCurrentWebSocketUrl:function(){const t=o(),[r,n]=e.useState(void 0);return e.useEffect((()=>{const e=()=>n(t.url);return t.on("ws.beforeConnect",e),()=>t.off("ws.beforeConnect",e)}),[t]),r},useConnect:function(){const e=o();return async t=>await e.connect(t)},useKeyframe:function(t){const r=o(),[n,s]=e.useState(r.getFramesByKey(t));return e.useEffect((()=>{const e=(...e)=>s(e[0]);return r.keyframes.on(t,e),()=>r.keyframes.off(t,e)}),[r]),[n,e.useCallback((e=>r.sendKeyframe(t,e)),[r])]},useKeyframeUpdateCallback:function(t,r,n){const s=o(),i=n?[s,t].concat(n):[s,t],a=()=>s.keyframes.off(t,r);return e.useEffect((()=>(s.keyframes.on(t,r),a)),i),a},useLiveAction:function(){const t=o(),r=e.useCallback((e=>t.toggleMicro(e)),[t]),n=e.useCallback(((e,r,n=0)=>t.broadcast(e,r,n)),[t]),s=e.useCallback((()=>t.exit()),[t]),i=e.useCallback((e=>t.kick(e)),[t]),a=e.useCallback(((e,r)=>t.forbidMicro(e,r)),[t]),c=e.useCallback(((e,r)=>t.forbidSync(e,r)),[t]),u=e.useCallback((e=>t.getFramesByKey(e)),[t]);return{broadcast:n,exit:s,kick:i,toggleMicro:r,forbidMicro:a,forbidSync:c,sendKeyframe:e.useCallback(((e,r)=>t.sendKeyframe(e,r)),[t]),getFramesByKey:u,setSelfInfo:e.useCallback((e=>t.setSelfInfo(e)),[t]),updateStatus:e.useCallback(((e,r,n,s)=>t.updateStatus(e,r,n,s)),[t])}},useLiveEventCallback:function(t,r,n){const s=o(),i=()=>s.off(t,r),a=n?[s,t].concat(n):[s,t];return e.useEffect((()=>(s.on(t,r),i)),a),i},useReadyState:function(){const t=o(),[r,n]=e.useState(t.readyState);return e.useEffect((()=>{const e=e=>n(e);return t.on("ws.readyStateUpdate",e),()=>t.off("ws.readyStateUpdate",e)}),[t]),r},useRTCAction:function(){const t=o(),r=e.useCallback((e=>t.$RTC.join(e)),[t]);return{join:r,quit:e.useCallback((()=>t.$RTC.quit()),[t]),shock:e.useCallback((()=>t.$RTC.shock()),[t]),toggleMicro:e.useCallback((e=>t.$RTC.toggleMicro(e)),[t]),detectMicro:e.useCallback((()=>t.$RTC.detectMicro()),[t])}},useRTCEventCallback:function(t,r,n){const s=o(),i=()=>s.$RTC.off(t,r),a=n?[s,t].concat(n):[s,t];return e.useEffect((()=>(s.$RTC.on(t,r),i)),a),i},useSelfInfo:function(){const t=o(),[r,n]=e.useState(t.selfInfo||{}),s=e=>n(e);return e.useEffect((()=>(t.on("selfInfoUpdate",s),()=>t.off("selfInfoUpdate",s))),[t]),[r,e.useCallback((async e=>await t.setSelfInfo(e)),[t])]},useSnapshot:function(){const t=o(),[r,n]=e.useState(t.snapshot);return e.useEffect((()=>{const e=e=>n(e);return t.on("keyframes",e),()=>t.off("keyframes",e)})),r},useUserList:function(){const t=o(),[r,n]=e.useState(t.userList),s=e=>n(e);return e.useEffect((()=>(t.on("userListUpdate",s),()=>t.off("userListUpdate",s))),[t]),r},useWebSocketEventCallback:function(t,r,n){const s=o(),i=()=>s.off(t,r),a=n?[s,t].concat(n):[s,t];return e.useEffect((()=>(s.on(t,r),i)),a),i}}}})(),n})()}));
|