| File was renamed from ard-work/src/main/java/com/ard/tianyu/service/impl/UavStreamManager.java |
| | |
| | | package com.ard.tianyu.service.impl; |
| | | package com.ard.tianyu.service.stream; |
| | | |
| | | import com.ard.tianyu.model.receiver.BoxStreamUrlReceiver; |
| | | import com.ard.tianyu.domain.receiver.BoxStreamUrlReceiver; |
| | | import com.ard.tianyu.service.ITyService; |
| | | import com.ard.tianyu.websocket.utils.WebSocketUtil; |
| | | import com.ard.vtdu.domain.ArdVtdu; |
| | | import com.ard.vtdu.domain.Conf; |
| | | import com.ard.vtdu.service.IMediaService; |
| | | import com.dtflys.forest.exceptions.ForestNetworkException; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | |
| | | // 盒子拉流地址缓存 key:boxSn value: webrtcUrl |
| | | public static final ConcurrentMap<String, String> BOX_STREAM_PULL_MAP = new ConcurrentHashMap<>(); |
| | | // 盒子拉流用户集合缓存 key:boxSn value:Set<UserId> |
| | | public static final ConcurrentMap<String, Set<String>> STREAM_USER_MAP = new ConcurrentHashMap<>(); |
| | | public static final ConcurrentMap<String, Set<Long>> STREAM_USER_MAP = new ConcurrentHashMap<>(); |
| | | |
| | | /** |
| | | * 开始拉流 |
| | |
| | | * @param boxSn 盒子序列号 |
| | | * @param userId 用户ID |
| | | */ |
| | | public void startPullStream(String boxSn, String userId) { |
| | | public void startPullStream(String boxSn, Long userId) { |
| | | String webrtcUrl = ""; |
| | | STREAM_USER_MAP.computeIfAbsent(boxSn, k -> ConcurrentHashMap.newKeySet()).add(userId); |
| | | //不管谁拉流都判断流媒体中是否存在 |
| | |
| | | * @param boxSn 盒子序列号 |
| | | * @param userId 用户ID |
| | | */ |
| | | public void stopPullStream(String boxSn, String userId) { |
| | | public void stopPullStream(String boxSn, Long userId) { |
| | | synchronized (this) { |
| | | Set<String> users = STREAM_USER_MAP.get(boxSn); |
| | | 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); |
| | |
| | | * |
| | | * @param userId 用户ID |
| | | */ |
| | | public void stopAllPullStreamByUser(String userId) { |
| | | public void stopAllPullStreamByUser(Long userId) { |
| | | synchronized (this) { |
| | | STREAM_USER_MAP.forEach((boxSn, users) -> stopPullStream(boxSn, userId)); |
| | | } |
| | |
| | | * @param userId 用户ID |
| | | * @param message 消息内容 |
| | | */ |
| | | private void sendMessageToUser(String userId, String message) { |
| | | private void sendMessageToUser(Long userId, String message) { |
| | | try { |
| | | WebSocketUtil.sendMessage(userId, message); |
| | | } catch (Exception e) { |