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

fix: host with new IO issues #668

Merged
merged 3 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/common/types/participant.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ export interface Participant {
// @NOTE - this is a hack to make the participant info work with the 3D avatar
avatarConfig?: unknown;
activeComponents?: ComponentNames[];
joinedMeeting?: boolean;
}

export type ParticipantByGroupApi = {
Expand All @@ -41,8 +40,8 @@ export interface Group {
}

export interface Avatar {
model3DUrl: string;
imageUrl: string;
model3DUrl?: string;
imageUrl?: string;
}

export type ParticipantByCommentsApi = {
Expand Down
106 changes: 29 additions & 77 deletions src/components/video/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,19 +161,6 @@ describe('VideoConference', () => {
});

describe('host handler', () => {
beforeEach(() => {
VideoConferenceInstance['initializedList'] = true;
VideoConferenceInstance['participantsTypes'][MOCK_LOCAL_PARTICIPANT.id] =
ParticipantType.HOST;
const { participants } = VideoConferenceInstance['useStore'](StoreType.GLOBAL);
participants.publish({
[MOCK_LOCAL_PARTICIPANT.id]: {
...MOCK_LOCAL_PARTICIPANT,
type: ParticipantType.HOST,
},
});
});

test('should set as host the first participant that joins the room and type is host', () => {
const participant: ParticipantInfo[] = [
{
Expand Down Expand Up @@ -211,15 +198,19 @@ describe('VideoConference', () => {
});

VideoConferenceInstance['roomState']['setHost'] = fn;
VideoConferenceInstance['onRealtimeParticipantsDidChange'](participant);
VideoConferenceInstance['onParticipantListUpdate']({
[MOCK_LOCAL_PARTICIPANT.id]: {
...participant[0],
},
});

expect(fn).toBeCalledWith(MOCK_LOCAL_PARTICIPANT.id);
expect(fn).toBeCalledWith(MOCK_LOCAL_PARTICIPANT.id);
});

test('should keep the host if it is already set and stays in the room', () => {
const originalList: ParticipantInfo[] = [
{
const originalList: Record<string, ParticipantInfo> = {
[MOCK_LOCAL_PARTICIPANT.id]: {
timestamp: 0,
id: MOCK_LOCAL_PARTICIPANT.id,
name: MOCK_LOCAL_PARTICIPANT.name,
Expand All @@ -234,7 +225,7 @@ describe('VideoConference', () => {
timestamp: 0,
},
},
];
};

VideoConferenceInstance['useStore'](StoreType.GLOBAL).participants.publish({
[MOCK_LOCAL_PARTICIPANT.id]: {
Expand All @@ -243,9 +234,8 @@ describe('VideoConference', () => {
});

VideoConferenceInstance['roomState'].setHost = jest.fn();
VideoConferenceInstance['onRealtimeParticipantsDidChange'](originalList);
VideoConferenceInstance['onParticipantListUpdate'](originalList);

VideoConferenceInstance['participantsTypes']['second-id'] = ParticipantType.HOST;
const secondList: ParticipantInfo[] = [
{
timestamp: 1,
Expand Down Expand Up @@ -297,15 +287,13 @@ describe('VideoConference', () => {
},
];

VideoConferenceInstance['participantsTypes'] = { 'another-client-id': ParticipantType.HOST };
VideoConferenceInstance['useStore'](StoreType.GLOBAL).participants.publish({
'another-client-id': participant[0],
});

VideoConferenceInstance['roomState'].setHost = jest.fn();
VideoConferenceInstance['onRealtimeParticipantsDidChange'](participant);

VideoConferenceInstance['participantsTypes'] = {};
VideoConferenceInstance['useStore'](StoreType.GLOBAL).participants.publish({
[MOCK_LOCAL_PARTICIPANT.id]: { ...MOCK_LOCAL_PARTICIPANT },
});
Expand Down Expand Up @@ -555,23 +543,6 @@ describe('VideoConference', () => {
});
});

test('should emit event to update global participant data when participant joins', () => {
const participant = {
...MOCK_LOCAL_PARTICIPANT,
name: 'John Doe',
type: ParticipantType.HOST,
};

VideoConferenceInstance['room'].emit = jest.fn();

VideoConferenceInstance['onParticipantJoined'](participant);

expect(VideoConferenceInstance['room'].emit).toBeCalledWith(
MeetingEvent.MY_PARTICIPANT_UPDATED,
participant,
);
});

test('should publish message to client when my participant left', () => {
VideoConferenceInstance['publish'] = jest.fn();

Expand Down Expand Up @@ -655,10 +626,6 @@ describe('VideoConference', () => {
},
});

VideoConferenceInstance['participantsOnMeeting'] = [];
VideoConferenceInstance['publish'] = jest.fn();
VideoConferenceInstance['onParticipantListUpdate']();

const participantInfoList: ParticipantInfo[] = [
{
id: participants.value[MOCK_LOCAL_PARTICIPANT.id].id,
Expand All @@ -672,6 +639,14 @@ describe('VideoConference', () => {
},
];

VideoConferenceInstance['participantsOnMeeting'] = [];
VideoConferenceInstance['publish'] = jest.fn();
VideoConferenceInstance['onParticipantListUpdate']({
[MOCK_LOCAL_PARTICIPANT.id]: {
...participants.value[MOCK_LOCAL_PARTICIPANT.id],
},
});

expect(VideoConferenceInstance['publish']).toBeCalledWith(
MeetingEvent.MEETING_PARTICIPANT_LIST_UPDATE,
participantInfoList,
Expand Down Expand Up @@ -707,8 +682,18 @@ describe('VideoConference', () => {
VideoConferenceInstance['publish'] = jest.fn();
VideoConferenceInstance['onHostAvailabilityChange'] = jest.fn();

VideoConferenceInstance['onParticipantListUpdate']();
VideoConferenceInstance['onParticipantListUpdate']();
VideoConferenceInstance['onParticipantListUpdate']({
[MOCK_LOCAL_PARTICIPANT.id]: {
...participants[MOCK_LOCAL_PARTICIPANT.id],
timestamp: 0,
},
});
VideoConferenceInstance['onParticipantListUpdate']({
[MOCK_LOCAL_PARTICIPANT.id]: {
...participants[MOCK_LOCAL_PARTICIPANT.id],
timestamp: 0,
},
});

expect(VideoConferenceInstance['publish']).toBeCalledTimes(3);
});
Expand Down Expand Up @@ -898,37 +883,4 @@ describe('VideoConference', () => {
expect(VIDEO_MANAGER_MOCK.publishMessageToFrame).toBeCalledWith(MeetingControlsEvent.HANG_UP);
});
});

describe('updateParticipantGlobally', () => {
test('should publish participants list update in store', () => {
const participant = {
[MOCK_LOCAL_PARTICIPANT.id]: {
...MOCK_LOCAL_PARTICIPANT,
},
};

const update = {
id: MOCK_LOCAL_PARTICIPANT.id,
name: 'New Name',
};

const mockFn = jest.fn();

VideoConferenceInstance['useStore'] = jest.fn().mockReturnValue({
participants: {
value: participant,
publish: mockFn,
},
});

VideoConferenceInstance['updateParticipantGlobally']({ data: update } as any);

expect(mockFn).toBeCalledWith({
[MOCK_LOCAL_PARTICIPANT.id]: {
...participant[MOCK_LOCAL_PARTICIPANT.id],
...update,
},
});
});
});
});
Loading
Loading