I am attempting to work through the github project, "CastHelloText-chrome" at: https://github.com/googlecast/CastHelloText-chrome
I have been through the samples and the official documentation. Currently I am trying to pass a simple string to the sender.
This is my function:
function DispatchToSender() {
debugger;
try {
if (window.messageBus == null) {
window.messageBus =
window.castReceiverManager.getCastMessageBus(
'urn:x-cast:com.radiodile.mobilex');
}
//I now pass in "theSenderID" based on Ali's comment
window.messageBus.send(theSenderID, "This gun's for hire");
} catch (e) {
console.log("Dispath to sender exception: " + e);
}
}
This does nothing and the documentation is very sparse on this use-case (at least to my overheated brain)
Can someone give me a nudge in the right direction please?
Thanks!
PS - My DispatchToSender() function does step into the following:
// Returns true if the specified port id is in this context. This is used by function hasPort(portId) { return portId in ports; }; // the C++ to avoid creating the javascript message for all the contexts that // don't care about a particular message.
The above seems to be part of the JS SDK I reference from my custom receiver. It never gets past that so I am sure I am doing something wrong but there are no examples for dummies such as moi :))
UPDATE For Ali Naddaf's comment - still no luck
I have read your comment sir and tried the following.
receiver.html
from initialization in receiver.html - I set a page level variable, "theSenderID" to the event.senderId value
// handler for the CastMessageBus message event
window.messageBus.onMessage = function (event) {
console.log('Message [' + event.senderId + ']: ' + event.data);
theSenderID = event.senderId; // CAPTURE THE SENDER ID FOR RE-USE IN DISPATCH EVENT FN()
// display the message from the sender
displayText(event.data);
// inform all senders on the CastMessageBus of the incoming message event
// sender message listener will be invoked
window.messageBus.send(event.senderId, event.data);
}
I then attempt to send a message like so in the DispatchEvent() function I wrote:
window.messageBus.send(theSenderID, "This gun's for hire");
In the above I do have a value for theSenderID and it is: "6:client-54624"
When I call window.messageBus.send I see no exception but in my sender app I never receive the message:
chromehellotext.html
/**
* utility function to log messages from the receiver
* @param {string} namespace The namespace of the message
* @param {string} message A message string
*/
function receiverMessage(namespace, message) {
appendMessage("receiverMessage: " + namespace + ", " + message);
};
Please note before reading your comment I was using the custom namespace I created as the senderId because of the first parameter in the sender's, "receiverMessage()" function.
The receiverMessage() does work and was intercepting the setApplicationState(text) value in the DisplayText() function of the receiver for the chromehellotext sample.
I am thoroughly confused.
I haven't tried broadcast message but it seems a better practice to communicate directly with the sender?
Thanks!!
The send method is: send(senderId, message)
so I am not clear what you are passing for sender id; that should be the unique sender id that is assigned to that sender by the receiver SDK when it joins/starts the session. If you don't care about one sender vs all connected senders, use broadcast(message)