angularjs - How to listen to socket emit on sails.io.js? -


i'm using sails 0.11 in back-end, , angularjs in front-end.

i have twittercontroller in sails following code, open stream twitter streaming api (this uses node module twit):

var twit = require('twit');  var t = new twit(sails.config.twit);  var stream = t.stream('statuses/filter', {     track: ['apple'] });  module.exports = {     open: function(req, res) {         if (!req.issocket) {             return res.badrequest();         }          var socketid = sails.sockets.id(req.socket);          stream.start();          stream.on('tweet', function(tweet) {             sails.log.debug('tweet received.');             sails.sockets.emit(socketid, 'tweet', tweet);         });     } }; 

in front-end (with angular-sails module):

$sails.get('/twitter/open').then(function(resp) {   console.log(resp.status); }, function(resp) {   alert('houston, got problem!'); }); 

this of course reaches back-end controller, , streaming starts, how listen

sails.sockets.emit(socketid, 'tweet', tweet);

issued server?.

i'd appreciate here!.

sails library creates global variable "io", can use also:

io.socket.on("tweet", function(data){}) 

Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -