feat: allow toggling eavesdropping

This commit is contained in:
talksik
2026-03-21 18:34:41 -07:00
parent 59ffa7ad6e
commit e61f838a98
4 changed files with 140 additions and 34 deletions
+20 -3
View File
@@ -8,15 +8,32 @@ interface AutoplayState {
activeParticle: MediaParticle | null;
/** The stream this particle belongs to (for click-to-navigate) */
streamId: string | null;
/** Play a media particle, preempting any currently playing */
/** When true, incoming play requests are ignored */
muted: boolean;
/** Play a media particle, preempting any currently playing. No-op when muted. */
play: (particle: MediaParticle, streamId: string) => void;
/** Stop autoplay and clear state */
stop: () => void;
/** Toggle muted state */
toggleMuted: () => void;
}
export const useAutoplayStore = create<AutoplayState>((set) => ({
export const useAutoplayStore = create<AutoplayState>((set, get) => ({
activeParticle: null,
streamId: null,
play: (particle, streamId) => set({ activeParticle: particle, streamId }),
muted: false,
play: (particle, streamId) => {
if (get().muted) return;
set({ activeParticle: particle, streamId });
},
stop: () => set({ activeParticle: null, streamId: null }),
toggleMuted: () => {
const wasMuted = get().muted;
// If muting, also stop any current playback
if (!wasMuted) {
set({ muted: true, activeParticle: null, streamId: null });
} else {
set({ muted: false });
}
},
}));