0

I'm considering moving from my own ejabberd servers (XMPP) to Pusher or Pubnub (Pusher preferably). And I was wondering what the best way to re-create the roster functionality using this technology is.

Each user has a variable number of people to which's presence he is subscribed and with whom he can chat.

I can think of two ways of doing that but I don't know which is the best.

I can either subscribe to the presence of each user individually or put all users in one room and listen to all presence.

However if the number of users reaches thousands I can imagine that it would not be a viable solution.

What do you think ?

Rakan Nimer
  • 574
  • 5
  • 9

1 Answers1

0
(function(){
    var p = PUBNUB.init({
       'subscribe_key':'foo',
       'publish_key':'bar'
    })
    var do_leave = function(message,env,channel){
        //leave code here

    };
    var do_join = function(message,env,channel){
       //join code here
    };
    var do_timeout = function(message,env,channel){
       //timeout code here

    };
    p.subscribe({
        channel    : "hello_world",                        // CONNECT TO THIS CHANNEL.
        message    : function( message, env, channel ) {}, // RECEIVED A MESSAGE.
        presence   : function( message, env, channel ) {
             if( message.action === 'leave' ){ // handle leave
                 do_leave.apply(this,arguments);
             }
             else if (message.action === 'join'){ // handle join
                 do_join.apply(this,arguments);

             }
             else{//timeout
                 do_timeout.apply(this,arguments);
             }
        }

   });

   // to get the current state use the here_now request
   p.here_now({
    channel  : 'hello_world',
    callback : function (message) { console.log(message) }
   });
})();

Full disclosure I'm a PubNub employee. To your question of 'is doing thousands scalable'? We've done well over thousands of people per channel so I wouldn't worry about that for now.

Jordan Shaw
  • 539
  • 4
  • 9
  • How about pricing ? Each person going online would be sending presence (so one message to thousands of users.) My quota would be over just by sending presence data. – Rakan Nimer Sep 12 '13 at 10:11
  • Jordan, here_now will return those thousands of uuid's as well, which can be a non-optimal when all you need is a handful of them – davidkomer Sep 13 '13 at 12:49
  • 1
    Rakan, presence requests are not counted in terms of pricing. If you have a special use case you can contact us. David, that's a good point. If you want to start subsetting users you can either do that through sub channels or within the application logic. So you'll have a global join/leave you could run here_now only within the sub channels to prevent returning large datasets. – Jordan Shaw Sep 30 '13 at 21:39