I've looked high and low for an answer and I can't seem to find anything, Google's Docs seem incomplete to the matter of message sending to a Custom Receiver.
Also previous answers on StackOverflow seem to only be using the V1 Receiver API which don't seem to work with the V2 API.
Could anybody point me in the right direction to simply explain how to send a message from a Chrome Sender App to a Receiver using the V2 API?
You can configure your Chromecast Voice Remote to control devices like your TV, receiver or soundbar by setting up the volume, power and input buttons. If you didn't configure these buttons when you first set up your Chromecast with Google TV, you can set them up later in Chromecast settings.
The new Cast Application Framework (CAF) SDK, also known as Web Receiver v3, is a major upgrade from the Receiver v2 SDK. The Web Receiver SDK provides an easy, streamlined SDK for developing media Web Receiver applications. The Web Receiver provides an API that is more consistent with the new CAF sender APIs.
The Google Cloud Adoption Framework helps you identify key activities and objectives that will reliably accelerate your cloud journey.
On the sender side you can send messages via the session object you get in the session listener:
session.sendMessage(namespace, message, onSuccess, onFailure);
https://developers.google.com/cast/docs/reference/chrome/chrome.cast.Session#sendMessage
On the receiver side you create a message bus and listen for incoming messages:
messageBus = castReceiverManager.getCastMessageBus(
namespace,
cast.receiver.CastMessageBus.MessageType.JSON
);
messageBus.onMessage = function(event) {
var sender = event.senderId;
var message = event.data;
};
https://developers.google.com/cast/docs/reference/receiver/cast.receiver.CastReceiverManager#getCastMessageBus https://developers.google.com/cast/docs/reference/receiver/cast.receiver.CastMessageBus
You can define the namespace
yourself, but it must be the same in sender and receiver and start with urn:x-cast:
And it's important to define the correct Message type for the information you are going to send, but JSON is probably the most versatile.
You can also use the message bus to send messages back to the sender:
messageBus.send(senderId, message);
with a listener on the Sender side:
session.addMessageListener(namespace, function (ns, message) {
});
https://developers.google.com/cast/docs/reference/chrome/chrome.cast.Session#addMessageListener
I also have a very simple Chrome Sender/Custom Receiver sample up on Github with a complete implementation of sending messages: https://github.com/Scarygami/chromecast_experiments/tree/master/photocast
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With