Answer the question
In order to leave comments, you need to log in
How to implement receiving new messages when connecting to WebSocket?
There is a project:
- Laravel 5.2
- Node JS
- Socket.IO 1.4.5
Socket Server:
var app = require('express')();
var http = require('http').Server(app);
var io = require('socket.io')(http);
var Redis = require('ioredis');
var redis = new Redis();
redis.psubscribe('*', function(err, count) {
});
redis.on('pmessage', function(pattern, channel, message) {
message = JSON.parse(message);
io.emit(channel + ':' + message.event, message.data);
});
http.listen(9543, function(){
console.log('Listening on Port 9543');
});
Answer the question
In order to leave comments, you need to log in
As far as I remember, there is no such thing out of the box.
In this case, I would do this:
- duplicate the event in the same radish, mark it as "unread"
- when a message is received on the client, send a return request through the socket marked "read", and kill that key in the radish via nodejs
- when reconnecting, pick up all "unread" messages
Look, there may be other message queue implementations that support this mechanism out of the box.
Ps: completely off topic (practically).
In general, I am also writing my own project, there will be dialogs (on a separate page, just routes).
Which is better:
ajax or reading about Node and on it?
ps: whole project in php + jquery
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question