This commit is contained in:
dute7liang
2024-01-11 23:38:56 +08:00
parent f7485b9066
commit 728192d4f0
21 changed files with 231 additions and 58 deletions

View File

@@ -20,6 +20,7 @@ import com.ruoyi.cai.ws.bean.Room;
import com.ruoyi.cai.ws.constant.RedisConstant;
import com.ruoyi.cai.ws.dto.WsToken;
import com.ruoyi.cai.ws.manager.WebSocketManager;
import com.ruoyi.cai.ws.util.MapGetUtil;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.helper.LoginHelper;
import org.springframework.beans.factory.annotation.Autowired;
@@ -30,6 +31,7 @@ import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;
import java.util.stream.Collectors;
@@ -56,14 +58,29 @@ public class ChatManager {
String token = IdManager.nextIdStr();
String tokenKey = String.format(RedisConstant.WS_TOKEN, token);
Map<String,Object> map = new HashMap<>();
map.put("userId",userId);
map.put("roomId",roomId);
map.put("fromUid",fromUid);
map.put("toUid",toUid);
map.put("userId",userId);
redisTemplate.opsForHash().putAll(tokenKey,map);
redisTemplate.expire(tokenKey,1, TimeUnit.DAYS);
return token;
}
public WsToken getToken(String token){
String tokenKey = String.format(RedisConstant.WS_TOKEN, token);
Map<Object, Object> entries = redisTemplate.opsForHash().entries(tokenKey);
if(entries.isEmpty()){
return null;
}
WsToken wsToken = new WsToken();
wsToken.setRoomId(MapGetUtil.getLong(entries.get("roomId")));
wsToken.setFromUid(MapGetUtil.getLong(entries.get("fromUid")));
wsToken.setToUid(MapGetUtil.getLong(entries.get("toUid")));
wsToken.setUserId(MapGetUtil.getLong(entries.get("userId")));
return wsToken;
}
public CallResp call(CallReq callReq){
Long userId = LoginHelper.getUserId();
User fromUser = userService.getById(userId);