angularangular-pwa

How to prevent push notification when app is open in angular using PwPush


I am using PwPush to push notification from server to desktop. Now if my angular app is already open in chrome I don't want to see push notification instead I just want to update UI. Right now I only get push notification even if app is open or closed. Is there a way to achieve this in angular?


Solution

  • It seems like I was going about this wrong way. The push notification shows if I send payload with notification key values pair. but if I send simple payload without notification key then everything works fine like I want. I still get the message and notification is not shown

    For visulisation I changed the payload from this

          let payload = {
            notification: {
                title: 'Title',
                body: 'This is my body',
                
                icon: 'assets/icons/icon-384x384.png',
                actions: [
                    { action: 'bar', title: 'Focus last' },
                    { action: 'baz', title: 'Navigate last' },
                ],
                data: {
                    onActionClick: {
                        default: { operation: 'openWindow' },
                        bar: {
                            operation: 'focusLastFocusedOrOpen',
                            url: 'https://www.google.com',
                        },
                        baz: {
                            operation: 'navigateLastFocusedOrOpen',
                            url: '/signin',
                        },
                    },
                    url:"https://www.google.com",
                },
            },
        };
    

    to this

          let payload = {
            "body":"some stuff",
        };