| | |
| | | import com.dji.sample.common.model.CustomClaim; |
| | | import com.dji.sample.common.model.ResponseResult; |
| | | import com.dji.sample.component.mqtt.model.ChannelName; |
| | | import com.dji.sample.component.mqtt.model.CommonTopicReceiver; |
| | | import com.dji.sample.manage.model.Chan; |
| | | import com.dji.sample.manage.model.dto.CapacityDeviceDTO; |
| | | import com.dji.sample.manage.model.dto.LiveTypeDTO; |
| | | import com.dji.sample.manage.model.receiver.CapacityDeviceReceiver; |
| | | import com.dji.sample.manage.model.receiver.ServiceReplyReceiver; |
| | | import com.dji.sample.manage.model.receiver.LiveCapacityReceiver; |
| | | import com.dji.sample.manage.service.ILiveStreamService; |
| | | import com.fasterxml.jackson.core.type.TypeReference; |
| | | import com.fasterxml.jackson.databind.ObjectMapper; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.integration.annotation.ServiceActivator; |
| | | import org.springframework.messaging.Message; |
| | | import org.springframework.messaging.MessageHeaders; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | |
| | | @Autowired |
| | | private ILiveStreamService liveStreamService; |
| | | |
| | | @Autowired |
| | | private ObjectMapper mapper; |
| | | |
| | | /** |
| | | * Analyze the live streaming capabilities of drones. |
| | | * This data is necessary if drones are required for live streaming. |
| | | * @param device the capacity of drone |
| | | * @param liveCapacity the capacity of drone and dock |
| | | */ |
| | | @ServiceActivator(inputChannel = ChannelName.INBOUND_STATE_CAPACITY) |
| | | public void stateCapacity(CapacityDeviceReceiver device) { |
| | | boolean parseCapacity = liveStreamService.saveLiveCapacity(device); |
| | | log.debug("The result of parsing the live capacity is {}.", parseCapacity); |
| | | public void stateCapacity(LiveCapacityReceiver liveCapacity, MessageHeaders headers) { |
| | | liveStreamService.saveLiveCapacity(liveCapacity, headers.getTimestamp()); |
| | | } |
| | | |
| | | /** |
| | | * Get live capability data of all drones in the current user's workspace from the database. |
| | | * @param request |
| | | * 从数据库中获取当前工作区中所有无人机的实时性能数据。 |
| | | * @param workspaceId |
| | | * @return live capability |
| | | */ |
| | | @GetMapping("/capacity") |
| | | public ResponseResult<List<CapacityDeviceDTO>> getLiveCapacity(HttpServletRequest request) { |
| | | // Get information about the current user. |
| | | CustomClaim customClaim = (CustomClaim)request.getAttribute(TOKEN_CLAIM); |
| | | @GetMapping("/capacity/{workspace_id}") |
| | | public ResponseResult<List<CapacityDeviceDTO>> getLiveCapacity(@PathVariable("workspace_id") String workspaceId,String sn) { |
| | | // Get information about the current user. 获取当前登录用户的信息 |
| | | // CustomClaim customClaim = (CustomClaim)request.getAttribute(TOKEN_CLAIM); |
| | | |
| | | List<CapacityDeviceDTO> liveCapacity = liveStreamService.getLiveCapacity(customClaim.getWorkspaceId()); |
| | | |
| | | List<CapacityDeviceDTO> liveCapacity = liveStreamService.getLiveCapacity(workspaceId,sn); |
| | | return ResponseResult.success(liveCapacity); |
| | | } |
| | | |
| | | /** |
| | | * Live streaming according to the parameters passed in from the web side. |
| | | * 根据从web端传入的参数进行直播。 |
| | | * @param liveParam Live streaming parameters. |
| | | * @return |
| | | */ |
| | |
| | | return liveStreamService.liveStart(liveParam); |
| | | } |
| | | |
| | | @PostMapping("/streams/address") |
| | | public ResponseResult liveAddress(@RequestParam String deviceSn,@RequestParam String deviceName) throws IOException { |
| | | return liveStreamService.liveAddress(deviceSn,deviceName); |
| | | } |
| | | |
| | | /** |
| | | * Stop live streaming according to the parameters passed in from the web side. |
| | | * 根据从web端传入的参数停止直播。 |
| | | * @param liveParam Live streaming parameters. |
| | | * @return |
| | | */ |
| | |
| | | } |
| | | |
| | | /** |
| | | * Set the quality of the live streaming according to the parameters passed in from the web side. |
| | | * @param liveParam Live streaming parameters. |
| | | * 根据从web端传入的参数设置直播的质量。 |
| | | * @param liveParam 直播参数 |
| | | * @return |
| | | */ |
| | | @PostMapping("/streams/update") |
| | |
| | | return liveStreamService.liveSetQuality(liveParam); |
| | | } |
| | | |
| | | /** |
| | | * Handle the reply message from the pilot side to the on-demand video. |
| | | * @param message reply message |
| | | * @throws IOException |
| | | */ |
| | | @ServiceActivator(inputChannel = ChannelName.INBOUND_SERVICE_REPLY) |
| | | public void serviceReply(Message<?> message) throws IOException { |
| | | byte[] payload = (byte[])message.getPayload(); |
| | | ObjectMapper mapper = new ObjectMapper(); |
| | | CommonTopicReceiver<ServiceReplyReceiver> receiver = mapper.readValue(payload, |
| | | new TypeReference<CommonTopicReceiver<ServiceReplyReceiver>>() { |
| | | }); |
| | | Chan<CommonTopicReceiver> chan = Chan.getInstance(); |
| | | // Put the message to the chan object. |
| | | chan.put(receiver); |
| | | @PostMapping("/streams/switch") |
| | | public ResponseResult liveLensChange(@RequestBody LiveTypeDTO liveParam) { |
| | | return liveStreamService.liveLensChange(liveParam); |
| | | } |
| | | } |
| | | |
| | | } |