Thursday, March 2, 2017

Laravel + Node + Redis + Socket: Wildcard channel subscription

Is it possible for node/ioredis to subscribe to a wildcard channel coming from Laravel events? For example if Laravel broadcasted to a channel user-notification-<user_id> and that the specific client would just subscribe to that specific channel so that we don't have to broadcast general events to all clients? I saw this code (link below) which make me think that node can subscribe to all channels that will be broadcasted from the events:

Broadcasting Events with Laravel and Socket.io

redis.psubscribe('*', function(err, count) {
    //
});
redis.on('pmessage', function(subscribed, channel, message) {
    message = JSON.parse(message);
    console.log('Channel is ' + channel + ' and message is ' + message);
    io.emit(channel, message.data);
}); 

I know Pusher/Ably is able to take advantage of Laravel events and broadcast it to a specific channel per user. I don't think socket.io rooms can be used here but I'm not sure.



via Drew Adorador

Advertisement