Pusher WebSocketError - >代码:4200 - 消息:请立即重新连接

时间:2017-03-15 10:33:20

标签: php angularjs pusher

我们使用Pusher作为我们的通知系统,有时会导致问题。

问题是有时连接会自动关闭,并且控制台上会显示以下错误(实际上这是我几周前在控制台上出现的较旧错误):

  

Pusher:错误:   { “类型”: “WebSocketError”, “错误”:{ “类型”: “PusherError”, “数据”:{ “代码”:1006}}}

最近我看到了这个:

  

Pusher:错误:{“type”:“WebSocketError”,“error”:{“type”:“PusherError”,“data”:{“code”:4200,“message”:“请立即重新连接”} }}

这是客户端(JS)代码:

   function initPusher(user) {
      if (pusher) {
          return;
       } else {
            Pusher.logToConsole = false;
            pusher = new Pusher('pusher key', {
                cluster: 'eu',
                encrypted: true
            });

            try {
                var channel = pusher.subscribe(user.user_channel);
                channel.bind('app_event', function(data) {
                    if (data['event_type'] === 'reply-message') {
                        $rootScope.$broadcast('REPLY_RECEIVED', data);
                    } else if (data['event_type'] === 'new-message') {
                        $rootScope.$broadcast('MESSAGE_RECEIVED', data);
                    }
                });
            } catch(err) {
                $state.go('logout');
            }
        }
    }

在登录时调用此函数并刷新每个页面。

虽然我猜这是客户端问题,但我添加了相关的PHP代码,其中API在index.php中实例化:

require_once __DIR__.'/../vendor/pusher/pusher-php-server/lib/Pusher.php';

$options = array(
    'cluster' => 'eu',
    'encrypted' => true
);

$pusher = new Pusher(
    'pusher key',
    'secret',
    'app id,
    $options
);

更多详情

  • 正在使用的后端框架为Silex,前端框架为AngularJS

  • 我们正在使用欧盟Pusher集群,并且在连接仍处于打开状态时工作正常。

  • 我已经看过this链接,但找不到我问题的答案。

0 个答案:

没有答案
相关问题