@zegocloud/zego-uikit-prebuilt 1.8.5 → 1.8.7

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zegocloud/zego-uikit-prebuilt",
3
- "version": "1.8.5",
3
+ "version": "1.8.7",
4
4
  "description": "zegocloud prebuilt meeting webrtc sdk",
5
5
  "keywords": [
6
6
  "sdk",
@@ -2288,7 +2288,7 @@ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpac
2288
2288
  /***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
2289
2289
 
2290
2290
  "use strict";
2291
- eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"ZimManager\": function() { return /* binding */ ZimManager; }\n/* harmony export */ });\n/* harmony import */ var _model__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../model */ \"./src/sdk/model/index.ts\");\n/* harmony import */ var _view_pages_ZegoCallInvitation_callInvitationControl__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../view/pages/ZegoCallInvitation/callInvitationControl */ \"./src/sdk/view/pages/ZegoCallInvitation/callInvitationControl.tsx\");\n/* harmony import */ var _InRoomInviteManager__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./InRoomInviteManager */ \"./src/sdk/modules/tools/InRoomInviteManager.ts\");\nvar __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {\n function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\n return new (P || (P = Promise))(function (resolve, reject) {\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\n function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\n step((generator = generator.apply(thisArg, _arguments || [])).next());\n });\n};\n\n\n\nclass ZimManager {\n constructor(ZIM, expressConfig) {\n this._inRoomInviteMg = {};\n this.isLogin = false;\n this.isServiceActivated = true; //IM 服务是否开通\n this.callInfo = {};\n this.inSendOperation = false; //防止重复点击\n this.inRefuseOperation = false; //防止重复点击\n this.inAcceptOperation = false; //防止重复点击\n this.inCancelOperation = false; //防止重复点击\n this.config = {\n enableCustomCallInvitationWaitingPage: false,\n enableCustomCallInvitationDialog: false,\n enableNotifyWhenAppRunningInBackgroundOrQuit: false,\n };\n this.hostID = \"\";\n this.incomingTimer = null;\n this.outgoingTimer = null;\n this.notifyJoinRoomCallback = () => { };\n this.notifyLeaveRoomCallback = (reason) => { };\n this.onUpdateRoomIDCallback = () => { };\n this.onRoomTextMessageCallback = (msgs) => { };\n // @ts-ignore\n this._zim = ZIM.create({ appID: expressConfig.appID }) || ZIM.getInstance();\n this._inRoomInviteMg = new _InRoomInviteManager__WEBPACK_IMPORTED_MODULE_2__[\"default\"](this._zim, expressConfig);\n this.expressConfig = expressConfig;\n this.initListener();\n this.login();\n }\n login(retryTime = 1) {\n return __awaiter(this, void 0, void 0, function* () {\n console.warn(\"retryTime\", retryTime);\n if (retryTime > 4) {\n console.error(\"【ZEGOCLOUD】zim login failed, retryTime \", retryTime);\n return;\n }\n this._zim.login({\n userID: this.expressConfig.userID,\n userName: this.expressConfig.userName,\n }, this.expressConfig.token)\n .then(() => {\n // 登录成功\n console.warn(\"zim login success!!\");\n this.isLogin = true;\n })\n .catch((err) => {\n // 登录失败\n this.isLogin = false;\n console.error(\"【ZEGOCLOUD】zim login failed !!\", err);\n if (err.code === 6000014) {\n this.isServiceActivated = false;\n return;\n }\n if (err.code === 6000111) {\n return;\n }\n setTimeout(() => {\n this.login(++retryTime);\n }, 2000 * retryTime);\n });\n });\n }\n initListener() {\n var _a, _b;\n // 被邀请者收到邀请后的回调通知(被邀请者)\n this._zim.on(\"callInvitationReceived\", (zim, { callID, inviter, timeout, extendedData }) => {\n var _a, _b, _c, _d;\n console.warn(\"callInvitationReceived\", {\n callID,\n inviter,\n timeout,\n extendedData,\n });\n const { type } = JSON.parse(extendedData);\n if (type > _model__WEBPACK_IMPORTED_MODULE_0__.ZegoInvitationType.VideoCall) {\n this._inRoomInviteMg.onCallInvitationReceived(callID, inviter, timeout, extendedData);\n }\n else {\n if (this.callInfo.callID) {\n // 如果已被邀请,就拒绝其他的\n callID !== this.callInfo.callID &&\n this.refuseInvitation(\"busy\", callID);\n }\n else {\n const { inviter_name, type, data } = JSON.parse(extendedData);\n const { call_id, invitees, custom_data } = JSON.parse(data);\n this.callInfo = {\n callID,\n invitees: invitees.map((i) => ({\n userID: i.user_id,\n userName: i.user_name,\n })),\n inviter: {\n userID: inviter,\n userName: inviter_name,\n },\n acceptedInvitees: [],\n roomID: call_id,\n type: type,\n isGroupCall: invitees.length > 1,\n };\n this.onUpdateRoomIDCallback();\n // 设置来电计时器,当断网等收不到消息时以超时为由结束call\n if (this.incomingTimer) {\n this.clearIncomingTimer();\n }\n else {\n this.incomingTimer = setTimeout(() => {\n if (this.callInfo.callID) {\n this.config.onIncomingCallTimeout &&\n this.config.onIncomingCallTimeout(this.callInfo.roomID, this.callInfo.inviter);\n _view_pages_ZegoCallInvitation_callInvitationControl__WEBPACK_IMPORTED_MODULE_1__.callInvitationControl.callInvitationDialogHide();\n this.endCall(_model__WEBPACK_IMPORTED_MODULE_0__.CallInvitationEndReason.Timeout);\n }\n this.clearIncomingTimer();\n }, (timeout + 1) * 1000);\n }\n if (!this.config.enableCustomCallInvitationDialog) {\n // 展示默认UI\n _view_pages_ZegoCallInvitation_callInvitationControl__WEBPACK_IMPORTED_MODULE_1__.callInvitationControl.callInvitationDialogShow({ userID: inviter, userName: inviter_name }, () => {\n this.clearIncomingTimer();\n this.refuseInvitation(\"decline\");\n _view_pages_ZegoCallInvitation_callInvitationControl__WEBPACK_IMPORTED_MODULE_1__.callInvitationControl.callInvitationDialogHide();\n this.endCall(_model__WEBPACK_IMPORTED_MODULE_0__.CallInvitationEndReason.Declined);\n }, () => {\n this.clearIncomingTimer();\n this.acceptInvitation();\n this.notifyJoinRoomCallback();\n }, (_b = (_a = this.config) === null || _a === void 0 ? void 0 : _a.ringtoneConfig) === null || _b === void 0 ? void 0 : _b.incomingCallUrl);\n }\n // 透传接收到邀请回调\n if (this.config.onIncomingCallReceived) {\n this.config.onIncomingCallReceived(this.callInfo.roomID, this.callInfo.inviter, this.callInfo.type, this.callInfo.invitees);\n }\n // 对外再包一层,不暴露内部逻辑\n const refuse = (data) => {\n this.clearIncomingTimer();\n this.refuseInvitation(\"decline\", \"\", data);\n _view_pages_ZegoCallInvitation_callInvitationControl__WEBPACK_IMPORTED_MODULE_1__.callInvitationControl.callInvitationDialogHide();\n this.endCall(_model__WEBPACK_IMPORTED_MODULE_0__.CallInvitationEndReason.Declined);\n };\n const accept = (data) => {\n this.clearIncomingTimer();\n this.acceptInvitation(data);\n this.notifyJoinRoomCallback();\n };\n (_d = (_c = this.config) === null || _c === void 0 ? void 0 : _c.onConfirmDialogWhenReceiving) === null || _d === void 0 ? void 0 : _d.call(_c, type, { userID: inviter, userName: inviter_name }, (data) => {\n refuse(data);\n }, (data) => {\n accept(data);\n }, custom_data);\n }\n }\n });\n // 被邀请者收到邀请被取消后的回调通知(被邀请者)\n this._zim.on(\"callInvitationCancelled\", (zim, { callID, inviter, extendedData }) => {\n console.warn(\"callInvitationCancelled\", {\n callID,\n inviter,\n extendedData,\n });\n this._inRoomInviteMg.onCallInvitationCanceled(callID, inviter, extendedData);\n if (!this.callInfo.callID)\n return;\n // 透传取消呼叫事件\n if (this.config.onIncomingCallCanceled) {\n this.config.onIncomingCallCanceled(this.callInfo.roomID, this.callInfo.inviter);\n }\n this.clearIncomingTimer();\n _view_pages_ZegoCallInvitation_callInvitationControl__WEBPACK_IMPORTED_MODULE_1__.callInvitationControl.callInvitationDialogHide();\n this.endCall(_model__WEBPACK_IMPORTED_MODULE_0__.CallInvitationEndReason.Canceled);\n });\n // 邀请者的邀请被接受后的回调通知(邀请者)\n this._zim.on(\"callInvitationAccepted\", (zim, { callID, invitee, extendedData }) => {\n console.warn(\"callInvitationAccepted\", {\n callID,\n invitee,\n extendedData,\n });\n this._inRoomInviteMg.onCallInvitationAccepted(callID, invitee, extendedData);\n if (!this.callInfo.callID)\n return;\n this.clearOutgoingTimer();\n this.callInfo.acceptedInvitees.push({\n userID: invitee,\n userName: \"\",\n });\n if (!this.callInfo.isGroupCall) {\n _view_pages_ZegoCallInvitation_callInvitationControl__WEBPACK_IMPORTED_MODULE_1__.callInvitationControl.callInvitationWaitingPageHide();\n this.notifyJoinRoomCallback();\n }\n // 透传接受邀请事件\n if (this.config.onOutgoingCallAccepted) {\n const callee = this.callInfo.invitees.find((i) => i.userID === invitee) || { userID: invitee };\n this.config.onOutgoingCallAccepted(this.callInfo.roomID, callee);\n }\n });\n // 邀请者的邀请被拒绝后的回调通知(邀请者)\n this._zim.on(\"callInvitationRejected\", (zim, { callID, invitee, extendedData }) => {\n console.warn(\"callInvitationRejected\", {\n callID,\n invitee,\n extendedData,\n });\n this._inRoomInviteMg.onCallInvitationRefused(callID, invitee, extendedData);\n if (!this.callInfo.callID)\n return;\n let reason;\n if (extendedData.length) {\n const data = JSON.parse(extendedData);\n reason = data.reason;\n }\n // 透传拒绝事件\n const callee = this.callInfo.invitees.find((i) => i.userID === invitee) || { userID: invitee };\n if (reason === \"busy\") {\n this.config.onOutgoingCallRejected &&\n this.config.onOutgoingCallRejected(this.callInfo.roomID, callee);\n }\n else {\n this.config.onOutgoingCallDeclined &&\n this.config.onOutgoingCallDeclined(this.callInfo.roomID, callee);\n }\n if (!this.callInfo.isGroupCall) {\n // 单人邀请,隐藏waitingPage,清除callInfo\n this.clearOutgoingTimer();\n _view_pages_ZegoCallInvitation_callInvitationControl__WEBPACK_IMPORTED_MODULE_1__.callInvitationControl.callInvitationWaitingPageHide();\n this.endCall(reason === \"busy\"\n ? _model__WEBPACK_IMPORTED_MODULE_0__.CallInvitationEndReason.Busy\n : _model__WEBPACK_IMPORTED_MODULE_0__.CallInvitationEndReason.Declined);\n }\n else {\n // 多人邀请,\n // 移除拒绝者\n this.callInfo.invitees = this.callInfo.invitees.filter((i) => i.userID !== invitee);\n if (this.callInfo.invitees.length === 0) {\n // 全部拒绝后需要退出房间\n this.clearOutgoingTimer();\n this.notifyLeaveRoomCallback(_model__WEBPACK_IMPORTED_MODULE_0__.CallInvitationEndReason.Declined);\n }\n }\n });\n //被邀请者响应超时后,“邀请者”收到的回调通知, 超时时间单位:秒(邀请者)\n this._zim.on(\"callInviteesAnsweredTimeout\", (zim, { callID, invitees }) => {\n console.warn(\"callInviteesAnsweredTimeout\", { callID, invitees });\n this._inRoomInviteMg.onCallInviteesAnsweredTimeout(callID, invitees);\n if (!this.callInfo.callID)\n return;\n this.clearOutgoingTimer();\n // 透传超时事件\n if (this.config.onOutgoingCallTimeout) {\n const callees = invitees.map((i) => {\n return (this.callInfo.invitees.find((u) => u.userID === i) || {\n userID: i,\n });\n });\n this.config.onOutgoingCallTimeout(this.callInfo.roomID, callees);\n }\n this.answeredTimeoutCallback(invitees);\n });\n //被邀请者响应超时后,“被邀请者”收到的回调通知, 超时时间单位:秒 (被邀请者)\n this._zim.on(\"callInvitationTimeout\", (zim, { callID }) => {\n console.warn(\"callInvitationTimeout\", { callID });\n this._inRoomInviteMg.onCallInvitationTimeout(callID);\n if (!this.callInfo.callID)\n return;\n // 透传超时事件\n if (this.config.onIncomingCallTimeout) {\n this.config.onIncomingCallTimeout(this.callInfo.roomID, this.callInfo.inviter);\n }\n this.clearIncomingTimer();\n _view_pages_ZegoCallInvitation_callInvitationControl__WEBPACK_IMPORTED_MODULE_1__.callInvitationControl.callInvitationDialogHide();\n this.endCall(_model__WEBPACK_IMPORTED_MODULE_0__.CallInvitationEndReason.Timeout);\n });\n (_a = this._zim) === null || _a === void 0 ? void 0 : _a.on(\"connectionStateChanged\", (zim, data) => {\n console.warn(\"【zim】connectionStateChanged\", data);\n });\n (_b = this._zim) === null || _b === void 0 ? void 0 : _b.on(\"receiveRoomMessage\", (zim, data) => {\n console.warn(\"receiveRoomMessage\", data);\n const textMsgs = data.messageList\n .filter((msg) => msg.type === 1)\n .map((msg) => ({\n messageID: msg.messageID,\n timestamp: msg.timestamp,\n orderKey: msg.orderKey,\n senderUserID: msg.senderUserID,\n text: msg.message,\n }));\n this.onRoomTextMessageCallback &&\n this.onRoomTextMessageCallback(textMsgs);\n });\n }\n answeredTimeoutCallback(invitees) {\n if (!this.callInfo.callID)\n return;\n if (this.callInfo.isGroupCall) {\n // 多人邀请\n this.callInfo.invitees = this.callInfo.invitees.filter((i) => !invitees.find((u) => u === i.userID));\n if (this.callInfo.invitees.length === 0) {\n // 全部超时就退出房间,结束邀请\n this.notifyLeaveRoomCallback(_model__WEBPACK_IMPORTED_MODULE_0__.CallInvitationEndReason.Timeout);\n }\n }\n else {\n _view_pages_ZegoCallInvitation_callInvitationControl__WEBPACK_IMPORTED_MODULE_1__.callInvitationControl.callInvitationWaitingPageHide();\n this.endCall(_model__WEBPACK_IMPORTED_MODULE_0__.CallInvitationEndReason.Timeout);\n }\n }\n sendInvitation(invitees, type, timeout, data, notificationConfig) {\n var _a, _b, _c, _d, _e;\n return __awaiter(this, void 0, void 0, function* () {\n if (this.callInfo.callID)\n return Promise.reject(\"You already have a call invitation!\");\n if (!this.isServiceActivated)\n return Promise.reject(\"The call invitation service has not been activated.\");\n if (this.inSendOperation)\n return Promise.reject(\"send invitation repeat !!\");\n this.inSendOperation = true;\n const inviteesID = invitees.map((i) => i.userID);\n const roomID = `call_${this.expressConfig.userID}_${new Date().getTime()}`;\n const _data = JSON.stringify({\n call_id: roomID,\n invitees: invitees.map((u) => ({\n user_id: u.userID,\n user_name: u.userName,\n })),\n custom_data: data,\n });\n const extendedData = JSON.stringify({\n inviter_name: this.expressConfig.userName,\n type,\n data: _data,\n });\n const config = {\n timeout,\n extendedData,\n };\n // 发送离线消息\n if (this.config.enableNotifyWhenAppRunningInBackgroundOrQuit) {\n const pushConfig = {\n title: (notificationConfig === null || notificationConfig === void 0 ? void 0 : notificationConfig.title) || this.expressConfig.userName,\n content: (notificationConfig === null || notificationConfig === void 0 ? void 0 : notificationConfig.message) ||\n `Incoming ${invitees.length > 1 ? \"group \" : \"\"}${type === 0 ? \"voice\" : \"video\"} call...`,\n payload: extendedData,\n resourcesID: (_a = notificationConfig === null || notificationConfig === void 0 ? void 0 : notificationConfig.resourcesID) !== null && _a !== void 0 ? _a : \"zegouikit_call\",\n };\n config.pushConfig = pushConfig;\n }\n try {\n this.callInfo.callID = new Date().getTime().toString(); //临时生成个id,防止同时呼叫情况\n const res = yield this._zim.callInvite(inviteesID, config);\n const errorInvitees = res.errorInvitees.map((i) => {\n return invitees.find((u) => u.userID === i.userID);\n });\n if (res.errorInvitees.length >= invitees.length) {\n // 全部邀请失败,中断流程\n this.inSendOperation = false;\n this.clearCallInfo();\n return Promise.resolve({ errorInvitees });\n }\n // 过滤掉不在线的用户\n const onlineInvitee = invitees.filter((i) => !res.errorInvitees.find((e) => e.userID === i.userID));\n // 保存邀请信息,进入busy状态\n this.callInfo = {\n callID: res.callID,\n invitees: onlineInvitee,\n inviter: {\n userID: this.expressConfig.userID,\n userName: this.expressConfig.userName,\n },\n acceptedInvitees: [],\n roomID,\n type,\n isGroupCall: invitees.length > 1,\n };\n this.onUpdateRoomIDCallback();\n // 添加定时器,断网等情况导致收不到消息时,当超时处理\n this.outgoingTimer = setTimeout(() => {\n if (this.callInfo.callID) {\n // 透传超时事件\n this.config.onOutgoingCallTimeout &&\n this.config.onOutgoingCallTimeout(this.callInfo.roomID, this.callInfo.invitees);\n // 当超时后,没有一个人接受邀请,则主动退出房间\n !this.callInfo.acceptedInvitees.length &&\n this.answeredTimeoutCallback(onlineInvitee.map((u) => u.userID));\n }\n this.clearOutgoingTimer();\n }, (timeout + 1) * 1000);\n if (invitees.length > 1) {\n // 多人邀请,直接进房\n this.notifyJoinRoomCallback();\n }\n else {\n // 单人邀请,进入等待页\n if (!this.config.enableCustomCallInvitationWaitingPage) {\n _view_pages_ZegoCallInvitation_callInvitationControl__WEBPACK_IMPORTED_MODULE_1__.callInvitationControl.callInvitationWaitingPageShow(invitees[0], type, () => {\n var _a, _b;\n this.cancelInvitation();\n (_b = (_a = this.config) === null || _a === void 0 ? void 0 : _a.onCallInvitationEnded) === null || _b === void 0 ? void 0 : _b.call(_a, _model__WEBPACK_IMPORTED_MODULE_0__.CallInvitationEndReason.Canceled, \"\");\n }, (_c = (_b = this.config) === null || _b === void 0 ? void 0 : _b.ringtoneConfig) === null || _c === void 0 ? void 0 : _c.outgoingCallUrl);\n }\n const cancel = () => {\n var _a, _b;\n this.cancelInvitation();\n (_b = (_a = this.config) === null || _a === void 0 ? void 0 : _a.onCallInvitationEnded) === null || _b === void 0 ? void 0 : _b.call(_a, _model__WEBPACK_IMPORTED_MODULE_0__.CallInvitationEndReason.Canceled, \"\");\n };\n (_e = (_d = this.config) === null || _d === void 0 ? void 0 : _d.onWaitingPageWhenSending) === null || _e === void 0 ? void 0 : _e.call(_d, this.callInfo.type, invitees, () => {\n cancel();\n });\n }\n this.inSendOperation = false;\n return Promise.resolve({ errorInvitees });\n }\n catch (error) {\n this.clearCallInfo();\n this.inSendOperation = false;\n return Promise.reject(JSON.stringify(error));\n }\n });\n }\n cancelInvitation(data) {\n var _a;\n return __awaiter(this, void 0, void 0, function* () {\n if (this.inCancelOperation)\n return;\n if (!this.callInfo.callID)\n return;\n this.inCancelOperation = true;\n this.clearOutgoingTimer();\n const invitees = this.callInfo.invitees.map((i) => i.userID);\n const extendedData = {};\n if (data) {\n extendedData.custom_data = data;\n }\n try {\n yield ((_a = this._zim) === null || _a === void 0 ? void 0 : _a.callCancel(invitees, this.callInfo.callID, {\n extendedData: JSON.stringify(extendedData),\n }));\n _view_pages_ZegoCallInvitation_callInvitationControl__WEBPACK_IMPORTED_MODULE_1__.callInvitationControl.callInvitationWaitingPageHide();\n this.clearCallInfo();\n }\n catch (error) {\n console.error(\"【ZEGOCLOUD】cancelInvitation\", error);\n }\n this.inCancelOperation = false;\n });\n }\n refuseInvitation(reason, callID, data) {\n var _a;\n return __awaiter(this, void 0, void 0, function* () {\n if (this.inRefuseOperation)\n return;\n if (!this.callInfo.callID)\n return;\n this.inRefuseOperation = true;\n const extendedData = {};\n if (data) {\n extendedData.custom_data = data;\n }\n if (reason) {\n extendedData.reason = reason;\n }\n try {\n yield ((_a = this._zim) === null || _a === void 0 ? void 0 : _a.callReject(callID || this.callInfo.callID, {\n extendedData: JSON.stringify(extendedData),\n }));\n }\n catch (error) {\n console.error(\"【ZEGOCLOUD】refuseInvitation\", error);\n }\n this.inRefuseOperation = false;\n });\n }\n acceptInvitation(data) {\n var _a;\n return __awaiter(this, void 0, void 0, function* () {\n if (this.inAcceptOperation)\n return;\n if (!this.callInfo.callID)\n return;\n this.inAcceptOperation = true;\n const extendedData = {};\n if (data) {\n extendedData.custom_data = data;\n }\n try {\n yield ((_a = this._zim) === null || _a === void 0 ? void 0 : _a.callAccept(this.callInfo.callID, {\n extendedData: JSON.stringify(extendedData),\n }));\n _view_pages_ZegoCallInvitation_callInvitationControl__WEBPACK_IMPORTED_MODULE_1__.callInvitationControl.callInvitationDialogHide();\n }\n catch (error) {\n console.error(\"【ZEGOCLOUD】acceptInvitation\", error);\n }\n this.inAcceptOperation = false;\n });\n }\n clearCallInfo() {\n this.callInfo = {};\n }\n destroy() {\n var _a;\n (_a = this._zim) === null || _a === void 0 ? void 0 : _a.destroy();\n this._zim = null;\n }\n /** 通知UI层调用joinRoom */\n notifyJoinRoom(func) {\n func &&\n (this.notifyJoinRoomCallback = () => {\n var _a, _b;\n // 接收客户传递进来的roomConfig\n const roomConfig = ((_b = (_a = this.config) === null || _a === void 0 ? void 0 : _a.onSetRoomConfigBeforeJoining) === null || _b === void 0 ? void 0 : _b.call(_a, this.callInfo.type)) || {};\n func(this.callInfo.type, roomConfig, this.callInfo.isGroupCall\n ? _model__WEBPACK_IMPORTED_MODULE_0__.ScenarioModel.GroupCall\n : _model__WEBPACK_IMPORTED_MODULE_0__.ScenarioModel.OneONoneCall);\n });\n }\n /** 通知UI层调用leaveRoom */\n notifyLeaveRoom(func) {\n this.notifyLeaveRoomCallback = (reason) => {\n func && func();\n this.endCall(reason);\n };\n }\n /**收到邀请后需要更新roomID*/\n onUpdateRoomID(func) {\n func &&\n (this.onUpdateRoomIDCallback = () => {\n func(this.callInfo.roomID);\n this.expressConfig.roomID = this.callInfo.roomID;\n });\n }\n /**结束 call,清除 callInfo */\n endCall(reason) {\n var _a, _b;\n if (reason === _model__WEBPACK_IMPORTED_MODULE_0__.CallInvitationEndReason.LeaveRoom &&\n !this.callInfo.acceptedInvitees.length &&\n this.callInfo.inviter.userID === this.expressConfig.userID) {\n // 主叫人如果在所有人接收邀请前离开房间,则取消所有人的邀请\n this.cancelInvitation();\n }\n (_b = (_a = this.config) === null || _a === void 0 ? void 0 : _a.onCallInvitationEnded) === null || _b === void 0 ? void 0 : _b.call(_a, reason, \"\");\n this.clearCallInfo();\n }\n setCallInvitationConfig(config) {\n this.config = Object.assign(this.config, config);\n }\n clearOutgoingTimer() {\n if (this.outgoingTimer) {\n clearTimeout(this.outgoingTimer);\n this.outgoingTimer = null;\n }\n }\n clearIncomingTimer() {\n if (this.incomingTimer) {\n clearTimeout(this.incomingTimer);\n this.incomingTimer = null;\n }\n }\n onRoomTextMessage(func) {\n this.onRoomTextMessageCallback = func;\n }\n enterRoom() {\n var _a;\n if (this.isLogin) {\n (_a = this._zim) === null || _a === void 0 ? void 0 : _a.enterRoom({\n roomID: this.callInfo.callID || this.expressConfig.roomID,\n roomName: this.callInfo.callID || this.expressConfig.roomID,\n }).then((res) => {\n console.warn(\"【zim enterRoom】success\");\n }).catch((error) => {\n console.error(\"【zim enterRoom】failed\", error);\n });\n }\n }\n leaveRoom() {\n var _a;\n (_a = this._zim) === null || _a === void 0 ? void 0 : _a.leaveRoom(this.callInfo.callID || this.expressConfig.roomID).then((res) => {\n console.warn(\"【zim leaveRoom】success\");\n }).catch((error) => {\n console.error(\"【zim leaveRoom】failed\", error);\n });\n }\n}\n\n\n//# sourceURL=webpack://zegocloud_client_sdk_web/./src/sdk/modules/tools/ZimManager.ts?");
2291
+ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"ZimManager\": function() { return /* binding */ ZimManager; }\n/* harmony export */ });\n/* harmony import */ var _model__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../model */ \"./src/sdk/model/index.ts\");\n/* harmony import */ var _view_pages_ZegoCallInvitation_callInvitationControl__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../view/pages/ZegoCallInvitation/callInvitationControl */ \"./src/sdk/view/pages/ZegoCallInvitation/callInvitationControl.tsx\");\n/* harmony import */ var _InRoomInviteManager__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./InRoomInviteManager */ \"./src/sdk/modules/tools/InRoomInviteManager.ts\");\nvar __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {\n function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\n return new (P || (P = Promise))(function (resolve, reject) {\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\n function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\n step((generator = generator.apply(thisArg, _arguments || [])).next());\n });\n};\n\n\n\nclass ZimManager {\n constructor(ZIM, expressConfig) {\n this._inRoomInviteMg = {};\n this.isLogin = false;\n this.isServiceActivated = true; //IM 服务是否开通\n this.callInfo = {};\n this.inSendOperation = false; //防止重复点击\n this.inRefuseOperation = false; //防止重复点击\n this.inAcceptOperation = false; //防止重复点击\n this.inCancelOperation = false; //防止重复点击\n this.config = {\n enableCustomCallInvitationWaitingPage: false,\n enableCustomCallInvitationDialog: false,\n enableNotifyWhenAppRunningInBackgroundOrQuit: false,\n };\n this.hostID = \"\";\n this.incomingTimer = null;\n this.outgoingTimer = null;\n this.notifyJoinRoomCallback = () => { };\n this.notifyLeaveRoomCallback = (reason) => { };\n this.onUpdateRoomIDCallback = () => { };\n this.onRoomTextMessageCallback = (msgs) => { };\n // @ts-ignore\n this._zim = ZIM.create({ appID: expressConfig.appID }) || ZIM.getInstance();\n this._inRoomInviteMg = new _InRoomInviteManager__WEBPACK_IMPORTED_MODULE_2__[\"default\"](this._zim, expressConfig);\n this.expressConfig = expressConfig;\n this.initListener();\n this.login();\n }\n login(retryTime = 1) {\n return __awaiter(this, void 0, void 0, function* () {\n console.warn(\"retryTime\", retryTime);\n if (retryTime > 4) {\n console.error(\"【ZEGOCLOUD】zim login failed, retryTime \", retryTime);\n return;\n }\n this._zim.login({\n userID: this.expressConfig.userID,\n userName: this.expressConfig.userName,\n }, this.expressConfig.token)\n .then(() => {\n // 登录成功\n console.warn(\"zim login success!!\");\n this.isLogin = true;\n })\n .catch((err) => {\n // 登录失败\n this.isLogin = false;\n console.error(\"【ZEGOCLOUD】zim login failed !!\", err);\n if (err.code === 6000014) {\n this.isServiceActivated = false;\n return;\n }\n if (err.code === 6000111) {\n return;\n }\n setTimeout(() => {\n this.login(++retryTime);\n }, 2000 * retryTime);\n });\n });\n }\n initListener() {\n var _a, _b;\n // 被邀请者收到邀请后的回调通知(被邀请者)\n this._zim.on(\"callInvitationReceived\", (zim, { callID, inviter, timeout, extendedData }) => {\n var _a, _b, _c, _d;\n console.warn(\"callInvitationReceived\", {\n callID,\n inviter,\n timeout,\n extendedData,\n });\n const { type } = JSON.parse(extendedData);\n if (type > _model__WEBPACK_IMPORTED_MODULE_0__.ZegoInvitationType.VideoCall) {\n this._inRoomInviteMg.onCallInvitationReceived(callID, inviter, timeout, extendedData);\n }\n else {\n if (this.callInfo.callID) {\n // 如果已被邀请,就拒绝其他的\n callID !== this.callInfo.callID &&\n this.refuseInvitation(\"busy\", callID);\n }\n else {\n const { inviter_name, type, data } = JSON.parse(extendedData);\n const { call_id, invitees, custom_data } = JSON.parse(data);\n this.callInfo = {\n callID,\n invitees: invitees.map((i) => ({\n userID: i.user_id,\n userName: i.user_name,\n })),\n inviter: {\n userID: inviter,\n userName: inviter_name,\n },\n acceptedInvitees: [],\n roomID: call_id,\n type: type,\n isGroupCall: invitees.length > 1,\n };\n this.onUpdateRoomIDCallback();\n // 设置来电计时器,当断网等收不到消息时以超时为由结束call\n if (this.incomingTimer) {\n this.clearIncomingTimer();\n }\n else {\n this.incomingTimer = setTimeout(() => {\n if (this.callInfo.callID) {\n this.config.onIncomingCallTimeout &&\n this.config.onIncomingCallTimeout(this.callInfo.roomID, this.callInfo.inviter);\n _view_pages_ZegoCallInvitation_callInvitationControl__WEBPACK_IMPORTED_MODULE_1__.callInvitationControl.callInvitationDialogHide();\n this.endCall(_model__WEBPACK_IMPORTED_MODULE_0__.CallInvitationEndReason.Timeout);\n }\n this.clearIncomingTimer();\n }, (timeout + 1) * 1000);\n }\n if (!this.config.enableCustomCallInvitationDialog) {\n // 展示默认UI\n _view_pages_ZegoCallInvitation_callInvitationControl__WEBPACK_IMPORTED_MODULE_1__.callInvitationControl.callInvitationDialogShow({ userID: inviter, userName: inviter_name }, () => {\n this.clearIncomingTimer();\n this.refuseInvitation(\"decline\");\n _view_pages_ZegoCallInvitation_callInvitationControl__WEBPACK_IMPORTED_MODULE_1__.callInvitationControl.callInvitationDialogHide();\n this.endCall(_model__WEBPACK_IMPORTED_MODULE_0__.CallInvitationEndReason.Declined);\n }, () => {\n this.clearIncomingTimer();\n this.acceptInvitation();\n this.notifyJoinRoomCallback();\n }, (_b = (_a = this.config) === null || _a === void 0 ? void 0 : _a.ringtoneConfig) === null || _b === void 0 ? void 0 : _b.incomingCallUrl);\n }\n // 透传接收到邀请回调\n if (this.config.onIncomingCallReceived) {\n this.config.onIncomingCallReceived(this.callInfo.roomID, this.callInfo.inviter, this.callInfo.type, this.callInfo.invitees);\n }\n // 对外再包一层,不暴露内部逻辑\n const refuse = (data) => {\n this.clearIncomingTimer();\n this.refuseInvitation(\"decline\", \"\", data);\n _view_pages_ZegoCallInvitation_callInvitationControl__WEBPACK_IMPORTED_MODULE_1__.callInvitationControl.callInvitationDialogHide();\n this.endCall(_model__WEBPACK_IMPORTED_MODULE_0__.CallInvitationEndReason.Declined);\n };\n const accept = (data) => {\n this.clearIncomingTimer();\n this.acceptInvitation(data);\n this.notifyJoinRoomCallback();\n };\n (_d = (_c = this.config) === null || _c === void 0 ? void 0 : _c.onConfirmDialogWhenReceiving) === null || _d === void 0 ? void 0 : _d.call(_c, type, { userID: inviter, userName: inviter_name }, (data) => {\n refuse(data);\n }, (data) => {\n accept(data);\n }, custom_data);\n }\n }\n });\n // 被邀请者收到邀请被取消后的回调通知(被邀请者)\n this._zim.on(\"callInvitationCancelled\", (zim, { callID, inviter, extendedData }) => {\n console.warn(\"callInvitationCancelled\", {\n callID,\n inviter,\n extendedData,\n });\n this._inRoomInviteMg.onCallInvitationCanceled(callID, inviter, extendedData);\n if (!this.callInfo.callID)\n return;\n // 透传取消呼叫事件\n if (this.config.onIncomingCallCanceled) {\n this.config.onIncomingCallCanceled(this.callInfo.roomID, this.callInfo.inviter);\n }\n this.clearIncomingTimer();\n _view_pages_ZegoCallInvitation_callInvitationControl__WEBPACK_IMPORTED_MODULE_1__.callInvitationControl.callInvitationDialogHide();\n this.endCall(_model__WEBPACK_IMPORTED_MODULE_0__.CallInvitationEndReason.Canceled);\n });\n // 邀请者的邀请被接受后的回调通知(邀请者)\n this._zim.on(\"callInvitationAccepted\", (zim, { callID, invitee, extendedData }) => {\n console.warn(\"callInvitationAccepted\", {\n callID,\n invitee,\n extendedData,\n });\n this._inRoomInviteMg.onCallInvitationAccepted(callID, invitee, extendedData);\n if (!this.callInfo.callID)\n return;\n this.clearOutgoingTimer();\n this.callInfo.acceptedInvitees.push({\n userID: invitee,\n userName: \"\",\n });\n if (!this.callInfo.isGroupCall) {\n _view_pages_ZegoCallInvitation_callInvitationControl__WEBPACK_IMPORTED_MODULE_1__.callInvitationControl.callInvitationWaitingPageHide();\n this.notifyJoinRoomCallback();\n }\n // 透传接受邀请事件\n if (this.config.onOutgoingCallAccepted) {\n const callee = this.callInfo.invitees.find((i) => i.userID === invitee) || { userID: invitee };\n this.config.onOutgoingCallAccepted(this.callInfo.roomID, callee);\n }\n });\n // 邀请者的邀请被拒绝后的回调通知(邀请者)\n this._zim.on(\"callInvitationRejected\", (zim, { callID, invitee, extendedData }) => {\n console.warn(\"callInvitationRejected\", {\n callID,\n invitee,\n extendedData,\n });\n this._inRoomInviteMg.onCallInvitationRefused(callID, invitee, extendedData);\n if (!this.callInfo.callID)\n return;\n let reason;\n if (extendedData.length) {\n const data = JSON.parse(extendedData);\n reason = data.reason;\n }\n // 透传拒绝事件\n const callee = this.callInfo.invitees.find((i) => i.userID === invitee) || { userID: invitee };\n if (reason === \"busy\") {\n this.config.onOutgoingCallRejected &&\n this.config.onOutgoingCallRejected(this.callInfo.roomID, callee);\n }\n else {\n this.config.onOutgoingCallDeclined &&\n this.config.onOutgoingCallDeclined(this.callInfo.roomID, callee);\n }\n if (!this.callInfo.isGroupCall) {\n // 单人邀请,隐藏waitingPage,清除callInfo\n this.clearOutgoingTimer();\n _view_pages_ZegoCallInvitation_callInvitationControl__WEBPACK_IMPORTED_MODULE_1__.callInvitationControl.callInvitationWaitingPageHide();\n this.endCall(reason === \"busy\"\n ? _model__WEBPACK_IMPORTED_MODULE_0__.CallInvitationEndReason.Busy\n : _model__WEBPACK_IMPORTED_MODULE_0__.CallInvitationEndReason.Declined);\n }\n else {\n // 多人邀请,\n // 移除拒绝者\n this.callInfo.invitees = this.callInfo.invitees.filter((i) => i.userID !== invitee);\n if (this.callInfo.invitees.length === 0) {\n // 全部拒绝后需要退出房间\n this.clearOutgoingTimer();\n this.notifyLeaveRoomCallback(_model__WEBPACK_IMPORTED_MODULE_0__.CallInvitationEndReason.Declined);\n }\n }\n });\n //被邀请者响应超时后,“邀请者”收到的回调通知, 超时时间单位:秒(邀请者)\n this._zim.on(\"callInviteesAnsweredTimeout\", (zim, { callID, invitees }) => {\n console.warn(\"callInviteesAnsweredTimeout\", { callID, invitees });\n this._inRoomInviteMg.onCallInviteesAnsweredTimeout(callID, invitees);\n if (!this.callInfo.callID)\n return;\n this.clearOutgoingTimer();\n // 透传超时事件\n if (this.config.onOutgoingCallTimeout) {\n const callees = invitees.map((i) => {\n return (this.callInfo.invitees.find((u) => u.userID === i) || {\n userID: i,\n });\n });\n this.config.onOutgoingCallTimeout(this.callInfo.roomID, callees);\n }\n this.answeredTimeoutCallback(invitees);\n });\n //被邀请者响应超时后,“被邀请者”收到的回调通知, 超时时间单位:秒 (被邀请者)\n this._zim.on(\"callInvitationTimeout\", (zim, { callID }) => {\n console.warn(\"callInvitationTimeout\", { callID });\n this._inRoomInviteMg.onCallInvitationTimeout(callID);\n if (!this.callInfo.callID)\n return;\n // 透传超时事件\n if (this.config.onIncomingCallTimeout) {\n this.config.onIncomingCallTimeout(this.callInfo.roomID, this.callInfo.inviter);\n }\n this.clearIncomingTimer();\n _view_pages_ZegoCallInvitation_callInvitationControl__WEBPACK_IMPORTED_MODULE_1__.callInvitationControl.callInvitationDialogHide();\n this.endCall(_model__WEBPACK_IMPORTED_MODULE_0__.CallInvitationEndReason.Timeout);\n });\n (_a = this._zim) === null || _a === void 0 ? void 0 : _a.on(\"connectionStateChanged\", (zim, data) => {\n console.warn(\"【zim】connectionStateChanged\", data);\n });\n (_b = this._zim) === null || _b === void 0 ? void 0 : _b.on(\"receiveRoomMessage\", (zim, data) => {\n console.warn(\"receiveRoomMessage\", data);\n const textMsgs = data.messageList\n .filter((msg) => msg.type === 1)\n .map((msg) => ({\n messageID: msg.messageID,\n timestamp: msg.timestamp,\n orderKey: msg.orderKey,\n senderUserID: msg.senderUserID,\n text: msg.message,\n }));\n this.onRoomTextMessageCallback &&\n this.onRoomTextMessageCallback(textMsgs);\n });\n }\n answeredTimeoutCallback(invitees) {\n if (!this.callInfo.callID)\n return;\n if (this.callInfo.isGroupCall) {\n // 多人邀请\n this.callInfo.invitees = this.callInfo.invitees.filter((i) => !invitees.find((u) => u === i.userID));\n if (this.callInfo.invitees.length === 0) {\n // 全部超时就退出房间,结束邀请\n this.notifyLeaveRoomCallback(_model__WEBPACK_IMPORTED_MODULE_0__.CallInvitationEndReason.Timeout);\n }\n }\n else {\n _view_pages_ZegoCallInvitation_callInvitationControl__WEBPACK_IMPORTED_MODULE_1__.callInvitationControl.callInvitationWaitingPageHide();\n this.endCall(_model__WEBPACK_IMPORTED_MODULE_0__.CallInvitationEndReason.Timeout);\n }\n }\n sendInvitation(invitees, type, timeout, data, notificationConfig) {\n var _a, _b, _c, _d, _e;\n return __awaiter(this, void 0, void 0, function* () {\n if (this.callInfo.callID)\n return Promise.reject(\"You already have a call invitation!\");\n if (!this.isServiceActivated)\n return Promise.reject(\"The call invitation service has not been activated.\");\n if (this.inSendOperation)\n return Promise.reject(\"send invitation repeat !!\");\n this.inSendOperation = true;\n const inviteesID = invitees.map((i) => i.userID);\n const roomID = `call_${this.expressConfig.userID}_${new Date().getTime()}`;\n const _data = {\n call_id: roomID,\n invitees: invitees.map((u) => ({\n user_id: u.userID,\n user_name: u.userName,\n })),\n inviter: {\n id: this.expressConfig.userID,\n name: this.expressConfig.userName,\n },\n type,\n custom_data: data,\n };\n const extendedData = {\n inviter_name: this.expressConfig.userName,\n type,\n data: JSON.stringify(_data),\n };\n const config = {\n timeout,\n extendedData: JSON.stringify(extendedData),\n };\n // 发送离线消息\n if (this.config.enableNotifyWhenAppRunningInBackgroundOrQuit) {\n const pushConfig = {\n title: (notificationConfig === null || notificationConfig === void 0 ? void 0 : notificationConfig.title) || this.expressConfig.userName,\n content: (notificationConfig === null || notificationConfig === void 0 ? void 0 : notificationConfig.message) ||\n `Incoming ${invitees.length > 1 ? \"group \" : \"\"}${type === 0 ? \"voice\" : \"video\"} call...`,\n payload: JSON.stringify(Object.assign({}, _data, extendedData)),\n resourcesID: (_a = notificationConfig === null || notificationConfig === void 0 ? void 0 : notificationConfig.resourcesID) !== null && _a !== void 0 ? _a : \"zegouikit_call\",\n };\n config.pushConfig = pushConfig;\n }\n try {\n this.callInfo.callID = new Date().getTime().toString(); //临时生成个id,防止同时呼叫情况\n const res = yield this._zim.callInvite(inviteesID, config);\n const errorInvitees = res.errorInvitees.map((i) => {\n return invitees.find((u) => u.userID === i.userID);\n });\n if (res.errorInvitees.length >= invitees.length) {\n // 全部邀请失败,中断流程\n this.inSendOperation = false;\n this.clearCallInfo();\n return Promise.resolve({ errorInvitees });\n }\n // 过滤掉不在线的用户\n const onlineInvitee = invitees.filter((i) => !res.errorInvitees.find((e) => e.userID === i.userID));\n // 保存邀请信息,进入busy状态\n this.callInfo = {\n callID: res.callID,\n invitees: onlineInvitee,\n inviter: {\n userID: this.expressConfig.userID,\n userName: this.expressConfig.userName,\n },\n acceptedInvitees: [],\n roomID,\n type,\n isGroupCall: invitees.length > 1,\n };\n this.onUpdateRoomIDCallback();\n // 添加定时器,断网等情况导致收不到消息时,当超时处理\n this.outgoingTimer = setTimeout(() => {\n if (this.callInfo.callID) {\n // 透传超时事件\n this.config.onOutgoingCallTimeout &&\n this.config.onOutgoingCallTimeout(this.callInfo.roomID, this.callInfo.invitees);\n // 当超时后,没有一个人接受邀请,则主动退出房间\n !this.callInfo.acceptedInvitees.length &&\n this.answeredTimeoutCallback(onlineInvitee.map((u) => u.userID));\n }\n this.clearOutgoingTimer();\n }, (timeout + 1) * 1000);\n if (invitees.length > 1) {\n // 多人邀请,直接进房\n this.notifyJoinRoomCallback();\n }\n else {\n // 单人邀请,进入等待页\n if (!this.config.enableCustomCallInvitationWaitingPage) {\n _view_pages_ZegoCallInvitation_callInvitationControl__WEBPACK_IMPORTED_MODULE_1__.callInvitationControl.callInvitationWaitingPageShow(invitees[0], type, () => {\n var _a, _b;\n this.cancelInvitation();\n (_b = (_a = this.config) === null || _a === void 0 ? void 0 : _a.onCallInvitationEnded) === null || _b === void 0 ? void 0 : _b.call(_a, _model__WEBPACK_IMPORTED_MODULE_0__.CallInvitationEndReason.Canceled, \"\");\n }, (_c = (_b = this.config) === null || _b === void 0 ? void 0 : _b.ringtoneConfig) === null || _c === void 0 ? void 0 : _c.outgoingCallUrl);\n }\n const cancel = () => {\n var _a, _b;\n this.cancelInvitation();\n (_b = (_a = this.config) === null || _a === void 0 ? void 0 : _a.onCallInvitationEnded) === null || _b === void 0 ? void 0 : _b.call(_a, _model__WEBPACK_IMPORTED_MODULE_0__.CallInvitationEndReason.Canceled, \"\");\n };\n (_e = (_d = this.config) === null || _d === void 0 ? void 0 : _d.onWaitingPageWhenSending) === null || _e === void 0 ? void 0 : _e.call(_d, this.callInfo.type, invitees, () => {\n cancel();\n });\n }\n this.inSendOperation = false;\n return Promise.resolve({ errorInvitees });\n }\n catch (error) {\n this.clearCallInfo();\n this.inSendOperation = false;\n return Promise.reject(JSON.stringify(error));\n }\n });\n }\n cancelInvitation(data) {\n var _a;\n return __awaiter(this, void 0, void 0, function* () {\n if (this.inCancelOperation)\n return;\n if (!this.callInfo.callID)\n return;\n this.inCancelOperation = true;\n this.clearOutgoingTimer();\n const invitees = this.callInfo.invitees.map((i) => i.userID);\n const extendedData = {};\n if (data) {\n extendedData.custom_data = data;\n }\n try {\n yield ((_a = this._zim) === null || _a === void 0 ? void 0 : _a.callCancel(invitees, this.callInfo.callID, {\n extendedData: JSON.stringify(extendedData),\n }));\n _view_pages_ZegoCallInvitation_callInvitationControl__WEBPACK_IMPORTED_MODULE_1__.callInvitationControl.callInvitationWaitingPageHide();\n this.clearCallInfo();\n }\n catch (error) {\n console.error(\"【ZEGOCLOUD】cancelInvitation\", error);\n }\n this.inCancelOperation = false;\n });\n }\n refuseInvitation(reason, callID, data) {\n var _a;\n return __awaiter(this, void 0, void 0, function* () {\n if (this.inRefuseOperation)\n return;\n if (!this.callInfo.callID)\n return;\n this.inRefuseOperation = true;\n const extendedData = {};\n if (data) {\n extendedData.custom_data = data;\n }\n if (reason) {\n extendedData.reason = reason;\n }\n try {\n yield ((_a = this._zim) === null || _a === void 0 ? void 0 : _a.callReject(callID || this.callInfo.callID, {\n extendedData: JSON.stringify(extendedData),\n }));\n }\n catch (error) {\n console.error(\"【ZEGOCLOUD】refuseInvitation\", error);\n }\n this.inRefuseOperation = false;\n });\n }\n acceptInvitation(data) {\n var _a;\n return __awaiter(this, void 0, void 0, function* () {\n if (this.inAcceptOperation)\n return;\n if (!this.callInfo.callID)\n return;\n this.inAcceptOperation = true;\n const extendedData = {};\n if (data) {\n extendedData.custom_data = data;\n }\n try {\n yield ((_a = this._zim) === null || _a === void 0 ? void 0 : _a.callAccept(this.callInfo.callID, {\n extendedData: JSON.stringify(extendedData),\n }));\n _view_pages_ZegoCallInvitation_callInvitationControl__WEBPACK_IMPORTED_MODULE_1__.callInvitationControl.callInvitationDialogHide();\n }\n catch (error) {\n console.error(\"【ZEGOCLOUD】acceptInvitation\", error);\n }\n this.inAcceptOperation = false;\n });\n }\n clearCallInfo() {\n this.callInfo = {};\n }\n destroy() {\n var _a;\n (_a = this._zim) === null || _a === void 0 ? void 0 : _a.destroy();\n this._zim = null;\n }\n /** 通知UI层调用joinRoom */\n notifyJoinRoom(func) {\n func &&\n (this.notifyJoinRoomCallback = () => {\n var _a, _b;\n // 接收客户传递进来的roomConfig\n const roomConfig = ((_b = (_a = this.config) === null || _a === void 0 ? void 0 : _a.onSetRoomConfigBeforeJoining) === null || _b === void 0 ? void 0 : _b.call(_a, this.callInfo.type)) || {};\n func(this.callInfo.type, roomConfig, this.callInfo.isGroupCall\n ? _model__WEBPACK_IMPORTED_MODULE_0__.ScenarioModel.GroupCall\n : _model__WEBPACK_IMPORTED_MODULE_0__.ScenarioModel.OneONoneCall);\n });\n }\n /** 通知UI层调用leaveRoom */\n notifyLeaveRoom(func) {\n this.notifyLeaveRoomCallback = (reason) => {\n func && func();\n this.endCall(reason);\n };\n }\n /**收到邀请后需要更新roomID*/\n onUpdateRoomID(func) {\n func &&\n (this.onUpdateRoomIDCallback = () => {\n func(this.callInfo.roomID);\n this.expressConfig.roomID = this.callInfo.roomID;\n });\n }\n /**结束 call,清除 callInfo */\n endCall(reason) {\n var _a, _b;\n if (reason === _model__WEBPACK_IMPORTED_MODULE_0__.CallInvitationEndReason.LeaveRoom &&\n !this.callInfo.acceptedInvitees.length &&\n this.callInfo.inviter.userID === this.expressConfig.userID) {\n // 主叫人如果在所有人接收邀请前离开房间,则取消所有人的邀请\n this.cancelInvitation();\n }\n (_b = (_a = this.config) === null || _a === void 0 ? void 0 : _a.onCallInvitationEnded) === null || _b === void 0 ? void 0 : _b.call(_a, reason, \"\");\n this.clearCallInfo();\n }\n setCallInvitationConfig(config) {\n this.config = Object.assign(this.config, config);\n }\n clearOutgoingTimer() {\n if (this.outgoingTimer) {\n clearTimeout(this.outgoingTimer);\n this.outgoingTimer = null;\n }\n }\n clearIncomingTimer() {\n if (this.incomingTimer) {\n clearTimeout(this.incomingTimer);\n this.incomingTimer = null;\n }\n }\n onRoomTextMessage(func) {\n this.onRoomTextMessageCallback = func;\n }\n enterRoom() {\n var _a;\n if (this.isLogin) {\n (_a = this._zim) === null || _a === void 0 ? void 0 : _a.enterRoom({\n roomID: this.callInfo.callID || this.expressConfig.roomID,\n roomName: this.callInfo.callID || this.expressConfig.roomID,\n }).then((res) => {\n console.warn(\"【zim enterRoom】success\");\n }).catch((error) => {\n console.error(\"【zim enterRoom】failed\", error);\n });\n }\n }\n leaveRoom() {\n var _a;\n (_a = this._zim) === null || _a === void 0 ? void 0 : _a.leaveRoom(this.callInfo.callID || this.expressConfig.roomID).then((res) => {\n console.warn(\"【zim leaveRoom】success\");\n }).catch((error) => {\n console.error(\"【zim leaveRoom】failed\", error);\n });\n }\n}\n\n\n//# sourceURL=webpack://zegocloud_client_sdk_web/./src/sdk/modules/tools/ZimManager.ts?");
2292
2292
 
2293
2293
  /***/ }),
2294
2294