sc-stateless-presence icon indicating copy to clipboard operation
sc-stateless-presence copied to clipboard

user leave action not dispatched in presence when socket disconnect

Open rohittailor opened this issue 7 years ago • 8 comments

Hi,

I am trying to get channel users and getting it but when user close browser and socket disconnect from server, user leave event is not coming in trackPresence callback and also getPresenceList is returning all users (even when the socket disconnect).

I am tracking channel presence in all clients.

Please let me know if I am missing anything here.

rohittailor avatar Jan 24 '18 06:01 rohittailor

@rohittailor Is this in a production or testing environment?

Note that if you have two tabs open in the same browser, by default they will share the same session and if you close one, then the user will still be online because they will still have one tab open.

Could you give more specific steps/instructions so that I can reproduce the issue?

Also note that in some edge cases where there is network failure, it's possible that there can be a delay of several seconds before the presence list is updated.

jondubois avatar Jan 24 '18 23:01 jondubois

You can provide an optional presenceInterval option so that it can detect these edge cases sooner; the default interval is 10000 (10 seconds) https://github.com/SocketCluster/sc-stateless-presence/blob/master/index.js#L5 but note that making the interval shorter will use up more bandwidth.

So you can trade efficiency/performance for accuracy.

jondubois avatar Jan 24 '18 23:01 jondubois

Hi @jondubois ,

Its in my local DEV environment. I have not provided any presenceInterval option so its taking default one.

Two client apps are connected to same server. One is the admin app and another is customer facing. From admin app I am trying to fetch presence of channel (subscribed from customer facing app).

I opened apps in different browsers to make sure session is not shared, but still when I close the browser or refresh it , presence list is not getting updated and trackPresence callback is not getting dispatch. When I try getPresenceList its returning all users.

From socket I can see socket disconnect event when I close the browser but presence is not getting updated.

rohittailor avatar Jan 25 '18 04:01 rohittailor

Hi @jondubois ,

Please let me know if you are able to reproduce the issue.

Thanks, Rohit

rohittailor avatar Feb 05 '18 10:02 rohittailor

@rohittailor I tried to reproduce the issue but couldn't. I found a separate issue which caused an error to be thrown if the client wasn't tracking a specific channel but it worked apart from that.

On the server in worker.js, I add my stateless logic:

scStatelessPresence.attach(this);

Then inside the 'connection' handler, I have this dummy code:

scServer.on('connection', (socket) => {
      socket.on('login', (data) => {
        socket.setAuthToken({
          username: data.username
        });
      });
});

On the front end, I have this:

var presence = scStatelessPresenceClient.create(socket);

var sampleChannel = socket.subscribe('sample');

presence.trackPresence('sample', function (action) {
        console.log('PRESENCE:', action);
});

Then from one tab, I log in with (inside the developer console):

socket.emit('login', {username: 'bob123'});

and in another tab, I log in with:

socket.emit('login', {username: 'alice456'});

Then in the dev console, I also check with:

presence.getPresenceList('sample');

jondubois avatar Feb 05 '18 22:02 jondubois

@rohittailor Let me know if you're doing something different which might be causing the issue.

jondubois avatar Feb 05 '18 22:02 jondubois

@jondubois Sorry for delay in response. I am currently using SocketCluster version "4.3.2". I sm upgrading to latest version. Will get back if that resolve the issue.

rohittailor avatar Feb 16 '18 07:02 rohittailor

@rohittailor Could it be that a socket authenticated a second time using a different username? There was an issue there. Fixed in v1.0.7.

jondubois avatar Apr 29 '18 10:04 jondubois