Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sendbird, cordova push notification functionality

I am building a chat application using Sendbird and cordova, however they seem to offer an api for push notifications for all platforms except from Javascript. They have push notifications for Android, ios,Unity and .Net + Xamarin.. Because i am a newbie I'm not sure if the JS api is incomplete or they have design decisions for not implementing it.

Can someone assist me with a way to get push notifications for Sendbird and Cordova, I assume FCM will be required.

like image 969
sqwale Avatar asked Nov 07 '22 12:11

sqwale


1 Answers

I have found a scrappy solution.

You will need to use the platfrom API and install the following two commands.

  1. cordova plugin add phonegap-plugin-push --variable SENDER_ID="xxxxxxxx" --save
  2. cordova plugin add cordova-plugin-fcm

Before the above works in your project you will need to follow the steps 1 & 2 for Android and/or 1,2 and 3 for iOs.

Once all is complete you should have put the following two files in the root directory of your project such that "www" is a sibling to the files in terms of hierarchy.

  1. google-services.json
  2. GoogleService-Info.plist

once compelete follow this step from phone-gap-push. You ideally only need the following snippet to register the token.

const push = PushNotification.init({
android: {
},
browser: {
    pushServiceURL: 'http://push.api.phonegap.com/v1/push'
},
ios: {
    alert: "true",
    badge: "true",
    sound: "true"
},
windows: {}
});

push.on('registration', (data) => {
 // what you get back in your data variable will be two things
 // registrationId and registrationType

 // Use the returned values to make the platform api call to sendbird    
});

Important things to note sendbird only send push notifications when you are offline. Either the iOs or Android documentaion for push notifications highlights these disclaimers very well.

By setting up push notification service to an app, your app users can receive messages even when they are offline. Typically, you might want users to receive push notifications after their app goes into the background. SendBird SDK automatically detects if your app enters the background and updates the user's connection status to Disconnected. Therefore, in normal cases, you do not have to call disconnect explicitly.

There you have it a corodva/phonegap/javascript implementation of push notifications on Sendbird.

And no I can't tell you why Sendbird didn't document similar! If anyone has a better more efficient way I am all ears.

like image 177
sqwale Avatar answered Nov 14 '22 23:11

sqwale