Hi there,
I have a working player with HLS and a aestoken. Now I need to pass that aestoken to the CAF Receiver and add it to the request. Maybe somebody can help.
Here is my (JavaScript) code on the Sender:
window.setupBitmovinHLSPlayer = function (playername, videoname, urlStreamingLink, aestoken, posterurl) {
var conf = {
key: 'xxxxx',
cast: {
enable: true
},
remotecontrol: {
type: 'googlecast',
receiverVersion: 'v3',
receiverApplicationId: 'xxxxx'
},
network: {
preprocessHttpRequest: (type, request) => {
if (type === bitmovin.player.HttpRequestType.KEY_HLS_AES) {
request.headers['Authorization'] = 'Bearer ' + aestoken;
}
return Promise.resolve(request);
}
}
};
var source = {
title: videoname,
hls: urlStreamingLink,
poster: posterurl,
metadata: {
aesToken: aestoken,
},
};
var player = new bitmovin.player.Player(document.getElementById(playername), conf);
player.load(source);
};
On the Receiver I have (TypeScript):
import { CastReceiverContext, ContentProtection, NetworkRequestInfo, PlayerManager } from 'chromecast-caf-receiver/cast.framework';
import { LoadRequestData } from 'chromecast-caf-receiver/cast.framework.messages';
import { CAFDrmConfig, CAFMediaInfoCustomData, CAFSourceOptions } from 'bitmovin-player';
const CAST_MESSAGE_NAMESPACE = 'urn:x-cast:com.bitmovin.player.caf';
export default class CAFReceiver {
private readonly player: PlayerManager;
private readonly context: CastReceiverContext;
constructor() {
this.context = cast.framework.CastReceiverContext.getInstance();
this.player = this.context.getPlayerManager();
}
public init() {
// cast.framework.CastReceiverContext.getInstance().setLoggerLevel(cast.framework.LoggerLevel.DEBUG);
this.attachEvents();
this.context.start();
}
private attachEvents() {
this.player.setMessageInterceptor(cast.framework.messages.MessageType.LOAD, this.onLoad);
this.context.addCustomMessageListener(CAST_MESSAGE_NAMESPACE, this.onCustomMessage);
}
private readonly onLoad = (loadRequestData: LoadRequestData): LoadRequestData => {
const customData = loadRequestData.media.customData as CAFMediaInfoCustomData;
if (customData?.options) {
this.setWithCredentials(customData.options);
}
if (customData?.drm) {
this.setDRM(customData.drm);
}
if (loadRequestData.media.customData && loadRequestData.media.customData.metadata) {
console.info('received some metadata from the Bitmovin Player',
loadRequestData.media.customData.metadata);
}
return loadRequestData;
};
private setDRM({ protectionSystem, licenseUrl, headers, withCredentials }: CAFDrmConfig): void {
this.context.getPlayerManager().setMediaPlaybackInfoHandler((_loadRequest, playbackConfig) => {
playbackConfig.licenseUrl = licenseUrl;
playbackConfig.protectionSystem = protectionSystem as ContentProtection;
if (typeof headers === 'object') {
playbackConfig.licenseRequestHandler = (requestInfo) => {
requestInfo.headers = headers;
};
}
if (withCredentials) {
playbackConfig.licenseRequestHandler = setWithCredentialsFlag;
}
return playbackConfig;
});
}
private setWithCredentials(options: CAFSourceOptions): void {
const playerManager = this.context.getPlayerManager();
const playbackConfig = Object.assign(new cast.framework.PlaybackConfig(), playerManager.getPlaybackConfig());
if (options.withCredentials) {
playbackConfig.segmentRequestHandler = setWithCredentialsFlag;
playbackConfig.captionsRequestHandler = setWithCredentialsFlag;
}
if (options.manifestWithCredentials) {
playbackConfig.manifestRequestHandler = setWithCredentialsFlag;
}
playerManager.setPlaybackConfig(playbackConfig);
}
private readonly onCustomMessage = (message: cast.framework.system.Event) => {
console.log('Received custom channel message', message);
};
}
function setWithCredentialsFlag(requestInfo: NetworkRequestInfo): void {
requestInfo.withCredentials = true;
}
Can somebody show me how to add the metadata.easToken to the request?
Many thanks in advance.
Peter