zhaowenyu
2025-12-12 7beea5916728a84617d4791775d0aac70ab32eee
ard-sample/src/main/java/com/ard/sample/component/websocket/handler/LiveStreamHandler.java
@@ -31,7 +31,7 @@
    /**
     * 开启直播
     */
    public void StartLiveStreaming(String sn) {
    public void StartLiveStreaming(String sn ,String userId) {
        //调用开始直播
        ResponseResult rlive = null;
        String resultLive = "";
@@ -41,6 +41,7 @@
            // 如果存在直播则读取直播地址返回
            if (RedisOpsUtils.checkExist(RedisConst.WEBSOCKET_VIDEO_ADDRESS_PREFIX + sn)) {
                resultLive = String.valueOf(RedisOpsUtils.get(RedisConst.WEBSOCKET_VIDEO_ADDRESS_PREFIX + sn));
                log.info("SN: {}-redis中存在相机的播放地址信息,直接返回地址!", sn);
            } else {
                log.info("SN: {}-redis中未找到相机的播放地址信息!停止直播后再开启直播", sn);
                StopLiveStreaming(sn);
@@ -53,9 +54,14 @@
                    rlive.setType(MessageType.LIVESTREAM.getType());
                    resultLive = _objectMapper.writeValueAsString(rlive);
                    RedisOpsUtils.set(RedisConst.WEBSOCKET_VIDEO_ADDRESS_PREFIX + sn, resultLive);
                    LiveDTO live = (LiveDTO) rlive.getData();
                    Boolean isWeb = _deviceService.updateWebrtcUrl(sn,live.getWebrtcUrl());
                    if (isWeb) {
                        log.info("SN: {}-更新webrtc地址成功!", sn);
                    }
                }
            }
            _dockWebSocketHandler.sendMessageToSubscribers(sn, MessageType.LIVESTREAM.getType(), resultLive);
            _dockWebSocketHandler.sendMessageToSubscribers(sn, MessageType.LIVESTREAM.getType(), resultLive, userId);
            log.info("SN: {}-直播地址:{}", sn, resultLive);
        } catch (Exception e) {
            log.info("SN: {}-开启直播失败!原因:{}", sn, e.getMessage());
@@ -125,9 +131,21 @@
            }
            List<CapacityCameraDTO> camerasList = device.getCamerasList();
            for (CapacityCameraDTO camera : camerasList) {
                if (camera.getName() == null || camera.getName().isEmpty()) {
                    continue;
                // 机场3中飞行器,没有name,需要其他条件确定主摄像头参数
                for(CapacityVideoDTO video : camera.getVideosList())
                {
                    if(video.getSwitchVideoTypes().size() == 1 && camera.getName() == null)
                    {
                        continue;
                    }
                }
//                camera.getVideosList().get(0).getSwitchVideoTypes().add("main");
//                if(camera.getVideosList().size() == 1 && camera.getName() == null) {
//                    continue;
//                }
//                if (camera.getName() == null || camera.getName().isEmpty()) {
//                    continue;
//                }
                String videoid = device.getSn() + "/" + camera.getIndex();
                List<CapacityVideoDTO> videosList = camera.getVideosList();
                for (CapacityVideoDTO video : videosList) {