From ff66c356cabbcec9a9a68017b96e9edb8e4aae93 Mon Sep 17 00:00:00 2001 From: 648540858 <648540858@qq.com> Date: Fri, 10 Dec 2021 11:08:04 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=90=AF=E5=8A=A8=E5=90=8E?= =?UTF-8?q?=E6=B8=85=E7=90=86=E8=BF=87=E6=9C=9F=E4=BF=A1=E6=81=AF=E7=9A=84?= =?UTF-8?q?=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../zlm/event/ZLMKeepliveTimeoutListener.java | 2 +- .../zlm/event/ZLMOfflineEventListener.java | 6 +- .../zlm/event/ZLMOnlineEventListener.java | 6 +- .../service/impl/MediaServerServiceImpl.java | 1 - .../service/impl/StreamPushServiceImpl.java | 88 +++++++++++-------- 5 files changed, 56 insertions(+), 47 deletions(-) diff --git a/src/main/java/com/genersoft/iot/vmp/media/zlm/event/ZLMKeepliveTimeoutListener.java b/src/main/java/com/genersoft/iot/vmp/media/zlm/event/ZLMKeepliveTimeoutListener.java index 6b88ec9a..c2ae319f 100644 --- a/src/main/java/com/genersoft/iot/vmp/media/zlm/event/ZLMKeepliveTimeoutListener.java +++ b/src/main/java/com/genersoft/iot/vmp/media/zlm/event/ZLMKeepliveTimeoutListener.java @@ -30,7 +30,7 @@ public class ZLMKeepliveTimeoutListener extends KeyExpirationEventMessageListene public ZLMKeepliveTimeoutListener(RedisMessageListenerContainer listenerContainer) { super(listenerContainer); // 配置springboot默认Config为空,即不让应用去修改redis的默认配置,因为Redis服务出于安全会禁用CONFIG命令给远程用户使用 - setKeyspaceNotificationsConfigParameter(""); +// setKeyspaceNotificationsConfigParameter(""); } /** diff --git a/src/main/java/com/genersoft/iot/vmp/media/zlm/event/ZLMOfflineEventListener.java b/src/main/java/com/genersoft/iot/vmp/media/zlm/event/ZLMOfflineEventListener.java index b7135527..a8b0e43b 100644 --- a/src/main/java/com/genersoft/iot/vmp/media/zlm/event/ZLMOfflineEventListener.java +++ b/src/main/java/com/genersoft/iot/vmp/media/zlm/event/ZLMOfflineEventListener.java @@ -31,10 +31,8 @@ public class ZLMOfflineEventListener implements ApplicationListener pushList = getPushList(mediaServerId); + Map pushItemMap = new HashMap<>(); + // redis记录 + List streamInfoPushList = redisCatchStorage.getStreams(mediaServerId, "PUSH"); + Map streamInfoPushItemMap = new HashMap<>(); if (pushList.size() > 0) { - Map pushItemMap = new HashMap<>(); for (StreamPushItem streamPushItem : pushList) { pushItemMap.put(streamPushItem.getApp() + streamPushItem.getStream(), streamPushItem); } - zlmresTfulUtils.getMediaList(mediaServerItem, (mediaList ->{ - if (mediaList == null) return; - String dataStr = mediaList.getString("data"); - - Integer code = mediaList.getInteger("code"); - List streamPushItems = null; - if (code == 0 ) { - if (dataStr != null) { - streamPushItems = handleJSON(dataStr, mediaServerItem); - } - } - - if (streamPushItems != null) { - for (StreamPushItem streamPushItem : streamPushItems) { - pushItemMap.remove(streamPushItem.getApp() + streamPushItem.getStream()); - } - } - Collection offlinePushItems = pushItemMap.values(); - if (offlinePushItems.size() > 0) { - String type = "PUSH"; - streamPushMapper.delAll(new ArrayList<>(offlinePushItems)); - for (StreamPushItem offlinePushItem : offlinePushItems) { - JSONObject jsonObject = new JSONObject(); - jsonObject.put("serverId", userSetup.getServerId()); - jsonObject.put("app", offlinePushItem.getApp()); - jsonObject.put("stream", offlinePushItem.getStream()); - jsonObject.put("register", false); - jsonObject.put("mediaServerId", mediaServerId); - redisCatchStorage.sendStreamChangeMsg(type, jsonObject); - // 移除redis内流的信息 - redisCatchStorage.removeStream(mediaServerItem.getId(), "PUSH", offlinePushItem.getApp(), offlinePushItem.getStream()); - } - } - })); } + if (streamInfoPushList.size() > 0) { + for (StreamInfo streamInfo : streamInfoPushList) { + streamInfoPushItemMap.put(streamInfo.getApp() + streamInfo.getStreamId(), streamInfo); + } + } + zlmresTfulUtils.getMediaList(mediaServerItem, (mediaList ->{ + if (mediaList == null) return; + String dataStr = mediaList.getString("data"); + + Integer code = mediaList.getInteger("code"); + List streamPushItems = null; + if (code == 0 ) { + if (dataStr != null) { + streamPushItems = handleJSON(dataStr, mediaServerItem); + } + } + + if (streamPushItems != null) { + for (StreamPushItem streamPushItem : streamPushItems) { + pushItemMap.remove(streamPushItem.getApp() + streamPushItem.getStream()); + streamInfoPushItemMap.remove(streamPushItem.getApp() + streamPushItem.getStream()); + } + } + Collection offlinePushItems = pushItemMap.values(); + if (offlinePushItems.size() > 0) { + String type = "PUSH"; + streamPushMapper.delAll(new ArrayList<>(offlinePushItems)); + } + Collection offlineStreamInfoItems = streamInfoPushItemMap.values(); + if (offlineStreamInfoItems.size() > 0) { + String type = "PUSH"; + for (StreamInfo offlineStreamInfoItem : offlineStreamInfoItems) { + JSONObject jsonObject = new JSONObject(); + jsonObject.put("serverId", userSetup.getServerId()); + jsonObject.put("app", offlineStreamInfoItem.getApp()); + jsonObject.put("stream", offlineStreamInfoItem.getStreamId()); + jsonObject.put("register", false); + jsonObject.put("mediaServerId", mediaServerId); + redisCatchStorage.sendStreamChangeMsg(type, jsonObject); + // 移除redis内流的信息 + redisCatchStorage.removeStream(mediaServerItem.getId(), "PUSH", offlineStreamInfoItem.getApp(), offlineStreamInfoItem.getStreamId()); + } + } + })); } @Override @@ -211,6 +225,8 @@ public class StreamPushServiceImpl implements IStreamPushService { List streamInfoList = redisCatchStorage.getStreams(mediaServerId, type); if (streamInfoList.size() > 0) { for (StreamInfo streamInfo : streamInfoList) { + // 移除redis内流的信息 + redisCatchStorage.removeStream(mediaServerId, type, streamInfo.getApp(), streamInfo.getStreamId()); JSONObject jsonObject = new JSONObject(); jsonObject.put("serverId", userSetup.getServerId()); jsonObject.put("app", streamInfo.getApp()); @@ -218,8 +234,6 @@ public class StreamPushServiceImpl implements IStreamPushService { jsonObject.put("register", false); jsonObject.put("mediaServerId", mediaServerId); redisCatchStorage.sendStreamChangeMsg(type, jsonObject); - // 移除redis内流的信息 - redisCatchStorage.removeStream(mediaServerId, type, streamInfo.getApp(), streamInfo.getStreamId()); } } }