CAF Receiver, shutdown handling

2019-08-04 23:18发布

问题:

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)

回答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



回答2:

Synthax with CAF Receiver:

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