1

in the doc it's written that you can sends event to all connected users by using the following server side code for an update event

function backandCallback(userInput, dbRow, parameters, userProfile)       
{  
  socket.emitAll("items_updated", userInput);  
} 

then in your angular client code, you can listen for this event by doing the following

Backand.on('items_updated', function (data) {
  //Get the 'items' object that have changed
  console.log(data);
});

i'm working with anonymous users, i can't use emitUsers or emitRoles to restrict to only concerned users.

As i don't want all anonymous users to receive all update events but only the ones for the item they are on (stupid to listen for updates you don't care isn't it!), would there be a way to only listen for events on a specific item?

thanks for your help

RAJ
  • 9,697
  • 1
  • 33
  • 63
lanlau
  • 116
  • 7

1 Answers1

4

In fact i've found the solution thanks to Backand brilliant support team (thanks Itay!).

The solution is quite simple, you can play with the event name string !

back to my example, let's say i only want the user listen for changes on the item he is actually viewing (item id is 57 for example), the code then will be:
- on the server code side

function backandCallback(userInput, dbRow, parameters, userProfile)       
{  
  //if the updated item has an id=57 for example, 
  //the event emitted will be "items_updated_57"
  socket.emitAll("item_updated_" + dbRow.id, userInput);  
} 

- on the angular client code

//currentItem id
var itemId=57;    
Backand.on('item_updated_'+ itemId, function (data) {
      //will be triggered when we receive an event named 
      // "item_updated_57"
      console.log(data);
    });
lanlau
  • 116
  • 7