Feature(web): Add toolbar audio toggle button
This commit is contained in:
@@ -737,6 +737,7 @@
|
||||
.toolbar-btn-bar:hover { background: rgba(255,255,255,0.2); }
|
||||
.toolbar-btn-bar.active { background: rgba(52,199,89,0.8); }
|
||||
.toolbar-btn-bar.active:hover { background: rgba(52,199,89,1); }
|
||||
.toolbar-btn-bar.muted { opacity: 0.55; }
|
||||
.toolbar-btn-bar:disabled { opacity: 0.4; cursor: not-allowed; }
|
||||
.toolbar-btn-bar:disabled:hover { background: rgba(255,255,255,0.1); }
|
||||
#screen-page:fullscreen .screen-toolbar { display: none; }
|
||||
@@ -1174,6 +1175,7 @@
|
||||
<div class="toolbar-right">
|
||||
<span id="screen-status" class="screen-status connecting">Connecting...</span>
|
||||
<button class="toolbar-btn-bar" id="btn-rdp-reset-bar" onclick="sendRdpReset()" title="RDP Reset">↻</button>
|
||||
<button class="toolbar-btn-bar" id="btn-audio-bar" onclick="toggleAudio()" title="Mute audio">🔊</button>
|
||||
<button class="toolbar-btn-bar" id="btn-mouse-bar" onclick="toggleControl()" title="Mouse Control">🖱</button>
|
||||
<button class="toolbar-btn-bar" id="btn-keyboard-bar" onclick="toggleKeyboard()" title="Keyboard" disabled>⌨</button>
|
||||
<button class="fullscreen-btn" onclick="toggleFullscreen()" title="Fullscreen (F11)">⛶</button>
|
||||
@@ -1548,11 +1550,22 @@
|
||||
// Wait for resolution_changed message
|
||||
updateScreenStatus('waiting', 'Waiting for video...');
|
||||
}
|
||||
// Audio state may or may not be cached yet on the server.
|
||||
// If not, the audio_state event below will populate it.
|
||||
if (typeof msg.audio_enabled === 'boolean') {
|
||||
applyAudioState(msg.audio_enabled);
|
||||
}
|
||||
} else {
|
||||
updateScreenStatus('error', msg.msg);
|
||||
setTimeout(() => showPage('devices-page'), 2000);
|
||||
}
|
||||
break;
|
||||
case 'audio_state':
|
||||
applyAudioState(!!msg.enabled);
|
||||
break;
|
||||
case 'audio_toggle_result':
|
||||
if (!msg.ok) console.warn('[Audio] toggle failed:', msg.msg);
|
||||
break;
|
||||
case 'term_ready':
|
||||
termState.ready = true;
|
||||
document.getElementById('term-status-info').textContent =
|
||||
@@ -2463,6 +2476,9 @@
|
||||
document.getElementById('device-name').textContent = currentDevice.name;
|
||||
document.getElementById('frame-info').textContent = '';
|
||||
updateScreenStatus('connecting');
|
||||
// Default the audio button to "on" optimistically; server will
|
||||
// correct via connect_result.audio_enabled or audio_state event.
|
||||
applyAudioState(true);
|
||||
showPage('screen-page');
|
||||
ws.send(JSON.stringify({ cmd: 'connect', id: String(id), token }));
|
||||
}
|
||||
@@ -2906,6 +2922,26 @@
|
||||
}
|
||||
}
|
||||
|
||||
// Reflect server-confirmed audio on/off on the toolbar icon. Server is
|
||||
// authoritative — toggleAudio() does not flip state locally; it only
|
||||
// sends the request and waits for the audio_state broadcast.
|
||||
function applyAudioState(enabled) {
|
||||
audioEnabled = !!enabled;
|
||||
const btn = document.getElementById('btn-audio-bar');
|
||||
if (btn) {
|
||||
// 0x1F50A speaker / 0x1F507 muted speaker
|
||||
btn.innerHTML = audioEnabled ? '🔊' : '🔇';
|
||||
btn.title = audioEnabled ? 'Mute audio' : 'Unmute audio';
|
||||
btn.classList.toggle('muted', !audioEnabled);
|
||||
}
|
||||
}
|
||||
|
||||
function toggleAudio() {
|
||||
if (ws && ws.readyState === WebSocket.OPEN && token) {
|
||||
ws.send(JSON.stringify({ cmd: 'audio_toggle', token }));
|
||||
}
|
||||
}
|
||||
|
||||
// Detect touch device (mobile/tablet)
|
||||
const isTouchDevice = ('ontouchstart' in window) || (navigator.maxTouchPoints > 0);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user