Show last authors
1 {{box cssClass="floatinginfobox" title="**Contents**"}}
2 {{toc /}}
3 {{/box}}
4
5 = Overview =
6
7 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.
8
9 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.
10
11 = Enabling Push Notifications =
12
13 First, enable the PushNotification module.
14
15 {{code}}
16 [module::PushNotification]
17 enabled=true
18 {{/code}}
19
20 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.
21
22 {{code}}
23 [module::Registrar]
24 # Allow applications to be woken up for 7 days
25 # after their last REGISTER.
26 max-expires=604800
27 {{/code}}
28
29 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.
30
31 {{code}}
32 [module::Router]
33 fork-late=true
34
35 # Make chat messages to be hold for 7 days
36 # before to be dropped. Call invitations are hold for 32s
37 # in conformance with RFC 3261.
38 message-delivery-timeout=604800
39 {{/code}}
40
41 = Configuring for each mobile platform =
42
43 == Apple ==
44
45 (% class="wikigeneratedid" id="HMaketheauthenticationcertificates" %)
46 **Make the authentication certificates**
47
48 Apple push authentication service authenticates the nodes which are authorized to send push notification by using client TLS certificates. Following instructions
49
50 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).
51 1. Connect to [[Apple developer website>>https://developer.apple.com/account/ios/certificate/certificateCreate.action]] and ask for an Apple Push Notification Service SSL certificate (either SandBox or Production)
52 1. Select your application in the list and select the file you generated earlier when a CSR file is requested. Finalize the procedure.
53 1. Now, you must export your certificate (named "Apple Development iOS Push Services: <bundle-id>"), including the private key from Keychain Access, to p12 format.
54 1. 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:
55 1*. for Sandbox certificates: {{code}}openssl pkcs12 -nodes -in <generated-file>.p12 -out <bundle-id>.dev.pem{{/code}}
56 1*. for Production certificates: {{code}}openssl pkcs12 -nodes -in <generated-file>.p12 -out <bundle-id>.prod.pem{{/code}}
57
58 (% class="wikigeneratedid" id="HConfigureFlexisip" %)
59 **Configure Flexisip**
60
61 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.
62
63 {{code}}
64 [module::PushNotification]
65 apple=true
66 {{/code}}
67
68 == Android (Firebase) ==
69
70 (% class="wikigeneratedid" id="HRegisteryourapplicationonFirebaseservice" %)
71 **Register your application on Firebase service**
72
73 [[Sign in into Firebase>>https://console.firebase.google.com/?authuser=0]] and follow [[Add Firebase using the Firebase console>>https://firebase.google.com/docs/android/setup?authuser=0#console]] procedure. Steps 3 and 4 may be skipped.
74
75 (% class="wikigeneratedid" id="HFlexisipconfiguration" %)
76 **Flexisip configuration**
77
78 Enable the ##firebase## backend and set ##firebase-projects-api-keys## parameter, where## <sender_id>## and ##<server_key>## can be gotten form Firebase console in //"Settings" section > "Cloud messaging" tab//.
79
80 {{code language="ini"}}
81 [module::PushNotification]
82 firebase=true
83 firebase-projects-api-keys=<sender id>:<server key>
84 {{/code}}
85
86 = Testing =
87
88 You may test that your server-side configuration is ok by using the //flexisip-pusher //tool embedded in the Flexisip installation package. It enables to manually send a notification request to the push notification server. You may invoke //flexisip-pusher// using the following:
89
90 {{code language="bash"}}
91 ./flexisip_pusher --pn-provider <provider> --pn-param <params> --pn-prid <prid> --debug
92 {{/code}}
93
94 (% class="wikigeneratedid" %)
95 where **<provider>**, **<params>** and **<prid>** indicate which push server to use and all the information required to send a push notification to a specific device, as normalized by [[rfc8599>>https://datatracker.ietf.org/doc/html/rfc8599]]. A summary of the possible values is also available [[in our « Push notification » specification>>doc:Flexisip.D\. Specifications.Push notifications.WebHome||anchor="HRequestingPushNotificationswhileregisteringtheSIPuseragent"]].
96
97 == Testing on iOS ==
98
99 To send a classic « Remote » push notification:
100
101 {{code language="bash"}}
102 ./flexisip_pusher --pn-provider apns.dev --pn-param ABCD1234.<bundle-id> --pn-prid <token> --apple-push-type RemoteBasic --debug
103 {{/code}}
104
105 To send a VoIP push notification:
106
107 {{code language="bash"}}
108 ./flexisip_pusher --pn-provider apns.dev --pn-param ABCD1234.<bundle-id>.voip --pn-prid <token> --apple-push-type PushKit --debug
109 {{/code}}
110
111 Check the the following message to know whether the push request has been successfully sent:
112
113 {{code language="none"}}
114 1 push notification(s) sent, 1 successfully and 0 failed.
115 {{/code}}
116
117 If you get the following error:
118
119 {{code language="none"}}
120 E: PNR 0x7fed1a449858 with identifier 1 failed with error 8 (Invalid token)
121 {{/code}}
122
123 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!
124
125 == Testing on Android ==
126
127 Here's how to send an Android (Firebase) push notification:
128
129 {{code language="bash"}}
130 ./flexisip_pusher --pn-provider fcm --pn-param <ProjectID> --pn-prid <device_token> --key <secret_key> --debug
131 {{/code}}