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

Commit ec21c51

Browse files
Merge pull request #714 from SuperViz/fix/build-esm-files
fix: update global participant object when they enter the meeting room
2 parents bbace2b + 3e29e5e commit ec21c51

File tree

10 files changed

+188
-117
lines changed

10 files changed

+188
-117
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
"yargs": "^17.7.2"
8383
},
8484
"dependencies": {
85-
"@superviz/socket-client": "1.8.0",
85+
"@superviz/socket-client": "1.8.2",
8686
"bowser": "^2.11.0",
8787
"bowser-jr": "^1.0.6",
8888
"debug": "^4.3.4",

src/components/video/index.ts

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,11 @@ export class VideoConference extends BaseComponent {
9090
* @returns {void}
9191
*/
9292
public toggleMicrophone(): void {
93+
if (this.localParticipant.type === ParticipantType.AUDIENCE) {
94+
console.warn('[SuperViz] Audience cannot toggle microphone');
95+
return;
96+
}
97+
9398
return this.videoManager?.publishMessageToFrame(MeetingControlsEvent.TOGGLE_MICROPHONE);
9499
}
95100

@@ -99,6 +104,11 @@ export class VideoConference extends BaseComponent {
99104
* @returns {void}
100105
*/
101106
public toggleCam(): void {
107+
if (this.localParticipant.type === ParticipantType.AUDIENCE) {
108+
console.warn('[SuperViz] Audience cannot toggle camera');
109+
return;
110+
}
111+
102112
this.videoManager?.publishMessageToFrame(MeetingControlsEvent.TOGGLE_CAM);
103113
}
104114

@@ -108,6 +118,11 @@ export class VideoConference extends BaseComponent {
108118
* @returns {void}
109119
*/
110120
public toggleScreenShare(): void {
121+
if (this.localParticipant.type === ParticipantType.AUDIENCE) {
122+
console.warn('[SuperViz] Audience cannot toggle screen share');
123+
return;
124+
}
125+
111126
return this.videoManager?.publishMessageToFrame(MeetingControlsEvent.TOGGLE_SCREENSHARE);
112127
}
113128

@@ -126,6 +141,11 @@ export class VideoConference extends BaseComponent {
126141
* @returns {void}
127142
*/
128143
public toggleRecording(): void {
144+
if (this.localParticipant.isHost) {
145+
console.warn('[SuperViz] Only host can toggle recording');
146+
return;
147+
}
148+
129149
return this.videoManager?.publishMessageToFrame(MeetingControlsEvent.TOGGLE_RECORDING);
130150
}
131151

@@ -509,6 +529,23 @@ export class VideoConference extends BaseComponent {
509529
this.publish(MeetingEvent.MY_PARTICIPANT_JOINED, participant);
510530
this.kickParticipantsOnHostLeave = !this.params?.allowGuests;
511531

532+
const { localParticipant, participants } = this.useStore(StoreType.GLOBAL);
533+
534+
const newParticipantName = participant.name.trim();
535+
536+
localParticipant.publish({
537+
...localParticipant.value,
538+
name: newParticipantName,
539+
});
540+
541+
participants.publish({
542+
...participants.value,
543+
[participant.id]: {
544+
...localParticipant.value,
545+
name: newParticipantName,
546+
},
547+
});
548+
512549
if (this.videoConfig.canUseDefaultAvatars) {
513550
this.roomState.updateMyProperties({
514551
avatar: participant.avatar,
@@ -536,6 +573,25 @@ export class VideoConference extends BaseComponent {
536573
private onParticipantLeft = (_: VideoParticipant): void => {
537574
this.logger.log('video conference @ on participant left', this.localParticipant);
538575

576+
const { localParticipant, participants } = this.useStore(StoreType.GLOBAL);
577+
578+
localParticipant.publish({
579+
...localParticipant.value,
580+
activeComponents: localParticipant.value.activeComponents?.filter(
581+
(ac) => ac !== ComponentNames.VIDEO_CONFERENCE,
582+
),
583+
});
584+
585+
participants.publish({
586+
...participants.value,
587+
[this.localParticipant.id]: {
588+
...localParticipant.value,
589+
activeComponents: localParticipant.value.activeComponents?.filter(
590+
(ac) => ac !== ComponentNames.VIDEO_CONFERENCE,
591+
),
592+
},
593+
});
594+
539595
this.connectionService.removeListeners();
540596
this.publish(MeetingEvent.DESTROY);
541597
this.publish(MeetingEvent.MY_PARTICIPANT_LEFT, this.localParticipant);

src/components/who-is-online/index.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ describe('Who Is Online', () => {
440440

441441
expect(whoIsOnlineComponent['room'].emit).toHaveBeenCalledWith(
442442
WhoIsOnlineEvent.START_FOLLOW_ME,
443-
event.detail.id,
443+
event.detail,
444444
);
445445
});
446446
});

src/components/who-is-online/index.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,14 +171,27 @@ export class WhoIsOnline extends BaseComponent {
171171

172172
this.room.presence.get((list) => {
173173
const dataList = list
174-
.filter((participant) => participant.data['id'] && participant.data['avatar'])
174+
.filter((participant) => participant.data['id'])
175175
.map(({ data }: { data: any }) => {
176+
let avatar = data.avatar;
177+
178+
if (!avatar) {
179+
avatar = this.getAvatar({
180+
avatar: data.avatar,
181+
color: data.slot.color,
182+
name: data.name,
183+
letterColor: data.slot.textColor,
184+
});
185+
}
186+
176187
const tooltip = this.getTooltipData(data);
177188
const controls = this.getControls(data);
189+
178190
return {
179191
...data,
180192
tooltip,
181193
controls,
194+
avatar,
182195
isLocalParticipant: data.id === this.localParticipantId,
183196
};
184197
}) as WhoIsOnlineParticipant[];
@@ -433,7 +446,7 @@ export class WhoIsOnline extends BaseComponent {
433446
private follow = ({ detail }: CustomEvent) => {
434447
const { everyoneFollowsMe } = this.useStore(StoreType.WHO_IS_ONLINE);
435448
everyoneFollowsMe.publish(!!detail?.id);
436-
this.room.emit(WhoIsOnlineEvent.START_FOLLOW_ME, detail?.id);
449+
this.room.emit(WhoIsOnlineEvent.START_FOLLOW_ME, detail);
437450

438451
if (this.following) {
439452
this.publish(WhoIsOnlineEvent.START_FOLLOW_ME, this.following);

src/core/launcher/index.test.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,13 @@ describe('Launcher', () => {
149149
LimitsService.checkComponentLimit = jest.fn().mockReturnValue(LIMITS_MOCK.videoConference);
150150

151151
LauncherInstance.addComponent(MOCK_COMPONENT);
152+
153+
// it will be updated by IOC when the participant is updated
154+
LauncherInstance['participant'] = {
155+
...MOCK_LOCAL_PARTICIPANT,
156+
activeComponents: [MOCK_COMPONENT.name],
157+
};
158+
152159
LauncherInstance.addComponent(MOCK_COMPONENT);
153160

154161
expect(MOCK_COMPONENT.attach).toHaveBeenCalledTimes(1);
@@ -159,7 +166,7 @@ describe('Launcher', () => {
159166

160167
LauncherInstance.addComponent(MOCK_COMPONENT);
161168

162-
expect(MOCK_COMPONENT.attach).not.toBeCalled();
169+
expect(MOCK_COMPONENT.attach).not.toHaveBeenCalled();
163170
});
164171
});
165172

src/core/launcher/index.ts

Lines changed: 40 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,7 @@ export class Launcher extends Observable implements DefaultLauncher {
4141
super();
4242
this.logger = new Logger('@superviz/sdk/launcher');
4343

44-
const { localParticipant, participants, group, isDomainWhitelisted } = this.useStore(
45-
StoreType.GLOBAL,
46-
);
44+
const { localParticipant, group, isDomainWhitelisted } = this.useStore(StoreType.GLOBAL);
4745

4846
localParticipant.publish({ ...participant });
4947
isDomainWhitelisted.subscribe(this.onAuthentication);
@@ -53,6 +51,16 @@ export class Launcher extends Observable implements DefaultLauncher {
5351
this.ioc = new IOC(localParticipant.value);
5452
this.room = this.ioc.createRoom('launcher', 'unlimited');
5553

54+
// Assign a slot to the participant
55+
this.slotService = new SlotService(this.room, this.useStore);
56+
localParticipant.publish({
57+
...localParticipant.value,
58+
slot: this.slotService.slot,
59+
activeComponents: [],
60+
});
61+
62+
this.participant = localParticipant.value;
63+
5664
// internal events without realtime
5765
this.eventBus = new EventBus();
5866

@@ -67,10 +75,10 @@ export class Launcher extends Observable implements DefaultLauncher {
6775
* @param component - component to add
6876
* @returns {void}
6977
*/
70-
public addComponent = (component: Partial<BaseComponent>): void => {
78+
public addComponent = async (component: Partial<BaseComponent>): Promise<void> => {
7179
if (!this.canAddComponent(component)) return;
7280

73-
const { hasJoinedRoom, localParticipant, group } = useStore(StoreType.GLOBAL);
81+
const { hasJoinedRoom, group, localParticipant } = useStore(StoreType.GLOBAL);
7482

7583
if (!hasJoinedRoom.value) {
7684
this.logger.log('launcher service @ addComponent - not joined yet');
@@ -92,17 +100,18 @@ export class Launcher extends Observable implements DefaultLauncher {
92100
this.activeComponents.push(component.name);
93101
this.activeComponentsInstances.push(component);
94102

103+
localParticipant.publish({
104+
...this.participant,
105+
activeComponents: this.activeComponents,
106+
});
107+
95108
this.room.presence.update({
96-
...localParticipant.value,
109+
...this.participant,
110+
slot: this.slotService.slot,
97111
activeComponents: this.activeComponents,
98112
});
99113

100-
ApiService.sendActivity(
101-
localParticipant.value.id,
102-
group.value.id,
103-
group.value.name,
104-
component.name,
105-
);
114+
ApiService.sendActivity(this.participant.id, group.value.id, group.value.name, component.name);
106115
};
107116

108117
/**
@@ -192,7 +201,7 @@ export class Launcher extends Observable implements DefaultLauncher {
192201
private canAddComponent = (component: Partial<BaseComponent>): boolean => {
193202
const isProvidedFeature = config.get<boolean>(`features.${component.name}`);
194203
const componentLimit = LimitsService.checkComponentLimit(component.name);
195-
const isComponentActive = this.activeComponents.includes(component.name);
204+
const isComponentActive = this.activeComponents?.includes(component.name);
196205

197206
const verifications = [
198207
{
@@ -242,6 +251,16 @@ export class Launcher extends Observable implements DefaultLauncher {
242251
);
243252
};
244253

254+
private onLocalParticipantUpdate = (participant: Participant): void => {
255+
this.activeComponents = participant.activeComponents || [];
256+
257+
if (this.activeComponents.length) {
258+
this.activeComponentsInstances = this.activeComponentsInstances.filter((ac) => {
259+
return this.activeComponents.includes(ac.name);
260+
});
261+
}
262+
};
263+
245264
/**
246265
* @function onLocalParticipantUpdateOnStore
247266
* @description handles the update of the local participant in the store.
@@ -250,19 +269,13 @@ export class Launcher extends Observable implements DefaultLauncher {
250269
*/
251270
private onLocalParticipantUpdateOnStore = (participant: Participant): void => {
252271
this.participant = participant;
253-
};
272+
this.activeComponents = participant.activeComponents || [];
254273

255-
/**
256-
* @function onParticipantJoined
257-
* @description on participant joined
258-
* @param ablyParticipant - ably participant
259-
* @returns {void}
260-
*/
261-
private onParticipantJoined = (participant: Socket.PresenceEvent<Participant>): void => {
262-
if (participant.id !== this.participant.id) return;
263-
264-
this.logger.log('launcher service @ onParticipantJoined - local participant joined');
265-
this.attachComponentsAfterJoin();
274+
if (this.activeComponents.length) {
275+
this.activeComponentsInstances = this.activeComponentsInstances.filter((component) => {
276+
return this.activeComponents.includes(component.name);
277+
});
278+
}
266279
};
267280

268281
private onSameAccount = (): void => {
@@ -330,13 +343,11 @@ export class Launcher extends Observable implements DefaultLauncher {
330343
): Promise<void> => {
331344
if (presence.id !== this.participant.id) return;
332345

333-
// Assign a slot to the participant
334-
this.slotService = new SlotService(this.room, this.useStore);
335-
336346
this.room.presence.update(this.participant);
337347

338348
this.logger.log('launcher service @ onParticipantJoined - local participant joined');
339-
this.onParticipantJoined(presence);
349+
350+
this.attachComponentsAfterJoin();
340351
this.publish(ParticipantEvent.LOCAL_JOINED, this.participant);
341352
this.publish(ParticipantEvent.JOINED, this.participant);
342353
};

src/services/io/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ export class IOC {
2323
*/
2424
public destroy(): void {
2525
this.client.destroy();
26-
this.client.connection.off();
2726
}
2827

2928
/**
@@ -43,7 +42,7 @@ export class IOC {
4342

4443
if (
4544
needsToReconnectStates.includes(state.state) &&
46-
state.reason !== 'Unauthorized connection'
45+
!['io client disconnect', 'Unauthorized connection'].includes(state.reason)
4746
) {
4847
this.forceReconnect();
4948
}

0 commit comments

Comments
 (0)