Closed rjculaway closed 2 years ago
While the approach is not incorrect, but, quite roundabout.
Some minor notes:
deactive
instead of disconnect
.rxStompServiceFactory
- it is designed for use with Angular DI.RxStomp
directly, it will keep your code simpler.I would suggest the following approach to achieve what you need:
deactivate
. You can call activate
again.ng2-stompjs
does - see https://github.com/stomp-js/ng2-stompjs/blob/develop/src/app/rx-stomp.service.ts and https://github.com/stomp-js/ng2-stompjs/blob/develop/src/app/rx-stomp-service-factory.tsHi @kum-deepak
Taking your advice, I created different configs inheriting InjectableRxStompConfig
.
I also have created different services inheriting RxStompService
, initializing them using factories.
So now in my module, I have
providers: [
{
provide: IotStompConfig
},
{
provide: IotStompService,
useFactory: iotStompServiceFactory,
deps: [IotStompConfig]
}
]
and a factory that does the initialization
export const iotStompServiceFactory= (rxStompConfig: IotStompConfig): IotStompService=> {
const rxStompService = new IotStompService();
rxStompService.configure(rxStompConfig);
rxStompService.activate();
return rxStompService;
};
I think this is a good approach. :+1:
Hello @kum-deepak,
I'm currently try to connect to multiple web socket connections at the same time. I created a web socket service where i'm able to pass a broker URL from whatever component that requires web socket. Here's my code:
I think connections are being established correctly, but I just want to get your input to know whether this is the correct way of doing this.
I use it in this fashion:
Component A
webSocketService.connect('connectionA')
Component B
webSocketService.connect('connectionB')
;When I connect to
connectionB
won't this affectconnectionA
since i'm technically using the same service?My other concern is, how do i disconnect from all connections when for example my session expires due to either being idle or logging out?
Would really appreciate your help on this. Thank you so much!