@@ -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 } ;
0 commit comments