Files
2026-10-23 09:34:51 -04:00

13 lines
1023 B
JavaScript

'use strict';
// Send what is playing to a TV or speaker. Safari/iOS use the AirPlay picker; Chrome and Edge use the browser's own cast picker (Chromecast and
// compatible TVs). The TV fetches the stream itself, so this works best where it can reach the server the same way this device does.
const castOk = el => !!el && (!!(el.remote && el.remote.prompt) || typeof el.webkitShowPlaybackTargetPicker === 'function');
async function castTo(el) {
if (!el) return toast('Start something playing first');
try {
if (el.remote && el.remote.prompt) await el.remote.prompt();
else if (typeof el.webkitShowPlaybackTargetPicker === 'function') el.webkitShowPlaybackTargetPicker();
else toast('This browser cannot send to a TV or speaker. Try Safari (AirPlay) or Chrome (Cast).');
} catch (e) { if (e && e.name !== 'NotAllowedError' && e.name !== 'AbortError') toast(e.name === 'NotSupportedError' || e.name === 'InvalidStateError' ? 'No TV or speaker found on this network' : (e.message || 'Could not cast')); }
}