调用
new WebSocket(url).onmessage=()=>{
heartbeat.reset();
}
//心跳
const heartbeat = new function () {
this.timeout = 18000;
this.timeoutObj = null;
this.reset = function () {
clearTimeout(this.timeoutObj);
this.start();
}
this.start = function () {
this.timeoutObj = setTimeout(function () {
ws.send("heartbeat");
this.reset()
}.bind(this), this.timeout);
}
}
网友评论