#Rx-stomp & providers and modules

5 messages · Page 1 of 1 (latest)

rancid kestrel
#

export function rxStompServiceFactory() {
console.log("zzzzzzzzz")
const rxStomp = new RxStompService();
const aRxStompConfig = inject(RxStompConfig)
rxStomp.configure(aRxStompConfig);
console.log("rxStompServiceFactory")
console.log(aRxStompConfig)
rxStomp.activate();
return rxStomp;
}

export class SharedModule {
static forRoot(): ModuleWithProviders<SharedModule> {
return {
ngModule: SharedModule,
providers: [
{
provide: APP_INITIALIZER,

      // useFactory: (i18NService: I18nService) => () => i18NService.initMessages(I18Enum.ru),
      // or
      useFactory: initializeService,
      deps: [ConfigurationService],
      multi: true,
    },
    {
      provide: RxStompConfig,
      useValue: myRxStompConfig,
    },
    {
      provide: RxStompService,
      useFactory: rxStompServiceFactory,
      deps: [RxStompConfig],
    },
    ...myexportedservices,
  ],
};

}

i never get the "zzzzz" in the console !!!

why ??

any idea ?

#

the module is loaded by this :
@NgModule({
declarations: [
AppComponent,
HeaderComponent,
FooterComponent,
NavBarComponent,
RulesPage,
HomePage
],
imports: [
AngularSharedModules.forRoot(),
UiModule.forRoot(),
SharedModule.forRoot(),
SecuriteModule.forRoot(),
BrowserModule,
AppRoutingModule,
],
providers: [
{
provide : CONFIGURATION,
useValue : {
apptitle: environment.apptitle,
production: environment.production,
baseurl: environment.baseurl,
backendurl: environment.backendurl,
SECURED_BASE_APIURL: environment.SECURED_BASE_APIURL,
PUBLIC_BASE_APIURL: environment.PUBLIC_BASE_APIURL,
theme: environment.theme
}
}
],
bootstrap: [AppComponent],
})
export class AppModule {}

restive quartz
#

Probably because you never inject RxStompService anywhere.

rancid kestrel
# restive quartz Probably because you never inject RxStompService anywhere.

export class TableDeJeuxGameComponent implements OnInit, OnDestroy {
receivedMessages: string[] = [];
// @ts-ignore, to suppress warning related to being undefined
private topicSubscription: Subscription;

constructor(private rxStompService: RxStompService) {

//https://stomp-js.github.io/guide/ng2-stompjs/rx-stomp/connection-status-ng2-stompjs.html


console.log("this.rxStompService");
console.log(this.rxStompService);

//this.rxStompService.configure(myRxStompConfig);
//this.rxStompService.activate();

rxStompService.connectionState$.subscribe(state => {
  // state is an Enum (Integer), RxStompState[state] is the corresponding string
  console.log("***************RxStompState[state]");
  console.log(RxStompState[state]);
});

// In case you want to respond to each connection establishment
rxStompService.connected$.subscribe(() => {
  console.log('I will be called for each time connection is established.');
});

// If you want to execute only once. It will execute immediately if connected
// otherwise on first subsequent connection.
rxStompService.connected$.pipe(take(1)).subscribe(() => {
console.log('I will be called only once.');
});

}

ngOnInit() {
console.log("this.rxStompService ngoninit");
this.topicSubscription = this.rxStompService
.watch('/messages/messages/hello')
.subscribe((message: Message) => {
this.receivedMessages.push(message.body);
});
}

ngOnDestroy() {
this.topicSubscription.unsubscribe();
}

onSendMessage() {
const message = Message generated at ${new Date()};
this.rxStompService.publish({ destination: '/app/hello', body: message, headers: {'content-type': 'application/json'}});
}

}

#

i do have " constructor(private rxStompService: RxStompService) {..." the RxStompService is injected (but wich one ? where does it come from...)