|  |  | 
 |  |  | 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.ApplicationListener; | 
 |  |  | import org.springframework.context.event.EventListener; | 
 |  |  | import org.springframework.scheduling.annotation.Async; | 
 |  |  | import org.springframework.stereotype.Component; | 
 |  |  |  | 
 |  |  | import java.text.SimpleDateFormat; | 
 |  |  |  | 
 |  |  | /** | 
 |  |  |  * @description: 在线事件监听器,监听到离线后,修改设备离在线状态。 设备在线有两个来源: | 
 |  |  | 
 |  |  |    @Autowired | 
 |  |  |    private IMediaServerService mediaServerService; | 
 |  |  |  | 
 |  |  |    private SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); | 
 |  |  |    @Autowired | 
 |  |  |    private IPlayService playService; | 
 |  |  |  | 
 |  |  |    @Async | 
 |  |  |    @Async("taskExecutor") | 
 |  |  |    @EventListener | 
 |  |  |    public void onApplicationEvent(ZLMOnlineEvent event) { | 
 |  |  |  | 
 |  |  |       logger.info("ZLM上线事件触发,ID:" + event.getMediaServerId()); | 
 |  |  |       logger.info("[ZLM] 上线 ID:" + event.getMediaServerId()); | 
 |  |  |       streamPushService.zlmServerOnline(event.getMediaServerId()); | 
 |  |  |       streamProxyService.zlmServerOnline(event.getMediaServerId()); | 
 |  |  |  | 
 |  |  |       playService.zlmServerOnline(event.getMediaServerId()); | 
 |  |  |    } | 
 |  |  |  | 
 |  |  |    @Async | 
 |  |  |    @Async("taskExecutor") | 
 |  |  |    @EventListener | 
 |  |  |    public void onApplicationEvent(ZLMOfflineEvent event) { | 
 |  |  |  | 
 |  |  |       logger.info("ZLM离线事件触发,ID:" + event.getMediaServerId()); | 
 |  |  |       logger.info("[ZLM] 离线,ID:" + event.getMediaServerId()); | 
 |  |  |       // 处理ZLM离线 | 
 |  |  |       mediaServerService.zlmServerOffline(event.getMediaServerId()); | 
 |  |  |       streamProxyService.zlmServerOffline(event.getMediaServerId()); | 
 |  |  |       streamPushService.zlmServerOffline(event.getMediaServerId()); | 
 |  |  |       // TODO 处理对国标的影响 | 
 |  |  |       playService.zlmServerOffline(event.getMediaServerId()); | 
 |  |  |    } | 
 |  |  | } |