消息
This commit is contained in:
164
unpackage/dist/dev/mp-weixin/TUIKit/plugins/extension-server/callkit.js
vendored
Normal file
164
unpackage/dist/dev/mp-weixin/TUIKit/plugins/extension-server/callkit.js
vendored
Normal file
@@ -0,0 +1,164 @@
|
||||
"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) {
|
||||
common_vendor.index.__f__("log", "at TUIKit/plugins/extension-server/callkit.ts:32", "TUICallkit login success!");
|
||||
common_vendor.i.$TUICallKit.enableFloatWindow(true);
|
||||
} else {
|
||||
common_vendor.index.__f__("error", "at TUIKit/plugins/extension-server/callkit.ts:36", `TUICallkit login failed,${res.msg}`);
|
||||
}
|
||||
});
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Native plugin callkit implements onGetExtension method
|
||||
*/
|
||||
onGetExtension(extensionID, params) {
|
||||
if (!common_vendor.i.$TUICallKit) {
|
||||
common_vendor.index.__f__("warn", "at TUIKit/plugins/extension-server/callkit.ts:49", "请检查原生插件 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) {
|
||||
common_vendor.index.__f__("warn", "at TUIKit/plugins/extension-server/callkit.ts:95", "请检查原生插件 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) {
|
||||
common_vendor.index.__f__("log", "at TUIKit/plugins/extension-server/callkit.ts:108", "TUICallkit groupCall success");
|
||||
} else {
|
||||
common_vendor.index.__f__("error", "at TUIKit/plugins/extension-server/callkit.ts:110", `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) {
|
||||
common_vendor.index.__f__("log", "at TUIKit/plugins/extension-server/callkit.ts:122", "TUICallkit call success");
|
||||
} else {
|
||||
common_vendor.index.__f__("log", "at TUIKit/plugins/extension-server/callkit.ts:124", `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) {
|
||||
common_vendor.index.__f__("log", "at TUIKit/plugins/extension-server/callkit.ts:143", "TUICallkit groupCall success");
|
||||
} else {
|
||||
common_vendor.index.__f__("log", "at TUIKit/plugins/extension-server/callkit.ts:145", `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) {
|
||||
common_vendor.index.__f__("log", "at TUIKit/plugins/extension-server/callkit.ts:158", "TUICallkit call success");
|
||||
} else {
|
||||
common_vendor.index.__f__("log", "at TUIKit/plugins/extension-server/callkit.ts:160", `TUICallkit call failed,${res.msg}`);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
} catch (error) {
|
||||
common_vendor.i.showToast({
|
||||
title: "拨打失败!",
|
||||
icon: "error"
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
exports.CallkitPluginServer = CallkitPluginServer;
|
||||
//# sourceMappingURL=../../../../.sourcemap/mp-weixin/TUIKit/plugins/extension-server/callkit.js.map
|
||||
Reference in New Issue
Block a user