pope-test-lite-chat-api
Version:
Tencent Cloud Chat SDK for Web/Mini Program/uni-app/React Native/Donut
3 lines (2 loc) • 3.03 kB
JavaScript
;function e(e,n,t,s){return new(t||(t=Promise))((function(r,o){function i(e){try{c(s.next(e))}catch(e){o(e)}}function a(e){try{c(s.throw(e))}catch(e){o(e)}}function c(e){var n;e.done?r(e.value):(n=e.value,n instanceof t?n:new t((function(e){e(n)}))).then(i,a)}c((s=s.apply(e,n||[])).next())}))}Object.defineProperty(exports,"__esModule",{value:!0}),"function"==typeof SuppressedError&&SuppressedError;const n=new Set(["tui_room_svr.*","callkit_records_svr.*","room_engine_srv.*","room_engine_http_srv.*","room_engine_mic.*","live_engine_srv.*","live_engine_http_srv.*","live_engine_pk.*","trtc_ai_service.*","call_engine_srv.*"]),t="tui_room_svr.*";console.log("business-command-transfer.ts");var s=new class{constructor(){this._transferredCommands=n}install(e){this._core=e;const{notificationCenter:n,InnerEvent:t,helper:s}=e;n.subscribeInnerEvent(t.CLOUD_CONFIG_UPDATE,this._onCloudConfigUpdate,this),n.subscribeInnerEvent(t.LOGOUT,this._reset,this),n.subscribeInnerEvent(t.DESTROY,this._dispose,this),n.subscribeInnerEvent("im_open_push.msg_push",n.InnerEventSubType.BUSINESS_COMMAND,this._onServerPushBusinessCommand,this),s.registerExperimentalAPI("sendTRTCCustomData",this,"transferBusinessCommand"),s.registerExperimentalAPI("sendRoomCustomData",this,"transferBusinessCommand")}transferBusinessCommand(n){return e(this,void 0,void 0,(function*(){const s="transferBusinessCommand";try{const{serviceCommand:r=t}=n||{};if(!this._isValidTransferredCommand(r))throw new this._core.helper.ChatError({code:2995,functionName:s});const o=yield function(n,s){return e(this,void 0,void 0,(function*(){const{helper:e,channel:r}=s,{serviceCommand:o=t,data:i}=n||{};let a={};try{a="string"==typeof i?JSON.parse(i):i}catch(e){console.warn(e)}const c=e.generateProtocolData({servcmd:o,data:a}),u=`${c.head.seq}${o}`;return r.sendPacket(c,{requestId:u})}))}(n,this._core);return{code:0,data:o||{}}}catch(e){throw console.warn(e),new this._core.helper.ChatError({code:null==e?void 0:e.errorCode,data:{},functionName:s})}}))}_onCloudConfigUpdate(e={}){try{if("string"!=typeof e.rtc_cmd)return;const n=JSON.parse(e.rtc_cmd);Array.isArray(n)&&(this._transferredCommands=new Set([...this._transferredCommands,...n]))}catch(e){console.log(e)}}_isValidTransferredCommand(e=""){const n=`${null==e?void 0:e.split(".")[0]}.*`;return this._transferredCommands.has(n)}_onServerPushBusinessCommand(e){const{OuterEvent:n,notificationCenter:t}=this._core,{MsgContent:s}=e||{},{ROOM_CUSTOM_DATA_RECEIVED:r}=n;t.emitOuterEvent(r,{name:r,data:s})}_reset(){this._transferredCommands=n}_dispose(){const{notificationCenter:e,InnerEvent:n}=this._core;this._reset(),e.unSubscribeInnerEvent(n.CLOUD_CONFIG_UPDATE,this._onCloudConfigUpdate,this),e.unSubscribeInnerEvent(n.LOGOUT,this._reset,this),e.unSubscribeInnerEvent(n.DESTROY,this._dispose,this),e.unSubscribeInnerEvent("im_open_push.msg_push",e.InnerEventSubType.BUSINESS_COMMAND,this._onServerPushBusinessCommand,this)}};exports.default=s;
//# sourceMappingURL=business-command-transfer.js.map