build-container / build (push) Successful in 13m46s
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
13 lines
1023 B
JavaScript
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')); }
|
|
}
|