Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't check connection status correctly #133

Open
SerjKomarovsky opened this issue Aug 16, 2019 · 1 comment
Open

Can't check connection status correctly #133

SerjKomarovsky opened this issue Aug 16, 2019 · 1 comment

Comments

@SerjKomarovsky
Copy link

SerjKomarovsky commented Aug 16, 2019

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)
        )
    )
@nsjames
Copy link
Contributor

nsjames commented Aug 24, 2019

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants