Can't install Custom Receiver on Chromecast

568 views Asked by At

I'm receiving message Application not installed every time I'm trying to connect to Chromecast with Custom Receiver. I believe the problem could be 1) wrong process of uploading to Chromecast. 2) some error inside the JS code (I'm not strong with it..)

Custom Receiver code. Probably error inside the code. It supposed to decode JSON message with Base 64 string to Image.

</head>
<body>
<img id="androidImage" src="" />
<script type="text/javascript" src="//www.gstatic.com/cast/sdk/libs/receiver/2.0.0/cast_receiver.js"></script>
<script type="text/javascript">
  window.onload = function() {
    cast.receiver.logger.setLevelValue(0);
    window.castReceiverManager = cast.receiver.CastReceiverManager.getInstance();
    console.log('Starting Receiver Manager');

    // handler for the 'ready' event
    castReceiverManager.onReady = function(event) {
      console.log('Received Ready event: ' + JSON.stringify(event.data));
      window.castReceiverManager.setApplicationState("Application status is ready...");
    };

    // handler for 'senderconnected' event
    castReceiverManager.onSenderConnected = function(event) {
      console.log('Received Sender Connected event: ' + event.data);
      console.log(window.castReceiverManager.getSender(event.data).userAgent);
    };

    // handler for 'senderdisconnected' event
    castReceiverManager.onSenderDisconnected = function(event) {
      console.log('Received Sender Disconnected event: ' + event.data);
      if (window.castReceiverManager.getSenders().length == 0) {
        window.close();
      }
    };

    // handler for 'systemvolumechanged' event
    castReceiverManager.onSystemVolumeChanged = function(event) {
      console.log('Received System Volume Changed event: ' + event.data['level'] + ' ' +
          event.data['muted']);
    };

    // create a CastMessageBus to handle messages for a custom namespace
    window.messageBus =
      window.castReceiverManager.getCastMessageBus(
          'urn:x-cast:com.it.innovations.smartbus');

    // handler for the CastMessageBus message event
    window.messageBus.onMessage = function(event) {
      console.log('Message recieved');

      var obj = JSON.parse(event.data)

      console.log('Message type: ' + obj.type);
      if (obj.type == "text") {
        console.log('Skipping message: ' + obj.data);
      }

      if (obj.type == "image") {
        var source = 'data:image/png;base64,'.concat(obj.data)
        displayImage(source);
      }

      // inform all senders on the CastMessageBus of the incoming message event
      // sender message listener will be invoked
      window.messageBus.send(event.senderId, event.data);
    }

    // initialize the CastReceiverManager with an application status message
    window.castReceiverManager.start({statusText: "Application is starting"});
    console.log('Receiver Manager started');
  };


  function displayImage(source) {
    console.log('received image');
    document.getElementById("androidImage").src=source;
    window.castReceiverManager.setApplicationState('image source changed');
  };

</script>

ps. The namespace is the same as in sender App.

The process of installation of Custom Receiver:

  1. Created .js file (also tried .html) with code above.
  2. Hosted that file on Google Drive (link). Also tried with .html file and a link with direct file download.
  3. Made link world visible.
  4. Added this link in Cast Console for registered Custom Receiver in field URL
  5. Use APP ID in sender app of registered Receiver.

Seems like it tries to install this receiver every time I connect to Chromecast but then it takes few seconds (screen is black) and crashes with code 15 (timeout). I was trying default APP ID and then it connects to receiver properly but it isn't able to decode string.

Also I can't debug receiver by chromecast-ip:9222 since its not installed yet.

I would appreciate any help. Thanks.

1

There are 1 answers

5
Ali Naddaf On

First lets fix your hosting issue. Using Google Drive for hosting while you are developing your receiver is fine but you need to follow certain steps to make sure it is hosted properly. Please refer to this page to see the proper steps; when it is correctly hosted, your URL should look like www.googledrive.com/host/[doc id]