I'm using RXJS websocket for my application. After logging in data is send from my server to the client and the data is stored in an observable using shareReplay to keep the data when navigating the application.
if(!this.data$ || this.data$Completed) {
this.data$ = this.dataService.get(this.CTRL, 'list').pipe(
finalize(() => {
console.log('finalizing data list');
this.data$Completed = true;
}),
map(data => [....]), // irrelevant
tap((d) => console.log('data: ', d)),
shareReplay(1),
tap((d) => console.log('data 2: ', d)),
);
}
Console output is as intended
// first subscribe
data: [{…}]
data 2: [{…}]
// every other subscribe when resubscribing after navigation / different components
data 2: [{…}]
data 2: [{…}]
data 2: [{…}]
...
When logging off the connection is terminated and the finalize method is triggered. When loggin back in the data is send again, but the shareReplay does not work anymore. I get data only on the first subscribe, but not after navigating and resubscribing.
// logout
finalizing data list
// logging in again
data: [{…}]
data 2: [{…}]
I also noticed that the rxjs websocket multiplex in that case sends subscribe commands to the server, so obvisously I subscribe to the websocket subject and not the ReplaySubject.