我正在使用 Google Cast SDK 的原生包装器,我无法将消息从发送者发送到接收者。我可以投射媒体或暂停并恢复它。问题仅与自定义消息有关。我的自定义消息侦听器永远不会在接收方调用。消息是否应该具有我缺少的特定结构?提前致谢。
发件人:
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);
});