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

Commit

Permalink
Merge pull request #758 from SuperViz/fix/participants-updates
Browse files Browse the repository at this point in the history
fix: update the participant in the IO room every time it is updated in the store
  • Loading branch information
carlossantos74 authored Aug 27, 2024
2 parents 7bae3d3 + 599b8aa commit 168dca6
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 27 deletions.
1 change: 1 addition & 0 deletions src/components/video/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,7 @@ export class VideoConference extends BaseComponent {
[participant.id]: {
...participants.value[participant.id],
name: newParticipantName,
type: this.params.userType,
},
});

Expand Down
19 changes: 5 additions & 14 deletions src/services/presence-3d-manager/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,6 @@ describe('Presence3DManager', () => {
localParticipant.publish(MOCK_LOCAL_PARTICIPANT);
});

describe('constructor', () => {
test('should create a Presence3DManager instance', () => {
expect(presence3DManager).toBeInstanceOf(Presence3DManager);
expect(presence3DManager['room']).toBeDefined();
expect(presence3DManager['useStore']).toBeDefined();
expect(presence3DManager['participants3DObservers']).toEqual([]);
expect(presence3DManager['localParticipant']).toBe(MOCK_LOCAL_PARTICIPANT);
expect(presence3DManager['logger']).toBeDefined();
});
});

describe('initializeParticipantsList', () => {
test('should update the list of participants', () => {
presence3DManager['unthrottledUpdatePresence3D'] = jest.fn();
Expand Down Expand Up @@ -276,7 +265,7 @@ describe('Presence3DManager', () => {
id: '123',
});

expect(presence3DManager['room'].presence.update).not.toBeCalled();
expect(presence3DManager['room'].presence.update).not.toHaveBeenCalledTimes(2);
});

test('should not update presence if participant is not local', () => {
Expand All @@ -289,7 +278,7 @@ describe('Presence3DManager', () => {
id: '123',
});

expect(presence3DManager['room'].presence.update).not.toBeCalled();
expect(presence3DManager['room'].presence.update).not.toHaveBeenCalledTimes(2);
});

test('should update presence if participant is local', () => {
Expand All @@ -304,7 +293,9 @@ describe('Presence3DManager', () => {

presence3DManager['unthrottledUpdatePresence3D'](modifiedLocalParticipant);

expect(presence3DManager['room'].presence.update).toBeCalledWith(modifiedLocalParticipant);
expect(presence3DManager['room'].presence.update).toHaveBeenCalledWith(
modifiedLocalParticipant,
);
});
});

Expand Down
28 changes: 15 additions & 13 deletions src/services/presence-3d-manager/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,20 @@ export class Presence3DManager {
const { localParticipant } = this.useStore(StoreType.GLOBAL);

// have to set manually because useStore is binded to the 3d plugin that creates the service
localParticipant.subscribe((participant) => {
if (this.localParticipant) {
if (
this.localParticipant.name !== participant.name ||
this.localParticipant.avatar?.model3DUrl !== participant.avatar?.model3DUrl ||
this.localParticipant.slot !== participant.slot
) {
this.unthrottledUpdatePresence3D({ ...participant });
}
}
localParticipant.subscribe((data) => {
this.room.presence.update(data);

const { participants } = this.useStore(StoreType.PRESENCE_3D);

const participant = {
...participants.value.find((participant) => participant.id === data.id),
...data,
};

participants.publish([
...participants.value.filter((participant) => participant.id !== data.id),
participant,
]);

this.localParticipant = participant;
});
Expand Down Expand Up @@ -118,9 +122,7 @@ export class Presence3DManager {
};

private unthrottledUpdatePresence3D = (data: Participant): void => {
if (!data || !data.id) {
return;
}
if (!data?.id) return;

const { participants, hasJoined3D } = this.useStore(StoreType.PRESENCE_3D);

Expand Down

0 comments on commit 168dca6

Please sign in to comment.