Class CefriumPush
java.lang.Object
com.cefrium.CefriumPush
Delivers Web Push messages to the engine.
A page's PushManager.subscribe() registers with Firebase Cloud
Messaging, and FCM delivers each message to the app's
FirebaseMessagingService. An app that already has one passes every
message through handleMessage(Context, String, Bundle); the ones that belong to a web page
go to the engine, which wakes that page's service worker in the profile that
subscribed, and the rest stay with the app:
public void onMessageReceived(RemoteMessage message) {
if (CefriumPush.handleMessage(this, message.getFrom(),
message.toIntent().getExtras())) {
return; // A Web Push message, delivered to the page.
}
// The app's own message.
}
An app without its own Firebase service enables CefriumPushService
instead, which does the above. An app that uses another push service
installs a CefriumPushTransport with setTransport(CefriumPushTransport).
Messages that a CefriumRelayTransport relay sends through the app's
Firebase project arrive the same way and are handled here too.
-
Method Summary
Modifier and TypeMethodDescriptionstatic booleandeliverMessage(android.content.Context context, String appId, byte[] body) Hands a message that aCefriumPushTransportreceived to the engine.static booleanhandleMessage(android.content.Context context, String from, android.os.Bundle data) Hands a Web Push message to the engine.static booleanisWebPushMessage(android.os.Bundle data) static voidsetTransport(CefriumPushTransport transport) Serves every Web Push subscription made from now on withtransportinstead of Firebase Cloud Messaging; null restores FCM.
-
Method Details
-
isWebPushMessage
public static boolean isWebPushMessage(android.os.Bundle data) - Returns:
- true if
datais a Web Push message for the engine.
-
handleMessage
public static boolean handleMessage(android.content.Context context, String from, android.os.Bundle data) Hands a Web Push message to the engine.- Parameters:
context- any context of the app.from- the message's sender,RemoteMessage.getFrom().data- the message's extras,RemoteMessage.toIntent().getExtras().- Returns:
- true if it was a Web Push message, now on its way to the page; false if it belongs to the app.
-
setTransport
Serves every Web Push subscription made from now on withtransportinstead of Firebase Cloud Messaging; null restores FCM. Call it inApplication.onCreate(), so the transport is in place when a message or an unsubscribe arrives after a restart. Subscriptions made before keep the service they were made with. -
deliverMessage
Hands a message that aCefriumPushTransportreceived to the engine.- Parameters:
appId- the subscription, as passed toCefriumPushTransport.subscribe(String, String).body- the request body the application server sent: an RFC 8291aes128gcmmessage, still encrypted.- Returns:
- false if
appIdis not a subscription the transport made.
-