fix(NotificationContext): ensure audio playback is unlocked only for authenticated users
All checks were successful
Build & Push Docker Image / build (push) Successful in 6m32s
All checks were successful
Build & Push Docker Image / build (push) Successful in 6m32s
This commit is contained in:
@@ -98,10 +98,10 @@ export function NotificationProvider({ children }) {
|
|||||||
}
|
}
|
||||||
}, [user]);
|
}, [user]);
|
||||||
|
|
||||||
// Unlock audio playback on the first real user interaction.
|
// Unlock audio playback only for authenticated sessions.
|
||||||
// Browsers block audio from timer callbacks unless the element was previously
|
// This avoids any audio interaction while logged out (e.g. anonymous/incognito tabs).
|
||||||
// "touched" inside a gesture handler — this one-time listener does exactly that.
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
if (!user?.id) return;
|
||||||
const events = ['click', 'keydown', 'pointerdown'];
|
const events = ['click', 'keydown', 'pointerdown'];
|
||||||
const handler = () => {
|
const handler = () => {
|
||||||
unlockAudio();
|
unlockAudio();
|
||||||
@@ -109,11 +109,12 @@ export function NotificationProvider({ children }) {
|
|||||||
};
|
};
|
||||||
events.forEach(e => window.addEventListener(e, handler, { once: true }));
|
events.forEach(e => window.addEventListener(e, handler, { once: true }));
|
||||||
return () => events.forEach(e => window.removeEventListener(e, handler));
|
return () => events.forEach(e => window.removeEventListener(e, handler));
|
||||||
}, []);
|
}, [user?.id]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
activeUserId.current = user?.id ?? null;
|
activeUserId.current = user?.id ?? null;
|
||||||
if (!user) {
|
if (!user) {
|
||||||
|
_audioUnlocked = false;
|
||||||
setNotifications([]);
|
setNotifications([]);
|
||||||
setUnreadCount(0);
|
setUnreadCount(0);
|
||||||
seenIds.current = new Set();
|
seenIds.current = new Set();
|
||||||
|
|||||||
Reference in New Issue
Block a user