I'm using Django, Redis, nodejs and socket.io and having troubles solving a certain problem.
Suppose we have a chatroom with redis I and the pubsub pattern. On the nodejs server I listen for a Redis publish and emit the message to all the listening sockets. This is straight forward since on the nodejs side I have
var app = require('express')();
var http = require('http').Server(app);
var io = require('socket.io')(http);
var redis = require('redis');
io.on('connection', function(socket){
var pub = redis.createClient(), sub = rediscreateClient();
// we have multiple chat rooms, suppose variable chatroom is passed from the
// server when the page is rendered
sub.subscribe(chatroom);
...
sub.on("message", function(channel, message){
socket.emit(chatroom, message);
});
});
now suppose I want to extend this so that there's a 'like' button for each message. How do differentiate between someone sending a message or someone liking a comment, some sort of namespacing would be helpful, if I could do something along the lines of:
io.on('connection', function(socket){
var pub = redis.createClient(), sub = rediscreateClient();
// we have multiple chat rooms, suppose variable chatroom is passed from the
// server when the page is rendered
sub.subscribe(chatroom);
...
sub.on("message", "message-sent-namespace",function(channel, message){
socket.emit("message", message);
});
sub.on("message", "message-liked-namespace",function(channel, message){
socket.emit("like", message);
});
});
any suggestions? the publishing is done on the Django side.