Monday 30 January 2017

I'm having huge problems try to emit messages to a private room with socket.io and redis pub/sub.

So I'm building a facebook like private messenger. I've been trying to accomplish this for more than a week now. I feel like I'm a few lines of code away, but I'm flat out stuck and spinning my tires.Essentially, I'm having problems emitting messages to a private room. I have it so it console logs out what room I've joined, as you will see below, but I can't for the life of me get it to only send the message to the client in the same room. I've had so messages duplicate, or even triple how many times it's sent depending on how many users are using the messenger.I've had the following 2 functions work, but now all of the sudden don't. Both of these were creating duplicates and now don't work at all: socket.broadcast.in(data.room).emit(channel, data); socket.to(data.room).emit(channel, data);This still will emit messages to all clients though:socket.emit(channel, data);Here's my client:` var socket = io.connect('http://localhost:3000'); socket.on('message', function (data) { //Just console the message and user right now. console.log(data.message+" " + data.user); });`Here's my server: Here's a link to the server. I tried multiple times to format this, but can't get it right.I've already asked a question about this on stacks. Note, I'm also using laravel on the backend. I'm pretty positive that this isn't a Laravel problem though. Here's the repository for this project.I'm more than happy to gild anyone that provides me an answer. This question is literally stopping me from finishing an entire project. Thank you all for your time.

Submitted January 31, 2017 at 06:01AM by corbinthecoder

No comments:

Post a Comment