This page is under rewriting

Overview

PushNotification module allows Flexisip to wake a liblinphone-basd application up when a chat message or call invite cannot be delivered because the application is unavailable. This feature has become crucial since mobile OSs got used to making the application to hibernate in order to save power.

Today, Flexisip supports native push systems of Android, iOS and Windows Phone ; but can also delegate the work of sending the push request to a tier service using HTTP GET API.

Enabling Push Notifications

First, enable the PushNotification module.

[module::PushNotification]
enabled=true

Applications notify Flexisip of their push IDs by using custom parameters in their REGISTER requests, so that Flexisip is able to send push requests to a given application if this one is still register. Thus, expire time of a REGISTER influence how long an application can be woken up, so you should set Flexisip to authorize high expire value.

[module::Registrar]
# Allow applications to be woken up for 7 days
# after their last REGISTER.
max-expires=604800

Furthermore, by default, Flexisip immediately give up call session establishment or delivering a message when the destination isn't available. Thus, the application won't be able to receive the call invitation or the chat message for which it has been woken up because it simply has been dropped by the proxy. fork-late in module::Router section must be set to true to allow the proxy to hold call invitations and chat messages for a given time before dropping them.

[module::Router]
fork-late=true

# Make chat messages to be hold for 7 days
# before to be dropped. Call invitations are hold for 32s
# in conformance with RFC 3261.
message-delivery-timeout=604800

Creating and installing push certificates

Apple

Make the authentication certificates

Apple push authentication service authenticates the nodes which are authorized to send push notification by using client TLS certificates. Following instructions

  1. On macOS, open Keychain Access > Certificate Assistant > Request a certificate from a Certificate Authority. Enter your email and check "Saved to disk" box (this file will be deleted soon).
  2. Connect to Apple developer website and ask for an Apple Push Notification Service SSL certificate (either SandBox or Production)
  3. Select your application in the list and select the file you generated earlier when a CSR file is requested. Finalize the procedure.
  4. Now, you must export your certificate (named "Apple Development iOS Push Services: <bundle-id>"), including the private key from Keychain Access, to p12 format.
  5. Then, you need to convert your p12 certificate into PEM format. The PEM certificate MUST NOT be protected by a password. OpenSSL utilities may be used for such conversion:
    • for Sandbox certificates: openssl pkcs12 -nodes -in <generated-file>.p12 -out <bundle-id>.dev.pem
    • for Production certificates: openssl pkcs12 -nodes -in <generated-file>.p12 -out <bundle-id>.prod.pem

Configure Flexisip

To enable Apple push notification you just need to set apple=true and place the certificates you made earlier in /etc/flexisip/apn. The directory where to place Apple push certificates may be changed using apple-certificate-dir parameter.

[module::PushNotification]
apple=true

Android (Firebase)

Register your application on Firebase service

Sign in into Firebase and follow Add Firebase using the Firebase console procedure. Steps 3 and 4 may be skipped.

Client side

Edit the non_localizable_custom.xml file and add/edit to match the following:

<string name="push_type">firebase</string>
<string name="push_sender_id">your_firebase_id</string>

Server side

Firebase push notifications are supported in flexisip version 1.0.10-196 (0da032c963ad8c856bbde3769b58c7ae580cc815) and newer.

Edit the flexisip.conf file and add/edit to match the following (replace sender id and server key by the values from the firebase console, settings section, cloud messaging tab) :

[module::PushNotification]
firebase=true
firebase-projects-api-keys=<sender id>:<server key>

Then (re)start flexisip, and you'll have the push notifications for Android using firebase.

If you want to add multiple pairs of sender id and server key, separate them with a 'space' character in the firebase-projects-api-key.

Testing

You may test that your server-side configuration is ok by using the flexisip-pusher tool embedded in the Flexisip installation package. It enable to manually send a notification request to the push notification server. You may invoke flexisip-pusher using the following:

./flexisip_pusher --pntype <platform> --appid <appid> --pntok <device token> --debug

Testing on iOS

To send a push request to the Apple's server, one may use:

./flexisip_pusher --pntype apple --appid <bundle-id>.dev --pntok <tok> --debug

If it is alright, the ouput should look like:

Feb 14 06:42:14 ns3002422 flexisip: PushNotificationClient org.linphone.phone.voip.prod.pem PNR 0x7f3e04e79af8 sent 105/105 data
Feb 14 06:42:14 ns3002422 flexisip: PushNotificationClient org.linphone.phone.voip.prod.pem PNR 0x7f3e04e79af8 waiting for server response
Feb 14 06:42:15 ns3002422 flexisip: PushNotificationClient org.linphone.phone.voip.prod.pem PNR 0x7f3e04e79af8 nothing read, assuming success

If you get the following error:

E: PNR 0x7fed1a449858 with identifier 1 failed with error 8 (Invalid token)

It probably means that you are using the wrong application id. Note: to test the production certificate, you must generate an adhoc IPA and install it manually!

Testing on Android

You can test and troubleshoot your setup using the flexisip_pusher tool available with flexisip.

Here's how to send an Android (firebase) push notification:

/opt/belledonne-communications/bin/flexisip_pusher --pntype firebase --appid <sender_id> --key <server_key> --pntok <device_push_token> --debug