Currently, I am encapsulating a websocket within an RxJS observable in the following manner:
this.wsObserver = Observable.create(observer=>{
this.websocket.onmessage = (evt) => {
console.info("ws.onmessage: " + evt);
observer.next(evt);
};
});
While this method seems to work fine, when I subscribe multiple times, only the last subscriber triggers:
this.wsObserver.subscribe((result) => {
console.info("! result: " + result);
});
this.wsObserver.subscribe((result) => {
console.info("!2 result: " + result);
});
It seems that only !2 result:
is being logged. Can anyone explain why this is happening and what mistake might I be making?