Skip to content

Commit f9fe7ff

Browse files
committed
refactor(voip): route force-show controls through showControls
- Call showControls() from stateChange, trackStateChange, and toggleFocus instead of inlining controlsVisible in set() patches - Mock media emitter forwards variadic args in useCallStore tests - Add test and JSDoc for controls visibility / animation consumers Made-with: Cursor
1 parent b7fd474 commit f9fe7ff

2 files changed

Lines changed: 22 additions & 6 deletions

File tree

app/lib/services/voip/useCallStore.test.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ function createMockCall(callId: string) {
3030
listeners[ev]?.delete(fn);
3131
}
3232
};
33-
const emit = (ev: string) => {
34-
listeners[ev]?.forEach(fn => fn());
33+
const emit = (ev: string, ...args: unknown[]) => {
34+
listeners[ev]?.forEach(fn => fn(...args));
3535
};
3636
const call = {
3737
callId,
@@ -54,6 +54,19 @@ function createMockCall(callId: string) {
5454
return { call, emit };
5555
}
5656

57+
describe('createMockCall emitter', () => {
58+
it('forwards variadic arguments to listeners', () => {
59+
const { call, emit } = createMockCall('e1');
60+
const listener = jest.fn();
61+
call.emitter.on('stateChange', listener);
62+
63+
emit('stateChange', { kind: 'test' }, 2);
64+
65+
expect(listener).toHaveBeenCalledTimes(1);
66+
expect(listener).toHaveBeenCalledWith({ kind: 'test' }, 2);
67+
});
68+
});
69+
5770
describe('useCallStore controlsVisible', () => {
5871
beforeEach(() => {
5972
useCallStore.getState().resetNativeCallId();

app/lib/services/voip/useCallStore.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ interface CallStoreState {
6868
isSpeakerOn: boolean;
6969
callStartTime: number | null;
7070
focused: boolean;
71+
/** Zustand-driven for Call UI animations (subscribers re-render → `useAnimatedStyle`); see `decisions/call-view-controls-coderabbit.md`. */
7172
controlsVisible: boolean;
7273
dialpadValue: string;
7374

@@ -163,7 +164,8 @@ export const useCallStore = create<CallStore>((set, get) => ({
163164
if (!currentCall) return;
164165

165166
const newState = currentCall.state;
166-
set({ callState: newState, controlsVisible: true });
167+
set({ callState: newState });
168+
get().showControls();
167169

168170
// Set start time when call becomes active
169171
if (newState === 'active' && !get().callStartTime) {
@@ -179,9 +181,9 @@ export const useCallStore = create<CallStore>((set, get) => ({
179181
isMuted: currentCall.muted,
180182
isOnHold: currentCall.held,
181183
remoteMute: currentCall.remoteMute,
182-
remoteHeld: currentCall.remoteHeld,
183-
controlsVisible: true
184+
remoteHeld: currentCall.remoteHeld
184185
});
186+
get().showControls();
185187
};
186188

187189
const handleEnded = () => {
@@ -241,7 +243,8 @@ export const useCallStore = create<CallStore>((set, get) => ({
241243

242244
toggleFocus: () => {
243245
const isFocused = get().focused;
244-
set({ focused: !isFocused, controlsVisible: true });
246+
set({ focused: !isFocused });
247+
get().showControls();
245248
if (isFocused) {
246249
Navigation.back();
247250
} else {

0 commit comments

Comments
 (0)