diff --git a/src/app/[slug]/page.tsx b/src/app/[slug]/page.tsx index 1c761d6..7bd5653 100644 --- a/src/app/[slug]/page.tsx +++ b/src/app/[slug]/page.tsx @@ -148,15 +148,17 @@ export default function RoomPage() { roomSlug: slug, }); - // Auto-subscribe to push when location sharing starts + // Auto-subscribe to push when joining room (like location permission) + const hasRequestedPushRef = useRef(false); useEffect(() => { - if (isSharing && !isPushSubscribed && syncUrl) { - console.log('Auto-subscribing to push notifications for background pings'); + if (isConnected && !isPushSubscribed && !hasRequestedPushRef.current && syncUrl) { + hasRequestedPushRef.current = true; + console.log('Auto-requesting push notification permission'); subscribePush().catch((err) => { console.warn('Push subscription failed (user may have denied):', err.message); }); } - }, [isSharing, isPushSubscribed, subscribePush, syncUrl]); + }, [isConnected, isPushSubscribed, subscribePush, syncUrl]); // Restore last known location immediately when connected const hasRestoredLocationRef = useRef(false);