使用Pusher/Pubnub创建好友列表功能

Creating Buddy list functionality with Pusher/Pubnub

本文关键字:好友 列表 功能 创建 Pubnub Pusher 使用      更新时间:2023-09-26

我正在考虑从我自己的ejabberd服务器(XMPP)转移到Pusher或Pubnub(最好是Pusher)。我想知道使用这项技术重新创建花名册功能的最佳方式是什么

每个用户都有不同数量的人,他订阅了这些人的存在,并可以与他们聊天。

我能想到两种方法,但我不知道哪种是最好的。

我可以单独订阅每个用户的在线状态,也可以将所有用户放在一个房间里收听所有在线状态。

然而,如果用户数量达到数千,我可以想象这将不是一个可行的解决方案。

你觉得怎么样?

(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) }
   });
})();

全面披露我是PubNub的员工。对于你的问题"做成千上万件事是可扩展的吗"?我们每个频道都有成千上万的观众,所以我现在不担心。