gpt4 book ai didi

Chromecast 无法接收自定义消息(CAF 接收器)

转载 作者:行者123 更新时间:2023-12-01 05:53:31 28 4
gpt4 key购买 nike

我正在为 Google Cast SDK 使用 React Native 包装器,但无法从发送方向接收方发送消息。我能够转换媒体或暂停并恢复它。问题仅在于自定义消息。我的自定义消息监听器永远不会在接收方调用。消息是否应该具有我缺少的特定结构?提前致谢。

发件人:

  GoogleCast.initChannel('urn:x-cast:testChannel');

GoogleCast.sendMessage('urn:x-cast:testChannel', 'testMessage');

接收者:
const context = cast.framework.CastReceiverContext.getInstance();
const CUSTOM_CHANNEL = 'urn:x-cast:testChannel';
context.addCustomMessageListener(CUSTOM_CHANNEL, function(customEvent) {
// handle customEvent.
console.log('event received');
});

编辑:我能够从接收者向发送者发送消息:

接收者:
context.sendCustomMessage(CUSTOM_CHANNEL , undefined,  'myMessage');

发件人:
GoogleCast.EventEmitter.addListener(GoogleCast.CHANNEL_MESSAGE_RECEIVED, ({undefined, message}) => {
console.log(message);
});

最佳答案

我认为这是下面的问题

https://issuetracker.google.com/issues/117136854#comment7

所以试试这个...

发送

let message = {msg: 'testMessage'};
message = JSON.stringify(message);

GoogleCast.sendMessage('urn:x-cast:testChannel', message);

和接收器
  const CHANNEL = 'urn:x-cast:testChannel';
const ctx = cast.framework.CastReceiverContext.getInstance();
const options = new cast.framework.CastReceiverOptions();
const objToSender =
{
type: 'status',
message: 'Playing'
};

options.customNamespaces = Object.assign({});
options.customNamespaces[CHANNEL] = cast.framework.system.MessageType.JSON;

//receiving sender message
ctx.addCustomMessageListener(CHANNEL, customEvent => document.getElementById("main").innerHTML = customEvent.data.msg);

//message to sender app
ctx.sendCustomMessage(CHANNEL, objToSender);

ctx.start(options);

关于Chromecast 无法接收自定义消息(CAF 接收器),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51544887/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com