-
Notifications
You must be signed in to change notification settings - Fork 39
Description
Problem:
Presentation API and Remote Playback API each has a method to start a session, namely PresentationRequest.start() and RemotePlayback.prompt().
Each shows a potentially different list of receiver devices to choose from, so the user may need to open two different device selection dialogs to find a device.
Proposed solution:
We show a single dialog showing devices capable of either presentation or remote playback. After the user chooses a device, the controlling page initiates a presentation or remote playback depending on its preference and the chosen device's capabilities.
Example code:
const presentation = new PresentationRequest('https://example.com/myvideo.html');
const remote = document.querySelector('#my-video').remote;
const device = await navigator.secondScreen.prompt(presentation, remote);
// console.assert(device.supportsPresentation || device.supportsRemotePlayback);
if ((device.supportsPresentation && myPagePrefersPresentation()) ||
!device.supportsRemotePlayback) {
const connection = await device.startPresentation(); // Doesn't prompt
} else {
device.startRemotePlayback(); // Doesn't prompt
}Web IDL:
partial interface Navigator {
readonly attribute SecondScreen secondScreen;
};
interface SecondScreen {
Promise<SecondScreenDevice> prompt(PresentationRequest presentationRequest,
RemotePlayback remotePlayback);
};
interface SecondScreenDevice {
readonly attribute boolean supportsPresentation;
readonly attribute boolean supportsRemotePlayback;
Promise<PresentationConnection> startPresentation();
Promise<void> startRemotePlayback();
};SecondScreenDevice must expire after some time, to prevent the controller page from holding onto it and starting a session later when the user is not expecting. SecondScreenDevice should become invalid at the same time as user gesture would become inactivated (UA dependent; in about one second on Chrome). Once invalid, supportsPresentation and supportsRemotePlayback become false.
A call to startPresentation() or startRemotePlayback() gets rejected if supportsPresentation or supportsRemotePlayback is false, respectively.