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.
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 mut builder = WebPushMessageBuilder::new(endpoint, &auth, &p256dh).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)
}
}