I have a WsConnector
class responsible for connecting to my backend application and subscribing to a WebSocket topic.
export class WsConnector {
private stompClient: any;
connect(onMessage: (msg) => void) {
this.stompClient = Stomp.over(new SockJS('http://localhost:8080/ws'));
this.stompClient.connect({}, () => {
this.stompClient.subscribe('/topic/event', (msg: any) => {
console.log('Msg received in WsConnector')
onMessage(msg)
});
}, (err: any) => console.error(err));
}
}
In addition, I have another class that utilizes the WsConnector class as follows:
export class SimpleClass {
private ws = new WsConnector()
private onMessageReceived(msg: any): void {
console.log('Msg received in component')
}
constructor() {
this.ws.connect(() => this.onMessageReceived.bind(this))
}
}
While I am able to receive messages with the log 'Msg received in WsConnector', I am unable to see 'Msg received in component' indicating that the messages are not being passed to this function. What could be causing this issue?