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

Refactor requests between nodes and add clientRooms method #146

Merged
merged 1 commit into from Nov 28, 2016

Conversation

darrachequesne
Copy link
Member

This PR refactors the way requests are sent between nodes. The subJson
client has been removed, the subClient now listens to three channels by
default:

  • the usual channel, where the message are broadcast
  • the request channel, where any node can request information (for now,
    the clients in a given rooms or the rooms for a given client)
  • the response channel, where a node will receive answer to its requests

Fixes #138 (no more subJson)
Closes #143 (add clientRooms() method)

@artofspeed would that suit your needs?

This PR refactors the way requests are sent between nodes. The `subJson`
client has been removed, the subClient now listens to three channels by
default:
- the usual channel, where the message are broadcast
- the request channel, where any node can request information (for now,
  the clients in a given rooms or the rooms for a given client)
- the response channel, where a node will receive answer to its requests
@darrachequesne
Copy link
Member Author

Also, it should allow to add other useful requests, like making any socket.id join/leave a room, even on another node.

@barisusakli
Copy link
Contributor

This is nice, been waiting for this for a while now. socketio/socket.io#1884

@artofspeed
Copy link

artofspeed commented Nov 26, 2016

Absolutely. Thank you @darrachequesne this PR would be really useful!

@darrachequesne
Copy link
Member Author

Released as 2.0.0, any feedback is welcome!

@barisusakli
Copy link
Contributor

I can't seem to get .clients and .clientRooms to work after I upgrade socket.io dependencies.

These are my dependencies

 "socket.io": "1.7.1",
 "socket.io-client": "1.7.1",
 "socket.io-redis": "2.0.0",

Both .clients and .clientRooms result in

Error: timeout reached while waiting for clients response
    at Timeout._onTimeout (/home/baris/node-forum/node_modules/socket.io-redis/index.js:422:48)
    at ontimeout (timers.js:365:14)
    at tryOnTimeout (timers.js:237:5)

If I drop socket.io-redis dependency to 1.1.1 it works but I can't use .clientRooms.

The code is below.

// init
var redisAdapter = require('socket.io-redis');
var redis = require('../database/redis');
var pub = redis.connect();
var sub = redis.connect({return_buffers: true});
io.adapter(redisAdapter({pubClient: pub, subClient: sub}));

//usage
io.in('topic_1').clients(function (err, socketids) {
});

@barisusakli
Copy link
Contributor

Manually went through commits to find the first one that is causing .clients to stop working and its this PR 84261b2

@darrachequesne
Copy link
Member Author

That is the change induced by this very PR.

Both server1.in('woot').clients(function(err, clients){ and server1.adapter.clients(['woot'], function(err, clients){ should work though.

Could you debug with DEBUG=socket.io-redis* please?

@barisusakli
Copy link
Contributor

barisusakli commented Nov 29, 2016

See my PR #155 that fixed the issue for me.

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

Successfully merging this pull request may close these issues.

None yet

3 participants