I'm trying to initialise the cast message bus on my receiver application. I am using the CastReferencePlayer Sample I'm able to initialise the channel at launch, and receive one message.
But after media is playing, I'm not able to receive
any additional messages over the channel using the same send
methods on
the sender. My sender is an iOS Device
Where is the best place to init the message bus to ensure that the channel is open to receive messages throughout the life of the app?
I am currently starting the channel
in sampleplayer.CastPlayer.prototype.start = function()
. But I'm not sure if this is the correct place to start the message bus as I'm only receiving the message once at startup (i.e. before the media starts to play).
sampleplayer.CastPlayer.prototype.start = function() {
var messageBus = this.receiverManager_.getCastMessageBus(
"urn:x-cast:com.myTestChannel.app",
cast.receiver.CastMessageBus.MessageType.JSON);
messageBus.onMessage = function(event) {
var message = event.data;
if (message.testID) {
console.log("Message received");
} else if (message.someKey) {
console.log("pause message received");
}
};
this.receiverManager_.start();
};
I have tried to place the channel creation code in a window.onload
function inside my player.js
but this reacts the same as before (i.e. initial message only).
Does anyone have any idea where I should be placing the code to init the channel? Any help would be appreciated.
EDIT: I have done some more investigating and discovered that it is just my iOS sender that will not send multiple messages to the receiver. I have tried both android and chrome and multiple messages work. Is anyone aware of problems with sending messages from an iOS sender.
The problem with my code was in my sender.
The sendTextMessage
method was not firing the after the first instance due to the my reference to the cast channel being destroyed.