3

i'm trying to add logic to the shutdown event on my receiver app but every time the sender disconnects, debugger just closes and no logic is executed (like sending some HttpRequests). My piece of code:

this.context.addEventListener(
        cast.framework.system.ShutdownEvent,
        e => {
                this._sendStats();
        });

Also tried cast.framework.system.SHUTDOWN and cast.framework.system.SENDER_DISCONNECTED. Is there other way to get the expected result (executing logic on apps shutdown)

Kici
  • 170
  • 3
  • 14

2 Answers2

1

You need to use the event type: cast.framework.system.EventType.SHUTDOWN:

https://developers.google.com/cast/docs/reference/caf_receiver/cast.framework.system#.EventType

Leon Nicholls
  • 4,623
  • 2
  • 16
  • 17
  • 1
    this still not guarantee that async action (eg: XHR call) will be executed. Is it possible to guarantee await of all async actions on the shutdown event handler? – Dzianis Dashkevich Jan 16 '20 at 11:42
1

Synthax with CAF Receiver:

context.addEventListener(cast.framework.system.EventType.SHUTDOWN,
      e => {
        console.log("Shutdown");
    });
Hrk
  • 2,725
  • 5
  • 29
  • 44