Javascript Can';t在Chromecast上安装自定义接收器

Javascript Can';t在Chromecast上安装自定义接收器,javascript,chromecast,google-cast,Javascript,Chromecast,Google Cast,每次我尝试使用自定义接收器连接Chromecast时,我都会收到消息应用程序未安装。我相信问题可能是1)上传到Chromecast的过程错误。2) JS代码中出现了一些错误(我不太懂) 自定义接收器代码。代码中可能有错误。它应该用base64字符串将JSON消息解码为图像 </head> <body> <img id="androidImage" src="" /> <script type="text/javascript" src="//www.gs

每次我尝试使用自定义接收器连接Chromecast时,我都会收到消息
应用程序未安装
。我相信问题可能是1)上传到Chromecast的过程错误。2) JS代码中出现了一些错误(我不太懂)

自定义接收器代码。代码中可能有错误。它应该用base64字符串将JSON消息解码为图像

</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>

window.onload=函数(){
cast.receiver.logger.setLevelValue(0);
window.castrecivermanager=cast.receiver.castrecivermanager.getInstance();
log(“启动接收器管理器”);
//“就绪”事件的处理程序
castrecivermanager.onReady=函数(事件){
log('Received Ready event:'+JSON.stringify(event.data));
window.castrecivermanager.setApplicationState(“应用程序状态为就绪…”);
};
//“SenderConnectiond”事件的处理程序
castReceiverManager.onSenderConnected=函数(事件){
console.log('接收到的发送方连接的事件:'+事件.data);
log(window.castrecivermanager.getSender(event.data.userAgent);
};
//“senderdisconnected”事件的处理程序
castReceiverManager.onSenderDisconnected=函数(事件){
console.log('接收到的发送方断开连接的事件:'+事件.data);
if(window.castReceiverManager.getSenders().length==0){
window.close();
}
};
//“systemvolumechanged”事件的处理程序
CastreCiverManager.onSystemVolumeChanged=函数(事件){
console.log('接收到的系统卷更改事件:'+事件.数据['level']+''+
事件数据['mute'];
};
//创建CastMessageBus以处理自定义命名空间的消息
window.messageBus=
window.castReceiverManager.getCastMessageBus(
“urn:x-cast:com.it.innovations.smartbus”);
//CastMessageBus消息事件的处理程序
window.messageBus.onMessage=函数(事件){
console.log(“收到消息”);
var obj=JSON.parse(event.data)
console.log('消息类型:'+obj.type);
如果(对象类型==“文本”){
console.log('跳过消息:'+obj.data);
}
如果(对象类型==“图像”){
var source='data:image/png;base64'.concat(obj.data)
显示图像(源);
}
//将传入消息事件通知CastMessageBus上的所有发件人
//将调用发件人消息侦听器
window.messageBus.send(event.senderId,event.data);
}
//使用应用程序状态消息初始化CastreceDriverManager
window.castrecivermanager.start({statusText:“应用程序正在启动”});
log(“接收器管理器已启动”);
};
函数displayImage(源){
log(“接收到的图像”);
document.getElementById(“androidImage”).src=source;
window.castReceiverManager.setApplicationState(“图像源已更改”);
};

另外,名称空间与发件人应用中的名称空间相同

定制接收器的安装过程:

  • 用上面的代码创建了.js文件(也尝试了.html)
  • 在Google Drive()上托管了该文件。还尝试了.html文件和直接文件下载链接
  • 使链接世界可见
  • 在Cast控制台中为字段URL中注册的自定义接收器添加了此链接
  • 在已注册收件人的发件人应用程序中使用应用程序ID
  • 似乎每次我连接到Chromecast时它都会尝试安装这个接收器,但这需要几秒钟的时间(屏幕是黑色的)然后崩溃,代码是15(超时)。我尝试默认的应用程序ID,然后它正确连接到接收器,但它无法解码字符串

    此外,我无法通过chromecast ip:9222调试接收器,因为它尚未安装


    我将感谢任何帮助。谢谢

    首先让我们修复您的主机问题。在开发接收器时使用GoogleDrive进行托管是可以的,但您需要遵循某些步骤以确保它被正确托管。请参阅以查看正确的步骤;当它被正确托管时,您的URL应该看起来像www.googledrive.com/host/[doc id]

    是的,我完全遵循了它。但谷歌似乎禁用了主机。我就是这么说的。我以前是这样主持的,我不认为有什么变化;按照手动步骤(而不是使用脚本)将URL注册为
    https://www.googledrive.com/host/{doc id}
    并将收件人的URL更新为此格式,然后查看是否有效。好的,似乎是托管文件-www.googledrive.com/host/0Bz2Lss3i7uJHZGRKLUx3amJLOTQ。但我无法将此链接放入Cast控制台,请参阅链接已传递。但现在,当我连接到Chromecast时,屏幕右侧有一个带滚动条的黑屏,持续5-10秒。在此之后,我仍然在
    ApplicationConnectionResultCallback.onResult
    中收到超时(15)错误,这可能是什么原因?然后您需要调试接收器。当你的应用程序启动时,你可以尝试使用9222端口连接到chrome进行调试,看看你是否可以了解更多正在发生的事情;看来你原来的问题现在已经解决了。