liurunyu
2025-02-11 7b119de9ee015934f8b001b6038e282522993c80
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package com.dy.pipIrrRemote.largeScreen;
 
/**
 * @Author: liurunyu
 * @Date: 2025/2/11 8:37
 * @Description
 */
 
import com.alibaba.fastjson2.JSON;
import com.dy.common.util.DateTime;
import com.dy.common.webUtil.WebSocketMessage;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
 
@Component
public class WebSocketHeartBeat {
 
    // 设置定时十秒一次
    @Scheduled(cron = "0/10 * * * * ?")
    public void WsHeartBeat() throws Exception {
        WebSocketServer.sendAllMessage(getHeartBeatMessage());
    }
 
    public static String getHeartBeatMessage() {
        WebSocketMessage vo = new WebSocketMessage() ;
        vo.type = WebSocketMessage.TYPE_HEARTBEAT ;
        vo.code = "" ;//心跳数据编码就是空字符串
        vo.content = DateTime.yyyy_MM_dd_HH_mm_ss() ;
        return JSON.toJSONString(vo) ;
    }
 
}