We have a REST server implemented with HapiJS and a Websockets server implemented with Socket.IO (they are both running on a single server but on different ports). I want to notify the Websockets server from the HapiJS server to send an event with some data to a particular client.
The socket server is running on port 8081 and the REST is on 8080.
The idea is that a client makes an action (POST request), that is logged in an "Actions History" table. That action concerns other users, so they should be notified when this happens in real time. That is why the other users are listening on the websocket connection.
How can I tell the sockets server to emit an event to a particular client and that should be done from the REST server?
I thought for 3 ways at the moment:
- Separate servers for sockets and rest and communicate using RabbitMQ
I tried to implement Socket.IO-Emitter but it requires Redis database (I still don't know why). When I try to connect using the emitter from the HapiJS route handler to the socket I get:
export function* postRefreshEvent(userId) { var connection = require('socket.io-emitter')({ host: '127.0.0.1', port: 8081 }); connection.in('UserHistory').emit('refresh', userId); return {statusCode: OK} } Error: Ready check failed: Redis connection gone from end event.
at RedisClient.on_info_cmd
Refresh is not executed in the Socket server. I just don't see the log displayed.
- Make a special event and use an ordinary socket.io client to connect from the hapijs to websockets and emit there the new event.
A sample GIST.
Have you figured out something like this? I appreciate every help!