"use strict"; const common_vendor = require("../../../common/vendor.js"); class CallkitPluginServer { constructor() { common_vendor.R.registerEvent(common_vendor.E.TUILogin.EVENT.LOGIN_STATE_CHANGED, common_vendor.E.TUILogin.EVENT_SUB_KEY.USER_LOGIN_SUCCESS, this); common_vendor.R.registerService(common_vendor.E.TUICalling.SERVICE.NAME, this); common_vendor.R.registerExtension(common_vendor.E.TUIChat.EXTENSION.INPUT_MORE.EXT_ID, this); } /** * Listen for the successful notification of TUILogin.login and then log in with callkit */ onNotifyEvent(eventName, subKey) { if (eventName === common_vendor.E.TUILogin.EVENT.LOGIN_STATE_CHANGED) { let SDKAppID, userID, userSig, context; switch (subKey) { case common_vendor.E.TUILogin.EVENT_SUB_KEY.USER_LOGIN_SUCCESS: context = common_vendor.A.getContext(); SDKAppID = context.SDKAppID; userID = context.userID; userSig = context.userSig; common_vendor.i.$TUICallKit && common_vendor.i.$TUICallKit.login({ SDKAppID, userID, userSig }, (res) => { if (res.code === 0) { console.log("TUICallkit login success!"); common_vendor.i.$TUICallKit.enableFloatWindow(true); } else { console.error(`TUICallkit login failed,${res.msg}`); } }); break; } } } /** * Native plugin callkit implements onGetExtension method */ onGetExtension(extensionID, params) { if (!common_vendor.i.$TUICallKit) { console.warn("请检查原生插件 TencentCloud-TUICallKit 是否已集成"); return []; } if (extensionID === common_vendor.E.TUIChat.EXTENSION.INPUT_MORE.EXT_ID) { const list = []; const voiceCallExtension = { weight: 1e3, text: "语音通话", icon: "https://web.sdk.qcloud.com/component/TUIKit/assets/call.png", data: { name: "voiceCall" }, listener: { onClicked: (options) => { this.setCallExtension(options); } } }; const videoCallExtension = { weight: 900, text: "视频通话", icon: "https://web.sdk.qcloud.com/component/TUIKit/assets/call-video-reverse.svg", data: { name: "videoCall" }, listener: { onClicked: (options) => { this.setCallExtension(options); } } }; if (!(params == null ? void 0 : params.filterVoice)) { list.push(voiceCallExtension); } if (!(params == null ? void 0 : params.filterVideo)) { list.push(videoCallExtension); } return list; } } /** * Native plugin callkit implements onCall method */ onCall(method, params) { if (!common_vendor.i.$TUICallKit) { console.warn("请检查原生插件 TencentCloud-TUICallKit 是否已集成"); return; } if (method === common_vendor.E.TUICalling.SERVICE.METHOD.START_CALL) { const { groupID = void 0, userIDList = [], type, callParams } = params; if (groupID) { common_vendor.i.$TUICallKit.groupCall({ groupID, userIDList, callMediaType: type, callParams }, (res) => { if (res.code === 0) { console.log("TUICallkit groupCall success"); } else { console.error(`TUICallkit groupCall failed,${res.msg}`); } }); } else if (userIDList.length === 1) { common_vendor.i.$TUICallKit.call( { userID: userIDList[0], callMediaType: type, callParams }, (res) => { if (res.code === 0) { console.log("TUICallkit call success"); } else { console.log(`TUICallkit call failed,${res.msg}`); } } ); } } } setCallExtension(options) { const { groupID = void 0, userIDList = [], type, callParams } = options; try { if (groupID) { common_vendor.i.$TUICallKit.groupCall({ groupID, userIDList, callMediaType: type, callParams }, (res) => { if (res.code === 0) { console.log("TUICallkit groupCall success"); } else { console.log(`TUICallkit groupCall failed,${res.msg}`); } }); } else if (userIDList.length === 1) { common_vendor.i.$TUICallKit.call( { userID: userIDList[0], callMediaType: type, callParams }, (res) => { if (res.code === 0) { console.log("TUICallkit call success"); } else { console.log(`TUICallkit call failed,${res.msg}`); } } ); } } catch (error) { common_vendor.i.showToast({ title: "拨打失败!", icon: "error" }); } } } exports.CallkitPluginServer = CallkitPluginServer;