scatter-js
scatter-js copied to clipboard
Can't check connection status correctly
Hello gus. I'm trying to check connection state to Scatter in realtime.
When I close Scatter socket connection still active. And when I'm trying to connect to Scatter again (without page refresh):
actual result: connect(APP_NAME)
connects to current socket connection
expected result: socket connection should be closed
This is my code:
Rx.of(CONNECTION_STATE.UNKNOWN),
interval$factory(5000)
.pipe(
rx.switchMap(() => new Rx.Observable(async observer => {
try {
const isConnected = ScatterJS.scatter.isConnected
? await ScatterJS.scatter.isConnected()
: await ScatterJS.scatter.connect(APP_NAME)
observer.next(isConnected ? CONNECTION_STATE.CONNECTED : CONNECTION_STATE.DISCONNECTED)
} catch (e) {
observer.next(CONNECTION_STATE.UNKNOWN)
}
})),
rx.catchError(e => {
return Rx.of(CONNECTION_STATE.DISCONNECTED)
}),
rx.shareReplay(1)
)
)
So, the latest version of @scatterjs/core
fixed that, but I'm still not sure that an observable on the isConnected
will work. The underlying socket service is an object class which is torn down and re-constructed when re-connecting, so it might be trying to observe the old object, and then also keeping it registered in memory since it has linked references.