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

Force disconnect/login a client that is connected #27

Closed
jwanglof opened this issue Sep 30, 2015 · 4 comments
Closed

Force disconnect/login a client that is connected #27

jwanglof opened this issue Sep 30, 2015 · 4 comments

Comments

@jwanglof
Copy link

We have an Android application that is showing our web-application in a web view (we're using Crosswalk's webview, https://crosswalk-project.org/). When the application is loosing its focus (i.e. the user minimizes the application) we need to disconnect our socket, and when the application is regaining its focus we need to login with the socket again. Or is this the wrong way to do it?

We know when the application is loosing focus and when it's regaining focus.

We've tried to close the socket (with deepstreamClient.close()), and then login with it again. However, this gives us the error: this client's connection was closed, which is wanted since we actually closed the socket.

What we would need is a deepstreamClient.disconnect() or some kind of re-login on the current socket.

Is this possible to implement?
I can make a PR if I could get some hints where do add this functionality so you guys don't have to implement this =)

@yasserf
Copy link
Contributor

yasserf commented Oct 1, 2015

Disconnecting and connecting again sounds like expected behaviour!

You can look at connection for where the functionality would go.

By looking at the code it could be something like recreating the endpoint:

createEndPoint = function () {
    if( utils.isNode() ) {
        this._endpoint = new TcpConnection( url );
    } else {
        this._endpoint = engineIoClient( url, options );
    }

    this._endpoint.on( 'open', this._onOpen.bind( this ) );
    this._endpoint.on( 'error', this._onError.bind( this ) );
    this._endpoint.on( 'close', this._onClose.bind( this ) );
    this._endpoint.on( 'message', this._onMessage.bind( this ) );
}

Then rather than throw the exception in authenticate you can create a new endpoint:

    if( this._deliberateClose === true && this._state === C.CONNECTION_STATE.CLOSED ) {
               this._createEndpoint();
               this._deliberateClose = false;
              this._client.once( C.EVENT.CONNECTION_STATE_CHANGED, this.authenticate.bind( authParams, callback );
              return;
    }

There will be a couple of other issues you will get due to deepstream client having to resubscribe events / rpcs ( it currently only does it for records and lists ). We started work on this but still haven't decided on the exact approach to take. See #20.

Be great if you can add an e2e tests for this.

Thanks!

@yasserf
Copy link
Contributor

yasserf commented Nov 18, 2015

Hey @jwanglof,

Was wondering if you had a chance to look at this / if the approach worked.

Thanks!

@jwanglof
Copy link
Author

@yasserf: I haven't had any time to implement this. We have a working work-around on our frontend regarding connecting/disconnecting that we will be using until this is implemented. Either by you guys or by someone else =)
But I have this on my todo-list for sure

@yasserf
Copy link
Contributor

yasserf commented Nov 19, 2015

Awesome, just wanted to catch up and make sure it isn't a blocker.

Our own product will go through a hardening stage which will give us some dedicated bandwidth to target this and other features on our backlog

I'll let you know when we pick this up to avoid stepping on each others toes!

yasserf added a commit that referenced this issue Dec 5, 2015
Fixes #27 connecting after voluntary disconnect
WolframHempel added a commit that referenced this issue Dec 14, 2015
…ect-reconnect

Fixes #27 connecting after voluntary disconnect
yasserf added a commit that referenced this issue Feb 14, 2016
WolframHempel added a commit that referenced this issue Feb 15, 2016
…dy-event

Fixes #27 anonymous record ready event
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants