648540858
2022-05-11 f6893cf95b15531dfc45950fea7e780e045ba2ae
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package com.genersoft.iot.vmp.media.zlm.event;
 
import com.genersoft.iot.vmp.service.IMediaServerService;
import com.genersoft.iot.vmp.service.IPlayService;
import com.genersoft.iot.vmp.service.IStreamProxyService;
import com.genersoft.iot.vmp.service.IStreamPushService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
 
 
/**
 * @description: 在线事件监听器,监听到离线后,修改设备离在线状态。 设备在线有两个来源:
 *               1、设备主动注销,发送注销指令
 *               2、设备未知原因离线,心跳超时
 * @author: swwheihei
 * @date: 2020年5月6日 下午1:51:23
 */
@Component
public class ZLMStatusEventListener {
    
    private final static Logger logger = LoggerFactory.getLogger(ZLMStatusEventListener.class);
 
    @Autowired
    private IStreamPushService streamPushService;
 
    @Autowired
    private IStreamProxyService streamProxyService;
 
    @Autowired
    private IMediaServerService mediaServerService;
 
    @Autowired
    private IPlayService playService;
 
    @Async
    @EventListener
    public void onApplicationEvent(ZLMOnlineEvent event) {
 
        logger.info("【ZLM上线】ID:" + event.getMediaServerId());
        streamPushService.zlmServerOnline(event.getMediaServerId());
        streamProxyService.zlmServerOnline(event.getMediaServerId());
 
    }
 
    @Async
    @EventListener
    public void onApplicationEvent(ZLMOfflineEvent event) {
 
        logger.info("ZLM离线事件触发,ID:" + event.getMediaServerId());
        // 处理ZLM离线
        mediaServerService.zlmServerOffline(event.getMediaServerId());
        streamProxyService.zlmServerOffline(event.getMediaServerId());
        streamPushService.zlmServerOffline(event.getMediaServerId());
        playService.zlmServerOffline(event.getMediaServerId());
    }
}