【发布时间】:2013-07-24 12:04:05
【问题描述】:
我有一个小的 sn-p,即使我只调用一次 subscribe 方法,它也会引发“现有订阅频道”异常。
这可以通过将订阅请求移到“state_change”处理程序之外来避免,但我想知道是什么原因造成的?可能是 Pusher 库中的错误?
<!doctype html>
<html>
<body>
<h1>Pusher subscribe testcase</h1>
<p>Tip: check your console</p>
<script src="https://d3dy5gmtp8yhk7.cloudfront.net/2.1/pusher.min.js"></script>
<script>
var pusher, channel;
pusher = new Pusher('xxxxxxxxxxxxxxxxx');
pusher.connection.bind('state_change', function(change){
if(change.current === 'connected'){
console.log('connected');
channel = pusher.subscribe('test-channel');
channel.bind('pusher:subscription_succeeded', function() {
console.log('subscribed');
});
}
})
</script>
</body>
</html>
这会导致:
connected
subscribed
Pusher : Error : {"type":"WebSocketError","error":{"type":"PusherError","data":{"code":null,"message":"Existing subscription to channel test-channel"}}}
【问题讨论】:
标签: javascript pusher