kindring 2 vuotta sitten
vanhempi
sitoutus
6bbedcebd9

+ 5 - 0
src/main/java/com/genersoft/iot/vmp/conf/security/AnonymousAuthenticationEntryPoint.java

@@ -2,7 +2,10 @@ package com.genersoft.iot.vmp.conf.security;
 
 import com.alibaba.fastjson2.JSONObject;
 import com.genersoft.iot.vmp.conf.security.dto.JwtUser;
+import com.genersoft.iot.vmp.service.impl.MediaServerServiceImpl;
 import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
 import org.springframework.security.core.AuthenticationException;
 import org.springframework.security.core.context.SecurityContextHolder;
@@ -19,6 +22,7 @@ import java.io.IOException;
  */
 @Component
 public class    AnonymousAuthenticationEntryPoint implements AuthenticationEntryPoint {
+    private final static Logger logger = LoggerFactory.getLogger(MediaServerServiceImpl.class);
 
     @Override
     public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException e) {
@@ -30,6 +34,7 @@ public class    AnonymousAuthenticationEntryPoint implements AuthenticationEntry
         JSONObject jsonObject = new JSONObject();
         jsonObject.put("code", ErrorCode.ERROR401.getCode());
         jsonObject.put("msg", ErrorCode.ERROR401.getMsg());
+        logger.info("未登陆用户");
         String logUri = "api/user/login";
         if (request.getRequestURI().contains(logUri)){
             jsonObject.put("msg", e.getMessage());

+ 1 - 0
src/main/java/com/genersoft/iot/vmp/gb28181/bean/Device.java

@@ -187,6 +187,7 @@ public class Device {
 	@Schema(description = "SIP交互IP(设备访问平台的IP)")
 	private String localIp;
 
+
 	@Schema(description = "是否作为消息通道")
 	private boolean asMessageChannel;
 

+ 26 - 16
src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRESTfulUtils.java

@@ -29,16 +29,20 @@ public class ZLMRESTfulUtils {
         void run(JSONObject response);
     }
 
-    private OkHttpClient getClient(){
+
+
+
+    private OkHttpClient getClient(Integer timeOut){
+        int timeout = timeOut != null ? timeOut : 5;
+        logger.info("改请求的超时时间为{}",timeout);
         if (client == null) {
             OkHttpClient.Builder httpClientBuilder = new OkHttpClient.Builder();
-            //todo 暂时写死超时时间 均为5s
-            // 设置连接超时时间
-            httpClientBuilder.connectTimeout(5,TimeUnit.SECONDS);
-            // 设置读取超时时间
-            httpClientBuilder.readTimeout(10,TimeUnit.SECONDS);
+            // 设置超时时间
+            httpClientBuilder.connectTimeout(timeout,TimeUnit.SECONDS);
+            // 设置读取超时时间 多添加5秒
+            httpClientBuilder.readTimeout(timeout + 5,TimeUnit.SECONDS);
             // 设置连接池
-            httpClientBuilder.connectionPool(new ConnectionPool(16, 5, TimeUnit.MINUTES));
+            httpClientBuilder.connectionPool(new ConnectionPool(timeout+5, timeout, TimeUnit.MINUTES));
             if (logger.isDebugEnabled()) {
                 HttpLoggingInterceptor logging = new HttpLoggingInterceptor(message -> {
                     logger.debug("http请求参数:" + message);
@@ -54,8 +58,11 @@ public class ZLMRESTfulUtils {
     }
 
 
-    public JSONObject sendPost(MediaServerItem mediaServerItem, String api, Map<String, Object> param, RequestCallback callback) {
-        OkHttpClient client = getClient();
+    public JSONObject sendPost(MediaServerItem mediaServerItem, String api, Map<String, Object> param, RequestCallback callback){
+        return sendPost(mediaServerItem,5,api,param,callback);
+    }
+    public JSONObject sendPost(MediaServerItem mediaServerItem,int timeout, String api, Map<String, Object> param, RequestCallback callback) {
+        OkHttpClient client = getClient(timeout);
 
         if (mediaServerItem == null) {
             return null;
@@ -83,15 +90,22 @@ public class ZLMRESTfulUtils {
                 .url(url)
                 .build();
             if (callback == null) {
+//                logger.info("按理来说,这是必然的选择");
                 try {
                     Response response = client.newCall(request).execute();
+                    logger.error("执行访问zlm请求任务结束");
                     if (response.isSuccessful()) {
                         ResponseBody responseBody = response.body();
                         if (responseBody != null) {
+                            logger.error("收到zlm返回值");
                             String responseStr = responseBody.string();
                             responseJSON = JSON.parseObject(responseStr);
+                        }else{
+                            logger.error("未收到zlm返回值");
                         }
+
                     }else {
+                        logger.error("zlm 请求失败 原因不明 {}",response.message());
                         response.close();
                         Objects.requireNonNull(response.body()).close();
                     }
@@ -144,9 +158,6 @@ public class ZLMRESTfulUtils {
                     }
                 });
             }
-
-
-
         return responseJSON;
     }
 
@@ -171,7 +182,7 @@ public class ZLMRESTfulUtils {
                 .build();
         logger.info(request.toString());
         try {
-            OkHttpClient client = getClient();
+            OkHttpClient client = getClient(5);
             Response response = client.newCall(request).execute();
             if (response.isSuccessful()) {
                 if (targetPath != null) {
@@ -184,7 +195,6 @@ public class ZLMRESTfulUtils {
                     }
                     File snapFile = new File(targetPath + File.separator + fileName);
                     FileOutputStream outStream = new FileOutputStream(snapFile);
-
                     outStream.write(Objects.requireNonNull(response.body()).bytes());
                     outStream.flush();
                     outStream.close();
@@ -288,8 +298,8 @@ public class ZLMRESTfulUtils {
         return sendPost(mediaServerItem, "stopSendRtp",param, null);
     }
 
-    public JSONObject startSendRtpPassive(MediaServerItem mediaServerItem, Map<String, Object> param){
-        return sendPost(mediaServerItem,"startSendRtpPassive" , param ,null);
+    public JSONObject startSendRtpPassive(MediaServerItem mediaServerItem, Map<String, Object> param,int timeout){
+        return sendPost(mediaServerItem,timeout,"startSendRtpPassive" , param ,null);
     }
 
     public JSONObject restartServer(MediaServerItem mediaServerItem) {

+ 9 - 9
src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRTPServerFactory.java

@@ -379,8 +379,8 @@ public class ZLMRTPServerFactory {
      * @param param
      * @return
      */
-    public JSONObject startSendRtpPassive(MediaServerItem mediaServerItem, Map<String, Object>param) {
-        return zlmresTfulUtils.startSendRtpPassive(mediaServerItem, param);
+    public JSONObject startSendRtpPassive(MediaServerItem mediaServerItem, Map<String, Object>param,int timeout) {
+        return zlmresTfulUtils.startSendRtpPassive(mediaServerItem, param,timeout);
     }
 	
 	/**
@@ -419,19 +419,19 @@ public class ZLMRTPServerFactory {
         param.put("app", app);
 
 
-//        param.put("recv_stream_id",streamId );
-//        param.put("stream", recv_stream_id);
+        param.put("recv_stream_id",streamId );
+        param.put("stream", recv_stream_id);
 //        param.put("from_mp4", 1);
         param.put("is_udp", 0);
         // start send rtp
-        param.put("dst_url", dst_url);
-        param.put("dst_port", dst_port);
+//        param.put("dst_url", dst_url);
+//        param.put("dst_port", dst_port);
         param.put("use_ps", 0);
         param.put("pt", 8);
-        param.put("close_delay_ms", 15000);
+        param.put("close_delay_ms", 10000);
 
-        param.put("stream", recv_stream_id);
-//        param.put("recv_stream_id", streamId);
+//        param.put("stream", recv_stream_id);
+        param.put("recv_stream_id", streamId);
 
 //        logger.info("[你好] send json: ");
 //        logger.info("[你好] send json: {}",param.toString());

+ 9 - 1
src/main/java/com/genersoft/iot/vmp/service/impl/MediaServerServiceImpl.java

@@ -198,9 +198,17 @@ public class MediaServerServiceImpl implements IMediaServerService {
             // 创建
             Map<String, Object> rtpParam = zlmrtpServerFactory.createStartSendRtpStreamAudioData(mediaServerItem,app, streamId,audioStreamId,_ssrc,addr, Integer.parseInt(port));
 //            logger.info("zlm start send {}",rtpParam.toString());
-            JSONObject result = zlmrtpServerFactory.startSendRtpPassive(mediaServerItem,rtpParam);
+            if (mediaServerItem == null || mediaServerItem.getId() == null) {
+                logger.warn("无法连接至zlm!!!!!!!");
+                return null;
+            }
+            JSONObject result = zlmrtpServerFactory.startSendRtpPassive(mediaServerItem,rtpParam,30);
 //            JSONObject result = zlmrtpServerFactory.startSendRtpStream(mediaServerItem,rtpParam);
             logger.info("zlm start send {}",result.toJSONString());
+            if(result.get("code") != "0"){
+                logger.error("[语音广播 流媒体异常] {}",result.get("msg"));
+                return null;
+            }
             RedisUtil.set(key, mediaServerItem);
             rtpServerPort = (int) result.get("local_port");
             return new SSRCInfo(rtpServerPort, ssrc, streamId);

+ 12 - 0
src/main/java/com/genersoft/iot/vmp/service/impl/PlayServiceImpl.java

@@ -403,6 +403,11 @@ public class PlayServiceImpl implements IPlayService {
                         json.getString("port"),
                         ssrcStr
                 );
+                if(ssrcInfo == null){
+                    logger.error("[zlm控制异常] 启用webrtc转发失败");
+                    nodeCallBack.run(1,"[zlm控制异常] 启用webrtc转发失败");
+                    return;
+                }
                 // 回复invite 200 信息至设备
                 cmder.sendBoradcastInviteCmd(request,mediaServerItem, ssrcInfo, device, null, null,
                 null,
@@ -483,7 +488,14 @@ public class PlayServiceImpl implements IPlayService {
         if (ObjectUtils.isEmpty(device.getMediaServerId()) || "auto".equals(device.getMediaServerId())) {
             mediaServerItem = mediaServerService.getMediaServerForMinimumLoad(null);
         } else {
+            // 尝试获取device配置的zlm服务
             mediaServerItem = mediaServerService.getOne(device.getMediaServerId());
+
+            // 如果默认zlm无法找到则随机分配一个zlm
+            if(mediaServerItem == null){
+                logger.warn("无法找到设备默认流媒体服务,即将使用默认流媒体服务");
+                mediaServerItem = mediaServerService.getMediaServerForMinimumLoad(null);
+            }
         }
         if (mediaServerItem == null) {
             logger.warn("点播时未找到可使用的ZLM...");

+ 1 - 0
src/main/java/com/genersoft/iot/vmp/storager/dao/DeviceMapper.java

@@ -42,6 +42,7 @@ public interface DeviceMapper {
             "asMessageChannel," +
             "geoCoordSys," +
             "treeType," +
+            "mediaServerId," +
             "online" +
             " FROM device WHERE deviceId = #{deviceId}")
     Device getDeviceByDeviceId(String deviceId);

+ 1 - 0
src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/play/PlayController.java

@@ -334,6 +334,7 @@ public class PlayController {
 							wvpResult.setMsg(tipMsg);
 							msg.setData(wvpResult);
 							// 回复之前所有的点播请求
+							logger.info("语音广播失败,取消invite等待");
 							resultHolder.invokeAllResult(msg);
 						} else if (code == 0) {
 							resultHolder.invokeAllResult(msg);

+ 2 - 2
src/main/resources/application.yml

@@ -125,9 +125,9 @@ sip:
 #zlm 默认服务器配置
 media:
     # [必须修改] zlm服务器唯一id,用于触发hook时区别是哪台服务器,general.mediaServerId
-    id: your_server_id
+    id: your_server_id_fail
     # [必须修改] zlm服务器的内网IP
-    ip: 192.168.1.60
+    ip: 191.168.1.60
     # [可选] 返回流地址时的ip,置空使用 media.ip
     stream-ip: 192.168.1.60
     #stream-ip: 192.168.1.203

+ 1 - 1
web_src/config/index.js

@@ -3,7 +3,7 @@
 // see http://vuejs-templates.github.io/webpack for documentation.
 
 const path = require('path')
-const baseUrl = "https://192.168.31.250:29001"
+const baseUrl = "https://192.168.1.26:29001"
 const ZLMServer = "https://192.168.1.60:29010"
 module.exports = {
   dev: {

+ 9 - 4
web_src/src/components/common/microphone.vue

@@ -42,7 +42,7 @@ export default {
   },
   beforeMount() {
     this.initAudioApplications();
-    this.getWebrtcAddress();
+
   },
   beforeDestroy() {
     if(this.player){
@@ -59,6 +59,7 @@ export default {
       this.player = null;
       this.mediaStream = null;
       this.audioConnected = false;
+      this.getWebrtcAddress();
     },
     // 录音按钮按下
     mouseDownHandle() {
@@ -123,13 +124,16 @@ export default {
           console.log('当前状态==>', state);
           if (state === 'connected') {
             // 等待1秒
-            await sleep(1000);
+            await sleep(2000);
             [err, res] = await handle(this.sendBroaderCast(this.pushConfig.stream,this.pushConfig.app));
-            if (err) {
-              this.audioStartFailed(err,`与设备交互错误信息失败${err.message}`)
+            let response = res.data;
+            if (err|| response.code!==0 ) {
+              // console.log(err);
+              this.audioStartFailed(err?err:response,`与设备交互错误信息失败${err?err.message:response.msg}`)
               this.mediaStream = null;
               return player.close();
             }
+            console.log(res);
             this.audioConnected = true;
             console.log('创建音视频通道成功');
           } else if(state === 'close'){
@@ -166,6 +170,7 @@ export default {
         console.log("-------");
       }
       this.$message.error(msg);
+      this.initAudioApplications();
     },
     async getWebrtcAddress(){
       let url = `/api/play/getWebRtcAddr`

+ 1 - 1
web_src/src/components/dialog/deviceEdit.vue

@@ -130,7 +130,7 @@ export default {
       this.form.subscribeCycleForCatalog = this.form.subscribeCycleForCatalog||0
       this.form.subscribeCycleForMobilePosition = this.form.subscribeCycleForMobilePosition||0
       this.form.mobilePositionSubmissionInterval = this.form.mobilePositionSubmissionInterval||0
-      this.$axios({
+      this.$axios.axios({
         method: 'post',
         url:`/api/device/query/device/${this.isEdit?'update':'add'}/`,
         params: this.form