From 82adc0cb23f3ee47322e78889cdaba57e9309000 Mon Sep 17 00:00:00 2001
From: 648540858 <648540858@qq.com>
Date: 星期二, 21 三月 2023 15:55:24 +0800
Subject: [PATCH] 完善语音对讲级联

---
 src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/BroadcastResponseMessageHandler.java |   47 +++++++++++++++++++++++++++++++++++------------
 1 files changed, 35 insertions(+), 12 deletions(-)

diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/BroadcastResponseMessageHandler.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/BroadcastResponseMessageHandler.java
index 0aa152c..4b6bbbc 100644
--- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/BroadcastResponseMessageHandler.java
+++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/BroadcastResponseMessageHandler.java
@@ -1,17 +1,18 @@
 package com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.response.cmd;
 
-import com.alibaba.fastjson.JSONObject;
+import com.genersoft.iot.vmp.common.VideoManagerConstants;
+import com.genersoft.iot.vmp.conf.DynamicTask;
 import com.genersoft.iot.vmp.gb28181.bean.AudioBroadcastCatch;
 import com.genersoft.iot.vmp.gb28181.bean.AudioBroadcastCatchStatus;
 import com.genersoft.iot.vmp.gb28181.bean.Device;
 import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform;
 import com.genersoft.iot.vmp.gb28181.session.AudioBroadcastManager;
 import com.genersoft.iot.vmp.gb28181.transmit.callback.DeferredResultHolder;
-import com.genersoft.iot.vmp.gb28181.transmit.callback.RequestMessage;
 import com.genersoft.iot.vmp.gb28181.transmit.event.request.SIPRequestProcessorParent;
 import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.IMessageHandler;
 import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.response.ResponseMessageHandler;
-import com.genersoft.iot.vmp.gb28181.utils.XmlUtil;
+import com.genersoft.iot.vmp.service.IPlayService;
+import gov.nist.javax.sip.message.SIPRequest;
 import org.dom4j.Element;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -21,7 +22,6 @@
 
 import javax.sip.InvalidArgumentException;
 import javax.sip.RequestEvent;
-import javax.sip.ServerTransaction;
 import javax.sip.SipException;
 import javax.sip.message.Response;
 import java.text.ParseException;
@@ -38,10 +38,13 @@
     private ResponseMessageHandler responseMessageHandler;
 
     @Autowired
-    private DeferredResultHolder deferredResultHolder;
+    private DynamicTask dynamicTask;
 
     @Autowired
     private AudioBroadcastManager audioBroadcastManager;
+
+    @Autowired
+    private IPlayService playService;
 
     @Override
     public void afterPropertiesSet() throws Exception {
@@ -50,20 +53,40 @@
 
     @Override
     public void handForDevice(RequestEvent evt, Device device, Element rootElement) {
+
+        SIPRequest request = (SIPRequest) evt.getRequest();
         try {
             String channelId = getText(rootElement, "DeviceID");
             if (!audioBroadcastManager.exit(device.getDeviceId(), channelId)) {
                 // 鍥炲410
-                responseAck(evt, Response.GONE);
+                responseAck((SIPRequest) evt.getRequest(), Response.GONE);
                 return;
             }
-            logger.info("鏀跺埌璇煶骞挎挱鐨勫洖澶嶏細{}/{}", device.getDeviceId(), channelId );
-            AudioBroadcastCatch audioBroadcastCatch = audioBroadcastManager.get(device.getDeviceId(), channelId);
-            audioBroadcastCatch.setStatus(AudioBroadcastCatchStatus.WaiteInvite);
-            audioBroadcastManager.update(audioBroadcastCatch);
-            responseAck(evt, Response.OK);
+            String result = getText(rootElement, "Result");
+            Element infoElement = rootElement.element("Info");
+            String reason = null;
+            if (infoElement != null) {
+                reason = getText(infoElement, "Reason");
+            }
+            logger.info("[璇煶骞挎挱]鍥炲锛歿}, {}/{}", reason == null? result : result + ": " + reason, device.getDeviceId(), channelId );
+
+            // 鍥炲200 OK
+            responseAck(request, Response.OK);
+            if (result.equalsIgnoreCase("OK")) {
+                AudioBroadcastCatch audioBroadcastCatch = audioBroadcastManager.get(device.getDeviceId(), channelId);
+                audioBroadcastCatch.setStatus(AudioBroadcastCatchStatus.WaiteInvite);
+                audioBroadcastManager.update(audioBroadcastCatch);
+                // 绛夊緟invite娑堟伅锛� 瓒呮椂鍒欑粨鏉�
+                String key = VideoManagerConstants.BROADCAST_WAITE_INVITE +  device.getDeviceId() + channelId;
+                dynamicTask.startDelay(key, ()->{
+                    logger.info("[璇煶骞挎挱]绛夊緟invite娑堟伅瓒呮椂锛歿}/{}", device.getDeviceId(), channelId);
+                    playService.stopAudioBroadcast(device.getDeviceId(), channelId);
+                }, 2000);
+            }else {
+                playService.stopAudioBroadcast(device.getDeviceId(), channelId);
+            }
         } catch (ParseException | SipException | InvalidArgumentException e) {
-            e.printStackTrace();
+            logger.error("[鍛戒护鍙戦�佸け璐 鍥芥爣绾ц仈 璇煶鍠婅瘽: {}", e.getMessage());
         }
     }
 

--
Gitblit v1.8.0