summaryrefslogtreecommitdiff
path: root/web
diff options
context:
space:
mode:
authorMaxim Devaev <[email protected]>2022-11-29 15:13:48 +0300
committerMaxim Devaev <[email protected]>2022-11-29 15:13:48 +0300
commit0e9b87ad6101582bd5f7542e60535ee602e11dd6 (patch)
treedc18b2be6a290be626463f8de0ec70d5cca9bad6 /web
parenta68eb4ed2d34682a696f5145868cc744cef9a949 (diff)
web: optional audio transmitting
Diffstat (limited to 'web')
-rw-r--r--web/share/js/kvm/stream.js42
-rw-r--r--web/share/js/kvm/stream_janus.js17
2 files changed, 34 insertions, 25 deletions
diff --git a/web/share/js/kvm/stream.js b/web/share/js/kvm/stream.js
index 650256f4..0239a27b 100644
--- a/web/share/js/kvm/stream.js
+++ b/web/share/js/kvm/stream.js
@@ -74,6 +74,12 @@ export function Streamer() {
$("stream-video").muted = !value;
$("stream-video").volume = value / 100;
$("stream-audio-volume-value").innerHTML = value + "%";
+ if (__streamer.getMode() === "janus") {
+ let allow_audio = !$("stream-video").muted;
+ if (__streamer.isAudioAllowed() !== allow_audio) {
+ __resetStream();
+ }
+ }
});
tools.el.setOnClick($("stream-screenshot-button"), __clickScreenshotButton);
@@ -122,6 +128,9 @@ export function Streamer() {
);
let mode = (__janus_enabled ? tools.storage.get("stream.mode", "janus") : "mjpeg");
tools.radio.clickValue("stream-mode-radio", mode);
+ if (!__janus_enabled) {
+ tools.feature.setEnabled($("stream-audio"), false); // Enabling in stream_janus.js
+ }
self.setState(__state);
};
@@ -239,22 +248,29 @@ export function Streamer() {
tools.slider.setValue(el, value);
};
+ var __resetStream = function(mode=null) {
+ if (mode === null) {
+ mode = __streamer.getMode();
+ }
+ __streamer.stopStream();
+ if (mode === "janus") {
+ __streamer = new JanusStreamer(__setActive, __setInactive, __setInfo, !$("stream-video").muted);
+ } else { // mjpeg
+ __streamer = new MjpegStreamer(__setActive, __setInactive, __setInfo);
+ tools.feature.setEnabled($("stream-audio"), false); // Enabling in stream_janus.js
+ }
+ if (wm.isWindowVisible($("stream-window"))) {
+ __streamer.ensureStream(__state);
+ }
+ };
+
var __clickModeRadio = function() {
let mode = tools.radio.getValue("stream-mode-radio");
tools.storage.set("stream.mode", mode);
if (mode !== __streamer.getMode()) {
tools.hidden.setVisible($("stream-image"), (mode !== "janus"));
tools.hidden.setVisible($("stream-video"), (mode === "janus"));
- if (mode === "janus") {
- __streamer.stopStream();
- __streamer = new JanusStreamer(__setActive, __setInactive, __setInfo);
- } else { // mjpeg
- __streamer.stopStream();
- __streamer = new MjpegStreamer(__setActive, __setInactive, __setInfo);
- }
- if (wm.isWindowVisible($("stream-window"))) {
- __streamer.ensureStream(__state);
- }
+ __resetStream(mode);
}
};
@@ -270,11 +286,7 @@ export function Streamer() {
var __clickResetButton = function() {
wm.confirm("Are you sure you want to reset stream?").then(function (ok) {
if (ok) {
- if (wm.isWindowVisible($("stream-window"))) {
- __streamer.stopStream();
- __streamer.ensureStream(__state);
- }
-
+ __resetStream();
let http = tools.makeRequest("POST", "/api/streamer/reset", function() {
if (http.readyState === 4) {
if (http.status !== 200) {
diff --git a/web/share/js/kvm/stream_janus.js b/web/share/js/kvm/stream_janus.js
index ad5b5b54..c79d54e2 100644
--- a/web/share/js/kvm/stream_janus.js
+++ b/web/share/js/kvm/stream_janus.js
@@ -29,7 +29,7 @@ import {tools, $} from "../tools.js";
var _Janus = null;
-export function JanusStreamer(__setActive, __setInactive, __setInfo) {
+export function JanusStreamer(__setActive, __setInactive, __setInfo, __allow_audio) {
var self = this;
var __stop = false;
@@ -45,7 +45,9 @@ export function JanusStreamer(__setActive, __setInactive, __setInfo) {
var __state = null;
var __frames = 0;
- self.getName = () => "H.264";
+ self.isAudioAllowed = () => __allow_audio;
+
+ self.getName = () => (__allow_audio ? "H.264 + Audio" : "H.264");
self.getMode = () => "janus";
self.getResolution = function() {
@@ -124,7 +126,6 @@ export function JanusStreamer(__setActive, __setInactive, __setInfo) {
__handle.webrtcStuff.remoteStream = null;
}
$("stream-video").srcObject = null;
- __setAudioEnabled(false);
if (__janus !== null) {
__janus.destroy();
}
@@ -179,7 +180,7 @@ export function JanusStreamer(__setActive, __setInactive, __setInfo) {
__setInactive();
__setInfo(false, false, "");
} else if (msg.result.status === "features") {
- __setAudioEnabled(msg.result.features.audio);
+ tools.feature.setEnabled($("stream-audio"), msg.result.features.audio);
}
} else if (msg.error_code || msg.error) {
__logError("Got uStreamer error message:", msg.error_code, "-", msg.error);
@@ -241,10 +242,6 @@ export function JanusStreamer(__setActive, __setInactive, __setInfo) {
});
};
- var __setAudioEnabled = function(enabled) {
- tools.feature.setEnabled($("stream-audio"), enabled);
- };
-
var __startInfoInterval = function() {
__stopInfoInterval();
__setActive();
@@ -292,9 +289,9 @@ export function JanusStreamer(__setActive, __setInactive, __setInfo) {
var __sendWatch = function() {
if (__handle) {
- __logInfo("Sending WATCH + FEATURES ...");
+ __logInfo(`Sending WATCH(audio=${__allow_audio}) + FEATURES ...`);
__handle.send({"message": {"request": "features"}});
- __handle.send({"message": {"request": "watch", "params": {"audio": true}}});
+ __handle.send({"message": {"request": "watch", "params": {"audio": __allow_audio}}});
}
};