trtc-electron-sdk
Version:
trtc electron sdk
75 lines (74 loc) • 4.06 kB
JavaScript
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const BaseStreamLayoutManager_1 = __importDefault(require("./BaseStreamLayoutManager"));
const types_1 = require("../types");
const trtc_define_1 = require("../../../trtc_define");
const logger_1 = __importDefault(require("../../../logger"));
class NoneStreamLayoutManager extends BaseStreamLayoutManager_1.default {
constructor(nativeStreamLayoutManager, context) {
super(nativeStreamLayoutManager, context);
this.logPrefix = "[TRTCNoneStreamLayoutManager]";
}
setLayout(layout) {
this.layout = Object.assign(Object.assign({}, layout), { layoutMode: types_1.TRTCStreamLayoutMode.None, userList: [] });
this.refreshLayout();
}
refreshLayout() {
var _a, _b;
if (this.context && this.layout.userList) {
this.centerLiveOwner();
if (this.layout.userList.length === 1 && this.layout.userList[0].rect && this.displayArea.width !== 0 && this.displayArea.height !== 0 && window.devicePixelRatio !== 0) {
const workingArea = this.layout.userList[0].rect;
(_a = this.context.mediaMixingDesigner) === null || _a === void 0 ? void 0 : _a.setWorkingArea({
left: workingArea.left / this.displayArea.width / window.devicePixelRatio,
top: workingArea.top / this.displayArea.height / window.devicePixelRatio,
right: workingArea.right / this.displayArea.width / window.devicePixelRatio,
bottom: workingArea.bottom / this.displayArea.height / window.devicePixelRatio,
}, this.layout.userList[0].fillMode);
}
logger_1.default.debug(`${this.logPrefix}refreshLayout:`, JSON.stringify(this.layout.userList));
(_b = this.nativeStreamLayoutManager) === null || _b === void 0 ? void 0 : _b.setStreamLayout(this.layout.userList);
}
else {
logger_1.default.error(`${this.logPrefix}refreshLayout context is null or no user`);
}
}
centerLiveOwner() {
if (this.context && this.layout) {
const layoutPixelWidth = this.displayArea.width * window.devicePixelRatio;
const layoutPixelHeight = this.displayArea.height * window.devicePixelRatio;
const mixingVideoWidth = this.context.mixingVideoSize.width;
const mixingVideoHeight = this.context.mixingVideoSize.height;
// Live Owner(local user)
let scaleRate;
if (mixingVideoWidth === 0 || mixingVideoHeight === 0) {
scaleRate = 1;
logger_1.default.error(`${this.logPrefix}centerLiveOwner mixingVideoSize is 0, use default scaleRate '1'`);
}
else {
scaleRate = Math.min(layoutPixelWidth / mixingVideoWidth, layoutPixelHeight / mixingVideoHeight);
}
const previewWidth = mixingVideoWidth * scaleRate;
const previewHeight = mixingVideoHeight * scaleRate;
const previewLeft = (layoutPixelWidth - previewWidth) / 2;
const previewTop = (layoutPixelHeight - previewHeight) / 2;
const previewRight = previewLeft + previewWidth;
const previewBottom = previewTop + previewHeight;
this.layout.userList = [{
userId: '',
rect: {
left: Math.round(previewLeft),
top: Math.round(previewTop),
right: Math.round(previewRight),
bottom: Math.round(previewBottom),
},
fillMode: trtc_define_1.TRTCVideoFillMode.TRTCVideoFillMode_Fill,
zOrder: 0
}];
}
}
}
exports.default = NoneStreamLayoutManager;