Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sending messages from Sender to Custom Receiver with Chromecast receiver API V2

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?

like image 544
2xAA Avatar asked Apr 29 '14 16:04

2xAA


People also ask

Can chromecast control my receiver?

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.

What is CAF receiver?

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.

What is Google Caf?

The Google Cloud Adoption Framework helps you identify key activities and objectives that will reliably accelerate your cloud journey.


1 Answers

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

like image 174
Scarygami Avatar answered Jan 04 '23 13:01

Scarygami