websocket心跳函数

2021-12-24  本文已影响0人  Feng_Du

调用
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);
}
}

上一篇下一篇

猜你喜欢

热点阅读