app: add enable audio setting

Signed-off-by: Dietmar Maurer <dietmar@proxmox.com>
This commit is contained in:
Dietmar Maurer 2025-04-03 10:48:55 +02:00
parent e454666a8b
commit 6f8f4bff62
3 changed files with 41 additions and 1 deletions

View File

@ -189,6 +189,7 @@ const UI = {
UI.initSetting('repeaterID', ''); UI.initSetting('repeaterID', '');
UI.initSetting('reconnect', false); UI.initSetting('reconnect', false);
UI.initSetting('reconnect_delay', 5000); UI.initSetting('reconnect_delay', 5000);
UI.initSetting('enable_audio', true);
}, },
// Adds a link to the label elements on the corresponding input elements // Adds a link to the label elements on the corresponding input elements
setupSettingLabels() { setupSettingLabels() {
@ -385,6 +386,8 @@ const UI = {
UI.addSettingChangeHandler('logging', UI.updateLogging); UI.addSettingChangeHandler('logging', UI.updateLogging);
UI.addSettingChangeHandler('reconnect'); UI.addSettingChangeHandler('reconnect');
UI.addSettingChangeHandler('reconnect_delay'); UI.addSettingChangeHandler('reconnect_delay');
UI.addSettingChangeHandler('enable_audio');
UI.addSettingChangeHandler('enable_audio', UI.updateEnableAudio);
}, },
addFullscreenHandlers() { addFullscreenHandlers() {
@ -898,6 +901,7 @@ const UI = {
UI.updateSetting('logging'); UI.updateSetting('logging');
UI.updateSetting('reconnect'); UI.updateSetting('reconnect');
UI.updateSetting('reconnect_delay'); UI.updateSetting('reconnect_delay');
UI.updateSetting('enable_audio');
document.getElementById('noVNC_settings') document.getElementById('noVNC_settings')
.classList.add("noVNC_open"); .classList.add("noVNC_open");
@ -1109,6 +1113,8 @@ const UI = {
UI.rfb.showDotCursor = UI.getSetting('show_dot'); UI.rfb.showDotCursor = UI.getSetting('show_dot');
UI.updateViewOnly(); // requires UI.rfb UI.updateViewOnly(); // requires UI.rfb
UI.updateEnableAudio(); // requires UI.rfb
}, },
disconnect() { disconnect() {
@ -1801,6 +1807,11 @@ const UI = {
selectbox.options.add(optn); selectbox.options.add(optn);
}, },
updateEnableAudio() {
if (!UI.rfb) return;
UI.rfb.enable_audio(UI.getSetting('enable_audio'));
},
/* ------^------- /* ------^-------
* /MISC * /MISC
* ============== * ==============

View File

@ -156,6 +156,7 @@ export default class RFB extends EventTargetMixin {
this._qemuAudioSupported = false; this._qemuAudioSupported = false;
this._page_had_user_interaction = false; this._page_had_user_interaction = false;
this._audio_enable = false;
this._audio_next_start = 0; this._audio_next_start = 0;
this._audio_sample_rate = 44100; this._audio_sample_rate = 44100;
this._audio_channels = 2; this._audio_channels = 2;
@ -2787,7 +2788,7 @@ export default class RFB extends EventTargetMixin {
} }
} }
if (this._page_had_user_interaction) { if (this._page_had_user_interaction && this._audio_enable) {
let ctime = this._audio_context.currentTime; let ctime = this._audio_context.currentTime;
if (ctime > this._audio_next_start) { if (ctime > this._audio_next_start) {
this._audio_next_start = ctime; this._audio_next_start = ctime;
@ -2806,6 +2807,19 @@ export default class RFB extends EventTargetMixin {
return true; return true;
} }
enable_audio(value) {
if (this._audio_enable !== value) {
this._audio_enable = value;
if (this._qemuAudioSupported) {
if (this._audio_enable) {
RFB.messages.enableQemuAudioUpdates(this._sock, this._audio_channels, this._audio_sample_rate);
} else {
RFB.messages.disableQemuAudioUpdates(this._sock);
}
}
}
}
allow_audio() { allow_audio() {
this._page_had_user_interaction = true; this._page_had_user_interaction = true;
} }
@ -3419,6 +3433,14 @@ RFB.messages = {
sock.flush(); sock.flush();
}, },
disableQemuAudioUpdates(sock, channels, sample_rate) {
sock.sQpush8(255); // msg-type
sock.sQpush8(1); // submessage-type
sock.sQpush16(1); // disable audio
sock.flush();
},
enableQemuAudioUpdates(sock, channels, sample_rate) { enableQemuAudioUpdates(sock, channels, sample_rate) {
sock.sQpush8(255); // msg-type sock.sQpush8(255); // msg-type

View File

@ -219,6 +219,13 @@
View only View only
</label> </label>
</li> </li>
<li>
<label>
<input id="noVNC_setting_enable_audio" type="checkbox"
class="toggle">
Enable Audio
</label>
</li>
<li><hr></li> <li><hr></li>
<li> <li>
<label> <label>