From bef7fb2440093bbf92a2d192ce1f1c4db219b07c Mon Sep 17 00:00:00 2001 From: dengming <dengming@ctfo.com> Date: 星期四, 10 三月 2022 15:08:41 +0800 Subject: [PATCH] 修复关闭按需拉流无效的问题 --- src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookSubscribe.java | 62 ++++++++++++++++++++++++++++--- 1 files changed, 56 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookSubscribe.java b/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookSubscribe.java index 995f916..84b36e3 100644 --- a/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookSubscribe.java +++ b/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookSubscribe.java @@ -1,14 +1,14 @@ package com.genersoft.iot.vmp.media.zlm; import com.alibaba.fastjson.JSONObject; +import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem; import org.springframework.stereotype.Component; -import java.util.HashMap; -import java.util.Map; +import java.util.*; import java.util.concurrent.ConcurrentHashMap; /** - * @Description:閽堝 ZLMediaServer鐨刪ook浜嬩欢璁㈤槄 + * @description:閽堝 ZLMediaServer鐨刪ook浜嬩欢璁㈤槄 * @author: pan * @date: 2020骞�12鏈�2鏃� 21:17:32 */ @@ -27,11 +27,12 @@ on_stream_changed, on_stream_none_reader, on_stream_not_found, - on_server_started + on_server_started, + on_server_keepalive } public interface Event{ - void response(JSONObject response); + void response(MediaServerItem mediaServerItem, JSONObject response); } private Map<HookType, Map<JSONObject, ZLMHttpHookSubscribe.Event>> allSubscribes = new ConcurrentHashMap<>(); @@ -57,14 +58,63 @@ if (result == null) { result = key.getString(s).equals(hookResponse.getString(s)); }else { + if (key.getString(s) == null) { + continue; + } result = result && key.getString(s).equals(hookResponse.getString(s)); } } - if (result) { + if (null != result && result) { event = eventMap.get(key); } } return event; } + + public void removeSubscribe(HookType type, JSONObject hookResponse) { + Map<JSONObject, Event> eventMap = allSubscribes.get(type); + if (eventMap == null) { + return; + } + + Set<Map.Entry<JSONObject, Event>> entries = eventMap.entrySet(); + if (entries.size() > 0) { + for (Map.Entry<JSONObject, Event> entry : entries) { + JSONObject key = entry.getKey(); + Boolean result = null; + for (String s : key.keySet()) { + if (result == null) { + result = key.getString(s).equals(hookResponse.getString(s)); + }else { + if (key.getString(s) == null) continue; + result = result && key.getString(s).equals(hookResponse.getString(s)); + } + } + if (null != result && result){ + entries.remove(entry); + } + } + } + } + + /** + * 鑾峰彇鏌愪釜绫诲瀷鐨勬墍鏈夌殑璁㈤槄 + * @param type + * @return + */ + public List<ZLMHttpHookSubscribe.Event> getSubscribes(HookType type) { + // ZLMHttpHookSubscribe.Event event= null; + Map<JSONObject, Event> eventMap = allSubscribes.get(type); + if (eventMap == null) { + return null; + } + List<ZLMHttpHookSubscribe.Event> result = new ArrayList<>(); + for (JSONObject key : eventMap.keySet()) { + result.add(eventMap.get(key)); + } + return result; + } + + } -- Gitblit v1.8.0