| | |
| | | return AjaxResult.success(json); |
| | | } |
| | | |
| | | /** |
| | | * 拉流代理(通过通道ID,简化传参) |
| | | * |
| | | * @param request HttpServletRequest |
| | | * @param channelId 通道ID |
| | | * @return |
| | | */ |
| | | @Operation(summary = "拉流代理(通过通道ID,简化传参)") |
| | | @PostMapping("/streamPullPlayByChannelId/{channelId}") |
| | | public DeferredResult<R<StreamContent>> streamPullPlayByChannelId( |
| | | HttpServletRequest request, |
| | | @PathVariable String channelId |
| | | ) { |
| | | log.info("[拉流代理-通道ID] channelId:{}", channelId); |
| | | Assert.hasText(channelId, "通道ID不可为空"); |
| | | |
| | | DeferredResult<R<StreamContent>> result = new DeferredResult<>(userSetting.getPlayTimeout().longValue()); |
| | | |
| | | ErrorCallback<StreamInfo> callback = (code, msg, streamInfo) -> { |
| | | if (code == InviteErrorCode.SUCCESS.getCode()) { |
| | | R<StreamContent> r = R.ok(); |
| | | if (streamInfo != null) { |
| | | if (userSetting.getUseSourceIpAsStreamIp()) { |
| | | streamInfo = streamInfo.clone(); |
| | | String host; |
| | | try { |
| | | URL url = new URL(request.getRequestURL().toString()); |
| | | host = url.getHost(); |
| | | } catch (MalformedURLException e) { |
| | | host = request.getLocalAddr(); |
| | | } |
| | | streamInfo.changeStreamIp(host); |
| | | } |
| | | if (!ObjectUtils.isEmpty(streamInfo.getMediaServer().getTranscodeSuffix()) |
| | | && !"null".equalsIgnoreCase(streamInfo.getMediaServer().getTranscodeSuffix())) { |
| | | streamInfo.setStream(streamInfo.getStream() + "_" + streamInfo.getMediaServer().getTranscodeSuffix()); |
| | | } |
| | | r.setData(new StreamContent(streamInfo)); |
| | | } else { |
| | | r.setCode(code); |
| | | r.setMsg(msg); |
| | | } |
| | | result.setResult(r); |
| | | } else { |
| | | result.setResult(R.fail(code, msg)); |
| | | } |
| | | }; |
| | | |
| | | mediaServerService.streamPullPlayByChannelId(channelId, callback); |
| | | return result; |
| | | } |
| | | |
| | | /** |
| | | * 停止拉流代理(通过通道ID) |
| | | * |
| | | * @param channelId 通道ID |
| | | * @return |
| | | */ |
| | | @Operation(summary = "停止拉流代理(通过通道ID)") |
| | | @PostMapping("/stopStreamPullPlayByChannelId/{channelId}") |
| | | public AjaxResult stopStreamPullPlayByChannelId(@PathVariable String channelId) { |
| | | log.info("[停止拉流代理-通道ID] channelId:{}", channelId); |
| | | Assert.hasText(channelId, "通道ID不可为空"); |
| | | mediaServerService.stopStreamPullPlayByChannelId(channelId); |
| | | return AjaxResult.success(); |
| | | } |
| | | |
| | | } |