I'm using a modular setup where Socket.IO is no part of my application or routes - but in an external module.
I have a PHP script that receives data and then updates the database. I've set it up to send a cURL request to the node application, and I'd like the route to trigger an event that my socket module listens for to go and emit a socket.io event, and update what the client see's in real-time.
Does an event emit to the entire application or have I gone about my approach all wrong?
Thanks.
Express 3 Route
var events = require('events');
var event_emitter = new events.EventEmitter();
router.post('/php-script-calls-this', function(req, res, next) {
event_emitter.emit('do-socket-event');
res.sendStatus(200);
});
Socket File (sub-module called in my io.js module)
module.exports = function(io, socket) {
var events = require('events');
var event_emitter = new events.EventEmitter();
event_emitter.on("do-socket-event", function() {
socket.emit("update-client-data");
});