From 0d8f4029444f21dbfed41e71d47f571012ee35e7 Mon Sep 17 00:00:00 2001 From: kim_sang_ june <79149384+drbug2000@users.noreply.github.com> Date: Fri, 16 Aug 2024 01:22:51 +0900 Subject: [PATCH 1/6] [refactoring] room name => room id LiveKit room name : roomId --- .../space/space_spring/dto/VoiceRoom/GetVoiceRoomList.java | 2 ++ src/main/java/space/space_spring/dto/VoiceRoom/RoomDto.java | 2 +- .../java/space/space_spring/service/VoiceRoomService.java | 6 ++++-- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/main/java/space/space_spring/dto/VoiceRoom/GetVoiceRoomList.java b/src/main/java/space/space_spring/dto/VoiceRoom/GetVoiceRoomList.java index 8b6b25d2..e512885d 100644 --- a/src/main/java/space/space_spring/dto/VoiceRoom/GetVoiceRoomList.java +++ b/src/main/java/space/space_spring/dto/VoiceRoom/GetVoiceRoomList.java @@ -36,6 +36,7 @@ public static class VoiceRoomInfo{ private int numParticipant; private int order; private List participantInfoList; + private String metadate; public static VoiceRoomInfo convertRoomDto(RoomDto roomDto){ if(roomDto==null){return null;} @@ -45,6 +46,7 @@ public static VoiceRoomInfo convertRoomDto(RoomDto roomDto){ .Active(roomDto.getNumParticipants()!=0) .numParticipant(roomDto.getNumParticipants()) .order(roomDto.getOrder()) + .metadate(roomDto.getMetadata()) .participantInfoList( GetParticipantList.ParticipantInfo.convertParticipantDtoList(roomDto.getParticipantDTOList()) ) diff --git a/src/main/java/space/space_spring/dto/VoiceRoom/RoomDto.java b/src/main/java/space/space_spring/dto/VoiceRoom/RoomDto.java index 95200207..b22252ec 100644 --- a/src/main/java/space/space_spring/dto/VoiceRoom/RoomDto.java +++ b/src/main/java/space/space_spring/dto/VoiceRoom/RoomDto.java @@ -97,7 +97,7 @@ public void setActiveRoom(List liveKitRoomList){ if(liveKitRoomList==null||liveKitRoomList.isEmpty()){return;} boolean find = false; for(LivekitModels.Room resRoom : liveKitRoomList){ - if(EqualRoomIdByNameTag(resRoom.getName(),this.id)){ + if(String.valueOf(this.id).equals( resRoom.getName() )){ this.numParticipants = resRoom.getNumParticipants(); this.sid = resRoom.getSid(); this.metadata = resRoom.getMetadata(); diff --git a/src/main/java/space/space_spring/service/VoiceRoomService.java b/src/main/java/space/space_spring/service/VoiceRoomService.java index b2e2ae3f..7e9423da 100644 --- a/src/main/java/space/space_spring/service/VoiceRoomService.java +++ b/src/main/java/space/space_spring/service/VoiceRoomService.java @@ -132,7 +132,7 @@ private List findBySpace(Space space){ } private List getParticipantDtoListById(long voiceRoomId){ Space space = voiceRoomRepository.findById(voiceRoomId).getSpace(); - List participantDtoList = liveKitUtils.getParticipantInfo(findNameTagById(voiceRoomId)); + List participantDtoList = liveKitUtils.getParticipantInfo(String.valueOf(voiceRoomId)); if(participantDtoList==null||participantDtoList.isEmpty()){ return Collections.emptyList(); } @@ -162,8 +162,10 @@ private String findNameTagById(long id){ public String getToken(long spaceId,long userId,long voiceRoomId){ String userName=userDao.findUserByUserId(userId).getUserName(); String userIdentity=String.valueOf(userId); + //Todo profileImage 추가 String metadata=""; - String roomName=findNameTagById(voiceRoomId); + //String roomName=findNameTagById(voiceRoomId); + String roomName = String.valueOf(voiceRoomId); return liveKitUtils.getRoomToken(userName,userIdentity,roomName,metadata).toJwt(); } } From a139ad75a4c90959134feca4e1f0fa70e8f21153 Mon Sep 17 00:00:00 2001 From: kim_sang_ june <79149384+drbug2000@users.noreply.github.com> Date: Fri, 16 Aug 2024 02:43:13 +0900 Subject: [PATCH 2/6] [feat] voiveRoom participant response profile image --- src/main/java/space/space_spring/dao/UserDao.java | 4 +--- .../java/space/space_spring/dao/UserSpaceDao.java | 7 +++++++ .../space/space_spring/service/VoiceRoomService.java | 11 +++++++---- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/main/java/space/space_spring/dao/UserDao.java b/src/main/java/space/space_spring/dao/UserDao.java index c2411313..719fe179 100644 --- a/src/main/java/space/space_spring/dao/UserDao.java +++ b/src/main/java/space/space_spring/dao/UserDao.java @@ -51,7 +51,5 @@ public User getUserByEmail(String email) { public User findUserByUserId(Long userId) { return em.find(User.class, userId); } - public String findProfileImageByUserId(Long userId){ - return "Test ProfileImage URL";//findUserByUserId(userId).getProfileImage(); - } + } diff --git a/src/main/java/space/space_spring/dao/UserSpaceDao.java b/src/main/java/space/space_spring/dao/UserSpaceDao.java index 66826e78..5e9d6d28 100644 --- a/src/main/java/space/space_spring/dao/UserSpaceDao.java +++ b/src/main/java/space/space_spring/dao/UserSpaceDao.java @@ -134,4 +134,11 @@ public String findUserSpaceAuthById(Long userSpaceId) { .getSingleResult(); } + + public Optional findProfileImageById(Long userSpaceId){ + String jpql = "SELECT us.userProfileImg FROM UserSpace us WHERE us.userSpaceId = :userSpaceId AND us.status = 'ACTIVE'"; + return em.createQuery(jpql, String.class) + .setParameter("userSpaceId",userSpaceId) + .getResultList().stream().findFirst(); + } } diff --git a/src/main/java/space/space_spring/service/VoiceRoomService.java b/src/main/java/space/space_spring/service/VoiceRoomService.java index 7e9423da..9ef3bb8f 100644 --- a/src/main/java/space/space_spring/service/VoiceRoomService.java +++ b/src/main/java/space/space_spring/service/VoiceRoomService.java @@ -12,6 +12,7 @@ import space.space_spring.entity.Space; import space.space_spring.entity.User; import space.space_spring.entity.VoiceRoom; +import space.space_spring.exception.CustomException; import space.space_spring.util.LiveKitUtils; import space.space_spring.util.space.SpaceUtils; import space.space_spring.util.user.UserUtils; @@ -20,6 +21,8 @@ import java.util.List; import java.util.Optional; +import static space.space_spring.response.status.BaseExceptionResponseStatus.USER_IS_NOT_IN_SPACE; + @Service @RequiredArgsConstructor public class VoiceRoomService { @@ -75,7 +78,7 @@ public List getVoiceRoomInfoList(long spaceId,Ge List participantDtoList = getParticipantDtoListById(roomDto.getId()); for(ParticipantDto participantDto: participantDtoList){ //Todo profileIamge 집어넣기 - participantDto.setProfileImage(findProfileImageByUserId(participantDto.getId())); + participantDto.setProfileImage(findProfileImageByUserId(participantDto.getUserSpaceId())); } //RoomDto에 값 집어넣기 //showParticipant = ture 일때, 참가자가 없으면 빈문자열[] 출력 @@ -121,8 +124,8 @@ public void deleteVoiceRoom(long voiceRoomId){ //Todo Base Entity에 일괄적으로 soft Delete를 적용하는 방법을 다같이 정하는 것이 좋아보임 } - private String findProfileImageByUserId(Long userId){ - return userDao.findProfileImageByUserId(userId); + private String findProfileImageByUserId(Long userSpaceId){ + return userSpaceDao.findProfileImageById(userSpaceId).orElse(""); } public List findBySpaceId(long spaceId){ return findBySpace(spaceUtils.findSpaceBySpaceId(spaceId)); @@ -138,7 +141,7 @@ private List getParticipantDtoListById(long voiceRoomId){ } for(ParticipantDto participantDto: participantDtoList){ //profileIamge 집어넣기 - participantDto.setProfileImage(findProfileImageByUserId(participantDto.getId())); + participantDto.setProfileImage(findProfileImageByUserId(participantDto.getUserSpaceId())); //userSpaceId 집어 넣기 User user = userDao.findUserByUserId(participantDto.getId()); participantDto.setUserSpaceId(userSpaceDao.findUserSpaceByUserAndSpace(user,space).get().getUserSpaceId()); From 9536b2f3a60586344060c41f89743159c1d1ac73 Mon Sep 17 00:00:00 2001 From: kim_sang_ june <79149384+drbug2000@users.noreply.github.com> Date: Fri, 16 Aug 2024 16:36:03 +0900 Subject: [PATCH 3/6] [delete] voiceRoom Dao function : not use --- .../space/space_spring/dao/VoiceRoomDao.java | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/src/main/java/space/space_spring/dao/VoiceRoomDao.java b/src/main/java/space/space_spring/dao/VoiceRoomDao.java index 95b9195c..9530676b 100644 --- a/src/main/java/space/space_spring/dao/VoiceRoomDao.java +++ b/src/main/java/space/space_spring/dao/VoiceRoomDao.java @@ -29,23 +29,6 @@ public Long createVoiceRoom(String name,int order,Space space){ return null; } } - @Transactional - public Integer findMaxOrderBySpace(Space space) { - String jpql = "SELECT MAX(r.order) FROM voice_room r WHERE r.space = :space"; - - return entityManager.createQuery(jpql, Integer.class) - .setParameter("space", space) - .getSingleResult(); - } - - @Transactional - public VoiceRoom findRoomWithMaxOrderBySpace(Space space) { - String jpql = "SELECT r FROM VoiceRoom r WHERE r.space = :space AND r.order = (SELECT MAX(r2.order) FROM VoiceRoom r2 WHERE r2.space = :space)"; - - return entityManager.createQuery(jpql, VoiceRoom.class) - .setParameter("space", space) - .getSingleResult(); - } } From 1d94e8eadb32966c96323377c2ecd639eb4fd175 Mon Sep 17 00:00:00 2001 From: kim_sang_ june <79149384+drbug2000@users.noreply.github.com> Date: Fri, 16 Aug 2024 17:25:37 +0900 Subject: [PATCH 4/6] [feat] LiveKit token metadata include user ProfileImage --- .../space/space_spring/controller/VoiceRoomController.java | 4 +++- src/main/java/space/space_spring/dao/UserSpaceDao.java | 6 ++++-- .../java/space/space_spring/service/VoiceRoomService.java | 4 ++-- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/main/java/space/space_spring/controller/VoiceRoomController.java b/src/main/java/space/space_spring/controller/VoiceRoomController.java index fc555a74..45c6717a 100644 --- a/src/main/java/space/space_spring/controller/VoiceRoomController.java +++ b/src/main/java/space/space_spring/controller/VoiceRoomController.java @@ -8,6 +8,7 @@ import org.springframework.web.bind.annotation.*; import space.space_spring.argumentResolver.jwtLogin.JwtLoginAuth; import space.space_spring.argumentResolver.userSpace.UserSpaceAuth; +import space.space_spring.argumentResolver.userSpace.UserSpaceId; import space.space_spring.dao.UserSpaceDao; import space.space_spring.dao.VoiceRoomRepository; import space.space_spring.dto.VoiceRoom.*; @@ -84,6 +85,7 @@ public BaseResponse getToken( @PathVariable("spaceId") @NotNull long spaceId, @JwtLoginAuth Long userId, @PathVariable("voiceRoomId") @NotNull Long roomId, + @UserSpaceId Long userSpaceId, HttpServletResponse response ){ @@ -92,7 +94,7 @@ public BaseResponse getToken( //해당 voiceRoom이 해당 space에 속한것이 맞는지 확인 validateVoiceRoomInSpace(spaceId,roomId); - response.setHeader("Authorization", "Bearer " + voiceRoomService.getToken(spaceId, userId,roomId)); + response.setHeader("Authorization", "Bearer " + voiceRoomService.getToken(spaceId, userId,userSpaceId,roomId)); return new BaseResponse( "보이스룸 토큰 생성에 성공했습니다." ); diff --git a/src/main/java/space/space_spring/dao/UserSpaceDao.java b/src/main/java/space/space_spring/dao/UserSpaceDao.java index 5e9d6d28..e9acf1e5 100644 --- a/src/main/java/space/space_spring/dao/UserSpaceDao.java +++ b/src/main/java/space/space_spring/dao/UserSpaceDao.java @@ -14,6 +14,7 @@ import space.space_spring.entity.enumStatus.UserSpaceAuth; import java.util.*; +import java.util.stream.Stream; import static space.space_spring.entity.enumStatus.UserSpaceAuth.MANAGER; @@ -137,8 +138,9 @@ public String findUserSpaceAuthById(Long userSpaceId) { public Optional findProfileImageById(Long userSpaceId){ String jpql = "SELECT us.userProfileImg FROM UserSpace us WHERE us.userSpaceId = :userSpaceId AND us.status = 'ACTIVE'"; - return em.createQuery(jpql, String.class) + List result = em.createQuery(jpql, String.class) .setParameter("userSpaceId",userSpaceId) - .getResultList().stream().findFirst(); + .getResultList(); + return result.isEmpty() ? Optional.empty() : Optional.ofNullable(result.get(0)); } } diff --git a/src/main/java/space/space_spring/service/VoiceRoomService.java b/src/main/java/space/space_spring/service/VoiceRoomService.java index 9ef3bb8f..819d063a 100644 --- a/src/main/java/space/space_spring/service/VoiceRoomService.java +++ b/src/main/java/space/space_spring/service/VoiceRoomService.java @@ -162,11 +162,11 @@ private String findNameTagById(long id){ return name+" #"+String.valueOf(id); } - public String getToken(long spaceId,long userId,long voiceRoomId){ + public String getToken(long spaceId,long userId,long userSpaceId,long voiceRoomId){ String userName=userDao.findUserByUserId(userId).getUserName(); String userIdentity=String.valueOf(userId); //Todo profileImage 추가 - String metadata=""; + String metadata="userProfileImage : "+userSpaceDao.findProfileImageById(userSpaceId).orElse(""); //String roomName=findNameTagById(voiceRoomId); String roomName = String.valueOf(voiceRoomId); return liveKitUtils.getRoomToken(userName,userIdentity,roomName,metadata).toJwt(); From bbae8d70c158c38c51274f0e065ef88fb68d2741 Mon Sep 17 00:00:00 2001 From: kim_sang_ june <79149384+drbug2000@users.noreply.github.com> Date: Sat, 17 Aug 2024 02:35:40 +0900 Subject: [PATCH 5/6] [feat] livekit participant metadata add userName --- src/main/java/space/space_spring/dao/UserSpaceDao.java | 8 ++++++++ .../java/space/space_spring/service/VoiceRoomService.java | 5 +++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/main/java/space/space_spring/dao/UserSpaceDao.java b/src/main/java/space/space_spring/dao/UserSpaceDao.java index e9acf1e5..4dbad3eb 100644 --- a/src/main/java/space/space_spring/dao/UserSpaceDao.java +++ b/src/main/java/space/space_spring/dao/UserSpaceDao.java @@ -143,4 +143,12 @@ public Optional findProfileImageById(Long userSpaceId){ .getResultList(); return result.isEmpty() ? Optional.empty() : Optional.ofNullable(result.get(0)); } + + public String findUserNameById(Long userSpaceId){ + String jpql = "SELECT us.userName FROM UserSpace us WHERE us.userSpaceId = :userSpaceId AND us.status = 'ACTIVE'"; + return em.createQuery(jpql, String.class) + .setParameter("userSpaceId", userSpaceId) + .getSingleResult(); + + } } diff --git a/src/main/java/space/space_spring/service/VoiceRoomService.java b/src/main/java/space/space_spring/service/VoiceRoomService.java index 819d063a..567e8959 100644 --- a/src/main/java/space/space_spring/service/VoiceRoomService.java +++ b/src/main/java/space/space_spring/service/VoiceRoomService.java @@ -165,8 +165,9 @@ private String findNameTagById(long id){ public String getToken(long spaceId,long userId,long userSpaceId,long voiceRoomId){ String userName=userDao.findUserByUserId(userId).getUserName(); String userIdentity=String.valueOf(userId); - //Todo profileImage 추가 - String metadata="userProfileImage : "+userSpaceDao.findProfileImageById(userSpaceId).orElse(""); + //Metadata에 profileImage와 userName 추가 + String metadata="userProfileImage : "+userSpaceDao.findProfileImageById(userSpaceId).orElse("") + +", userName : "+userSpaceDao.findUserNameById(userSpaceId); //String roomName=findNameTagById(voiceRoomId); String roomName = String.valueOf(voiceRoomId); return liveKitUtils.getRoomToken(userName,userIdentity,roomName,metadata).toJwt(); From a6a62aa486cea06879c75e83535ff3c4a4fd9820 Mon Sep 17 00:00:00 2001 From: kim_sang_ june <79149384+drbug2000@users.noreply.github.com> Date: Sat, 17 Aug 2024 02:45:29 +0900 Subject: [PATCH 6/6] [refactoring] livekit token name -> userSpaceName --- .../java/space/space_spring/service/VoiceRoomService.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/java/space/space_spring/service/VoiceRoomService.java b/src/main/java/space/space_spring/service/VoiceRoomService.java index 567e8959..ee93090f 100644 --- a/src/main/java/space/space_spring/service/VoiceRoomService.java +++ b/src/main/java/space/space_spring/service/VoiceRoomService.java @@ -163,11 +163,10 @@ private String findNameTagById(long id){ } public String getToken(long spaceId,long userId,long userSpaceId,long voiceRoomId){ - String userName=userDao.findUserByUserId(userId).getUserName(); + String userName=userSpaceDao.findUserNameById(userSpaceId); String userIdentity=String.valueOf(userId); //Metadata에 profileImage와 userName 추가 - String metadata="userProfileImage : "+userSpaceDao.findProfileImageById(userSpaceId).orElse("") - +", userName : "+userSpaceDao.findUserNameById(userSpaceId); + String metadata="userProfileImage : "+userSpaceDao.findProfileImageById(userSpaceId).orElse(""); //String roomName=findNameTagById(voiceRoomId); String roomName = String.valueOf(voiceRoomId); return liveKitUtils.getRoomToken(userName,userIdentity,roomName,metadata).toJwt();