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

Commit c29c19c

Browse files
Merge pull request #736 from SuperViz/lab
Fixing destroy flow
2 parents 6805915 + ddd8a64 commit c29c19c

File tree

3 files changed

+22
-28
lines changed

3 files changed

+22
-28
lines changed

src/core/launcher/index.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ describe('Launcher', () => {
114114

115115
LauncherInstance.addComponent(MOCK_COMPONENT);
116116

117-
expect(MOCK_COMPONENT.attach).not.toBeCalled();
117+
expect(MOCK_COMPONENT.attach).not.toHaveBeenCalled();
118118
});
119119

120120
test('should remove component', () => {

src/core/launcher/index.ts

+20-27
Original file line numberDiff line numberDiff line change
@@ -98,15 +98,25 @@ export class Launcher extends Observable implements DefaultLauncher {
9898
});
9999

100100
this.activeComponents.push(component.name);
101-
this.activeComponentsInstances.push(component);
101+
102+
if (this.activeComponentsInstances.some((c) => c.name === component.name)) {
103+
this.activeComponentsInstances = this.activeComponentsInstances.map((ac) => {
104+
if (ac.name === component.name) {
105+
return component;
106+
}
107+
return ac;
108+
});
109+
} else {
110+
this.activeComponentsInstances.push(component);
111+
}
102112

103113
localParticipant.publish({
104-
...this.participant,
114+
...localParticipant.value,
105115
activeComponents: this.activeComponents,
106116
});
107117

108118
this.room.presence.update({
109-
...this.participant,
119+
...localParticipant.value,
110120
slot: this.slotService.slot,
111121
activeComponents: this.activeComponents,
112122
});
@@ -141,7 +151,7 @@ export class Launcher extends Observable implements DefaultLauncher {
141151
*/
142152
public removeComponent = (component: Partial<BaseComponent>): void => {
143153
if (!this.activeComponents.includes(component.name)) {
144-
const message = `Component ${component.name} is not initialized yet.`;
154+
const message = `[SuperViz] Component ${component.name} is not initialized yet.`;
145155
this.logger.log(message);
146156
console.error(message);
147157
return;
@@ -176,15 +186,14 @@ export class Launcher extends Observable implements DefaultLauncher {
176186
this.activeComponents = [];
177187
this.activeComponentsInstances = [];
178188

179-
useGlobalStore().destroy();
189+
useGlobalStore()?.destroy();
180190

181-
this.eventBus.destroy();
191+
this.eventBus?.destroy();
182192
this.eventBus = undefined;
183193

184194
this.room?.presence.off(Socket.PresenceEvents.JOINED_ROOM);
185195
this.room?.presence.off(Socket.PresenceEvents.LEAVE);
186196
this.room?.presence.off(Socket.PresenceEvents.UPDATE);
187-
this.ioc.stateSubject.unsubscribe();
188197
this.ioc?.destroy();
189198

190199
this.isDestroyed = true;
@@ -207,20 +216,20 @@ export class Launcher extends Observable implements DefaultLauncher {
207216
const verifications = [
208217
{
209218
isValid: isProvidedFeature,
210-
message: `Component ${component.name} is not enabled in the room`,
219+
message: `[SuperViz] Component ${component.name} is not enabled in the room`,
211220
},
212221
{
213222
isValid: !this.isDestroyed,
214223
message:
215-
'Component can not be added because the superviz room is destroyed. Initialize a new room to add and use components.',
224+
'[SuperViz] Component can not be added because the superviz room is destroyed. Initialize a new room to add and use components.',
216225
},
217226
{
218227
isValid: !isComponentActive,
219-
message: `Component ${component.name} is already active. Please remove it first`,
228+
message: `[SuperViz] Component ${component.name} is already active. Please remove it first`,
220229
},
221230
{
222231
isValid: componentLimit.canUse,
223-
message: `You reached the limit usage of ${component.name}`,
232+
message: `[SuperViz] You reached the limit usage of ${component.name}`,
224233
},
225234
];
226235

@@ -252,16 +261,6 @@ export class Launcher extends Observable implements DefaultLauncher {
252261
);
253262
};
254263

255-
private onLocalParticipantUpdate = (participant: Participant): void => {
256-
this.activeComponents = participant.activeComponents || [];
257-
258-
if (this.activeComponents.length) {
259-
this.activeComponentsInstances = this.activeComponentsInstances.filter((ac) => {
260-
return this.activeComponents.includes(ac.name);
261-
});
262-
}
263-
};
264-
265264
/**
266265
* @function onLocalParticipantUpdateOnStore
267266
* @description handles the update of the local participant in the store.
@@ -271,12 +270,6 @@ export class Launcher extends Observable implements DefaultLauncher {
271270
private onLocalParticipantUpdateOnStore = (participant: Participant): void => {
272271
this.participant = participant;
273272
this.activeComponents = participant.activeComponents || [];
274-
275-
if (this.activeComponents.length) {
276-
this.activeComponentsInstances = this.activeComponentsInstances.filter((component) => {
277-
return this.activeComponents.includes(component.name);
278-
});
279-
}
280273
};
281274

282275
private onSameAccount = (): void => {

src/services/io/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export class IOC {
2222
* @returns {void}
2323
*/
2424
public destroy(): void {
25+
this.stateSubject.complete();
2526
this.client.destroy();
2627
}
2728

0 commit comments

Comments
 (0)