Ioni c 5 pu sh уведомление с Laravel Echo - PullRequest
0 голосов
/ 16 апреля 2020

Я пишу приложение, которое должно содержать pu sh уведомление. Я использую Ioni c 5 (Angular) на внешнем интерфейсе и Laravel на внутреннем. Laravel испускает уведомления через Echo.

Я хотел бы использовать это с конденсатором: https://ionicframework.com/docs/native/push

Однако это описание слегка затуманивает и лабиринт ...

Мой list.component.ts выглядит следующим образом:

// Echo imported
    import {Push, PushObject, PushOptions} from '@ionic-native/push/ngx';

...

    constructor(private push: Push) {
    window.Echo = new Echo.default({
                broadcaster: 'socket.io',
                host: 'https://myhost.eu:6000',
                auth: {
                    headers: {
                        'X-Auth-Token': localStorage.getItem('_token')
                    }
                }
            });
            window.Echo.private('auctions')
                .listen('NewAuctionCreated', (e) => {
                    console.log('in auction');
                    if (e.auction) {
                        e.auction.new = true;
                        this.items.unshift(e.auction);
                        this.playNotification();
                    }
                });
        this.pushNotification();
    }
...

    pushNotification() {
        // push
        // to check if we have permission
        this.push.hasPermission().then((res: any) => {
            if (res.isEnabled) {
                console.log('We have permission to send push notifications');
                console.log(res);
            } else {
                console.log('We do not have permission to send push notifications');
            }
        });


        // Create a channel (Android O and above). You'll need to provide the id, description and importance properties.
        this.push.createChannel({
            id: 'auctions',
            description: 'Auction channel created',
            // The importance property goes from 1 = Lowest, 2 = Low, 3 = Normal, 4 = High and 5 = Highest.
            importance: 5,
            badge: true
        }).then(() => console.log('Channel created'));

        // Delete a channel (Android O and above)
        // this.push.deleteChannel('testchannel1').then(() => console.log('Channel deleted'));

        // Return a list of currently configured channels
        this.push.listChannels().then((channels) => console.log('List of channels', channels));

        // to initialize push notifications
        const options: PushOptions = {
            android: {},
            ios: {
                alert: 'true',
                badge: true,
                sound: 'false'
            },
            windows: {},
            browser: {
                pushServiceURL: 'http://push.api.phonegap.com/v1/push'
            }
        }

        const pushObject: PushObject = this.push.init(options);


        pushObject.on('notification').subscribe((notification: any) => console.log('Received a notification', notification));

        pushObject.on('registration').subscribe((registration: any) => console.log('Device registered', registration));

        pushObject.on('error').subscribe(error => console.error('Error with Push plugin', error));
}

Как я могу отправлять и получать уведомления? (Эхо части и бэкэнд работают нормально)

...