Skip to content

Commit b2f4449

Browse files
authored
Merge pull request #11339 from daily-co/csdk-2392-add-callClientId-to-events
imp(cm): Rename callFrameId to callClientId
2 parents 677d891 + 5586fb0 commit b2f4449

22 files changed

+223
-181
lines changed

test/.test-utils/event-emitter.ts

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,26 @@ import {
55
DailyParticipant,
66
} from '@daily-co/daily-js';
77
import faker from 'faker';
8+
import { mockEvent } from './mocks';
89

910
export const emitStartedCamera = (callObject: DailyCall) => {
1011
// @ts-ignore
11-
callObject.emit('started-camera', {
12+
callObject.emit('started-camera', mockEvent({
1213
action: 'started-camera',
13-
});
14+
}));
1415
};
1516

1617
export const emitActiveSpeakerChange = (
1718
callObject: DailyCall,
1819
peerId: string
1920
) => {
2021
// @ts-ignore
21-
callObject.emit('active-speaker-change', {
22+
callObject.emit('active-speaker-change', mockEvent({
2223
action: 'active-speaker-change',
2324
activeSpeaker: {
2425
peerId,
2526
},
26-
});
27+
}));
2728
};
2829

2930
export const emitTrackStarted = (
@@ -32,69 +33,69 @@ export const emitTrackStarted = (
3233
track: Partial<MediaStreamTrack>
3334
) => {
3435
// @ts-ignore
35-
callObject.emit('track-started', {
36+
callObject.emit('track-started', mockEvent({
3637
action: 'track-started',
3738
participant,
3839
track,
39-
});
40+
}));
4041
};
4142

4243
export const emitParticipantLeft = (
4344
callObject: DailyCall,
4445
participant: Partial<DailyParticipant>
4546
) => {
4647
// @ts-ignore
47-
callObject.emit('participant-left', {
48+
callObject.emit('participant-left', mockEvent({
4849
action: 'participant-left',
4950
participant,
50-
});
51+
}));
5152
};
5253

5354
export const emitParticipantUpdated = (
5455
callObject: DailyCall,
5556
participant: Partial<DailyParticipant>
5657
) => {
5758
// @ts-ignore
58-
callObject.emit('participant-updated', {
59+
callObject.emit('participant-updated', mockEvent({
5960
action: 'participant-updated',
6061
participant,
61-
});
62+
}));
6263
};
6364

6465
export const emitParticipantJoined = (
6566
callObject: DailyCall,
6667
participant: Partial<DailyParticipant>
6768
) => {
6869
// @ts-ignore
69-
callObject.emit('participant-joined', {
70+
callObject.emit('participant-joined', mockEvent({
7071
action: 'participant-joined',
7172
participant,
72-
});
73+
}));
7374
};
7475

7576
export const emitJoinedMeeting = (
7677
callObject: DailyCall,
7778
participants: Record<string, Partial<DailyParticipant>>
7879
) => {
7980
// @ts-ignore
80-
callObject.emit('joined-meeting', {
81+
callObject.emit('joined-meeting', mockEvent({
8182
action: 'joined-meeting',
8283
participants,
83-
});
84+
}));
8485
};
8586

8687
export const emitLeftMeeting = (callObject: DailyCall) => {
8788
// @ts-ignore
88-
callObject.emit('left-meeting', {
89+
callObject.emit('left-meeting', mockEvent({
8990
action: 'left-meeting',
90-
});
91+
}));
9192
};
9293

9394
export const emitTranscriptionStarted = (
9495
callObject: DailyCall,
9596
data: Partial<DailyEventObjectTranscriptionStarted> = {}
9697
) => {
97-
const payload: DailyEventObjectTranscriptionStarted = {
98+
const payload: DailyEventObjectTranscriptionStarted = mockEvent({
9899
action: 'transcription-started',
99100
language: 'en',
100101
model: 'general',
@@ -104,7 +105,7 @@ export const emitTranscriptionStarted = (
104105
redact: true,
105106
includeRawResponse: false,
106107
...data,
107-
};
108+
});
108109
// @ts-ignore
109110
callObject.emit('transcription-started', payload);
110111
};
@@ -113,10 +114,10 @@ export const emitTranscriptionStopped = (
113114
callObject: DailyCall,
114115
updatedBy: string
115116
) => {
116-
const payload: DailyEventObjectTranscriptionStopped = {
117+
const payload: DailyEventObjectTranscriptionStopped = mockEvent({
117118
action: 'transcription-stopped',
118119
updatedBy: updatedBy ?? faker.datatype.uuid(),
119-
};
120+
});
120121
// @ts-ignore
121122
callObject.emit('transcription-stopped', payload);
122123
};

test/.test-utils/mocks.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import faker from 'faker';
2-
import { DailyParticipant, DailyTrackState } from "@daily-co/daily-js";
2+
import { DailyEventObject, DailyParticipant, DailyTrackState } from "@daily-co/daily-js";
33

44
export const mockTrackState = (t: Partial<DailyTrackState> = {}): DailyTrackState => ({
55
state: 'off',
@@ -37,3 +37,13 @@ export const mockParticipant = (p: Partial<DailyParticipant> = {}): DailyPartici
3737
...p
3838
};
3939
}
40+
41+
type EventPayload<T extends DailyEventObject> = Omit<T, 'callClientId'>;
42+
export function mockEvent<T extends DailyEventObject>(payload: EventPayload<T>): T {
43+
const callClientId = 'imjustaclientintheworld';
44+
45+
return {
46+
callClientId,
47+
...payload
48+
} as T;
49+
}

test/hooks/useActiveParticipant.test.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import React from 'react';
99

1010
import { DailyProvider } from '../../src/DailyProvider';
1111
import { useActiveParticipant } from '../../src/hooks/useActiveParticipant';
12+
import { mockEvent } from '../.test-utils/mocks';
1213

1314
jest.mock('../../src/DailyLiveStreaming', () => ({
1415
...jest.requireActual('../../src/DailyLiveStreaming'),
@@ -77,12 +78,12 @@ describe('useActiveParticipant', () => {
7778
}
7879
);
7980
const event: DailyEvent = 'active-speaker-change';
80-
const payload: DailyEventObjectActiveSpeakerChange = {
81+
const payload: DailyEventObjectActiveSpeakerChange = mockEvent({
8182
action: event,
8283
activeSpeaker: {
8384
peerId: 'local',
8485
},
85-
};
86+
});
8687
act(() => {
8788
// @ts-ignore
8889
daily.emit(event, payload);
@@ -117,12 +118,12 @@ describe('useActiveParticipant', () => {
117118
}
118119
);
119120
const event: DailyEvent = 'active-speaker-change';
120-
const payload: DailyEventObjectActiveSpeakerChange = {
121+
const payload: DailyEventObjectActiveSpeakerChange = mockEvent({
121122
action: event,
122123
activeSpeaker: {
123124
peerId: 'local',
124125
},
125-
};
126+
});
126127
act(() => {
127128
// @ts-ignore
128129
daily.emit(event, payload);

test/hooks/useAppMessage.test.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import React from 'react';
1010

1111
import { DailyProvider } from '../../src/DailyProvider';
1212
import { useAppMessage } from '../../src/hooks/useAppMessage';
13+
import { mockEvent } from '../.test-utils/mocks';
1314

1415
jest.mock('../../src/DailyDevices', () => ({
1516
...jest.requireActual('../../src/DailyDevices'),
@@ -64,11 +65,11 @@ describe('useAppMessage', () => {
6465
wrapper: createWrapper(daily),
6566
});
6667
const event: DailyEvent = 'app-message';
67-
const payload: DailyEventObjectAppMessage = {
68+
const payload: DailyEventObjectAppMessage = mockEvent({
6869
action: 'app-message',
6970
data: {},
7071
fromId: 'abcdef',
71-
};
72+
});
7273
act(() => {
7374
// @ts-ignore
7475
daily.emit(event, payload);

test/hooks/useCPULoad.test.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import React from 'react';
1010

1111
import { DailyProvider } from '../../src/DailyProvider';
1212
import { useCPULoad } from '../../src/hooks/useCPULoad';
13+
import { mockEvent } from '../.test-utils/mocks';
1314

1415
jest.mock('../../src/DailyDevices', () => ({
1516
...jest.requireActual('../../src/DailyDevices'),
@@ -74,11 +75,11 @@ describe('useCPULoad', () => {
7475
wrapper: createWrapper(daily),
7576
});
7677
const event: DailyEvent = 'cpu-load-change';
77-
const payload: DailyEventObjectCpuLoadEvent = {
78+
const payload: DailyEventObjectCpuLoadEvent = mockEvent({
7879
action: 'cpu-load-change',
7980
cpuLoadState: 'high',
8081
cpuLoadStateReason: 'encode',
81-
};
82+
});
8283
act(() => {
8384
// @ts-ignore
8485
daily.emit(event, payload);

0 commit comments

Comments
 (0)