This is what I've got so far, and I'm trying to find a solution so that:
ws api here
router.post('/', function (req, res) {
// Need to send ws.send() with post data
})
wss.on('connection', function(ws) {
ws.on('message', function(message) {
console.log('r : %s', message);
});
// ws is only defined under this callback as an object of type ws
});
You can use event like this :
//Create an event
var event = require('events').EventEmitter();
router.post('/', function (req, res) {
// fire an event
event.emit('homePage')
})
wss.on('connection', function(ws) {
ws.on('message', function(message) {
console.log('r : %s', message);
});
// listen the event
event.on('homePage', function(){
ws.emit('someEvent');
});
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With