本文介绍了Chromecast CAF Receiver应用程序中的身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个帮助URL,该URL将在播放前用令牌进行身份验证.如何向接收方CAF应用程序添加令牌头?我在文档中进行了搜索,但是找不到接收方CAF应用程序的身份验证参考.

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.

在V2播放器中,我们可以使用updateSegmentRequestInfo拦截请求,如下所示,但是我不确定如何使用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");
        };

推荐答案

在播放器加载事件中设置cookie.

Set cookies on player load event.

使用此代码:

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);

这篇关于Chromecast CAF Receiver应用程序中的身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-09 07:30