Commit cf8a1261b5a27b0e3270da2bd57fbe936b4e809b
1 parent
85f20df9
支持合并录像使用https
Showing
4 changed files
with
32 additions
and
21 deletions
src/main/java/com/genersoft/iot/vmp/media/zlm/AssistRESTfulUtils.java
| @@ -2,7 +2,9 @@ package com.genersoft.iot.vmp.media.zlm; | @@ -2,7 +2,9 @@ package com.genersoft.iot.vmp.media.zlm; | ||
| 2 | 2 | ||
| 3 | import com.alibaba.fastjson2.JSON; | 3 | import com.alibaba.fastjson2.JSON; |
| 4 | import com.alibaba.fastjson2.JSONObject; | 4 | import com.alibaba.fastjson2.JSONObject; |
| 5 | +import com.genersoft.iot.vmp.conf.exception.ControllerException; | ||
| 5 | import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem; | 6 | import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem; |
| 7 | +import com.genersoft.iot.vmp.vmanager.bean.ErrorCode; | ||
| 6 | import okhttp3.*; | 8 | import okhttp3.*; |
| 7 | import okhttp3.logging.HttpLoggingInterceptor; | 9 | import okhttp3.logging.HttpLoggingInterceptor; |
| 8 | import org.jetbrains.annotations.NotNull; | 10 | import org.jetbrains.annotations.NotNull; |
| @@ -13,7 +15,9 @@ import org.springframework.util.ObjectUtils; | @@ -13,7 +15,9 @@ import org.springframework.util.ObjectUtils; | ||
| 13 | 15 | ||
| 14 | import java.io.IOException; | 16 | import java.io.IOException; |
| 15 | import java.net.ConnectException; | 17 | import java.net.ConnectException; |
| 18 | +import java.net.MalformedURLException; | ||
| 16 | import java.net.SocketTimeoutException; | 19 | import java.net.SocketTimeoutException; |
| 20 | +import java.net.URL; | ||
| 17 | import java.util.HashMap; | 21 | import java.util.HashMap; |
| 18 | import java.util.List; | 22 | import java.util.List; |
| 19 | import java.util.Map; | 23 | import java.util.Map; |
| @@ -148,13 +152,14 @@ public class AssistRESTfulUtils { | @@ -148,13 +152,14 @@ public class AssistRESTfulUtils { | ||
| 148 | return responseJSON; | 152 | return responseJSON; |
| 149 | } | 153 | } |
| 150 | 154 | ||
| 151 | - public JSONObject sendPost(MediaServerItem mediaServerItem, String api, JSONObject param, ZLMRESTfulUtils.RequestCallback callback, Integer readTimeOut) { | 155 | + public JSONObject sendPost(MediaServerItem mediaServerItem, String url, |
| 156 | + JSONObject param, ZLMRESTfulUtils.RequestCallback callback, | ||
| 157 | + Integer readTimeOut) { | ||
| 152 | OkHttpClient client = getClient(readTimeOut); | 158 | OkHttpClient client = getClient(readTimeOut); |
| 153 | 159 | ||
| 154 | if (mediaServerItem == null) { | 160 | if (mediaServerItem == null) { |
| 155 | return null; | 161 | return null; |
| 156 | } | 162 | } |
| 157 | - String url = String.format("http://%s:%s/%s", mediaServerItem.getIp(), mediaServerItem.getRecordAssistPort(), api); | ||
| 158 | JSONObject responseJSON = new JSONObject(); | 163 | JSONObject responseJSON = new JSONObject(); |
| 159 | //-2自定义流媒体 调用错误码 | 164 | //-2自定义流媒体 调用错误码 |
| 160 | responseJSON.put("code",-2); | 165 | responseJSON.put("code",-2); |
| @@ -253,8 +258,8 @@ public class AssistRESTfulUtils { | @@ -253,8 +258,8 @@ public class AssistRESTfulUtils { | ||
| 253 | if (!ObjectUtils.isEmpty(remoteHost)) { | 258 | if (!ObjectUtils.isEmpty(remoteHost)) { |
| 254 | videoTaskInfoJSON.put("remoteHost", remoteHost); | 259 | videoTaskInfoJSON.put("remoteHost", remoteHost); |
| 255 | } | 260 | } |
| 256 | - | ||
| 257 | - return sendPost(mediaServerItem, "api/record/file/download/task/add", videoTaskInfoJSON, null, 30); | 261 | + String urlStr = String.format("%s/api/record/file/download/task/add", remoteHost);; |
| 262 | + return sendPost(mediaServerItem, urlStr, videoTaskInfoJSON, null, 30); | ||
| 258 | } | 263 | } |
| 259 | 264 | ||
| 260 | public JSONObject queryTaskList(MediaServerItem mediaServerItem, String app, String stream, String callId, String taskId, Boolean isEnd) { | 265 | public JSONObject queryTaskList(MediaServerItem mediaServerItem, String app, String stream, String callId, String taskId, Boolean isEnd) { |
src/main/java/com/genersoft/iot/vmp/service/ICloudRecordService.java
| @@ -32,7 +32,7 @@ public interface ICloudRecordService { | @@ -32,7 +32,7 @@ public interface ICloudRecordService { | ||
| 32 | /** | 32 | /** |
| 33 | * 添加合并任务 | 33 | * 添加合并任务 |
| 34 | */ | 34 | */ |
| 35 | - String addTask(String app, String stream, String mediaServerId, String startTime, String endTime, String callId, String remoteHost); | 35 | + String addTask(String app, String stream, MediaServerItem mediaServerItem, String startTime, String endTime, String callId, String remoteHost); |
| 36 | 36 | ||
| 37 | 37 | ||
| 38 | /** | 38 | /** |
src/main/java/com/genersoft/iot/vmp/service/impl/CloudRecordServiceImpl.java
| @@ -107,23 +107,10 @@ public class CloudRecordServiceImpl implements ICloudRecordService { | @@ -107,23 +107,10 @@ public class CloudRecordServiceImpl implements ICloudRecordService { | ||
| 107 | } | 107 | } |
| 108 | 108 | ||
| 109 | @Override | 109 | @Override |
| 110 | - public String addTask(String app, String stream, String mediaServerId, String startTime, String endTime, String callId, String remoteHost) { | 110 | + public String addTask(String app, String stream, MediaServerItem mediaServerItem, String startTime, String endTime, String callId, String remoteHost) { |
| 111 | // 参数校验 | 111 | // 参数校验 |
| 112 | assert app != null; | 112 | assert app != null; |
| 113 | assert stream != null; | 113 | assert stream != null; |
| 114 | - MediaServerItem mediaServerItem = null; | ||
| 115 | - if (mediaServerId == null) { | ||
| 116 | - mediaServerItem = mediaServerService.getDefaultMediaServer(); | ||
| 117 | - }else { | ||
| 118 | - mediaServerItem = mediaServerService.getOne(mediaServerId); | ||
| 119 | - } | ||
| 120 | - if (mediaServerItem == null) { | ||
| 121 | - throw new ControllerException(ErrorCode.ERROR100.getCode(), "未找到可用的流媒体"); | ||
| 122 | - }else { | ||
| 123 | - if (remoteHost == null) { | ||
| 124 | - remoteHost = "http://" + mediaServerItem.getStreamIp() + ":" + mediaServerItem.getRecordAssistPort(); | ||
| 125 | - } | ||
| 126 | - } | ||
| 127 | if (mediaServerItem.getRecordAssistPort() == 0) { | 114 | if (mediaServerItem.getRecordAssistPort() == 0) { |
| 128 | throw new ControllerException(ErrorCode.ERROR100.getCode(), "为配置Assist服务"); | 115 | throw new ControllerException(ErrorCode.ERROR100.getCode(), "为配置Assist服务"); |
| 129 | } | 116 | } |
| @@ -163,7 +150,7 @@ public class CloudRecordServiceImpl implements ICloudRecordService { | @@ -163,7 +150,7 @@ public class CloudRecordServiceImpl implements ICloudRecordService { | ||
| 163 | } | 150 | } |
| 164 | JSONObject result = assistRESTfulUtils.queryTaskList(mediaServerItem, app, stream, callId, taskId, isEnd); | 151 | JSONObject result = assistRESTfulUtils.queryTaskList(mediaServerItem, app, stream, callId, taskId, isEnd); |
| 165 | if (result == null || result.getInteger("code") != 0) { | 152 | if (result == null || result.getInteger("code") != 0) { |
| 166 | - throw new ControllerException(ErrorCode.ERROR100.getCode(), result.getString("msg")); | 153 | + throw new ControllerException(ErrorCode.ERROR100.getCode(), result == null ? "查询任务列表失败" : result.getString("msg")); |
| 167 | } | 154 | } |
| 168 | return result.getJSONArray("data"); | 155 | return result.getJSONArray("data"); |
| 169 | } | 156 | } |
src/main/java/com/genersoft/iot/vmp/vmanager/cloudRecord/CloudRecordController.java
| @@ -22,6 +22,7 @@ import org.springframework.beans.factory.annotation.Autowired; | @@ -22,6 +22,7 @@ import org.springframework.beans.factory.annotation.Autowired; | ||
| 22 | import org.springframework.data.redis.core.RedisTemplate; | 22 | import org.springframework.data.redis.core.RedisTemplate; |
| 23 | import org.springframework.web.bind.annotation.*; | 23 | import org.springframework.web.bind.annotation.*; |
| 24 | 24 | ||
| 25 | +import javax.servlet.http.HttpServletRequest; | ||
| 25 | import java.util.ArrayList; | 26 | import java.util.ArrayList; |
| 26 | import java.util.Calendar; | 27 | import java.util.Calendar; |
| 27 | import java.util.List; | 28 | import java.util.List; |
| @@ -154,6 +155,7 @@ public class CloudRecordController { | @@ -154,6 +155,7 @@ public class CloudRecordController { | ||
| 154 | @Parameter(name = "callId", description = "鉴权ID", required = false) | 155 | @Parameter(name = "callId", description = "鉴权ID", required = false) |
| 155 | @Parameter(name = "remoteHost", description = "返回地址时的远程地址", required = false) | 156 | @Parameter(name = "remoteHost", description = "返回地址时的远程地址", required = false) |
| 156 | public String addTask( | 157 | public String addTask( |
| 158 | + HttpServletRequest request, | ||
| 157 | @RequestParam(required = false) String app, | 159 | @RequestParam(required = false) String app, |
| 158 | @RequestParam(required = false) String stream, | 160 | @RequestParam(required = false) String stream, |
| 159 | @RequestParam(required = false) String mediaServerId, | 161 | @RequestParam(required = false) String mediaServerId, |
| @@ -162,7 +164,24 @@ public class CloudRecordController { | @@ -162,7 +164,24 @@ public class CloudRecordController { | ||
| 162 | @RequestParam(required = false) String callId, | 164 | @RequestParam(required = false) String callId, |
| 163 | @RequestParam(required = false) String remoteHost | 165 | @RequestParam(required = false) String remoteHost |
| 164 | ){ | 166 | ){ |
| 165 | - return cloudRecordService.addTask(app, stream, mediaServerId, startTime, endTime, callId, remoteHost); | 167 | + System.out.println(request.getScheme()); |
| 168 | + System.out.println(request.getLocalAddr()); | ||
| 169 | + System.out.println(request.getRemoteAddr()); | ||
| 170 | + System.out.println(request.getRequestURI()); | ||
| 171 | + MediaServerItem mediaServerItem; | ||
| 172 | + if (mediaServerId == null) { | ||
| 173 | + mediaServerItem = mediaServerService.getDefaultMediaServer(); | ||
| 174 | + }else { | ||
| 175 | + mediaServerItem = mediaServerService.getOne(mediaServerId); | ||
| 176 | + } | ||
| 177 | + if (mediaServerItem == null) { | ||
| 178 | + throw new ControllerException(ErrorCode.ERROR100.getCode(), "未找到可用的流媒体"); | ||
| 179 | + }else { | ||
| 180 | + if (remoteHost == null) { | ||
| 181 | + remoteHost = request.getScheme() + "://" + request.getLocalAddr() + ":" + mediaServerItem.getRecordAssistPort(); | ||
| 182 | + } | ||
| 183 | + } | ||
| 184 | + return cloudRecordService.addTask(app, stream, mediaServerItem, startTime, endTime, callId, remoteHost); | ||
| 166 | } | 185 | } |
| 167 | 186 | ||
| 168 | @ResponseBody | 187 | @ResponseBody |