|
@@ -4,7 +4,7 @@ import { VUE_APP_WK_SERVER_SOCKET_FOR_AUDIO } from "@/constants/constants";
|
|
|
|
|
|
let ws;
|
|
|
let shouldReconnect = true;
|
|
|
-let heartbeatId = null;
|
|
|
+let heartbeatIds = [];
|
|
|
const RECONNECT_INTERVAL = 3000;
|
|
|
const HEARTBEAT_INTERVAL = 50 * 1000;
|
|
|
let reconnectNumber = 0;
|
|
@@ -25,7 +25,10 @@ export function openWS({ examRecordDataId }) {
|
|
|
|
|
|
ws.onclose = () => {
|
|
|
console.log("ws close by server");
|
|
|
- clearInterval(heartbeatId);
|
|
|
+ for (const heartbeatId of heartbeatIds) {
|
|
|
+ clearInterval(heartbeatId);
|
|
|
+ }
|
|
|
+ heartbeatIds = [];
|
|
|
if (shouldReconnect) {
|
|
|
console.log("close -> reconnect");
|
|
|
setTimeout(() => {
|
|
@@ -82,13 +85,15 @@ export function openWS({ examRecordDataId }) {
|
|
|
}
|
|
|
|
|
|
function heartbeat() {
|
|
|
- heartbeatId = setInterval(() => {
|
|
|
+ const heartbeatId = setInterval(() => {
|
|
|
ws.send(
|
|
|
JSON.stringify({
|
|
|
eventType: "HEARTBEAT",
|
|
|
})
|
|
|
);
|
|
|
}, HEARTBEAT_INTERVAL);
|
|
|
+
|
|
|
+ heartbeatIds.push(heartbeatId);
|
|
|
}
|
|
|
|
|
|
export function closeWsWithoutReconnect() {
|