Make requests on chromecast receiver shutdown event

649 Views Asked by At

I'm developing a chromecast custom receiver, and I need to send a request to the server once the sender disconnects from receiver. When I use ios or android senders, I can see that the 'sender disconnect' event is triggered, but when I use the browser, that event is not triggered.

Because of that, I'm trying to use the 'shutdown' event, to send that request, once the sender is disconnected.

I tried to pass an 'async/await' function as callback to the shutdown event, and tried to force an 'await' on the request, but I get the ' Application should not send requests before the system is ready (they will be ignored)'

I also tried to use the window 'beforeunload' event, but with no success.

Is there any way to send a request, once the 'shutdown' event is triggered?

Cheers

1

There are 1 best solutions below

1
On

For us the Dispatching Shutdown event occurred in both cases. Web and Mobile senders. So I'm not sure what's happening on your end but will definitely need more information regarding what you're doing in order to look further into it.

Anyhow, if you are setting addEventListeners on your end like this:

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

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

Which will result in your calls not firing. You should instead be doing:

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

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

Here's the docs for their reference: https://developers.google.com/cast/docs/reference/web_receiver/cast.framework.system#.EventType