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

Commit 098150f

Browse files
Merge pull request #760 from SuperViz/beta
fix: update the participant in the IO room every time it is updated in the store
2 parents 9280ddf + c6ae4e9 commit 098150f

File tree

3 files changed

+21
-27
lines changed

3 files changed

+21
-27
lines changed

src/components/video/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,7 @@ export class VideoConference extends BaseComponent {
574574
[participant.id]: {
575575
...participants.value[participant.id],
576576
name: newParticipantName,
577+
type: this.params.userType,
577578
},
578579
});
579580

src/services/presence-3d-manager/index.test.ts

+5-14
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,6 @@ describe('Presence3DManager', () => {
2222
localParticipant.publish(MOCK_LOCAL_PARTICIPANT);
2323
});
2424

25-
describe('constructor', () => {
26-
test('should create a Presence3DManager instance', () => {
27-
expect(presence3DManager).toBeInstanceOf(Presence3DManager);
28-
expect(presence3DManager['room']).toBeDefined();
29-
expect(presence3DManager['useStore']).toBeDefined();
30-
expect(presence3DManager['participants3DObservers']).toEqual([]);
31-
expect(presence3DManager['localParticipant']).toBe(MOCK_LOCAL_PARTICIPANT);
32-
expect(presence3DManager['logger']).toBeDefined();
33-
});
34-
});
35-
3625
describe('initializeParticipantsList', () => {
3726
test('should update the list of participants', () => {
3827
presence3DManager['unthrottledUpdatePresence3D'] = jest.fn();
@@ -276,7 +265,7 @@ describe('Presence3DManager', () => {
276265
id: '123',
277266
});
278267

279-
expect(presence3DManager['room'].presence.update).not.toBeCalled();
268+
expect(presence3DManager['room'].presence.update).not.toHaveBeenCalledTimes(2);
280269
});
281270

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

292-
expect(presence3DManager['room'].presence.update).not.toBeCalled();
281+
expect(presence3DManager['room'].presence.update).not.toHaveBeenCalledTimes(2);
293282
});
294283

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

305294
presence3DManager['unthrottledUpdatePresence3D'](modifiedLocalParticipant);
306295

307-
expect(presence3DManager['room'].presence.update).toBeCalledWith(modifiedLocalParticipant);
296+
expect(presence3DManager['room'].presence.update).toHaveBeenCalledWith(
297+
modifiedLocalParticipant,
298+
);
308299
});
309300
});
310301

src/services/presence-3d-manager/index.ts

+15-13
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,20 @@ export class Presence3DManager {
2727
const { localParticipant } = this.useStore(StoreType.GLOBAL);
2828

2929
// have to set manually because useStore is binded to the 3d plugin that creates the service
30-
localParticipant.subscribe((participant) => {
31-
if (this.localParticipant) {
32-
if (
33-
this.localParticipant.name !== participant.name ||
34-
this.localParticipant.avatar?.model3DUrl !== participant.avatar?.model3DUrl ||
35-
this.localParticipant.slot !== participant.slot
36-
) {
37-
this.unthrottledUpdatePresence3D({ ...participant });
38-
}
39-
}
30+
localParticipant.subscribe((data) => {
31+
this.room.presence.update(data);
32+
33+
const { participants } = this.useStore(StoreType.PRESENCE_3D);
34+
35+
const participant = {
36+
...participants.value.find((participant) => participant.id === data.id),
37+
...data,
38+
};
39+
40+
participants.publish([
41+
...participants.value.filter((participant) => participant.id !== data.id),
42+
participant,
43+
]);
4044

4145
this.localParticipant = participant;
4246
});
@@ -118,9 +122,7 @@ export class Presence3DManager {
118122
};
119123

120124
private unthrottledUpdatePresence3D = (data: Participant): void => {
121-
if (!data || !data.id) {
122-
return;
123-
}
125+
if (!data?.id) return;
124126

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

0 commit comments

Comments
 (0)