diff --git a/web/ts/splitview.ts b/web/ts/splitview.ts index 34a3e4e03..b97d49632 100644 --- a/web/ts/splitview.ts +++ b/web/ts/splitview.ts @@ -1,6 +1,8 @@ import { getPlayers } from "./TUMLiveVjs"; import Split from "split.js"; import { cloneEvents } from "./global"; +import videojs, { VideoJsPlayer } from "video.js"; +import PlayerOptions = videojs.PlayerOptions; const mouseMovingTimeout = 2200; @@ -37,16 +39,16 @@ export class SplitView { this.videoWrapperResizeObs.observe(this.videoWrapper); this.detectMouseNotMoving(); - this.players[0].ready(() => { + this.players[1].ready(() => { this.setTrackBarModes(0, "disabled"); }); - this.players[1].ready(() => { + this.players[0].ready(() => { this.setupControlBars(); this.overwriteFullscreenToggle(); }); - cloneEvents(this.players[0].el(), this.players[1].el(), ["mousemove", "mouseenter", "mouseleave"]); + cloneEvents(this.players[1].el(), this.players[0].el(), ["mousemove", "mouseenter", "mouseleave"]); // Setup splitview // eslint-disable-next-line @typescript-eslint/no-this-alias @@ -107,15 +109,15 @@ export class SplitView { } private setupControlBars() { - this.players[0].controlBar.hide(); - this.players[0].muted(true); + this.players[1].controlBar.hide(); + this.players[1].muted(true); - this.players[1].el().addEventListener("fullscreenchange", () => { + this.players[0].el().addEventListener("fullscreenchange", () => { this.isFullscreen = document.fullscreenElement !== null; this.updateControlBarSize(this.getSizes()); }); - const mainControlBarElem = this.players[1].controlBar.el(); + const mainControlBarElem = this.players[0].controlBar.el(); mainControlBarElem.style.position = "absolute"; mainControlBarElem.style.zIndex = "1"; @@ -126,38 +128,40 @@ export class SplitView { const wrapperSize = this.videoWrapper.getBoundingClientRect().width; let marginLeft; - if (this.isFullscreen) { - marginLeft = "0"; - } else if (sizes[0] === 100) { - marginLeft = `${this.gutterWidth / 2 - wrapperSize}px`; //`calc(${this.gutterWidth / 2}px - 100vw)`; - } else if (sizes[0] === 0) { - marginLeft = `-${this.gutterWidth / 2}px`; + if (sizes[0] === 0) { + marginLeft = `${this.gutterWidth / 2}px`; } else { - const leftContainerWidth = (sizes[0] * wrapperSize) / 100; - marginLeft = `-${leftContainerWidth}px`; + marginLeft = `0px`; } - - const mainControlBarElem = this.players[1].controlBar.el(); - mainControlBarElem.style.marginLeft = marginLeft; + const mainControlBarElem = this.players[0].controlBar.el(); mainControlBarElem.style.width = `${wrapperSize}px`; + mainControlBarElem.style.marginLeft = marginLeft; - const textTrackDisplay = this.players[1].el_.querySelector(".vjs-text-track-display"); + const textTrackDisplay = this.players[0].el_.querySelector(".vjs-text-track-display"); if (textTrackDisplay) { - textTrackDisplay.style.left = marginLeft; + textTrackDisplay.style.width = `${wrapperSize}px`; + textTrackDisplay.style.zIndex = "1"; } } private overwriteFullscreenToggle() { - const fullscreenToggle = this.players[1].controlBar.fullscreenToggle; + const fullscreenToggle = this.players[0].controlBar.fullscreenToggle; fullscreenToggle.off("click"); fullscreenToggle.on("click", async () => { - if (document.fullscreenElement === null) { - await this.splitParent.requestFullscreen(); - } else { - await document.exitFullscreen(); - } + await this.toggleFullscreen(); }); + + (this.players[0] as VideoJsPlayer).options_.userActions.doubleClick = async () => await this.toggleFullscreen(); + (this.players[1] as VideoJsPlayer).options_.userActions.doubleClick = async () => await this.toggleFullscreen(); + } + + private async toggleFullscreen() { + if (document.fullscreenElement === null) { + await this.splitParent.requestFullscreen(); + } else { + await document.exitFullscreen(); + } } private setTrackBarModes(k: number, mode: string) {