视频
This commit is contained in:
Generated
Vendored
+11
@@ -0,0 +1,11 @@
|
||||
export declare class CallManager {
|
||||
private _globalCallPagePath;
|
||||
private _isPageRedirected;
|
||||
init(params: any): Promise<void>;
|
||||
private _watchTUIStore;
|
||||
private _unwatchTUIStore;
|
||||
private _handleCallStatusChange;
|
||||
private _handleCallStatusToCalling;
|
||||
private _handleCallStatusToIdle;
|
||||
destroyed(): Promise<void>;
|
||||
}
|
||||
+133
@@ -0,0 +1,133 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||
};
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.CallManager = void 0;
|
||||
const index_1 = require("../../index");
|
||||
const index_2 = require("../const/index");
|
||||
const index_3 = require("../utils/validate/index");
|
||||
/**
|
||||
* @param {Number} sdkAppID 用户的sdkAppID 必传
|
||||
* @param {String} userID 用户的userID 必传
|
||||
* @param {String} userSig 用户的userSig 必传
|
||||
* @param {String} globalCallPagePath 跳转的路径 必传
|
||||
* @param {ChatSDK} tim tim实例 非必传
|
||||
*/
|
||||
const PREFIX = 'callManager';
|
||||
class CallManager {
|
||||
constructor() {
|
||||
this._globalCallPagePath = '';
|
||||
this._isPageRedirected = false;
|
||||
this._handleCallStatusChange = (value) => __awaiter(this, void 0, void 0, function* () {
|
||||
switch (value) {
|
||||
case index_2.CallStatus.CALLING:
|
||||
case index_2.CallStatus.CONNECTED:
|
||||
this._handleCallStatusToCalling();
|
||||
break;
|
||||
case index_2.CallStatus.IDLE:
|
||||
this._handleCallStatusToIdle();
|
||||
break;
|
||||
}
|
||||
});
|
||||
}
|
||||
init(params) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const { sdkAppID, userID, userSig, globalCallPagePath, tim } = params;
|
||||
if (!globalCallPagePath) {
|
||||
console.error(`${PREFIX} globalCallPagePath Can not be empty!`);
|
||||
return;
|
||||
}
|
||||
;
|
||||
this._globalCallPagePath = globalCallPagePath;
|
||||
try {
|
||||
yield index_1.TUICallKitServer.init({
|
||||
sdkAppID,
|
||||
userID,
|
||||
userSig,
|
||||
tim,
|
||||
});
|
||||
this._watchTUIStore();
|
||||
// 全局监听下,关闭悬浮窗
|
||||
index_1.TUICallKitServer.enableFloatWindow(false);
|
||||
console.log(`${PREFIX} init Ready!`);
|
||||
}
|
||||
catch (error) {
|
||||
console.error(`${PREFIX} init fail!`);
|
||||
}
|
||||
});
|
||||
}
|
||||
// =========================【监听 TUIStore 中的状态】=========================
|
||||
_watchTUIStore() {
|
||||
index_1.TUIStore === null || index_1.TUIStore === void 0 ? void 0 : index_1.TUIStore.watch(index_1.StoreName.CALL, {
|
||||
[index_1.NAME.CALL_STATUS]: this._handleCallStatusChange,
|
||||
}, {
|
||||
notifyRangeWhenWatch: index_1.NAME.MYSELF,
|
||||
});
|
||||
}
|
||||
_unwatchTUIStore() {
|
||||
index_1.TUIStore === null || index_1.TUIStore === void 0 ? void 0 : index_1.TUIStore.unwatch(index_1.StoreName.CALL, {
|
||||
[index_1.NAME.CALL_STATUS]: this._handleCallStatusChange,
|
||||
});
|
||||
}
|
||||
_handleCallStatusToCalling() {
|
||||
if (this._isPageRedirected)
|
||||
return;
|
||||
// @ts-ignore
|
||||
wx.navigateTo({
|
||||
url: `/${this._globalCallPagePath}`,
|
||||
success: () => {
|
||||
this._isPageRedirected = true;
|
||||
},
|
||||
fail: () => {
|
||||
console.error(`${PREFIX} navigateTo fail!`);
|
||||
},
|
||||
complete: () => { },
|
||||
});
|
||||
}
|
||||
_handleCallStatusToIdle() {
|
||||
if (!this._isPageRedirected)
|
||||
return;
|
||||
// @ts-ignore
|
||||
wx.navigateBack({
|
||||
success: () => {
|
||||
this._isPageRedirected = false;
|
||||
},
|
||||
fail: () => {
|
||||
console.error(`${PREFIX} navigateBack fail!`);
|
||||
},
|
||||
complete: () => { },
|
||||
});
|
||||
}
|
||||
// 卸载 callManger
|
||||
destroyed() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
this._globalCallPagePath = '';
|
||||
this._isPageRedirected = false;
|
||||
this._unwatchTUIStore();
|
||||
yield index_1.TUICallKitServer.destroyed();
|
||||
});
|
||||
}
|
||||
}
|
||||
__decorate([
|
||||
(0, index_3.avoidRepeatedCall)(),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [Object]),
|
||||
__metadata("design:returntype", Promise)
|
||||
], CallManager.prototype, "init", null);
|
||||
exports.CallManager = CallManager;
|
||||
Reference in New Issue
Block a user