feat: allow toggling eavesdropping
This commit is contained in:
@@ -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 });
|
||||
}
|
||||
},
|
||||
}));
|
||||
|
||||
Reference in New Issue
Block a user