Skip to content
New issue

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

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

Already on GitHub? # to your account

socket io - logout event not fired for anonymous users #1238

Closed
FelixButzbach opened this issue Mar 4, 2019 · 2 comments · Fixed by #1355
Closed

socket io - logout event not fired for anonymous users #1238

FelixButzbach opened this issue Mar 4, 2019 · 2 comments · Fixed by #1355

Comments

@FelixButzbach
Copy link

I read a lot through all the issues and half of the internet but it seams that the disconnect event is not passed through on the server.

In my app I want to track all users that open the page. I also need to know when they leave the page. The only way way I found to know when someone disconnects is by hacking the original io object into the app, like this:

in app.js

app.configure(socketio(io => {
    // Registering Socket.io middleware
    io.use(function (socket, next) {
        // Exposing a request property to services and hooks
        socket.feathers.clientId = socket.id;
       // Adding the original socket
        socket.feathers.io = socket
        next();
    });
}));

And now I am able to do this in channels.js

app.on('connection', connection => {
  // On a new real-time connection, add it to the anonymous channel
  app.channel('anonymous').join(connection);
  
  // Keep the clientId around for later
  const clientId = connection.clientId
  
  // Do something with the clientId
  console.log('connection ', clientId);

  // Register the listener for the disconnect event
  connection.io.on('disconnect', event => {
    console.log('dissssss', event, clientId);  
  })

});

This seams pretty hacky and I can't believe there is no other way, but I couldn't find it. Please let me know if this is a legitimate way of doing this.
I am using the latest version of feathers.

ps. The solution given here #957 is not working for me, I think because I don\t authenticate the users...

@FelixButzbach
Copy link
Author

I assume that the answer on this issue (#1243) are valid here as well, but I would be happy about some comment on my approach. Good, Bad, Can do?

@FelixButzbach
Copy link
Author

@daffl nice. Thanks!

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

Successfully merging a pull request may close this issue.

1 participant