Sails Hook for server sent events, this extension adds a new method to Response Object (res) of SailsJs
add the following line to your package.json:
"sails-hook-sse": "https://github.com/makmakulet/sails-hook-sse.git"
run npm install
$ npm install
Controller:
//-- api/controllers/TestController.js
module.exports = {
index: function(req, res) {
res.sse({field: [Math.random(), Math.random()]});
},
list: function(req, res) {
res.sse('some_event', {field: [Math.random(), Math.random()]});
}
};
Client Side:
var sseSource = new EventSource("/test");
sseSource.onmessage = function(e) {
console.log(e.data);
}
@data: <object | string> value to be emitted by server on the connected client.
@return: the @data as an event-stream