Closed rpigab closed 2 years ago
Moved the issue to the main library.
There are fundamentally two approaches, please see https://github.com/stomp-js/ng2-stompjs/issues/194#issuecomment-630840872, see also https://stomp-js.github.io/faqs/faqs.html#p-my-authentication-tokens-expire-where-should-i-write-code-to-acquire-fresh-tokens-p
If your token may change over time, please use the beforeConnect
callback approach.
This question has been asked as different variants in the past, so, searching with https://github.com/stomp-js/ng2-stompjs/issues?q=is%3Aissue+async may bring issues that might have sample code.
Please let me know if you need any additional information.
Thanks a lot! This is what I was looking for :slightly_smiling_face:
Hello, I'm trying to implement a WebsocketService using InjectableRxStompConfig and RxStompService from '@stomp/ng2-stompjs', the documentation available at https://stomp-js.github.io/guide/ng2-stompjs/ng2-stomp-with-angular7.html suggests using the following InjectableRxStompConfig :
export const myRxStompConfig: InjectableRxStompConfig = { // Which server? brokerURL: 'ws://127.0.0.1:15674/ws', // etc. };
However, my backend expects an auth_code token string that I have to get through an HTTP GET request (I'm using Angular's HttpClient) each time a new session is created. Because this happens in the constructor, I cannot use HttpClient's observables, promises or anything asynchronous here.
I am unsure on how to proceed without having to move all constructor calls to onInit() methods, providing manually all StompConfig and Clients classes, this does not seem like a good idea. Am I taking the right path? Any ideas welcome.
Thanks!