參考Soket.IO官方文檔:https://socket.io/docs/client-api/,客戶端內置事件一共有10種,測試代碼以下:api
socket.on('connect', function(data){
onlineFlag = true;
console.log(data + ' - connect');
});
socket.on('connect_error', function(data){
console.log(data + ' - connect_error');
});
socket.on('connect_timeout', function(data){
console.log(data + ' - connect_timeout');
});
socket.on('error', function(data){
console.log(data + ' - error');
});
socket.on('disconnect', function(data){
onlineFlag = false;
console.log(data + ' - disconnect');
});
socket.on('reconnect', function(data){
console.log(data + ' - reconnect');
});
socket.on('reconnect_attempt', function(data){
console.log(data + ' - reconnect_attempt');
});
socket.on('reconnecting', function(data){
console.log(data + ' - reconnecting');
});
socket.on('reconnect_error', function(data){
console.log(data + ' - reconnect_error');
});
socket.on('reconnect_failed', function(data){
console.log(data + ' - reconnect_failed');
});
socket.on('ping', function(data){
console.log(data + ' - ping');
});
socket.on('pong', function(data){
console.log(data + ' - pong');
});socket
流程圖測試