summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKit La Touche <kit@transneptune.net>2025-07-23 21:34:32 -0400
committerKit La Touche <kit@transneptune.net>2025-07-23 21:34:32 -0400
commit411ba4920358aef3f221910150d926a99e34a5ae (patch)
tree724343887b7ff904147fc66e57c82045d31d2fa5
parent5e143954c58d2736edd7222cf1befc1aa1025d61 (diff)
Wire together notifs
-rw-r--r--src/push/handlers/mod.rs19
-rw-r--r--ui/routes/+layout.svelte12
2 files changed, 24 insertions, 7 deletions
diff --git a/src/push/handlers/mod.rs b/src/push/handlers/mod.rs
index 05249c2..afa76e0 100644
--- a/src/push/handlers/mod.rs
+++ b/src/push/handlers/mod.rs
@@ -35,10 +35,14 @@ pub async fn echo(
Json(echo): Json<Echo>,
) -> Result<(), crate::error::Internal> {
// Look this up from a subscription record? Or get it from the client and trust?
- let endpoint = "https://updates.push.services.mozilla.com/wpush/v1/...";
+ let endpoint = echo.endpoint;
// Get these from client:
- let p256dh = "key_from_browser_as_base64";
- let auth = "auth_from_browser_as_base64";
+ let p256dh = echo.keys.p256dh;
+ let auth = echo.keys.auth;
+
+ println!("endpoint: {:?}", endpoint);
+ println!("p256dh: {:?}", p256dh);
+ println!("auth: {:?}", auth);
// You would likely get this by deserializing a browser `pushSubscription` object.
let subscription_info = SubscriptionInfo::new(endpoint, p256dh, auth);
@@ -64,6 +68,15 @@ pub async fn echo(
#[derive(serde::Deserialize)]
+pub struct Keys {
+ pub p256dh: String,
+ pub auth: String,
+}
+
+#[derive(serde::Deserialize)]
pub struct Echo {
pub msg: String,
+ pub endpoint: String,
+ pub expirationTime: Option<String>,
+ pub keys: Keys,
}
diff --git a/ui/routes/+layout.svelte b/ui/routes/+layout.svelte
index 0910c16..a1f8d84 100644
--- a/ui/routes/+layout.svelte
+++ b/ui/routes/+layout.svelte
@@ -6,6 +6,8 @@
import logo from '$lib/assets/logo.png';
/* ==================== Start subscription library-esque ==================== */
+ let subscriptionJson = $state(null);
+
function doSubscribe() {
navigator.serviceWorker.ready
.then(async(registration) => {
@@ -23,12 +25,11 @@
applicationServerKey: convertedVapidKey
});
}).then((subscription) => {
- debugger;
- console.debug("Subscribed", subscription.endpoint);
+ subscriptionJson = JSON.parse(JSON.stringify(subscription));
return fetch("/api/register", {
method: "post",
headers: { "Content-type": "application/json" },
- body: JSON.stringify({ subscription: subscription })
+ body: JSON.stringify(subscriptionJson),
});
});
}
@@ -54,7 +55,10 @@
fetch("/api/echo", {
method: "post",
headers: { "Content-type": "application/json" },
- body: JSON.stringify({ msg: "oople doople" })
+ body: JSON.stringify({
+ ...subscriptionJson,
+ msg: "oople doople",
+ })
});
}