我想知道我的用户何时出现连接错误或连接中断。我读过很多书说这是可能的,但我无处可去,我开始认为这可能是我正在使用的https://github.com/beyondcode/laravel-websockets等第三方的问题,有没有人对此有任何问题?
以下根本不产生任何日志。
window.Echo.connector.pusher.bind('reconnect', (channel, data) => {
console.log('RE-CONNECTED');
});
window.Echo.connector.pusher.bind('reconnecting', (channel, data) => {
console.log('re-connecting...');
});
window.Echo.connector.pusher.bind('reconnect_error', (channel, data) => {
console.log('reconnection error!');
});
window.Echo.connector.pusher.bind('reconnect_attempt', (channel, data) => {
console.log('re-connecting...');
});
window.Echo.connector.pusher.bind('connect_error', (channel, data) => {
console.log('connect error...');
});
window.Echo.connector.pusher.bind('error', (channel, data) => {
console.log('error...');
});
window.Echo.connector.pusher.bind_global((channel, data) => {
console.log(channel, data);
});
如果我使用类似这样的建议
window.Echo.connector.socket.on('connect_error', function(){
console.log('connected', window.Echo.socketId());
});
window.Echo.connector.socket.on('connect', function(){
console.log('connected', window.Echo.socketId());
});
window.Echo.connector.socket.on('disconnect', function(){
console.log('disconnected');
});
window.Echo.connector.socket.on('reconnecting', function(attemptNumber){
console.log('reconnecting', attemptNumber);
});
我明白了Uncaught TypeError: Cannot read property 'on' of undefined