请求chromecast接收器关闭事件



我正在开发一个chromecast自定义接收器,一旦发送器与接收器断开连接,我需要向服务器发送请求。当我使用ios或android发件人时,我可以看到"发件人断开连接"事件被触发,但当我使用浏览器时,该事件不会被触发。

正因为如此,我试图在发送方断开连接后使用"shutdown"事件来发送该请求。

我试图传递一个"async/await"函数作为关闭事件的回调,并试图对请求强制执行"await",但我得到了"Application should not send requests before the system is ready (they will be ignored)">

我还尝试使用窗口"beforeunload"事件,但没有成功。

一旦触发"关闭"事件,是否有任何方法发送请求?

干杯

对我们来说,调度关闭事件在这两种情况下都发生了。Web和移动发件人。所以我不确定你这边发生了什么,但肯定需要更多关于你正在做什么的信息,以便进一步调查

无论如何,如果你在你的终端上设置addEventListeners,如下所示:

context.addEventListener(cast.framework.system.ShutdownEvent,
()=>{
console.log("ShutdownEvent Called");
});
context.addEventListener(cast.framework.system.SenderDisconnectedEvent,
()=>{
console.log("SenderDisconnectedEvent called");
});

这将导致你的电话不被接听。你应该做的是:

context.addEventListener(cast.framework.system.EventType.SHUTDOWN,             
()=>{
console.log("ShutdownEvent Called");
});
context.addEventListener(cast.framework.system.EventType.SENDER_DISCONNECTED,  
()=>{                                                                                                      console.log("SenderDisconnectedEvent called");                                     });

以下是供他们参考的文档:https://developers.google.com/cast/docs/reference/web_receiver/cast.framework.system#.EventType

最新更新