Laravel Echo错误处理(使用Pusher)

clo*_*986 2 laravel pusher laravel-5 laravel-echo

是否有关于此主题的指南?我已经阅读了pusher文档,并且使用类似于以下代码的方法来管理断开连接似乎相当容易:

pusher.connection.bind('disconnected', function() {
    // Do Something
})
Run Code Online (Sandbox Code Playgroud)

我不确定如何将其与Echo集成,因为我的代码如下:

window.EchoConnection = new Echo({
    broadcaster: 'pusher',
    key: window.EchoKey,
    cluster: 'eu',
    encrypted: true
});
Run Code Online (Sandbox Code Playgroud)

编辑:为了检查断开连接事件,请window.EchoConnection.connector.pusher.connection.disconnect()在控制台中运行

cre*_*re8 5

我还没有尝试过,但是根据github回购,这应该适用于pusher:

window.EchoConnection是一个回声对象。使用echo创建新的pusher实例时,该connector变量将为PusherConnector

if (this.options.broadcaster == 'pusher') {
   this.connector = new PusherConnector(this.options);
}
Run Code Online (Sandbox Code Playgroud)

在此变量上,您可以找到创建的Pusher实例:

connect(): void {
    this.pusher = new Pusher(this.options.key, this.options);
}
Run Code Online (Sandbox Code Playgroud)

将事件绑定到推送程序的理论解决方案是:

window.EchoConnection.connector.pusher.connection.bind('disconnected', function() {
    // Do Something
})
Run Code Online (Sandbox Code Playgroud)