Reputation: 797
I'm using backbone.io from https://github.com/scttnlsn/backbone.io, and would like to emit an event to a single client using that client's socket id. So rather than doing backend.emit('created', { id: 'myid', foo: 'bar' });
which will emit the event to all clients, I'd like to emit to a single client.
What's the best way of doing this?
Upvotes: 0
Views: 291
Reputation: 22758
I would do this:
Set up a channel for each user. If you need to make it hard for other clients to listen, name the channel with a hash based on the user id and the login time or something. Tell the client to listen to that channel.
Then if you want to send something to a specific user, you can look at your database, see their id and their login time, and then send data to that specific user.
Upvotes: 1