Skip to content

Commit 677d891

Browse files
authored
Merge pull request #11352 from daily-co/pre-1224
PRE-1224 Reset activeIdState when leaving meeting
2 parents 90d1828 + d51e402 commit 677d891

File tree

2 files changed

+32
-14
lines changed

2 files changed

+32
-14
lines changed

src/DailyParticipants.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,7 @@ export const DailyParticipants: React.FC<React.PropsWithChildren<{}>> = ({
346346
case 'call-instance-destroyed':
347347
case 'left-meeting': {
348348
reset(localIdState);
349+
reset(activeIdState);
349350
const ids = get(participantIdsState);
350351
if (Array.isArray(ids))
351352
ids.forEach((id) => reset(participantState(id)));

test/hooks/useActiveSpeakerId.test.tsx

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
/// <reference types="@types/jest" />
22

3-
import Daily, {
4-
DailyCall,
5-
DailyEvent,
6-
DailyEventObjectActiveSpeakerChange,
7-
} from '@daily-co/daily-js';
3+
import Daily, { DailyCall } from '@daily-co/daily-js';
84
import { act, renderHook, waitFor } from '@testing-library/react';
95
import React from 'react';
106

@@ -13,6 +9,7 @@ import { useActiveSpeakerId } from '../../src/hooks/useActiveSpeakerId';
139
import {
1410
emitActiveSpeakerChange,
1511
emitJoinedMeeting,
12+
emitLeftMeeting,
1613
} from '../.test-utils/event-emitter';
1714
import { mockParticipant } from '../.test-utils/mocks';
1815

@@ -62,6 +59,34 @@ describe('useActiveSpeakerId', () => {
6259
expect(result.current).toBeNull();
6360
});
6461
});
62+
it('reset to null when leaving meeting', async () => {
63+
const daily = Daily.createCallObject();
64+
(daily.participants as jest.Mock).mockImplementation(() => ({
65+
local: {
66+
session_id: 'local',
67+
user_name: '',
68+
},
69+
a: {
70+
session_id: 'a',
71+
user_name: 'Alpha',
72+
},
73+
}));
74+
const { result } = renderHook(() => useActiveSpeakerId(), {
75+
wrapper: createWrapper(daily),
76+
});
77+
act(() => {
78+
emitActiveSpeakerChange(daily, 'local');
79+
});
80+
await waitFor(() => {
81+
expect(result.current).toEqual('local');
82+
});
83+
act(() => {
84+
emitLeftMeeting(daily);
85+
});
86+
await waitFor(() => {
87+
expect(result.current).toEqual(null);
88+
});
89+
});
6590
describe('active-speaker-change event', () => {
6691
it('changes returned participant session id (local)', async () => {
6792
const daily = Daily.createCallObject();
@@ -78,16 +103,8 @@ describe('useActiveSpeakerId', () => {
78103
const { result } = renderHook(() => useActiveSpeakerId(), {
79104
wrapper: createWrapper(daily),
80105
});
81-
const event: DailyEvent = 'active-speaker-change';
82-
const payload: DailyEventObjectActiveSpeakerChange = {
83-
action: event,
84-
activeSpeaker: {
85-
peerId: 'local',
86-
},
87-
};
88106
act(() => {
89-
// @ts-ignore
90-
daily.emit(event, payload);
107+
emitActiveSpeakerChange(daily, 'local');
91108
});
92109
await waitFor(() => {
93110
expect(result.current).toEqual('local');

0 commit comments

Comments
 (0)