UNPKG

trtc-electron-sdk

Version:

trtc electron sdk

83 lines (82 loc) 3.12 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const type_1 = require("./type"); const logger_1 = __importDefault(require("../logger")); class LocalVideoRenderController { constructor(trtcCloud) { this.logPrefix = '[LocalVideoRenderController]'; this.trtcCloud = trtcCloud; this.currentState = type_1.LocalVideoRenderCallbackState.NotListening; this.isExternalRenderEnabled = false; this.isLocalPreviewStarted = false; this.hasLocalPreviewView = false; this.isLocalSharingStarted = false; this.hasLocalSharingView = false; } startLocalPreview(views) { this.isLocalPreviewStarted = true; this.hasLocalPreviewView = views !== null && views !== undefined; if (Array.isArray(views)) { this.hasLocalPreviewView = views.length >= 1; } this.update(); } stopLocalPreview() { this.isLocalPreviewStarted = false; this.hasLocalPreviewView = false; this.update(); } updateLocalView(views) { this.hasLocalPreviewView = views !== null && views !== undefined; if (Array.isArray(views)) { this.hasLocalPreviewView = views.length >= 1; } this.update(); } startScreenCapture(view = null) { this.isLocalSharingStarted = true; this.hasLocalSharingView = view !== null && view !== undefined; this.update(); } stopScreenCapture() { this.isLocalSharingStarted = false; this.hasLocalSharingView = false; this.update(); } setExternalRenderEnabled(enabled) { this.isExternalRenderEnabled = enabled; } update() { const targetState = this.calcTargetState(); if (targetState !== this.currentState) { if (targetState === type_1.LocalVideoRenderCallbackState.NotListening) { logger_1.default.log(`${this.logPrefix}update not listening`); this.trtcCloud.removeLocalVideoRenderCallback(); } else { logger_1.default.log(`${this.logPrefix}update listening`); this.trtcCloud.addLocalVideoRenderCallback(); } this.currentState = targetState; } else { return; } } calcTargetState() { if (this.isExternalRenderEnabled) { return type_1.LocalVideoRenderCallbackState.Listening; } if (this.isLocalPreviewStarted && this.hasLocalPreviewView) { return type_1.LocalVideoRenderCallbackState.Listening; } if (this.isLocalSharingStarted && this.hasLocalSharingView) { return type_1.LocalVideoRenderCallbackState.Listening; } return type_1.LocalVideoRenderCallbackState.NotListening; } } exports.default = LocalVideoRenderController;