From f84eebdb75a6af1894b057b0255b01992bdd4f03 Mon Sep 17 00:00:00 2001 From: 648540858 <648540858@qq.com> Date: Wed, 27 Jul 2022 16:16:12 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E9=83=A8=E5=88=86hook?= =?UTF-8?q?=E8=AE=A2=E9=98=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../iot/vmp/media/zlm/ZLMHttpHookListener.java | 8 +++++++- .../com/genersoft/iot/vmp/media/zlm/ZLMRunner.java | 11 +---------- .../iot/vmp/service/impl/MediaServerServiceImpl.java | 5 +++-- .../impl/RedisPushStreamStatusMsgListener.java | 6 +++--- 4 files changed, 14 insertions(+), 16 deletions(-) diff --git a/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java b/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java index 11dd8179..b1f0fecb 100644 --- a/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java +++ b/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java @@ -108,6 +108,7 @@ public class ZLMHttpHookListener { subscribe.response(null, json); } } + mediaServerService.updateMediaServerKeepalive(mediaServerId, json.getJSONObject("data")); JSONObject ret = new JSONObject(); ret.put("code", 0); @@ -619,10 +620,15 @@ public class ZLMHttpHookListener { subscribe.response(null, jsonObject); } } + + ZLMServerConfig zlmServerConfig = JSONObject.toJavaObject(jsonObject, ZLMServerConfig.class); + if (zlmServerConfig !=null ) { + mediaServerService.zlmServerOnline(zlmServerConfig); + } JSONObject ret = new JSONObject(); ret.put("code", 0); ret.put("msg", "success"); - return new ResponseEntity(ret.toString(),HttpStatus.OK); + return new ResponseEntity<>(ret.toString(),HttpStatus.OK); } private Map urlParamToMap(String params) { diff --git a/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRunner.java b/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRunner.java index 138af7ae..1bfb7300 100644 --- a/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRunner.java +++ b/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRunner.java @@ -75,19 +75,9 @@ public class ZLMRunner implements CommandLineRunner { if (startGetMedia != null) { startGetMedia.remove(zlmServerConfig.getGeneralMediaServerId()); } - mediaServerService.zlmServerOnline(zlmServerConfig); } }); - // 订阅 zlm保活事件, 当zlm离线时做业务的处理 - hookSubscribe.addSubscribe(ZLMHttpHookSubscribe.HookType.on_server_keepalive,new JSONObject(), - (MediaServerItem mediaServerItem, JSONObject response)->{ - String mediaServerId = response.getString("mediaServerId"); - if (mediaServerId !=null ) { - mediaServerService.updateMediaServerKeepalive(mediaServerId, response.getJSONObject("data")); - } - }); - // 获取zlm信息 logger.info("[zlm] 等待默认zlm中..."); @@ -113,6 +103,7 @@ public class ZLMRunner implements CommandLineRunner { } startGetMedia = null; } + hookSubscribe.removeSubscribe(ZLMHttpHookSubscribe.HookType.on_server_started, new JSONObject()); // TODO 清理数据库中与redis不匹配的zlm }, 60 * 1000 ); } diff --git a/src/main/java/com/genersoft/iot/vmp/service/impl/MediaServerServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/service/impl/MediaServerServiceImpl.java index a07a9f3c..bba86a7f 100644 --- a/src/main/java/com/genersoft/iot/vmp/service/impl/MediaServerServiceImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/service/impl/MediaServerServiceImpl.java @@ -355,14 +355,15 @@ public class MediaServerServiceImpl implements IMediaServerService { */ @Override public void zlmServerOnline(ZLMServerConfig zlmServerConfig) { - logger.info("[ZLM] 正在连接 : {} -> {}:{}", - zlmServerConfig.getGeneralMediaServerId(), zlmServerConfig.getIp(), zlmServerConfig.getHttpPort()); MediaServerItem serverItem = mediaServerMapper.queryOne(zlmServerConfig.getGeneralMediaServerId()); if (serverItem == null) { logger.warn("[未注册的zlm] 拒接接入:{}来自{}:{}", zlmServerConfig.getGeneralMediaServerId(), zlmServerConfig.getIp(),zlmServerConfig.getHttpPort() ); logger.warn("请检查ZLM的配置是否与WVP的一致"); return; + }else { + logger.info("[ZLM] 正在连接 : {} -> {}:{}", + zlmServerConfig.getGeneralMediaServerId(), zlmServerConfig.getIp(), zlmServerConfig.getHttpPort()); } serverItem.setHookAliveInterval(zlmServerConfig.getHookAliveInterval()); if (serverItem.getHttpPort() == 0) { diff --git a/src/main/java/com/genersoft/iot/vmp/service/impl/RedisPushStreamStatusMsgListener.java b/src/main/java/com/genersoft/iot/vmp/service/impl/RedisPushStreamStatusMsgListener.java index 86067024..50e894a6 100644 --- a/src/main/java/com/genersoft/iot/vmp/service/impl/RedisPushStreamStatusMsgListener.java +++ b/src/main/java/com/genersoft/iot/vmp/service/impl/RedisPushStreamStatusMsgListener.java @@ -66,7 +66,7 @@ public class RedisPushStreamStatusMsgListener implements MessageListener, Applic @Override public void onMessage(Message message, byte[] bytes) { // TODO 增加队列 - logger.warn("[REDIS 消息-推流设备状态变化]: {}", new String(message.getBody())); + logger.warn("[REDIS消息-推流设备状态变化]: {}", new String(message.getBody())); taskQueue.offer(message); if (!taskQueueHandlerRun) { @@ -76,7 +76,7 @@ public class RedisPushStreamStatusMsgListener implements MessageListener, Applic Message msg = taskQueue.poll(); PushStreamStatusChangeFromRedisDto statusChangeFromPushStream = JSON.parseObject(msg.getBody(), PushStreamStatusChangeFromRedisDto.class); if (statusChangeFromPushStream == null) { - logger.warn("[REDIS 消息]推流设备状态变化消息解析失败"); + logger.warn("[REDIS消息]推流设备状态变化消息解析失败"); return; } // 取消定时任务 @@ -106,7 +106,7 @@ public class RedisPushStreamStatusMsgListener implements MessageListener, Applic // 启动时设置所有推流通道离线,发起查询请求 redisCatchStorage.sendStreamPushRequestedMsgForStatus(); dynamicTask.startDelay(VideoManagerConstants.VM_MSG_GET_ALL_ONLINE_REQUESTED, ()->{ - logger.info("[REDIS 消息]未收到redis回复推流设备状态,执行推流设备离线"); + logger.info("[REDIS消息]未收到redis回复推流设备状态,执行推流设备离线"); // 五秒收不到请求就设置通道离线,然后通知上级离线 streamPushService.allStreamOffline(); }, 5000);