我正在尝试将代码从Pubnub迁移到Pusher。我们在Pubnub中有以下代码,我想将其迁移到pusher。
在下面的代码中,我们在addlistener中具有消息,状态和状态。我们如何使用Pusher实现相同的功能?
我已经看到在pusher中有bind方法,而且我也看到了针对状态通道的pusher事件,例如subscription_succeeded,member_added和member_removed方法。如何为以下代码编写消息和状态的推送代码
var _agile_lc_pubnub = {
pubKey : "xxxxxxxxxxxxxxxxxxxxxxxx",
subscriberKey : "xxxxxxxxxxxxxxxxxxxx",
init : function(){
// CREATE A PUBNUB OBJECT
Pubnub = new PubNub({ 'publishKey' : this.pubKey,
'subscribeKey' : this.subscriberKey,
ssl : true,
origin : 'pubsub.pubnub.com',
uuid: myUUID,
presenceTimeout: 25,
heartbeatInterval: 20
});
},
subscribe : function(channelID) {
if(!channelID)
return;
__agile_lc_config_prevSender = "user";
__agile_lc_config_agentName = "Support";
Pubnub.addListener({
message: function(m) {
console.log(m);
}
},
presence: function(presenceEvent) {
console.log(presenceEvent);
// handle presence
},
status:function(status){
console.log("Status Change "+status);
}
});
}
};