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 9523c996bf
commit c3fa007f35
3 changed files with 41 additions and 1 deletions

View File

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

View File

@ -156,6 +156,7 @@ export default class RFB extends EventTargetMixin {
this._qemuAudioSupported = false;
this._page_had_user_interaction = false;
this._audio_enable = false;
this._audio_next_start = 0;
this._audio_sample_rate = 44100;
this._audio_channels = 2;
@ -2781,7 +2782,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;
if (ctime > this._audio_next_start) {
this._audio_next_start = ctime;
@ -2800,6 +2801,19 @@ export default class RFB extends EventTargetMixin {
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() {
this._page_had_user_interaction = true;
}
@ -3413,6 +3427,14 @@ RFB.messages = {
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) {
sock.sQpush8(255); // msg-type

View File

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