|  |  | 
 |  |  |    @PostMapping(value = "/on_publish", produces = "application/json;charset=UTF-8")
 | 
 |  |  |    public ResponseEntity<String> onPublish(@RequestBody JSONObject json) {
 | 
 |  |  | 
 | 
 |  |  |       logger.debug("[ ZLM HOOK ]on_publish API调用,参数:" + json.toString());
 | 
 |  |  |       logger.info("[ ZLM HOOK ]on_publish API调用,参数:" + json.toString());
 | 
 |  |  |       JSONObject ret = new JSONObject();
 | 
 |  |  |       ret.put("code", 0);
 | 
 |  |  |       ret.put("msg", "success");
 | 
 |  |  | 
 |  |  |                if (mediaServerItem != null){
 | 
 |  |  |                   if (regist) {
 | 
 |  |  |                      StreamPushItem streamPushItem = null;
 | 
 |  |  |                      StreamInfo streamInfoByAppAndStream = mediaService.getStreamInfoByAppAndStream(mediaServerItem, app, streamId, tracks);
 | 
 |  |  |                      item.setStreamInfo(streamInfoByAppAndStream);
 | 
 |  |  | 
 | 
 |  |  |                      redisCatchStorage.addStream(mediaServerItem, type, app, streamId, item);
 | 
 |  |  |                      if (item.getOriginType() == OriginType.RTSP_PUSH.ordinal()
 | 
 |  |  |                            || item.getOriginType() == OriginType.RTMP_PUSH.ordinal()
 | 
 |  |  | 
 |  |  |                         }
 | 
 |  |  |                      }
 | 
 |  |  |                      if (gbStreams.size() > 0) {
 | 
 |  |  |                         eventPublisher.catalogEventPublishForStream(null, gbStreams.toArray(new GbStream[0]), CatalogEvent.ON);
 | 
 |  |  |                         eventPublisher.catalogEventPublishForStream(null, gbStreams, CatalogEvent.ON);
 | 
 |  |  |                      }
 | 
 |  |  | 
 | 
 |  |  |                   }else {
 | 
 |  |  | 
 |  |  |             if (redisCatchStorage.isChannelSendingRTP(streamInfoForPlayCatch.getChannelId())) {
 | 
 |  |  |                ret.put("close", false);
 | 
 |  |  |             } else {
 | 
 |  |  |                cmder.streamByeCmd(streamInfoForPlayCatch.getDeviceID(), streamInfoForPlayCatch.getChannelId());
 | 
 |  |  |                cmder.streamByeCmd(streamInfoForPlayCatch.getDeviceID(), streamInfoForPlayCatch.getChannelId(),
 | 
 |  |  |                      streamInfoForPlayCatch.getStream());
 | 
 |  |  |                redisCatchStorage.stopPlay(streamInfoForPlayCatch);
 | 
 |  |  |                storager.stopPlay(streamInfoForPlayCatch.getDeviceID(), streamInfoForPlayCatch.getChannelId());
 | 
 |  |  |             }
 | 
 |  |  |          }else{
 | 
 |  |  |             StreamInfo streamInfoForPlayBackCatch = redisCatchStorage.queryPlaybackByStreamId(streamId);
 | 
 |  |  |             if (streamInfoForPlayBackCatch != null) {
 | 
 |  |  |                cmder.streamByeCmd(streamInfoForPlayBackCatch.getDeviceID(), streamInfoForPlayBackCatch.getChannelId());
 | 
 |  |  |                cmder.streamByeCmd(streamInfoForPlayBackCatch.getDeviceID(),
 | 
 |  |  |                      streamInfoForPlayBackCatch.getChannelId(), streamInfoForPlayBackCatch.getStream());
 | 
 |  |  |                redisCatchStorage.stopPlayback(streamInfoForPlayBackCatch);
 | 
 |  |  |             }else {
 | 
 |  |  |                StreamInfo streamInfoForDownload = redisCatchStorage.queryDownloadByStreamId(streamId);
 | 
 |  |  | 
 |  |  |             }
 | 
 |  |  |          }
 | 
 |  |  |          MediaServerItem mediaServerItem = mediaServerService.getOne(mediaServerId);
 | 
 |  |  |          if (mediaServerItem != null && "-1".equals(mediaServerItem.getStreamNoneReaderDelayMS())) {
 | 
 |  |  |          if (mediaServerItem != null && mediaServerItem.getStreamNoneReaderDelayMS() == -1) {
 | 
 |  |  |             ret.put("close", false);
 | 
 |  |  |          }
 | 
 |  |  |          return new ResponseEntity<String>(ret.toString(),HttpStatus.OK);
 | 
 |  |  | 
 |  |  |       }
 | 
 |  |  |       String mediaServerId = json.getString("mediaServerId");
 | 
 |  |  |       MediaServerItem mediaInfo = mediaServerService.getOne(mediaServerId);
 | 
 |  |  |       if (userSetup.isAutoApplyPlay() && mediaInfo != null) {
 | 
 |  |  |       if (userSetup.isAutoApplyPlay() && mediaInfo != null && mediaInfo.isRtpEnable()) {
 | 
 |  |  |          String app = json.getString("app");
 | 
 |  |  |          String streamId = json.getString("stream");
 | 
 |  |  |          if ("rtp".equals(app)) {
 | 
 |  |  | 
 |  |  |                String channelId = s[1];
 | 
 |  |  |                Device device = redisCatchStorage.getDevice(deviceId);
 | 
 |  |  |                if (device != null) {
 | 
 |  |  |                   UUID uuid = UUID.randomUUID();
 | 
 |  |  |                   SSRCInfo ssrcInfo;
 | 
 |  |  |                   String streamId2 = null;
 | 
 |  |  |                   if (mediaInfo.isRtpEnable()) {
 | 
 |  |  |                      streamId2 = String.format("%s_%s", device.getDeviceId(), channelId);
 | 
 |  |  |                   }
 | 
 |  |  |                   ssrcInfo = mediaServerService.openRTPServer(mediaInfo, streamId2);
 | 
 |  |  |                   cmder.playStreamCmd(mediaInfo, ssrcInfo, device, channelId, (MediaServerItem mediaServerItemInuse, JSONObject response) -> {
 | 
 |  |  |                      logger.info("收到订阅消息: " + response.toJSONString());
 | 
 |  |  |                      playService.onPublishHandlerForPlay(mediaServerItemInuse, response, deviceId, channelId, uuid.toString());
 | 
 |  |  |                   }, null);
 | 
 |  |  |                   playService.play(mediaInfo,deviceId, channelId, null, null, null);
 | 
 |  |  |                }
 | 
 |  |  | 
 | 
 |  |  |             }
 | 
 |  |  |          }
 | 
 |  |  | 
 | 
 |  |  |       }
 | 
 |  |  | 
 | 
 |  |  |       JSONObject ret = new JSONObject();
 | 
 |  |  |       ret.put("code", 0);
 | 
 |  |  |       ret.put("msg", "success");
 | 
 |  |  |       return new ResponseEntity<String>(ret.toString(),HttpStatus.OK);
 | 
 |  |  |       return new ResponseEntity<>(ret.toString(),HttpStatus.OK);
 | 
 |  |  |    }
 | 
 |  |  |    
 | 
 |  |  |    /**
 |