-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreceiver.js
78 lines (66 loc) · 2.54 KB
/
receiver.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
const castContext = cast.framework.CastReceiverContext.getInstance();
const castDebugLogger = cast.debug.CastDebugLogger.getInstance();
const playerManager = castContext.getPlayerManager();
const TAG = 'receiver';
const LIVE_MEDIA_URL = 'https://streaming.cast.pe/devsummit/ds.smil/playlist.m3u8';
const LIVE_MEDIA_METADATA_SERVICE_URI =
'https://us-central1-cast-tses.cloudfunctions.net/io-2019-live';
/**
* Start playing the live stream as soon as the receiver is finished loading.
*/
castContext.addEventListener(
cast.framework.system.EventType.READY, (event) => {
const mediaInfo = new cast.framework.messages.MediaInformation();
const loadRequest =
new cast.framework.messages.LoadRequestData(mediaInfo);
castDebugLogger.info(TAG, 'Receiver started, initiating load request.');
playerManager.load(loadRequest);
});
/**
* Load interceptor
*/
playerManager.setMessageInterceptor(
cast.framework.messages.MessageType.LOAD,
(request) => {
castDebugLogger.info(TAG, 'Intercepting LOAD request');
request.autoplay = true;
request.media.streamType = cast.framework.messages.StreamType.LIVE;
request.media.contentUrl = LIVE_MEDIA_URL;
loadGuideData();
playerManager.removeSupportedMediaCommands(
cast.framework.messages.Command.SEEK, true);
return request;
}
);
/**
* Seek a seek interceptor is called whenever CAF receives a request to seek to
* a different location in media. This interceptor can be used to modify that
* seek request or disable seeking completely.
* @param {cast.framework.messages.MessageType.SEEK} The message to intercept.
*/
playerManager.setMessageInterceptor(
cast.framework.messages.MessageType.SEEK,
(seekData) => {
// if the SEEK supported media command is disabled, block seeking
if (!(playerManager.getSupportedMediaCommands() &
cast.framework.messages.Command.SEEK)) {
castDebugLogger.info(TAG, 'Seek blocked.');
return null;
}
return seekData;
}
);
/**
* Gets the current program guide data from our Google Cloud Function
* @return {cast.framework.messages.MediaMetadata[]} Latest program guide data
*/
function loadGuideData() {
return fetch(LIVE_MEDIA_METADATA_SERVICE_URI)
.then((response) => response.json())
.then(function(data) {
const containerMetadata =
new cast.framework.messages.ContainerMetadata();
containerMetadata.sections = data;
playerManager.getQueueManager().setContainerMetadata(containerMetadata);
});
}