Sender
******
Sender component built on the Google Web Sender SDK. Compatible with
PRESTOplay receiver apps; can also pair with other Web Receiver
SDK-based receivers with reduced feature support.
Code samples:
* Chromecast sender
(https://raw.githubusercontent.com/castlabs/prestoplay-web-code-samples/refs/heads/main/examples/cast/chromecast_sender.js):
casts a player's content, sets its title and image, and controls
playback on the receiver.
Load PRESTOplay for Web Apps and its Cast component:
import { clpp } from "@castlabs/prestoplay";
import "@castlabs/prestoplay/cl.cast";
Load the Google Web Sender SDK:
Use the "clpp.cast.onReady" callback to wait until the Cast component
and the underlying Google Web Sender SDK are ready, then use
"CastProxy"
(https://players.castlabs.com/web/latest/docs/api/clpp.cast.CastProxy.md)
to implement casting:
const player = new clpp.Player(...);
clpp.cast.onReady(() => {
const proxy = new clpp.cast.CastProxy(player, '');
});
Check whether casting is available by calling "CastProxy.canCast"
(https://players.castlabs.com/web/latest/docs/api/clpp.cast.CastProxy.md#canCast)
and listen for "clpp.events.CAST_STATUS_CHANGED" for changes:
let canCast = proxy.canCast();
player.on(clpp.events.CAST_STATUS_CHANGED, () => {
canCast = proxy.canCast();
});
Casting requires a Chromecast target device on the same Wi-Fi network,
a correct receiver app ID, and a published receiver app.
Basic example:
During casting, control remote playback on the receiver app from the
sender by calling "Player"
(https://players.castlabs.com/web/latest/docs/api/clpp.Player.md)
methods — the sender acts as a remote control for the receiver.
Events
======
"Player"
(https://players.castlabs.com/web/latest/docs/api/clpp.Player.md)
fires these Chromecast-related events:
* "clpp.events.CASTING_STARTED" — casting has started.
* "clpp.events.CASTING_ENDED" — casting has ended.
* "clpp.events.CAST_STATUS_CHANGED" — any cast status change (session
started or ended, Cast API availability, receiver connection, and so
on).
Limitations of the sender
=========================
The Chromecast Sender SDK has limitations that keep some "Player"
(https://players.castlabs.com/web/latest/docs/api/clpp.Player.md) APIs
from working while casting.
Track management
----------------
As on the receiver, video tracks and renditions can't be listed or
switched while casting. These "TrackManager"
(https://players.castlabs.com/web/latest/docs/api/clpp.TrackManager.md)
APIs aren't usable:
const tm = player.getTrackManager();
tm.getVideoTracks(); // empty array (DASH) or array containing only one item (HLS)
tm.getVideoRendition(); // null (DASH) or active rendition (HLS)
tm.getVideoTrack(); // null (DASH) or active track (HLS)
tm.setVideoTrack(track); // does nothing
Audio track and subtitle management work as expected.
Rendering UI
============
To render a play/pause button during a casting session, listen for the
state change event, since that's when "Player.isPaused"
(https://players.castlabs.com/web/latest/docs/api/clpp.Player.md#isPaused)
changes. Standard video "play" and "pause" events aren't available
here because playback happens in the receiver app:
player.on(clpp.events.STATE_CHANGED, function () {
renderPlayButton();
});