Merge branch 'refs/heads/master' into dev
This commit is contained in:
commit
f4124eb913
@ -5,7 +5,6 @@ import { generateUUID } from "ant-design-vue/lib/vc-select/util";
|
|||||||
|
|
||||||
let eventSource = null;
|
let eventSource = null;
|
||||||
let timer = null;
|
let timer = null;
|
||||||
let lastHeartbeat = new Date().getTime();
|
|
||||||
const uuid = generateUUID();
|
const uuid = generateUUID();
|
||||||
|
|
||||||
const throttledConnectSSE = _.throttle((username) => {
|
const throttledConnectSSE = _.throttle((username) => {
|
||||||
@ -32,16 +31,11 @@ function connectToSSE(username) {
|
|||||||
|
|
||||||
eventSource.addEventListener('message', handleMessage);
|
eventSource.addEventListener('message', handleMessage);
|
||||||
eventSource.addEventListener('error', handleError.bind(null, username));
|
eventSource.addEventListener('error', handleError.bind(null, username));
|
||||||
startHeartbeatCheck(username);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleMessage(event) {
|
function handleMessage(event) {
|
||||||
if (event.data === 'h') {
|
const msg = JSON.parse(event.data);
|
||||||
lastHeartbeat = new Date().getTime();
|
onMessage(msg);
|
||||||
} else {
|
|
||||||
const msg = JSON.parse(event.data);
|
|
||||||
onMessage(msg);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleError(username) {
|
function handleError(username) {
|
||||||
@ -55,18 +49,6 @@ function clearExistingTimer() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function startHeartbeatCheck(username) {
|
|
||||||
clearExistingTimer();
|
|
||||||
timer = setInterval(() => {
|
|
||||||
if (eventSource.readyState === 1 && new Date().getTime() - lastHeartbeat > 5000) {
|
|
||||||
eventSource.close();
|
|
||||||
}
|
|
||||||
if (eventSource.readyState === 2) {
|
|
||||||
throttledConnectSSE(username);
|
|
||||||
}
|
|
||||||
}, 3000);
|
|
||||||
}
|
|
||||||
|
|
||||||
function onMessage(msg) {
|
function onMessage(msg) {
|
||||||
const { url, body } = msg;
|
const { url, body } = msg;
|
||||||
const eventMapping = {
|
const eventMapping = {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user