Add master display UI with audio output management and styling
- Implement main.js for the master display functionality, including WebSocket connection, audio output management, and state handling. - Create style.css for the master display's visual design, ensuring a cohesive look and feel with a dark theme and responsive layout. - Integrate device management with a fallback for non-Electron environments, allowing users to select audio outputs. - Add features for managing favorites, including toggling favorites and filtering by genre. - Enhance user experience with a responsive favorites grid and drag-to-scroll functionality.
This commit is contained in:
@@ -1,13 +1,18 @@
|
||||
export function connectWs(onMessage) {
|
||||
export function connectWs(onMessage, opts = {}) {
|
||||
let ws, retry = 0, closed = false;
|
||||
function open() {
|
||||
const proto = location.protocol === 'https:' ? 'wss' : 'ws';
|
||||
ws = new WebSocket(`${proto}://${location.host}/ws`);
|
||||
ws.addEventListener('open', () => { retry = 0; });
|
||||
const params = new URLSearchParams();
|
||||
if (opts.room) params.set('room', opts.room);
|
||||
if (opts.kind) params.set('kind', opts.kind);
|
||||
const qs = params.toString();
|
||||
ws = new WebSocket(`${proto}://${location.host}/ws${qs ? '?' + qs : ''}`);
|
||||
ws.addEventListener('open', () => { retry = 0; opts.onOpen?.(); });
|
||||
ws.addEventListener('message', (ev) => {
|
||||
try { onMessage(JSON.parse(ev.data)); } catch { }
|
||||
});
|
||||
ws.addEventListener('close', () => {
|
||||
opts.onClose?.();
|
||||
if (closed) return;
|
||||
retry = Math.min(retry + 1, 6);
|
||||
setTimeout(open, 500 * 2 ** retry);
|
||||
@@ -17,6 +22,7 @@ export function connectWs(onMessage) {
|
||||
open();
|
||||
return {
|
||||
send(msg) { if (ws?.readyState === WebSocket.OPEN) ws.send(JSON.stringify(msg)); },
|
||||
close() { closed = true; ws?.close(); }
|
||||
close() { closed = true; ws?.close(); },
|
||||
get readyState() { return ws?.readyState; }
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user