voximplant / react-native-voximplant

Voximplant mobile SDK for React Native (iOS/Android)
http://voximplant.com
205 stars 39 forks source link

client.handlePushNotification: how to check if this is a voximplant push notification #77

Closed sanjaypojo closed 5 years ago

sanjaypojo commented 5 years ago

Hi @YuliaGrigorieva, what is the best practice when using client.handlePushNotification? I guess I should check if the notification contains the key voximplant and only then call this function? The demo application passes through all push notifications to voximplant, would be great if you could show an example of passing only voximplant related push notifications to client.handlePushNotification. Thanks!

YuliaGrigorieva commented 5 years ago

Hello, @sanjaypojo !

Generally, you can pass all notifications to the Voximplant SDK. Voximplant SDK will check if notification is VoIP notification from the Voximplant Cloud. If not, Voximplant SDK won't process it.

However you can check a push notification on the application side before providing it to the Voximplant SDK. To do it, please ensure that push notification data contains "voximplant" key.

Example for Android (push notification is handled by RNFirebase):

firebase.messaging().onMessage(async (message) => {
    console.log('PushManager: FCM: notification: ' + message.data);
    if (message.data.voximplant !== undefined) {
        LoginManager.getInstance().pushNotificationReceived(message.data);
    }
});

Best regards, Yulia Grigorieva

sanjaypojo commented 5 years ago

Perfect, thanks! The reason we want to do this is because we connect to voximplant whenever we get a voximplant push, but we don't want to do this for other push notifications