| | |
| | | package com.ard.tianyu.websocket.handler; |
| | | |
| | | import com.alibaba.fastjson2.JSON; |
| | | import com.ard.tianyu.domain.dto.state.UavState; |
| | | import com.ard.tianyu.domain.receiver.BoxStreamUrlReceiver; |
| | | import com.ard.tianyu.service.ITyService; |
| | | import com.ard.tianyu.websocket.domain.BaseMessage; |
| | | import com.ard.tianyu.websocket.utils.WebSocketUtil; |
| | | import com.ard.vtdu.domain.ArdVtdu; |
| | | import com.ard.vtdu.service.IMediaService; |
| | |
| | | public class UavStreamManager { |
| | | |
| | | private static final String STREAM_LOG_PREFIX = "【stream】"; |
| | | private static final String STREAM_NOT_FOUND_MSG = STREAM_LOG_PREFIX + "Box stream not found: "; |
| | | private static final String STREAM_CLOSED_MSG = STREAM_LOG_PREFIX + "Stream closed due to no active users: "; |
| | | private static final String STREAM_IN_USE_MSG = STREAM_LOG_PREFIX + "Stream is still in use, remaining users: "; |
| | | private static final String STREAM_NOT_FOUND_MSG = "Box stream not found: "; |
| | | private static final String STREAM_CLOSED_MSG = "Stream closed due to no active users: "; |
| | | private static final String STREAM_IN_USE_MSG = "Stream is still in use, remaining users: "; |
| | | |
| | | @Resource |
| | | private ITyService tyService; |
| | |
| | | webrtcUrl = addVtdu(boxSn); |
| | | if (Objects.equals(webrtcUrl, "")) { |
| | | log.warn("{}{}{}", STREAM_LOG_PREFIX, STREAM_NOT_FOUND_MSG, boxSn); |
| | | sendMessageToUser(userId, 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); |
| | | } else { |
| | | webrtcUrl = BOX_STREAM_PULL_MAP.get(boxSn); |
| | | } |
| | | sendMessageToUser(userId, webrtcUrl); |
| | | BaseMessage<String> baseMessage = new BaseMessage<>("stream", webrtcUrl); |
| | | sendMessageToUser(userId, JSON.toJSONString(baseMessage)); |
| | | } |
| | | |
| | | /** |
| | |
| | | Set<Long> users = STREAM_USER_MAP.get(boxSn); |
| | | if (users == null) { |
| | | log.warn("{}No active users for box: {}", STREAM_LOG_PREFIX, boxSn); |
| | | sendMessageToUser(userId, "No active users for box: " + boxSn); |
| | | BaseMessage<String> baseMessage = new BaseMessage<>("stream", "No active users for box: " + boxSn); |
| | | sendMessageToUser(userId, JSON.toJSONString(baseMessage)); |
| | | return; |
| | | } |
| | | |
| | | users.remove(userId); |
| | | String message = ""; |
| | | if (users.isEmpty()) { |
| | | mediaService.removePath(boxSn); |
| | | BOX_STREAM_PULL_MAP.remove(boxSn); |
| | | STREAM_USER_MAP.remove(boxSn); |
| | | log.info("{}{}{}", STREAM_LOG_PREFIX, STREAM_CLOSED_MSG, boxSn); |
| | | sendMessageToUser(userId, STREAM_CLOSED_MSG + boxSn); |
| | | message = STREAM_CLOSED_MSG + boxSn; |
| | | } else { |
| | | log.info("{}{}{}", STREAM_LOG_PREFIX, STREAM_IN_USE_MSG, users); |
| | | sendMessageToUser(userId, STREAM_IN_USE_MSG + users); |
| | | message = STREAM_IN_USE_MSG + boxSn; |
| | | } |
| | | BaseMessage<String> baseMessage = new BaseMessage<>("stream", message); |
| | | sendMessageToUser(userId, JSON.toJSONString(baseMessage)); |
| | | } |
| | | } |
| | | |