static/sw.js
function onMessageReceivedSubscriptionState() {
    let retrievedPushSubscription = null;
    self.registration.pushManager.getSubscription()
        .then(pushSubscription => {
            retrievedPushSubscription = pushSubscription;
            if (!pushSubscription) {
                return null;
            } else {
                return self.registration.pushManager.permissionState(
                    pushSubscription.options
                );
            }
        }).then(permissionStateOrNull => {
            if (permissionStateOrNull == null) {
                broadcastReply(WorkerMessengerCommand.AMP_SUBSCRIPTION_STATE, false);
            } else {
                const isSubscribed = !!retrievedPushSubscription &&
                    permissionStateOrNull === 'granted';
                broadcastReply(WorkerMessengerCommand.AMP_SUBSCRIPTION_STATE,
                    isSubscribed);
            }
        });
}
function onMessageReceivedSubscriptionState() {
    let retrievedPushSubscription = null;
    self.registration.pushManager.getSubscription()
        .then(pushSubscription => {
            retrievedPushSubscription = pushSubscription;
            if (!pushSubscription) {
                return null;
            } else {
                return self.registration.pushManager.permissionState(
                    pushSubscription.options
                );
            }
        }).then(permissionStateOrNull => {
            if (permissionStateOrNull == null) {
                broadcastReply(WorkerMessengerCommand.AMP_SUBSCRIPTION_STATE, false);
            } else {
                const isSubscribed = !!retrievedPushSubscription &&
                    permissionStateOrNull === 'granted';
                broadcastReply(WorkerMessengerCommand.AMP_SUBSCRIPTION_STATE,
                    isSubscribed);
            }
        });
}
function onMessageReceivedSubscriptionState ( ) { let retrievedPushSubscription = null ; self . registration . pushManager . getSubscription ( ) . then ( pushSubscription => { retrievedPushSubscription = pushSubscription ; if ( ! pushSubscription ) { return null ; } else { return self . registration . pushManager . permissionState ( pushSubscription . options ) ; } } ) . then ( permissionStateOrNull => { if ( permissionStateOrNull == null ) { broadcastReply ( WorkerMessengerCommand . AMP_SUBSCRIPTION_STATE , false ) ; } else { const isSubscribed = ! ! retrievedPushSubscription && permissionStateOrNull === 'granted' ; broadcastReply ( WorkerMessengerCommand . AMP_SUBSCRIPTION_STATE , isSubscribed ) ; } } ) ; }
Broadcasts a single boolean describing whether the user is subscribed.
Broadcasts a single boolean describing whether the user is subscribed .