From 21a96ad20fd75e55d03c00af8df8adb039f0c77a Mon Sep 17 00:00:00 2001
From: 648540858 <648540858@qq.com>
Date: 星期二, 20 六月 2023 12:51:06 +0800
Subject: [PATCH] 修复通道刷新

---
 src/main/java/com/genersoft/iot/vmp/service/impl/InviteStreamServiceImpl.java |   35 +++++++++++++++++++++++++++++------
 1 files changed, 29 insertions(+), 6 deletions(-)

diff --git a/src/main/java/com/genersoft/iot/vmp/service/impl/InviteStreamServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/service/impl/InviteStreamServiceImpl.java
index 8b8c839..2fb6816 100644
--- a/src/main/java/com/genersoft/iot/vmp/service/impl/InviteStreamServiceImpl.java
+++ b/src/main/java/com/genersoft/iot/vmp/service/impl/InviteStreamServiceImpl.java
@@ -6,7 +6,7 @@
 import com.genersoft.iot.vmp.common.InviteSessionType;
 import com.genersoft.iot.vmp.common.VideoManagerConstants;
 import com.genersoft.iot.vmp.service.IInviteStreamService;
-import com.genersoft.iot.vmp.service.bean.InviteErrorCallback;
+import com.genersoft.iot.vmp.service.bean.ErrorCallback;
 import com.genersoft.iot.vmp.utils.redis.RedisUtil;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -24,7 +24,7 @@
 
     private final Logger logger = LoggerFactory.getLogger(InviteStreamServiceImpl.class);
 
-    private final Map<String, List<InviteErrorCallback<Object>>> inviteErrorCallbackMap = new ConcurrentHashMap<>();
+    private final Map<String, List<ErrorCallback<Object>>> inviteErrorCallbackMap = new ConcurrentHashMap<>();
 
     @Autowired
     private RedisTemplate<Object, Object> redisTemplate;
@@ -141,9 +141,9 @@
     }
 
     @Override
-    public void once(InviteSessionType type, String deviceId, String channelId, String stream, InviteErrorCallback<Object> callback) {
+    public void once(InviteSessionType type, String deviceId, String channelId, String stream, ErrorCallback<Object> callback) {
         String key = buildKey(type, deviceId, channelId, stream);
-        List<InviteErrorCallback<Object>> callbacks = inviteErrorCallbackMap.get(key);
+        List<ErrorCallback<Object>> callbacks = inviteErrorCallbackMap.get(key);
         if (callbacks == null) {
             callbacks = new CopyOnWriteArrayList<>();
             inviteErrorCallbackMap.put(key, callbacks);
@@ -155,11 +155,11 @@
     @Override
     public void call(InviteSessionType type, String deviceId, String channelId, String stream, int code, String msg, Object data) {
         String key = buildKey(type, deviceId, channelId, stream);
-        List<InviteErrorCallback<Object>> callbacks = inviteErrorCallbackMap.get(key);
+        List<ErrorCallback<Object>> callbacks = inviteErrorCallbackMap.get(key);
         if (callbacks == null) {
             return;
         }
-        for (InviteErrorCallback<Object> callback : callbacks) {
+        for (ErrorCallback<Object> callback : callbacks) {
             callback.run(code, msg, data);
         }
         inviteErrorCallbackMap.remove(key);
@@ -175,4 +175,27 @@
     }
 
 
+    @Override
+    public void clearInviteInfo(String deviceId) {
+        removeInviteInfo(null, deviceId, null, null);
+    }
+
+    @Override
+    public int getStreamInfoCount(String mediaServerId) {
+        int count = 0;
+        String key = VideoManagerConstants.INVITE_PREFIX + "_*_*_*_*";
+        List<Object> scanResult = RedisUtil.scan(redisTemplate, key);
+        if (scanResult.size() == 0) {
+            return 0;
+        }else {
+            for (Object keyObj : scanResult) {
+                String keyStr = (String) keyObj;
+                InviteInfo inviteInfo = (InviteInfo) redisTemplate.opsForValue().get(keyStr);
+                if (inviteInfo != null && inviteInfo.getStreamInfo() != null && inviteInfo.getStreamInfo().getMediaServerId().equals(mediaServerId)) {
+                    count++;
+                }
+            }
+        }
+        return count;
+    }
 }

--
Gitblit v1.8.0