【发布时间】:2019-01-03 19:22:12
【问题描述】:
我正在为 Google Cast SDK 使用 react 本机包装器,但我无法将消息从发送方发送到接收方。我可以投射媒体或暂停并恢复它。问题仅与自定义消息有关。我的自定义消息侦听器永远不会在接收方调用。消息是否应该具有我缺少的特定结构?提前致谢。
发件人:
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);
});
【问题讨论】:
-
我也面临同样的问题。 addCustomMessageListener 函数只接收数字,而不是字符串。 @LeonNicholls,感谢您的支持,但是您提到的链接的接收器应用程序是在v2中开发的,最新的是CAF,v3。这个问题是 CAF 特有的。
标签: chromecast google-cast google-cast-sdk caf-receiver-sdk