From 4cd9757e532eca67dbb6fb69c827b2e2c6d4ded0 Mon Sep 17 00:00:00 2001 From: Alexey Khit Date: Sun, 8 Jan 2023 21:05:50 +0300 Subject: [PATCH] Fix status info in JS player --- www/video-stream.js | 46 +++++++++++++++++++++++++++------------------ 1 file changed, 28 insertions(+), 18 deletions(-) diff --git a/www/video-stream.js b/www/video-stream.js index bc64e0e0..c6b68a54 100644 --- a/www/video-stream.js +++ b/www/video-stream.js @@ -1,19 +1,23 @@ import {VideoRTC} from "./video-rtc.js"; class VideoStream extends VideoRTC { - constructor() { - super(); + set divMode(value) { + this.querySelector(".mode").innerText = value; + this.querySelector(".status").innerText = ""; + } - /** @type {HTMLDivElement} */ - this.divMode = null; - /** @type {HTMLDivElement} */ - this.divStatus = null; + set divError(value) { + const state = this.querySelector(".mode").innerText; + if (state !== "loading") return; + this.querySelector(".mode").innerText = "error"; + this.querySelector(".status").innerText = value; } /** * Custom GUI */ oninit() { + console.debug("stream.oninit"); super.oninit(); this.innerHTML = ` @@ -36,35 +40,36 @@ class VideoStream extends VideoRTC { `; - this.divStatus = this.querySelector(".status"); - this.divMode = this.querySelector(".mode"); - const info = this.querySelector(".info") this.insertBefore(this.video, info); } onconnect() { + console.debug("stream.onconnect"); const result = super.onconnect(); - if (result) { - this.divMode.innerText = "loading"; - } + if (result) this.divMode = "loading"; return result; } + ondisconnect() { + console.debug("stream.ondisconnect"); + super.ondisconnect(); + } + onopen() { + console.debug("stream.onopen"); const result = super.onopen(); this.onmessage["stream"] = msg => { + console.debug("stream.onmessge", msg); switch (msg.type) { case "error": - this.divMode.innerText = "error"; - this.divStatus.innerText = msg.value; + this.divError = msg.value; break; case "mse": case "mp4": case "mjpeg": - this.divMode.innerText = msg.type.toUpperCase(); - this.divStatus.innerText = ""; + this.divMode = msg.type.toUpperCase(); break; } } @@ -72,12 +77,17 @@ class VideoStream extends VideoRTC { return result; } + onclose() { + console.debug("stream.onclose"); + return super.onclose(); + } + onpcvideo(ev) { + console.debug("stream.onpcvideo"); super.onpcvideo(ev); if (this.pcState !== WebSocket.CLOSED) { - this.divMode.innerText = "RTC"; - this.divStatus.innerText = ""; + this.divMode = "RTC"; } } }