Skip to content

Commit 80e3eb0

Browse files
committed
refactor: 방 생성 시 webRTC 제어 가능하게 구현
1 parent 3c2986f commit 80e3eb0

File tree

7 files changed

+220
-22
lines changed

7 files changed

+220
-22
lines changed

src/main/java/com/back/domain/studyroom/controller/RoomController.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public class RoomController {
4343
@PostMapping
4444
@Operation(
4545
summary = "방 생성",
46-
description = "새로운 스터디 룸을 생성합니다. 방 생성자는 자동으로 방장(HOST)이 됩니다."
46+
description = "새로운 스터디 룸을 생성합니다. 방 생성자는 자동으로 방장(HOST)이 됩니다. useWebRTC로 화상/음성/화면공유 기능을 한 번에 제어할 수 있습니다."
4747
)
4848
@ApiResponses({
4949
@ApiResponse(responseCode = "201", description = "방 생성 성공"),
@@ -61,7 +61,8 @@ public ResponseEntity<RsData<RoomResponse>> createRoom(
6161
request.getIsPrivate() != null ? request.getIsPrivate() : false,
6262
request.getPassword(),
6363
request.getMaxParticipants() != null ? request.getMaxParticipants() : 10,
64-
currentUserId
64+
currentUserId,
65+
request.getUseWebRTC() != null ? request.getUseWebRTC() : true // 디폴트: true
6566
);
6667

6768
RoomResponse response = roomService.toRoomResponse(room);

src/main/java/com/back/domain/studyroom/dto/CreateRoomRequest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,10 @@ public class CreateRoomRequest {
2323
@Min(value = 2, message = "최소 2명 이상이어야 합니다")
2424
@Max(value = 100, message = "최대 100명까지 가능합니다")
2525
private Integer maxParticipants = 10;
26+
27+
// WebRTC 통합 제어 필드 (카메라, 오디오, 화면공유를 한 번에 제어)
28+
// true: WebRTC 기능 전체 활성화
29+
// false: WebRTC 기능 전체 비활성화
30+
// null: 디폴트 true로 처리
31+
private Boolean useWebRTC = true;
2632
}

src/main/java/com/back/domain/studyroom/dto/RoomResponse.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ public class RoomResponse {
1919
private String createdBy;
2020
private LocalDateTime createdAt;
2121

22+
// WebRTC 설정 정보 (프론트엔드에서 UI 제어용)
23+
private Boolean allowCamera;
24+
private Boolean allowAudio;
25+
private Boolean allowScreenShare;
26+
2227
public static RoomResponse from(Room room, long currentParticipants) {
2328
return RoomResponse.builder()
2429
.roomId(room.getId())
@@ -29,6 +34,9 @@ public static RoomResponse from(Room room, long currentParticipants) {
2934
.status(room.getStatus())
3035
.createdBy(room.getCreatedBy().getNickname())
3136
.createdAt(room.getCreatedAt())
37+
.allowCamera(room.isAllowCamera())
38+
.allowAudio(room.isAllowAudio())
39+
.allowScreenShare(room.isAllowScreenShare())
3240
.build();
3341
}
3442
}

src/main/java/com/back/domain/studyroom/entity/Room.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,19 +168,21 @@ public boolean isOwner(Long userId) {
168168
* 방 생성을 위한 정적 팩토리 메서드
169169
새로운 방을 생성할 때 모든 기본값을 설정 해주는 초기 메서드
170170
기본 상태에서 방장이 임의로 변형하고 싶은 부분만 변경해서 사용 가능
171+
* @param useWebRTC WebRTC 사용 여부 (true: 카메라/오디오/화면공유 전체 활성화, false: 전체 비활성화)
171172
*/
172173
public static Room create(String title, String description, boolean isPrivate,
173-
String password, int maxParticipants, User creator, RoomTheme theme) {
174+
String password, int maxParticipants, User creator, RoomTheme theme,
175+
boolean useWebRTC) {
174176
Room room = new Room();
175177
room.title = title;
176178
room.description = description;
177179
room.isPrivate = isPrivate;
178180
room.password = password;
179181
room.maxParticipants = maxParticipants;
180182
room.isActive = true; // 생성 시 기본적으로 활성화
181-
room.allowCamera = true; // 기본적으로 카메라 허용
182-
room.allowAudio = true; // 기본적으로 오디오 허용
183-
room.allowScreenShare = true; // 기본적으로 화면 공유 허용
183+
room.allowCamera = useWebRTC; // WebRTC 사용 여부에 따라 설정
184+
room.allowAudio = useWebRTC; // WebRTC 사용 여부에 따라 설정
185+
room.allowScreenShare = useWebRTC; // WebRTC 사용 여부에 따라 설정
184186
room.status = RoomStatus.WAITING; // 생성 시 대기 상태
185187
room.currentParticipants = 0; // 생성 시 참가자 0명
186188
room.createdBy = creator;

src/main/java/com/back/domain/studyroom/service/RoomService.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,26 +52,26 @@ public class RoomService {
5252
5353
* 기본 설정:
5454
- 상태: WAITING (대기 중)
55-
- 카메라/오디오/화면공유: application.yml의 설정값 사용
55+
- WebRTC: useWebRTC 파라미터에 따라 카메라/오디오/화면공유 통합 제어
5656
- 참가자 수: 0명에서 시작 후 방장 추가로 1명
5757
*/
5858
@Transactional
5959
public Room createRoom(String title, String description, boolean isPrivate,
60-
String password, int maxParticipants, Long creatorId) {
60+
String password, int maxParticipants, Long creatorId, boolean useWebRTC) {
6161

6262
User creator = userRepository.findById(creatorId)
6363
.orElseThrow(() -> new CustomException(ErrorCode.USER_NOT_FOUND));
6464

65-
Room room = Room.create(title, description, isPrivate, password, maxParticipants, creator, null);
65+
Room room = Room.create(title, description, isPrivate, password, maxParticipants, creator, null, useWebRTC);
6666
Room savedRoom = roomRepository.save(room);
6767

6868
RoomMember hostMember = RoomMember.createHost(savedRoom, creator);
6969
roomMemberRepository.save(hostMember);
7070

7171
// savedRoom.incrementParticipant(); // Redis로 이관 - DB 업데이트 제거
7272

73-
log.info("방 생성 완료 - RoomId: {}, Title: {}, CreatorId: {}",
74-
savedRoom.getId(), title, creatorId);
73+
log.info("방 생성 완료 - RoomId: {}, Title: {}, CreatorId: {}, WebRTC: {}",
74+
savedRoom.getId(), title, creatorId, useWebRTC);
7575

7676
return savedRoom;
7777
}

src/test/java/com/back/domain/studyroom/controller/RoomControllerTest.java

Lines changed: 129 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,16 @@ void setUp() {
6666
userProfile.setNickname("테스트유저");
6767
testUser.setUserProfile(userProfile);
6868

69-
// 테스트 방 생성
69+
// 테스트 방 생성 (WebRTC 사용)
7070
testRoom = Room.create(
7171
"테스트 방",
7272
"테스트 설명",
7373
false,
7474
null,
7575
10,
7676
testUser,
77-
null
77+
null,
78+
true // useWebRTC
7879
);
7980

8081
// 테스트 멤버 생성
@@ -94,7 +95,8 @@ void createRoom() {
9495
"테스트 설명",
9596
false,
9697
null,
97-
10
98+
10,
99+
true // useWebRTC
98100
);
99101

100102
given(roomService.createRoom(
@@ -103,7 +105,8 @@ void createRoom() {
103105
anyBoolean(),
104106
any(),
105107
anyInt(),
106-
eq(1L)
108+
eq(1L),
109+
anyBoolean() // useWebRTC 파라미터 추가
107110
)).willReturn(testRoom);
108111

109112
RoomResponse roomResponse = RoomResponse.from(testRoom, 1);
@@ -125,7 +128,8 @@ void createRoom() {
125128
anyBoolean(),
126129
any(),
127130
anyInt(),
128-
eq(1L)
131+
eq(1L),
132+
anyBoolean() // useWebRTC 파라미터 추가
129133
);
130134
verify(roomService, times(1)).toRoomResponse(any(Room.class));
131135
}
@@ -366,4 +370,124 @@ void getPopularRooms() {
366370
verify(roomService, times(1)).getPopularRooms(any());
367371
verify(roomService, times(1)).toRoomResponseList(anyList());
368372
}
373+
374+
@Test
375+
@DisplayName("방 생성 API - WebRTC 활성화 테스트")
376+
void createRoom_WithWebRTC() {
377+
// given
378+
given(currentUser.getUserId()).willReturn(1L);
379+
380+
CreateRoomRequest request = new CreateRoomRequest(
381+
"WebRTC 방",
382+
"화상 채팅 가능",
383+
false,
384+
null,
385+
10,
386+
true // WebRTC 활성화
387+
);
388+
389+
Room webRTCRoom = Room.create(
390+
"WebRTC 방",
391+
"화상 채팅 가능",
392+
false,
393+
null,
394+
10,
395+
testUser,
396+
null,
397+
true
398+
);
399+
400+
given(roomService.createRoom(
401+
anyString(),
402+
anyString(),
403+
anyBoolean(),
404+
any(),
405+
anyInt(),
406+
eq(1L),
407+
eq(true) // WebRTC true 검증
408+
)).willReturn(webRTCRoom);
409+
410+
RoomResponse roomResponse = RoomResponse.from(webRTCRoom, 1);
411+
given(roomService.toRoomResponse(any(Room.class))).willReturn(roomResponse);
412+
413+
// when
414+
ResponseEntity<RsData<RoomResponse>> response = roomController.createRoom(request);
415+
416+
// then
417+
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.CREATED);
418+
assertThat(response.getBody()).isNotNull();
419+
assertThat(response.getBody().getData().getAllowCamera()).isTrue();
420+
assertThat(response.getBody().getData().getAllowAudio()).isTrue();
421+
assertThat(response.getBody().getData().getAllowScreenShare()).isTrue();
422+
423+
verify(roomService, times(1)).createRoom(
424+
anyString(),
425+
anyString(),
426+
anyBoolean(),
427+
any(),
428+
anyInt(),
429+
eq(1L),
430+
eq(true)
431+
);
432+
}
433+
434+
@Test
435+
@DisplayName("방 생성 API - WebRTC 비활성화 테스트")
436+
void createRoom_WithoutWebRTC() {
437+
// given
438+
given(currentUser.getUserId()).willReturn(1L);
439+
440+
CreateRoomRequest request = new CreateRoomRequest(
441+
"채팅 전용 방",
442+
"텍스트만 가능",
443+
false,
444+
null,
445+
50,
446+
false // WebRTC 비활성화
447+
);
448+
449+
Room chatOnlyRoom = Room.create(
450+
"채팅 전용 방",
451+
"텍스트만 가능",
452+
false,
453+
null,
454+
50,
455+
testUser,
456+
null,
457+
false
458+
);
459+
460+
given(roomService.createRoom(
461+
anyString(),
462+
anyString(),
463+
anyBoolean(),
464+
any(),
465+
anyInt(),
466+
eq(1L),
467+
eq(false) // WebRTC false 검증
468+
)).willReturn(chatOnlyRoom);
469+
470+
RoomResponse roomResponse = RoomResponse.from(chatOnlyRoom, 1);
471+
given(roomService.toRoomResponse(any(Room.class))).willReturn(roomResponse);
472+
473+
// when
474+
ResponseEntity<RsData<RoomResponse>> response = roomController.createRoom(request);
475+
476+
// then
477+
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.CREATED);
478+
assertThat(response.getBody()).isNotNull();
479+
assertThat(response.getBody().getData().getAllowCamera()).isFalse();
480+
assertThat(response.getBody().getData().getAllowAudio()).isFalse();
481+
assertThat(response.getBody().getData().getAllowScreenShare()).isFalse();
482+
483+
verify(roomService, times(1)).createRoom(
484+
anyString(),
485+
anyString(),
486+
anyBoolean(),
487+
any(),
488+
anyInt(),
489+
eq(1L),
490+
eq(false)
491+
);
492+
}
369493
}

src/test/java/com/back/domain/studyroom/service/RoomServiceTest.java

Lines changed: 63 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,16 @@ void setUp() {
7171
userProfile.setNickname("테스트유저");
7272
testUser.setUserProfile(userProfile);
7373

74-
// 테스트 방 생성
74+
// 테스트 방 생성 (WebRTC 사용)
7575
testRoom = Room.create(
7676
"테스트 방",
7777
"테스트 설명",
7878
false,
7979
null,
8080
10,
8181
testUser,
82-
null
82+
null,
83+
true // useWebRTC
8384
);
8485

8586
// 테스트 멤버 생성
@@ -101,7 +102,8 @@ void createRoom_Success() {
101102
false,
102103
null,
103104
10,
104-
1L
105+
1L,
106+
true // useWebRTC
105107
);
106108

107109
// then
@@ -125,7 +127,8 @@ void createRoom_UserNotFound() {
125127
false,
126128
null,
127129
10,
128-
999L
130+
999L,
131+
true // useWebRTC
129132
))
130133
.isInstanceOf(CustomException.class)
131134
.hasFieldOrPropertyWithValue("errorCode", ErrorCode.USER_NOT_FOUND);
@@ -171,7 +174,8 @@ void joinRoom_WrongPassword() {
171174
"1234",
172175
10,
173176
testUser,
174-
null
177+
null,
178+
true // useWebRTC
175179
);
176180
given(roomRepository.findByIdWithLock(1L)).willReturn(Optional.of(privateRoom));
177181

@@ -242,7 +246,8 @@ void getRoomDetail_PrivateRoomForbidden() {
242246
"1234",
243247
10,
244248
testUser,
245-
null
249+
null,
250+
true // useWebRTC
246251
);
247252
given(roomRepository.findById(1L)).willReturn(Optional.of(privateRoom));
248253
given(roomMemberRepository.existsByRoomIdAndUserId(1L, 2L)).willReturn(false);
@@ -387,4 +392,56 @@ void kickMember_NoPermission() {
387392
.isInstanceOf(CustomException.class)
388393
.hasFieldOrPropertyWithValue("errorCode", ErrorCode.NOT_ROOM_MANAGER);
389394
}
395+
396+
@Test
397+
@DisplayName("방 생성 - WebRTC 활성화")
398+
void createRoom_WithWebRTC() {
399+
// given
400+
given(userRepository.findById(1L)).willReturn(Optional.of(testUser));
401+
given(roomRepository.save(any(Room.class))).willAnswer(invocation -> invocation.getArgument(0));
402+
given(roomMemberRepository.save(any(RoomMember.class))).willReturn(testMember);
403+
404+
// when
405+
Room createdRoom = roomService.createRoom(
406+
"WebRTC 방",
407+
"화상 채팅 가능",
408+
false,
409+
null,
410+
10,
411+
1L,
412+
true // WebRTC 사용
413+
);
414+
415+
// then
416+
assertThat(createdRoom).isNotNull();
417+
assertThat(createdRoom.isAllowCamera()).isTrue();
418+
assertThat(createdRoom.isAllowAudio()).isTrue();
419+
assertThat(createdRoom.isAllowScreenShare()).isTrue();
420+
}
421+
422+
@Test
423+
@DisplayName("방 생성 - WebRTC 비활성화")
424+
void createRoom_WithoutWebRTC() {
425+
// given
426+
given(userRepository.findById(1L)).willReturn(Optional.of(testUser));
427+
given(roomRepository.save(any(Room.class))).willAnswer(invocation -> invocation.getArgument(0));
428+
given(roomMemberRepository.save(any(RoomMember.class))).willReturn(testMember);
429+
430+
// when
431+
Room createdRoom = roomService.createRoom(
432+
"채팅 전용 방",
433+
"텍스트만 가능",
434+
false,
435+
null,
436+
50, // WebRTC 없으면 더 많은 인원 가능
437+
1L,
438+
false // WebRTC 미사용
439+
);
440+
441+
// then
442+
assertThat(createdRoom).isNotNull();
443+
assertThat(createdRoom.isAllowCamera()).isFalse();
444+
assertThat(createdRoom.isAllowAudio()).isFalse();
445+
assertThat(createdRoom.isAllowScreenShare()).isFalse();
446+
}
390447
}

0 commit comments

Comments
 (0)