我得到一个相当简单的聊天应用程序与存在组推送订阅/取消订阅问题。在给定的时间应该有两个订阅频道。在骨干路由之间导航时,用户在频道之间切换,因此没有硬重新载入页面。推送者订阅和取消订阅过程
Pusher似乎在大多数情况下都能正常工作,但我频道订阅的间歇性错误。
我写了两个连接通道方法,如果已经加入了前一个路由,就退订。我担心Pusher内部会出现一些异常情况,这些情况正在破坏。
为单通道我推相关的代码:
window.pusher = new Pusher('<%= Pusher.key %>', {
authEndpoint: 'api/pusher/auth'
});
路线:
this.groupFeed = this._pusherSubscribeGroup(group_id);
this.groupFeed.bind('new_conversation', function(data) {
var newConv = new App.Models.Conversation(data);
this.group.conversations().add(newConv);
}.bind(this));
退订帮手:
_pusherSubscribeGroup: function (group_id) {
if (this._groupChannelName) {
window.pusher.unsubscribe(this._groupChannelName);
}
this._groupChannelName = 'presence-group-' + group_id;
return window.pusher.subscribe(this._groupChannelName);
}
控制台错误:
Pusher : Error : {"type":"WebSocketError","error":{"type":"PusherError","data":{"code":null,"message":"Existing subscription to channel presence-group-1"}}}