UNPKG

trtc-electron-sdk

Version:

trtc electron sdk

186 lines (185 loc) 7.73 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.TRTCPluginManager = exports.TRTCPlugin = void 0; const trtc_define_1 = require("../../trtc_define"); const logger_1 = __importDefault(require("../../logger")); const NodeTRTCEngine = require('../../../build/Release/trtc_electron_sdk.node'); /** * TRTC 插件 */ class TRTCPlugin { constructor(pluginId, deviceId, nativeVideoEffectPlugin) { this.logPrefix = "[TRTCPlugin]"; this.pluginId = pluginId; this.device_id = deviceId; this.nativeVideoEffectPlugin = nativeVideoEffectPlugin; } get deviceId() { return this.device_id; } get id() { return this.pluginId; } enable(flag = true) { logger_1.default.log(`${this.logPrefix}enable:${flag} ${this.pluginId}`); this.nativeVideoEffectPlugin.enable(flag); } /** * @deprecated */ disable() { this.enable(false); } setParameter(param) { logger_1.default.log(`${this.logPrefix}setParameter:${this.pluginId}`); this.nativeVideoEffectPlugin.setParameter(param); } } exports.TRTCPlugin = TRTCPlugin; /** * TRTC 插件管理器 */ class TRTCPluginManager { constructor(options) { this.logPrefix = '[TRTCPluginManager]'; this.videoProcessBufferType = trtc_define_1.TRTCVideoBufferType.TRTCVideoBufferType_Buffer; this.videoProcessPixelFormat = trtc_define_1.TRTCVideoPixelFormat.TRTCVideoPixelFormat_I420; this.isIPCMode = options.isIPCMode; if (this.isIPCMode) { this.nodePluginManager = new NodeTRTCEngine.NodeRemoteVideoPluginManager(); } else { this.videoProcessBufferType = trtc_define_1.TRTCVideoBufferType.TRTCVideoBufferType_Buffer; this.videoProcessPixelFormat = trtc_define_1.TRTCVideoPixelFormat.TRTCVideoPixelFormat_I420; this.nodePluginManager = options.nodeTRTCCloud; } } ; destroy() { this.nodePluginManager = null; } setPluginParams(type, options) { logger_1.default.log(`${this.logPrefix}setPluginParams params:`, type, options); if (this.isIPCMode) { if (type === trtc_define_1.TRTCPluginType.TRTCPluginTypeVideoProcess) { this.nodePluginManager.setVideoPluginFormat(trtc_define_1.TRTCVideoBufferType.TRTCVideoBufferType_Buffer, options.pixelFormat); } else { logger_1.default.log(`${this.logPrefix}setPluginParams not supported params:`, type, options); } } else { switch (type) { case trtc_define_1.TRTCPluginType.TRTCPluginTypeVideoProcess: this._setVideoProcessPluginParams(options); break; case trtc_define_1.TRTCPluginType.TRTCPluginTypeMediaEncryptDecrypt: this._setMediaEncryptDecryptPluginParams(options); break; case trtc_define_1.TRTCPluginType.TRTCPluginTypeAudioProcess: this._setAudioProcessPluginParams(options); break; default: logger_1.default.log(`setPluginParams invalid type:${type}`); break; } } } _setVideoProcessPluginParams(options) { if (options.pixelFormat !== undefined) { switch (options.pixelFormat) { case trtc_define_1.TRTCVideoPixelFormat.TRTCVideoPixelFormat_I420: case trtc_define_1.TRTCVideoPixelFormat.TRTCVideoPixelFormat_RGBA32: case trtc_define_1.TRTCVideoPixelFormat.TRTCVideoPixelFormat_BGRA32: this.videoProcessBufferType = trtc_define_1.TRTCVideoBufferType.TRTCVideoBufferType_Buffer; break; case trtc_define_1.TRTCVideoPixelFormat.TRTCVideoPixelFormat_Texture_2D: this.videoProcessBufferType = trtc_define_1.TRTCVideoBufferType.TRTCVideoBufferType_Texture; break; default: logger_1.default.error(`${this.logPrefix}setPluginParams() unspported pixelFormat: ${options.pixelFormat}`); return; } this.videoProcessPixelFormat = options.pixelFormat; } if (options.enable !== undefined) { this.nodePluginManager.enableLocalVideoCustomProcess(!!options.enable, this.videoProcessPixelFormat, this.videoProcessBufferType); } } _setMediaEncryptDecryptPluginParams(options) { if (options.enable !== undefined) { this.nodePluginManager.enableEncodedDataCustomProcess(!!options.enable); } } _setAudioProcessPluginParams(options) { if (options.enable !== undefined) { this.nodePluginManager.enableAudioFrameCustomProcess(!!options.enable); } } addPlugin(options) { logger_1.default.log(`${this.logPrefix}addPlugin options:`, options); if (this.isIPCMode) { const nativeVideoEffectPlugin = this.nodePluginManager.addVideoPlugin(options.deviceId, options.id, options.path); return new TRTCPlugin(options.id, options.deviceId || '', nativeVideoEffectPlugin); } else { const pluginType = options.type || trtc_define_1.TRTCPluginType.TRTCPluginTypeVideoProcess; const realDeviceId = options.deviceId || ""; this.nodePluginManager.registerPlugin(options.id, options.path, pluginType, realDeviceId); return this._createPlugin(options.id, realDeviceId); } } _createPlugin(pluginId, deviceId) { return { id: pluginId, deviceId: deviceId || "", enable: (flag = true) => { return this.nodePluginManager.enablePlugin(pluginId, flag, deviceId || ""); }, disable: () => { return this.nodePluginManager.enablePlugin(pluginId, false, deviceId || ""); }, setParameter: (param) => { return this.nodePluginManager.setPluginParameter(pluginId, param, deviceId || ""); } }; } removePlugin(pluginId, deviceId) { logger_1.default.log(`${this.logPrefix}removePlugin pluginId:${pluginId} deviceId:${deviceId}`); if (this.isIPCMode) { this.nodePluginManager.removeVideoPlugin(deviceId, pluginId); } else { this.nodePluginManager.unregisterPlugin(pluginId, deviceId || ""); } } setCallback(callback) { if (this.isIPCMode) { this.nodePluginManager.setCallback(callback); } else { this.nodePluginManager.setPluginCallback(callback); } } /** * @deprecated */ getPluginList() { logger_1.default.log(`${this.logPrefix}getPluginList`); if (this.isIPCMode) { logger_1.default.warn(`${this.logPrefix}getPluginList not supported`); return null; } else { return this.nodePluginManager.getPluginIds().map((item) => { const ids = item.split('__'); return this._createPlugin(ids[0], ids[1]); }); } } } exports.TRTCPluginManager = TRTCPluginManager; exports.default = TRTCPluginManager;