feat: 信令跟踪保活续期

This commit is contained in:
TsMask
2024-10-15 15:14:38 +08:00
parent 6e11d2b16a
commit d77c4e43d4

View File

@@ -18,6 +18,7 @@ import {
packetStart, packetStart,
packetStop, packetStop,
packetFilter, packetFilter,
packetKeep,
} from '@/api/trace/packet'; } from '@/api/trace/packet';
const ws = new WS(); const ws = new WS();
const { t } = useI18n(); const { t } = useI18n();
@@ -29,6 +30,8 @@ type StateType = {
devices: { id: string; label: string; children: any[] }[]; devices: { id: string; label: string; children: any[] }[];
/**初始化 */ /**初始化 */
initialized: boolean; initialized: boolean;
/**保活调度器 */
keepTimer: any;
/**任务 */ /**任务 */
task: { task: {
taskNo: string; taskNo: string;
@@ -64,6 +67,7 @@ type StateType = {
const state = reactive<StateType>({ const state = reactive<StateType>({
devices: [], devices: [],
initialized: false, initialized: false,
keepTimer: null,
task: { task: {
taskNo: 'laYlTbq', taskNo: 'laYlTbq',
device: '192.168.5.58', device: '192.168.5.58',
@@ -274,6 +278,9 @@ function wsMessage(res: Record<string, any>) {
// 建联时发送请求 // 建联时发送请求
if (!requestId && data.clientId) { if (!requestId && data.clientId) {
state.initialized = true; state.initialized = true;
state.keepTimer = setInterval(() => {
packetKeep(state.task.taskNo, 120);
}, 90 * 1000);
return; return;
} }
@@ -320,7 +327,9 @@ onMounted(() => {
}); });
onBeforeUnmount(() => { onBeforeUnmount(() => {
ws.close(); clearInterval(state.keepTimer);
state.keepTimer = null;
if (ws.state() === WebSocket.OPEN) ws.close();
}); });
</script> </script>