Authentication in Chromecast CAF Receiver application

时间秒杀一切 提交于 2020-02-22 08:09:26

问题


I have a help URL which is to be authenticated with a token before playing it. How can I add a token header to a receiver CAF application? I searched in the documentation but couldn't find any reference of authentication for a receiver CAF application.

In V2 player we can intercept the request with updateSegmentRequestInfo as shown below but im not sure how to do it with CAF Application. Can someone help?

host.updateSegmentRequestInfo = function(requestInfo) {
            console.log("Inside updateSegmentRequestInfo");
            requestInfo.withCredentials = true;
            requestInfo.headers = {};
            requestInfo.headers['token'] = window.token;
            console.log("token sent");
        };

回答1:


Set cookies on player load event.

Use this code:

const context = cast.framework.CastReceiverContext.getInstance();
const playerManager = context.getPlayerManager();
const castOptions = new cast.framework.CastReceiverOptions();

let playbackConfig = (Object.assign(new cast.framework.PlaybackConfig(), playerManager.getPlaybackConfig()));

playerManager.setMessageInterceptor(
cast.framework.messages.MessageType.LOAD,
request => {

  // Set cookies here. 
  // No need to pass cookies into header in each segment.

  //  console.log("content id:", request.media.contentId);
  //  Set your segment valid hls format : below is example:
  //  Refer other format:
  //  https://developers.google.com/cast/docs/reference/caf_receiver/cast.framework.messages#.HlsSegmentFormat

  request.media.hlsSegmentFormat = cast.framework.messages.HlsSegmentFormat.TS;

  return request;
});

playbackConfig.manifestRequestHandler = requestInfo => {
    requestInfo.withCredentials = true;
};

playbackConfig.segmentRequestHandler = requestInfo => {
    requestInfo.withCredentials = true;
  };

playbackConfig.licenseRequestHandler = requestInfo => {
    requestInfo.withCredentials = true;
};

castOptions.playbackConfig = playbackConfig;
context.start(castOptions);


来源:https://stackoverflow.com/questions/49167374/authentication-in-chromecast-caf-receiver-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!