【问题标题】:Authentication in Chromecast CAF Receiver applicationChromecast CAF 接收器应用程序中的身份验证
【发布时间】:2018-08-16 11:13:35
【问题描述】:

我有一个帮助 URL,在播放它之前要使用令牌进行身份验证。如何将令牌标头添加到接收方 CAF 应用程序?我在文档中进行了搜索,但找不到任何有关接收器 CAF 应用程序的身份验证参考。

在 V2 播放器中,我们可以使用updateSegmentRequestInfo 拦截请求,如下所示,但我不确定如何使用 CAF 应用程序来拦截请求。有人可以帮忙吗?

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

【问题讨论】:

标签: authentication chromecast


【解决方案1】:

在播放器加载事件上设置 cookie。

使用此代码:

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

【讨论】:

  • 谢谢 以前我使用“cast.player.api.HlsSegmentFormat.MPEG2_TS”,但现在我使用的是“cast.framework.messages.HlsSegmentFormat.TS”。如果有人用谷歌搜索的话。
猜你喜欢
  • 2018-08-07
  • 1970-01-01
  • 2020-05-03
  • 2014-06-17
  • 1970-01-01
  • 1970-01-01
  • 2019-01-03
  • 2018-12-23
  • 2016-10-25
相关资源
最近更新 更多