Module messaging

Module messaging 

Source
Expand description

§Firebase Messaging

Rust implementation of the Firebase Cloud Messaging (FCM) web SDK surface. The goal is to mirror the @firebase/messaging APIs so applications can manage web push permissions, registration tokens and foreground/background notifications from Rust (including WASM builds).

Porting status: 40% [#### ] (details)

§Quick Start Example

use firebase_rs_sdk::messaging::{
    self, PermissionState, PushSubscriptionManager, ServiceWorkerManager,
};

#[cfg(all(target_arch = "wasm32", feature = "wasm-web"))]
// Requires building with `--features wasm-web,experimental-indexed-db`.
async fn initialise_messaging() -> messaging::error::MessagingResult<()> {
    if !messaging::is_supported() {
        return Err(messaging::error::unsupported_browser(
            "Browser is missing push APIs",
        ));
    }

    let mut sw_manager = ServiceWorkerManager::new();
    let registration = sw_manager.register_default().await?;

    let mut push_manager = PushSubscriptionManager::new();
    let vapid_key = "<your-public-vapid-key>";

    let messaging = messaging::get_messaging(None).await?;
    if matches!(messaging.request_permission().await?, PermissionState::Granted) {
        let subscription = push_manager.subscribe(&registration, vapid_key).await?;
        let details = subscription.details()?;
        let _token = messaging.get_token(Some(vapid_key)).await?;
    }
    Ok(())
}

§References to the Firebase JS SDK

Structs§

FcmOptions
Additional FCM options for a payload.
InstallationInfo
MessagePayload
Message data delivered by Firebase Cloud Messaging.
Messaging
MessagingError
NotificationPayload
Payload displayed to the user when a notification is shown.
PushSubscriptionManager
ServiceWorkerManager
ServiceWorkerRegistrationHandle
SubscriptionInfo
TokenRecord

Enums§

MessagingErrorCode
PermissionState
Notification permission states as exposed by the Web Notifications API.

Functions§

available_in_service_worker
available_in_window
failed_default_registration
get_messaging
internal_error
invalid_argument
invalid_service_worker_registration
is_supported
Returns false outside a web environment, where the required browser APIs are unavailable.
on_background_message
on_message
permission_blocked
read_token
register_messaging_component
remove_token
token_deletion_failed
token_subscribe_failed
token_subscribe_no_token
token_unsubscribe_failed
token_update_failed
token_update_no_token
unsupported_browser
write_token

Type Aliases§

MessageHandler
MessagingResult
Unsubscribe