Skip to content
This repository was archived by the owner on Oct 18, 2024. It is now read-only.

Commit bbace2b

Browse files
Merge pull request #713 from SuperViz/fix/build-esm-files
Add a flag to know when the participant entered the meeting room and little events corrections
2 parents b190876 + 3ac288b commit bbace2b

File tree

7 files changed

+80
-92
lines changed

7 files changed

+80
-92
lines changed

src/common/types/participant.types.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ export interface Participant {
2727
timestamp?: number;
2828
}
2929

30+
export interface VideoParticipant extends Participant {
31+
participantId?: string;
32+
color?: string;
33+
joinedMeeting?: boolean;
34+
}
35+
3036
export type ParticipantByGroupApi = {
3137
id: string;
3238
name: string;

src/components/video/index.test.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@ import {
1616
RealtimeEvent,
1717
TranscriptState,
1818
} from '../../common/types/events.types';
19-
import { Participant, ParticipantType } from '../../common/types/participant.types';
19+
import {
20+
Participant,
21+
ParticipantType,
22+
VideoParticipant,
23+
} from '../../common/types/participant.types';
2024
import { StoreType } from '../../common/types/stores.types';
2125
import { useStore } from '../../common/utils/use-store';
2226
import { IOC } from '../../services/io';
@@ -89,7 +93,7 @@ describe('VideoConference', () => {
8993
allowGuests: false,
9094
});
9195

92-
VideoConferenceInstance['localParticipant'] = MOCK_LOCAL_PARTICIPANT;
96+
VideoConferenceInstance['localParticipant'] = MOCK_LOCAL_PARTICIPANT as VideoParticipant;
9397
VideoConferenceInstance.attach({
9498
ioc: new IOC(MOCK_LOCAL_PARTICIPANT),
9599
config: MOCK_CONFIG,
@@ -113,7 +117,7 @@ describe('VideoConference', () => {
113117
VideoConferenceInstance['localParticipant'] = {
114118
...MOCK_LOCAL_PARTICIPANT,
115119
avatar: MOCK_AVATAR,
116-
};
120+
} as VideoParticipant;
117121

118122
VideoConferenceInstance.attach({
119123
ioc: new IOC(MOCK_LOCAL_PARTICIPANT),
@@ -484,6 +488,7 @@ describe('VideoConference', () => {
484488
expect(VideoConferenceInstance['roomState'].updateMyProperties).toHaveBeenCalledWith({
485489
name: 'John Doe',
486490
type: ParticipantType.HOST,
491+
joinedMeeting: true,
487492
});
488493
});
489494

@@ -503,6 +508,7 @@ describe('VideoConference', () => {
503508
name: 'John Doe',
504509
avatar: MOCK_AVATAR,
505510
type: ParticipantType.HOST,
511+
joinedMeeting: true,
506512
});
507513
});
508514

@@ -589,7 +595,7 @@ describe('VideoConference', () => {
589595
},
590596
});
591597

592-
const participantInfoList: Participant[] = [
598+
const participantInfoList: VideoParticipant[] = [
593599
{
594600
id: participants.value[MOCK_LOCAL_PARTICIPANT.id].id,
595601
avatar: participants.value[MOCK_LOCAL_PARTICIPANT.id].avatar,
@@ -598,6 +604,7 @@ describe('VideoConference', () => {
598604
isHost: participants.value[MOCK_LOCAL_PARTICIPANT.id].isHost ?? false,
599605
slot: participants.value[MOCK_LOCAL_PARTICIPANT.id].slot,
600606
timestamp: participants.value[MOCK_LOCAL_PARTICIPANT.id].timestamp,
607+
color: MEETING_COLORS.turquoise,
601608
},
602609
];
603610

@@ -648,12 +655,14 @@ describe('VideoConference', () => {
648655
[MOCK_LOCAL_PARTICIPANT.id]: {
649656
...participants[MOCK_LOCAL_PARTICIPANT.id],
650657
timestamp: 0,
658+
color: MEETING_COLORS.turquoise,
651659
},
652660
});
653661
VideoConferenceInstance['onParticipantListUpdate']({
654662
[MOCK_LOCAL_PARTICIPANT.id]: {
655663
...participants[MOCK_LOCAL_PARTICIPANT.id],
656664
timestamp: 0,
665+
color: MEETING_COLORS.turquoise,
657666
},
658667
});
659668

src/components/video/index.ts

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ import {
1212
RealtimeEvent,
1313
TranscriptState,
1414
} from '../../common/types/events.types';
15-
import { Participant, ParticipantType } from '../../common/types/participant.types';
15+
import {
16+
VideoParticipant,
17+
ParticipantType,
18+
Participant,
19+
} from '../../common/types/participant.types';
1620
import { StoreType } from '../../common/types/stores.types';
1721
import { Logger } from '../../common/utils';
1822
import { BrowserService } from '../../services/browser';
@@ -40,8 +44,8 @@ let KICK_PARTICIPANTS_TIMEOUT: ReturnType<typeof setTimeout> | null = null;
4044
export class VideoConference extends BaseComponent {
4145
public name: ComponentNames;
4246
protected logger: Logger;
43-
private participantsOnMeeting: Partial<Participant>[] = [];
44-
private localParticipant: Participant;
47+
private participantsOnMeeting: Partial<VideoParticipant>[] = [];
48+
private localParticipant: VideoParticipant;
4549
private videoManager: VideoConferenceManager;
4650
private connectionService: ConnectionService;
4751
private browserService: BrowserService;
@@ -178,15 +182,17 @@ export class VideoConference extends BaseComponent {
178182
* @returns {void}
179183
*/
180184
private startVideo = (): void => {
185+
const defaultAvatars =
186+
this.params?.userType !== ParticipantType.AUDIENCE && this.params?.defaultAvatars === true;
187+
181188
this.videoConfig = {
182189
language: this.params?.language,
183190
canUseRecording: !!this.params?.enableRecording,
184191
canShowAudienceList: this.params?.showAudienceList ?? true,
185192
canUseChat: !this.params?.chatOff,
186193
canUseCams: !this.params?.camsOff,
187194
canUseScreenshare: !this.params?.screenshareOff,
188-
canUseDefaultAvatars:
189-
!!this.params?.defaultAvatars && !this.localParticipant?.avatar?.model3DUrl,
195+
canUseDefaultAvatars: defaultAvatars && !this.localParticipant?.avatar?.model3DUrl,
190196
canUseGather: !!this.params?.enableGather,
191197
canUseFollow: !!this.params?.enableFollow,
192198
canUseGoTo: !!this.params?.enableGoTo,
@@ -301,7 +307,10 @@ export class VideoConference extends BaseComponent {
301307
this.useStore(StoreType.VIDEO);
302308

303309
localParticipant.subscribe((participant) => {
304-
this.localParticipant = participant;
310+
this.localParticipant = {
311+
...this.localParticipant,
312+
...participant,
313+
};
305314
});
306315

307316
drawing.subscribe(this.setDrawing);
@@ -321,7 +330,7 @@ export class VideoConference extends BaseComponent {
321330
* */
322331
private createParticipantFromPresence = (
323332
participant: PresenceEvent<Participant>,
324-
): ParticipantToFrame => {
333+
): VideoParticipant => {
325334
return {
326335
participantId: participant.id,
327336
id: participant.id,
@@ -396,9 +405,6 @@ export class VideoConference extends BaseComponent {
396405
private onMeetingStateChange = (state: MeetingState): void => {
397406
this.logger.log('video conference @ on meeting state change', state);
398407
this.publish(MeetingEvent.MEETING_STATE_UPDATE, state);
399-
400-
const { localParticipant } = this.useStore(StoreType.GLOBAL);
401-
localParticipant.publish(localParticipant.value);
402408
};
403409

404410
/**
@@ -496,7 +502,7 @@ export class VideoConference extends BaseComponent {
496502
* @param {Participant} participant - participant
497503
* @returns {void}
498504
*/
499-
private onParticipantJoined = (participant: Participant): void => {
505+
private onParticipantJoined = (participant: VideoParticipant): void => {
500506
this.logger.log('video conference @ on participant joined', participant);
501507

502508
this.publish(MeetingEvent.MEETING_PARTICIPANT_JOINED, participant);
@@ -508,6 +514,7 @@ export class VideoConference extends BaseComponent {
508514
avatar: participant.avatar,
509515
name: participant.name,
510516
type: participant.type,
517+
joinedMeeting: true,
511518
});
512519

513520
return;
@@ -516,6 +523,7 @@ export class VideoConference extends BaseComponent {
516523
this.roomState.updateMyProperties({
517524
name: participant.name,
518525
type: participant.type,
526+
joinedMeeting: true,
519527
});
520528
};
521529

@@ -525,7 +533,7 @@ export class VideoConference extends BaseComponent {
525533
* @param {Participant} _ - participant
526534
* @returns {void}
527535
*/
528-
private onParticipantLeft = (_: Participant): void => {
536+
private onParticipantLeft = (_: VideoParticipant): void => {
529537
this.logger.log('video conference @ on participant left', this.localParticipant);
530538

531539
this.connectionService.removeListeners();
@@ -546,10 +554,10 @@ export class VideoConference extends BaseComponent {
546554
* @param {Record<string, Participant>} participants - participants
547555
* @returns {void}
548556
*/
549-
private onParticipantListUpdate = (participants: Record<string, Participant>): void => {
557+
private onParticipantListUpdate = (participants: Record<string, VideoParticipant>): void => {
550558
this.logger.log('video conference @ on participant list update', participants);
551559

552-
const list: Participant[] = Object.values(participants).map((participant) => {
560+
const list: VideoParticipant[] = Object.values(participants).map((participant) => {
553561
return {
554562
id: participant.id,
555563
slot: participant.slot,
@@ -558,6 +566,7 @@ export class VideoConference extends BaseComponent {
558566
type: participant.type,
559567
isHost: participant.isHost ?? false,
560568
timestamp: participant.timestamp,
569+
color: participant.slot?.color || MEETING_COLORS.gray,
561570
};
562571
});
563572

@@ -792,12 +801,6 @@ export class VideoConference extends BaseComponent {
792801
MeetingEvent.MY_PARTICIPANT_UPDATED,
793802
this.createParticipantFromPresence(participant),
794803
);
795-
796-
localParticipant.publish({
797-
...localParticipant.value,
798-
...participant.data,
799-
type: this.params.userType as ParticipantType,
800-
});
801804
}
802805

803806
participants.publish({
@@ -883,9 +886,9 @@ export class VideoConference extends BaseComponent {
883886
}
884887

885888
return current;
886-
}, null) as Participant;
889+
}, null) as VideoParticipant;
887890

888-
this.room.presence.update<Participant>({
891+
this.room.presence.update<VideoParticipant>({
889892
...this.localParticipant,
890893
isHost: host.id === this.localParticipant.id,
891894
});

src/core/launcher/index.test.ts

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,17 @@ describe('Launcher', () => {
9090

9191
const { localParticipant } = LauncherInstance['useStore'](StoreType.GLOBAL);
9292

93+
LauncherInstance['onParticipantUpdatedIOC']({
94+
connectionId: 'connection1',
95+
data: {
96+
...MOCK_LOCAL_PARTICIPANT,
97+
activeComponents: [MOCK_COMPONENT.name],
98+
},
99+
id: MOCK_LOCAL_PARTICIPANT.id,
100+
name: MOCK_LOCAL_PARTICIPANT.name as string,
101+
timestamp: Date.now(),
102+
});
103+
93104
expect(localParticipant.value.activeComponents?.length).toBe(1);
94105
expect(localParticipant.value.activeComponents![0]).toBe(MOCK_COMPONENT.name);
95106
});
@@ -113,6 +124,17 @@ describe('Launcher', () => {
113124

114125
const { localParticipant } = LauncherInstance['useStore'](StoreType.GLOBAL);
115126

127+
LauncherInstance['onParticipantUpdatedIOC']({
128+
connectionId: 'connection1',
129+
data: {
130+
...MOCK_LOCAL_PARTICIPANT,
131+
activeComponents: [],
132+
},
133+
id: MOCK_LOCAL_PARTICIPANT.id,
134+
name: MOCK_LOCAL_PARTICIPANT.name as string,
135+
timestamp: Date.now(),
136+
});
137+
116138
expect(MOCK_COMPONENT.detach).toHaveBeenCalled();
117139
expect(localParticipant.value.activeComponents?.length).toBe(0);
118140
});
@@ -191,32 +213,20 @@ describe('Launcher', () => {
191213
expect(LauncherInstance['publish']).toHaveBeenCalled();
192214
});
193215

194-
test('should update activeComponentsInstances when participant list is updated', () => {
195-
LauncherInstance.addComponent(MOCK_COMPONENT);
196-
197-
LauncherInstance['onParticipantListUpdate']({
198-
participant1: {
199-
id: 'unit-test-participant-ably-id',
200-
activeComponents: [MOCK_COMPONENT.name],
201-
},
202-
});
203-
204-
expect(LauncherInstance['activeComponentsInstances'].length).toBe(1);
205-
});
206-
207216
test('should remove component when participant is not usign it anymore', () => {
208-
LauncherInstance.addComponent(MOCK_COMPONENT);
209-
210217
LauncherInstance['onParticipantUpdatedIOC']({
211218
connectionId: 'connection1',
212219
id: MOCK_LOCAL_PARTICIPANT.id,
213220
name: MOCK_LOCAL_PARTICIPANT.name as string,
214221
data: {
215222
...MOCK_LOCAL_PARTICIPANT,
223+
activeComponents: [],
216224
},
217225
timestamp: Date.now(),
218226
});
219227

228+
LauncherInstance.addComponent(MOCK_COMPONENT);
229+
220230
expect(LauncherInstance['activeComponentsInstances'].length).toBe(1);
221231

222232
LauncherInstance.removeComponent(MOCK_COMPONENT);
@@ -227,6 +237,7 @@ describe('Launcher', () => {
227237
name: MOCK_LOCAL_PARTICIPANT.name as string,
228238
data: {
229239
...MOCK_LOCAL_PARTICIPANT,
240+
activeComponents: LauncherInstance['activeComponents'],
230241
},
231242
timestamp: Date.now(),
232243
});

0 commit comments

Comments
 (0)