Skip to content

Handle Push Notifications

kristiyan-petrov edited this page Feb 27, 2024 · 11 revisions

We highly recommend to add push notification to your app in oder to receive incoming calls even when the app is killed.

Be Aware

Server side steps required:

  • Listen server-side for webhook coming from KaleyraVideo.

(Discover how your backend can be notified with upcoming call events registering event hook on_call_incoming here: https://developers.kaleyra.io/reference/video-v2-webhook-post).

  • Forward the data you have received via the webhook to your Android Application with a push notification framework of your choice (FCM, OneSignal or others)

Learn more about FCM
Learn more about OneSignal

Client side steps required:

  • Implement your client listener for notifications (FCM, OneSignal or any others) depends on the notification framework you have decided to use.
  • Once received the notification you will need to give the payload of the notification to our SDK. In case your application handles different types of notifications be sure to forward only the payload meant for our SDK (the one you have received from the webhook)

Client handle Payload

Incoming calls and chat messages push notification payloads can be passed to the BandyerSDK object as shown below. Be sure to connect the BandyerSDK instance before.

AccessTokenProvider accessTokenProvider = new AccessTokenProvider() {
            
	@Override
	public void provideAccessToken(@NonNull String userId, @NonNull Completion<String> completion) {
		// retrieve token [...]
		completion.success(accessToken); // or call completion.error(exception) if an error occurred during token retrieval process
	}
};

Session session = new Session(
	"userId",
	accessTokenProvider,
	sessionObserver);

BandyerSDK.getInstance().connect(
	session,
	errorReason -> Log.e(TAG, "Unable to connect BandyerSDK with error: " + errorReason)
);

BandyerSDK.getInstance().handleNotification(payload);

Example of the notification payload

The push notification payload received by your app is just a simple json containing the information your server sent to FCM.

{
   "event":"on_call_incoming",
   "room_id":"room_f61b4d202472",
   "data":{
      "initiator":"usr_123",
      "users":[
         {
            "user":{
               "userAlias":"usr_123"
            },
            "status":"invited"
         },
         {
            "user":{
               "userAlias":"usr_999"
            },
            "status":"invited"
         }
      ],
      "roomAlias":"room_f61b4d202472",
      "options":{
         "duration":0,
         "record":true,
         "recordingType":"automatic",
         "recording":"automatic",
         "creationDate":"2022-05-26T09:04:38.097Z",
         "callType":"audio_upgradable",
         "live":true
      }
   }
}
Clone this wiki locally