I'm using rooms to send a 'private' message to a client and it works however the message being sent is duplicated by the number of clients I have and I believe this is because of my .on('message')
since this is still triggering for every client but only emitting to the correct client (but multiple times..)
server
io.sockets.on('connection', function(socket {
socket.on('join', function(data)
{
console.log('enter');
socket.join(data.user);
});
var rClient = redis.createClient();
rClient.subscribe('messagex');
rClient.on('message', function(channel, message) {
io.in(message.user).emit('messagex', {content: message.content});
});
socket.on('disconnect', function() {
rClient.quit();
});
});
receiver client
<script>
var username = prompt("test");
var socket = io.connect('http://localhost:8100');
socket.emit('join', {user: username});
socket.on('messagex', function(data) {
$('#messages').append('<p>' + data.content + '</p>');
});
So I have 3 clients (each with different users/rooms open) at the receiver page and I send a message from the sender to say user user1, then I will only receive the message on user1 client but it will receive 3 of the same message each time and the number of times duplicated seems to be the number of clients I have..
try this
subscribe.unsubscribe(channel);
when connection disconnect unsubscribe
io.sockets.on('connection', function(socket {
socket.on('join', function(data)
{
console.log('enter');
socket.join(data.user);
});
var rClient = redis.createClient();
rClient.subscribe('messagex');
rClient.on('message', function(channel, message) {
io.in(message.user).emit('messagex', {content: message.content});
});
socket.on('disconnect', function() {
rClient.unsubscribe('messagex');
rClient.quit();
});
});
Why are there two sets of parenthesis here? return state.filter(({ id }) => { return id !== action.id }); I'm having such a tough time wrapping my head around this one ...
Why are there two sets of parenthesis here? return state.filter(({ id }) => { return id !== action.id }); I'm having such a tough time wrapping my head around this one ...
I have search a lot on Internet, but i did not found any good example for what i am looking. It may be due to i am new in angularjs. What i am looking, I have some common function which i need to ...
I have search a lot on Internet, but i did not found any good example for what i am looking. It may be due to i am new in angularjs. What i am looking, I have some common function which i need to ...
So I have this function inside a Component: clickedResultHandler = (embedLink) => { this.setState({embedSrcLink: embedLink}); } this function is called inside a descendant like this: <div ...
So I have this function inside a Component: clickedResultHandler = (embedLink) => { this.setState({embedSrcLink: embedLink}); } this function is called inside a descendant like this: <div ...
I'm working with auth in Nextjs, I'm wondering what is the best strategy to handle authentication in NextJS ? Here my services structure : If I understand well I have to handle the server side ...
I'm working with auth in Nextjs, I'm wondering what is the best strategy to handle authentication in NextJS ? Here my services structure : If I understand well I have to handle the server side ...