pub fn send(
ctx: &Ctx,
subscription: &Subscription,
message: &Value,
ttl: u32,
) -> impl Future<Output = Result<Sent>> + Send + use<>Expand description
Encrypts message (JSON, e.g. message) for
subscription and posts it to its push service, signed with the app’s
VAPID keys. The push service keeps it up to ttl seconds while the
browser is offline. One subrequest.
§Errors
Error::BadRequestwhen the subscription’s keys are invalid or the message is overMAX_PAYLOADbytes.Error::Internalwhen aVAPID_*setting is missing or invalid, or the push service refuses the message (other than 404/410), with its status and answer.
§Examples
use ocre::push::{self, Sent, Subscription};
use ocre::{Ctx, Result};
async fn notify(ctx: &Ctx, subscription: &Subscription) -> Result<()> {
let message = push::message("Your video is ready", "Download it now.", "/videos/42");
if push::send(ctx, subscription, &message, 24 * 3600).await? == Sent::Gone {
// delete the subscription
}
Ok(())
}