websocket无人机控制者和视频流数据增加boxSn
| | |
| | | /** |
| | | * 订阅指定设备的数据 |
| | | */ |
| | | public void subscribe(String boxSn, Long userId,Integer period) { |
| | | public void subscribe(String boxSn, Long userId, Integer period) { |
| | | subscriptions.computeIfAbsent(boxSn, k -> new HashSet<>()).add(userId); |
| | | if (subscriptions.get(boxSn).size() == 1) { |
| | | startPushTask(boxSn,period); |
| | | startPushTask(boxSn, period); |
| | | } |
| | | } |
| | | |
| | |
| | | /** |
| | | * 启动推送任务 |
| | | */ |
| | | private void startPushTask(String boxSn,Integer period) { |
| | | private void startPushTask(String boxSn, Integer period) { |
| | | // 如果已经存在任务,则不再创建 |
| | | if (pushTasks.containsKey(boxSn)) { |
| | | return; |
| | |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * 向订阅者发送数据 |
| | | */ |
| | |
| | | if (userIds != null) { |
| | | for (Long userId : userIds) { |
| | | try { |
| | | log.debug("给用户{}定时推送",userId); |
| | | log.debug("给用户{}定时推送", userId); |
| | | WebSocketUtil.sendMessage(userId, JSON.toJSONString(baseMessage)); |
| | | } catch (Exception e) { |
| | | log.error("Error sending message to session {}", userId, e); |
| | |
| | | } |
| | | |
| | | /** |
| | | * 处理无人机控制 |
| | | * 根据接收到的消息内容,决定无人机控制信息的订阅或退订 |
| | | * 处理无人机控制者 |
| | | * 根据接收到的消息内容,决定无人机控制者信息的订阅或退订 |
| | | * |
| | | * @param payload 消息负载,包含控制信息 |
| | | * @param userId 用户ID,用于标识用户 |
| | |
| | | import java.util.Map; |
| | | |
| | | @Service |
| | | public class UavControlManager extends BaseSubscriptionManager<Map<String, Long>> { |
| | | public class UavControlManager extends BaseSubscriptionManager<Map<String, Object>> { |
| | | |
| | | @Resource |
| | | private UavControlService uavControlService; |
| | |
| | | * @return 返回一个映射,包含无人机(fly)和载荷(payload)的当前控制者用户ID |
| | | */ |
| | | @Override |
| | | protected Map<String, Long> getData(String boxSn) { |
| | | protected Map<String, Object> getData(String boxSn) { |
| | | // 获取当前控制飞行的用户ID |
| | | Long flyUserId = uavControlService.getCurrentController(boxSn, "fly"); |
| | | // 获取当前控制载荷的用户ID |
| | | Long payloadUserId = uavControlService.getCurrentController(boxSn, "payload"); |
| | | // 创建一个映射,用于存储飞行和载荷的当前控制者用户ID |
| | | Map<String, Long> map=new HashMap<>(); |
| | | Map<String, Object> map=new HashMap<>(); |
| | | map.put("boxSn", boxSn); |
| | | // 将飞行当前控制者用户ID添加到映射中 |
| | | map.put("flyController", flyUserId); |
| | | // 将载荷当前控制者用户ID添加到映射中 |
| | |
| | | public void subscribe(String boxSn, Long userId) { |
| | | |
| | | STREAM_USER_MAP.computeIfAbsent(boxSn, k -> ConcurrentHashMap.newKeySet()).add(userId); |
| | | String webrtcUrl = getWebrtcUrl(boxSn); |
| | | BoxStreamUrlReceiver streamReceiver = getWebrtcUrl(boxSn); |
| | | String webrtcUrl = streamReceiver.getRtc(); |
| | | if (Objects.equals(webrtcUrl, "")) { |
| | | log.warn("{}{}{}", STREAM_LOG_PREFIX, STREAM_NOT_FOUND_MSG, boxSn); |
| | | BaseMessage<String> baseMessage = new BaseMessage<>("stream", STREAM_NOT_FOUND_MSG + boxSn); |
| | | sendMessageToUser(userId, JSON.toJSONString(baseMessage)); |
| | | } |
| | | BOX_STREAM_PULL_MAP.put(boxSn, webrtcUrl); |
| | | BaseMessage<String> baseMessage = new BaseMessage<>("stream", webrtcUrl); |
| | | BaseMessage<BoxStreamUrlReceiver> baseMessage = new BaseMessage<>("stream", streamReceiver); |
| | | sendMessageToUser(userId, JSON.toJSONString(baseMessage)); |
| | | } |
| | | |
| | |
| | | * @param boxSn 盒子编号 |
| | | * @return String webrtcUrl |
| | | */ |
| | | private String getWebrtcUrl(String boxSn) { |
| | | try { |
| | | BoxStreamUrlReceiver boxLiveUrl = tyService.getBoxLiveUrl(boxSn); |
| | | if (boxLiveUrl != null) { |
| | | return boxLiveUrl.getRtc(); |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("获取媒体地址异常:{}", e.getMessage()); |
| | | } |
| | | return ""; |
| | | private BoxStreamUrlReceiver getWebrtcUrl(String boxSn) { |
| | | BoxStreamUrlReceiver boxLiveUrl = tyService.getBoxLiveUrl(boxSn); |
| | | boxLiveUrl.setBoxSn(boxSn); |
| | | return boxLiveUrl; |
| | | } |
| | | } |
| | |
| | | @JsonIgnoreProperties(ignoreUnknown = true) |
| | | public class BoxStreamUrlReceiver { |
| | | |
| | | private String boxSn; |
| | | |
| | | @JsonProperty("rtsp") |
| | | private String rtsp; |
| | | |
| | |
| | | import com.ard.work.service.ITyService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | |
| | | List<ArdServerInfo> ardServerInfos = ardServerService.selectArdServerInfoList(new ArdServerInfo()); |
| | | return getBoxList(ardServerInfos); |
| | | } |
| | | |
| | | /** |
| | | * 获取指定服务器云盒列表 |
| | | * |
| | |
| | | TyHttpCommonReceiver<List<BoxInfoReceiver>> boxList = tyClient.getBoxList(serverId); |
| | | return boxList.getContent(); |
| | | } |
| | | |
| | | /** |
| | | * 获取直播地址 |
| | | * |
| | |
| | | @Override |
| | | public BoxStreamUrlReceiver getBoxLiveUrl(String boxSn) { |
| | | ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn); |
| | | if(ardDroneInfo== null){ |
| | | log.warn("未找到对应的飞行器信息,boxSn:{}",boxSn); |
| | | if (ardDroneInfo == null) { |
| | | log.warn("未找到对应的飞行器信息,boxSn:{}", boxSn); |
| | | return null; |
| | | } |
| | | TyHttpCommonReceiver<BoxStreamUrlReceiver> boxLiveUrl = tyClient.getBoxLiveUrl(ardDroneInfo.getServerId(),boxSn); |
| | | return boxLiveUrl.getContent(); |
| | | TyHttpCommonReceiver<BoxStreamUrlReceiver> boxLiveUrl = tyClient.getBoxLiveUrl(ardDroneInfo.getServerId(), |
| | | boxSn); |
| | | return boxLiveUrl == null ? null : boxLiveUrl.getContent(); |
| | | } |
| | | |
| | | /** |
| | |
| | | @Override |
| | | public List<BoxPhotosReceiver> getBoxPhotos(BoxPhotosDTO boxPhotosDTO) { |
| | | ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxPhotosDTO.getBoxSn()); |
| | | TyHttpCommonReceiver<List<BoxPhotosReceiver>> boxPhotos = tyClient.getBoxPhotos(ardDroneInfo.getServerId(),boxPhotosDTO); |
| | | TyHttpCommonReceiver<List<BoxPhotosReceiver>> boxPhotos = tyClient.getBoxPhotos(ardDroneInfo.getServerId(), |
| | | boxPhotosDTO); |
| | | return boxPhotos.getContent(); |
| | | } |
| | | |
| | |
| | | @Override |
| | | public Boolean updateBoxSettings(BoxSettingsDTO boxSettingsDTO) { |
| | | ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSettingsDTO.getBoxSn()); |
| | | TyHttpCommonReceiver<?> result = tyClient.updateBoxSettings(ardDroneInfo.getServerId(),boxSettingsDTO); |
| | | TyHttpCommonReceiver<?> result = tyClient.updateBoxSettings(ardDroneInfo.getServerId(), boxSettingsDTO); |
| | | return result.getState() == 1; |
| | | } |
| | | |
| | |
| | | break; |
| | | case 0x02: |
| | | // 处理注册消息 |
| | | HeartbeatReplyCmd heartbeatReplyCmd = (HeartbeatReplyCmd) tyCommand; |
| | | logPrint("心跳消息", heartbeatReplyCmd.getTimestamp()); |
| | | HeartbeatReplyCmd heartbeatReplyCmd = (HeartbeatReplyCmd) tyCommand; |
| | | logPrint("心跳消息", heartbeatReplyCmd.getTimestamp()); |
| | | break; |
| | | case 0x03: |
| | | // 处理订阅消息 |