websocket代码提交
This commit is contained in:
@@ -20,7 +20,6 @@ export default class SocketService {
|
|||||||
// 重新连接尝试的次数
|
// 重新连接尝试的次数
|
||||||
connectRetryCount = 0;
|
connectRetryCount = 0;
|
||||||
work:any;
|
work:any;
|
||||||
heartbeatTimer;
|
|
||||||
lastActivityTime= 0; // 上次活动时间戳
|
lastActivityTime= 0; // 上次活动时间戳
|
||||||
lastResponseHeartTime = Date.now();//最后一次收到心跳回复时间
|
lastResponseHeartTime = Date.now();//最后一次收到心跳回复时间
|
||||||
|
|
||||||
@@ -105,9 +104,11 @@ export default class SocketService {
|
|||||||
|
|
||||||
|
|
||||||
startHeartbeat() {
|
startHeartbeat() {
|
||||||
|
this.lastResponseHeartTime = Date.now();
|
||||||
const _this = this
|
const _this = this
|
||||||
const url = window.URL.createObjectURL(new Blob(['(function(e){setInterval(function(){this.postMessage(null)},9000)})()']));
|
const url = window.URL.createObjectURL(new Blob(['(function(e){setInterval(function(){this.postMessage(null)},9000)})()']));
|
||||||
this.work = new Worker(url)
|
this.workerBlobUrl = url; // 存储临时的Blob URL
|
||||||
|
this.work = new Worker(url);
|
||||||
this.work.onmessage = function(e){
|
this.work.onmessage = function(e){
|
||||||
//判断多久没收到心跳响应
|
//判断多久没收到心跳响应
|
||||||
|
|
||||||
@@ -133,10 +134,13 @@ export default class SocketService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
clearHeartbeat() {
|
clearHeartbeat() {
|
||||||
this.work.terminate();
|
if (this.work) {
|
||||||
if (this.heartbeatTimer) {
|
this.work.terminate();
|
||||||
clearInterval(this.heartbeatTimer);
|
this.work = null;
|
||||||
this.heartbeatTimer = null;
|
}
|
||||||
|
if (this.workerBlobUrl) {
|
||||||
|
window.URL.revokeObjectURL(this.workerBlobUrl); // 释放临时的Blob URL
|
||||||
|
this.workerBlobUrl = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user