angularjs - Socket.io: Not emitting to specific socket.id -


i'm trying loop through each user's array of sockets , send message socketid... it's not receiving on front end reason.

i tried these below, no avail.

https://github.com/automattic/socket.io/issues/1618

sending message specific id in socket.io 1.0

socket.io: not able send message particular socket using socket.id

backend:

users.foreach(function(subdoc){   console.log('>> notifyonline: iterating user...')   console.log(subdoc);    // every socket, send out emit.   (var j = 0, arr = subdoc.socketid.length; j < arr; j++ ) {     console.log('>> notfiyonline: sending out thoughts clients...');     console.log('>> emitting' + subdoc.socketid[j] + 'is type ' + typeof subdoc.socketid[j] );      // these don't seem     io.sockets.to(subdoc.socketid[j]).emit('notification:new', packet);     io.to(subdoc.socketid[j]).emit('notification:new', packet);    }; // end - each socket }); // end - foreach user 

frontend:

  // listens users followed online   socketfactory.on('notification:new', function (data) {     console.log('>> worldctrl: received live notification');     console.log(data);     $scope.$applyasync(function() {       $scope.rootuser.notifications.push(data);     });   }); // end - socketfactory 

edit

@jfriend00: data structure each user in users below. haven't put in code clear old socketid, of them inactive. it's result of mongoose query:

// mongoose query: model_onlineuser.find({ 'user._id' : { $in: followers }}, function (err, users) {    // notify users (backend code above) }); // end - find  // data structure: user in users [{ _id: 553b49db2242347514c654a9,   user:     { _id: '5503530ed3e910505be02cde',      displayname: 'some dudes name',      photo: 'some photo url' },   __v: 28,   followers:     [ '5525d19a5fb4ee095072c4ad',      '5525587a04f79c6e4d65015d',      '55067b0638d1c47238ebabbb' ],   socketid:     [ '2k1_8wq1jzmujlx3aaaf',      'xjqixhgirb5hyxcoaaad',      '7fdqv_dbp3fctillaaaf' ] }] 

edit 2

new: after user login through passport.js (facebook auth), redirect causes socket disconnect, socket.id becomes invalid... problem is not re-establishing connection ... forcenew : true.

solved:

problem 1: failure reconnect.

on disconnect (after passport login authentication), socket.io didn't re-establish connection socketid had in database became obsolete. solved adding client io.on('connect'):

{ 'forcenew' : true } 

problem 2: local testing environments

my testing procedures required sending messages users on other computers. testing on 2 separate local servers, trying emit each other's local host. when moved our testing single server, sockets started working expected.


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -