Receiver app
************
Receiver component built on the Google Web Receiver SDK. Same
supported media formats as that SDK. Covers a custom web receiver app.
Code samples:
* Chromecast receiver
(https://raw.githubusercontent.com/castlabs/prestoplay-web-code-samples/refs/heads/main/examples/cast/chromecast_receiver.js):
a custom receiver app with a queue, custom messages, and audio and
text track handling.
Load the Google Web Receiver SDK:
Load PRESTOplay for Web Apps and its Cast component:
import { clpp } from "@castlabs/prestoplay";
import "@castlabs/prestoplay/cl.cast";
Render the "cast-media-player"
(https://developers.google.com/cast/docs/web_receiver/basic#media_and_players)
tag, a built-in media player provided by the Google Cast framework
with basic UI controls that you can customize
(https://developers.google.com/cast/docs/web_receiver/customize_ui):
Create a "Player"
(https://players.castlabs.com/web/latest/docs/api/clpp.Player.md)
instance, pass it to the "Receiver"
(https://players.castlabs.com/web/latest/docs/api/clpp.cast.Receiver.md),
and start the receiver. The receiver listens for commands from the
sender and uses the player to play the stream:
const player = new clpp.Player('castPlayer', {
license: 'your-license-key',
});
const receiver = clpp.cast.Receiver.getInstance();
receiver.init(player);
receiver.start();
Full example:
Running in background
=====================
On Google TV Streamer, pressing the remote's Back or Home button sends
the receiver app to the background. Shut it down at that point:
// Receiver app
document.addEventListener('visibilitychange', () => {
if (document.hidden) {
console.info('Receiver app went to background, shut it down.');
receiver.stop();
}
});
Alternatively, listen for "clpp.events.CAST_VISIBILITY_CHANGED" on the
sender and implement your own behavior:
// Sender app
player.on(clpp.events.CAST_VISIBILITY_CHANGED, (e) => {
if (e.visible) {
// Receiver app is in the foreground
} else {
// Receiver app is in the background
}
});
Bring the receiver app from background to foreground by calling
"Player.play"
(https://players.castlabs.com/web/latest/docs/api/clpp.Player.md#play)
or "Player.open"
(https://players.castlabs.com/web/latest/docs/api/clpp.Player.md#open).
Tracks
======
The receiver adds extra properties to the "Track" object via the
"customData" field on the "MEDIA_STATUS"
(https://developers.google.com/cast/docs/reference/web_receiver/cast.framework.events.MediaStatusEvent)
message:
* For audio tracks: "audioTrackInfo"
(https://developers.google.com/cast/docs/reference/web_receiver/cast.framework.messages.AudioTrackInfo)
— channels, codec, and spatial audio information.
* For audio and text tracks: "roles" — an array of strings
representing the track's roles, or "undefined".
Limitations of the receiver
===========================
The Chromecast Receiver SDK has limitations that keep some "Player"
(https://players.castlabs.com/web/latest/docs/api/clpp.Player.md) APIs
from working in a receiver app.
Volume control
--------------
Volume control APIs aren't available on the receiver:
"Player.setVolume"
(https://players.castlabs.com/web/latest/docs/api/clpp.Player.md#setVolume),
"Player.getVolume"
(https://players.castlabs.com/web/latest/docs/api/clpp.Player.md#getVolume),
"Player.setMuted"
(https://players.castlabs.com/web/latest/docs/api/clpp.Player.md#setMuted),
"Player.isMuted"
(https://players.castlabs.com/web/latest/docs/api/clpp.Player.md#isMuted),
and the "mute" and "volume" configuration options have no effect.
Control volume from the sender instead by calling the same APIs there.
Track management
----------------
Video tracks and renditions can't be listed or switched on the
receiver. These "TrackManager"
(https://players.castlabs.com/web/latest/docs/api/clpp.TrackManager.md)
APIs are no-ops:
const tm = player.getTrackManager();
tm.getVideoTracks(); // empty array
tm.getVideoRendition(); // null
tm.getVideoTrack(); // null
tm.setVideoTrack(track); // does nothing
Audio track and subtitle management work as expected.