| | |
| | | import com.alibaba.fastjson2.JSONObject; |
| | | import com.ard.tianyu.domain.cache.UavStateCache; |
| | | import com.ard.tianyu.domain.dto.state.UavState; |
| | | import com.ard.tianyu.websocket.domain.BaseMessage; |
| | | import com.ard.tianyu.websocket.utils.WebSocketUtil; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.stereotype.Component; |
| | |
| | | private void sendDroneStateToSubscribers(String boxSn) { |
| | | // 获取当前无人机状态 |
| | | UavState uavState = getDroneState(boxSn); |
| | | BaseMessage<UavState>baseMessage=new BaseMessage<>("state",uavState); |
| | | // 向所有订阅者推送状态 |
| | | Set<Long> userIds = stateSubscriptions.get(boxSn); |
| | | if (userIds != null) { |
| | | for (Long userId : userIds) { |
| | | try { |
| | | WebSocketUtil.sendMessage(userId, JSON.toJSONString(uavState)); |
| | | WebSocketUtil.sendMessage(userId, JSON.toJSONString(baseMessage)); |
| | | } catch (Exception e) { |
| | | log.error("Error sending state message to session {}", userId, e); |
| | | } |