Crate web_push [−] [src]
Web Push
A library for creating and sending push notifications to a web browser. For content payload encryption it uses the Encrypted Content-Encoding for HTTP, draft 3. The client is asynchronious and uses Tokio with futures.
Example
extern crate tokio_core; extern crate web_push; extern crate base64; use web_push::*; use base64::URL_SAFE; let endpoint = "https://updates.push.services.mozilla.com/wpush/v1/..."; let p256dh = base64::decode_config("key_from_browser_as_base64", URL_SAFE).unwrap(); let auth = base64::decode_config("auth_from_browser_as_base64", URL_SAFE).unwrap(); let subscription_info = SubscriptionInfo::new( endpoint, "BLMbF9ffKBiWQLCKvTHb6LO8Nb6dcUh6TItC455vu2kElga6PQvUmaFyCdykxY2nOSSL3yKgfbmFLRTUaGv4yV8", "xS03Fi5ErfTNH_l9WHE9Ig" ); let mut builder = WebPushMessageBuilder::new(&subscription_info).unwrap(); let content = "Encrypted payload to be sent in the notification".as_bytes(); builder.set_payload(ContentEncoding::AesGcm, content); match builder.build() { Ok(message) => { let mut core = tokio_core::reactor::Core::new().unwrap(); let handle = core.handle(); let client = WebPushClient::new(&handle).unwrap(); let work = client.send(message); match core.run(work) { Err(error) => println!("ERROR: {:?}", error), _ => println!("OK") } }, Err(error) => { println!("ERROR in building message: {:?}", error) } }
Structs
SubscriptionInfo |
Client info for sending the notification. Maps the values from browser's subscription info JSON data. |
SubscriptionKeys |
Encryption keys from the client. |
VapidSignature |
A struct representing a VAPID signature. Should be generated using the VapidSignatureBuilder. |
VapidSignatureBuilder |
A VAPID signature builder for generating an optional signature to the request. With a given signature, one can pass the registration to Google's FCM service. And prevent unauthorized notifications to be sent to the client. |
WebPushClient |
An async client for sending the notification payload. |
WebPushMessage |
Everything needed to send a push notification to the user. |
WebPushMessageBuilder |
The main class for creating a notification payload. |
WebPushPayload |
The push content payload, already in an encrypted form. |
WebPushResponse |
The response future. When successful, returns an empty |
Enums
ContentEncoding | |
WebPushError |