trtc-electron-sdk
Version:
trtc electron sdk
65 lines (64 loc) • 3.07 kB
JavaScript
;
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;
if (this.context && this.layout.userList) {
this.centerLiveOwner();
(_a = this.nativeStreamLayoutManager) === null || _a === void 0 ? void 0 : _a.setStreamLayout(this.layout.userList);
}
else {
logger_1.default.error(`${this.logPrefix}setLayout 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: previewLeft,
top: previewTop,
right: previewRight,
bottom: previewBottom,
},
fillMode: trtc_define_1.TRTCVideoFillMode.TRTCVideoFillMode_Fit,
zOrder: 0
}];
}
}
}
exports.default = NoneStreamLayoutManager;