6

I am working with react native wrapper for Google Cast SDK and I couldn't send a message from the sender to receiver. I am able to cast media or pause and resume it. The problem is only about custom messages. My custom message listener is never called in the receiver side. Should the message have a specific structure that I am missing? Thanks in advance.

Sender:

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

Receiver:

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

Edit: I am able to send message from receiver to sender:

Receiver:

context.sendCustomMessage(CUSTOM_CHANNEL , undefined, 'myMessage'); 

Sender:

GoogleCast.EventEmitter.addListener(GoogleCast.CHANNEL_MESSAGE_RECEIVED, ({undefined, message}) => { console.log(message); }); 
3
  • Have you looked at this sample: github.com/googlecast/CastHelloText-android Commented Jul 30, 2018 at 20:54
  • I am facing the same problem. addCustomMessageListener function is only receiving numbers, not strings. @LeonNicholls ,thanks for your support, but the receiver app of the link you mentioned, is developed in v2, latest is CAF , v3. This problem is specific to CAF. Commented Oct 4, 2018 at 11:58
  • The issue is being investigated: issuetracker.google.com/issues/117136854 Commented Oct 4, 2018 at 17:50

1 Answer 1

5

I think this is problem bellow

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

So try this...

Send

let message = {msg: 'testMessage'}; message = JSON.stringify(message); GoogleCast.sendMessage('urn:x-cast:testChannel', message); 

and Receiver

 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); 
Sign up to request clarification or add additional context in comments.

2 Comments

thank you! I was struggling with this for way to long. this worked well!
OMG, you'd think google would mention that in their docs. Thanks!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.