Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/signaling #41

Merged
merged 2 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ name: Java CI with Gradle & Deploy to EC2
# develop 브랜치에 push가 되면 아래의 flow가 실행됨
on:
# Triggers the workflow on push or pull request events but only for the "develop" branch
push:
branches: [ "develop" ]
pull_request:
branches: [ "develop" ]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,24 @@ public ResponseEntity<WebcamResponseDto.CreateWebcamDto> createWebcamRoom(@Reque
WebcamResponseDto.CreateWebcamDto response = webcamServcie.createWebcamRoom(request);
return ResponseEntity.status(HttpStatus.OK).body(response);
}

/**
* 방 입장 후 상대방 memberId 받기
*/
@Operation(summary = "화상채팅 상대방 정보를 조회합니다", description = "상대방의 memberId를 조회합니다",
responses = {
@ApiResponse(responseCode = "200", description = "화상채팅 방을 생성했습니다."),
@ApiResponse(responseCode = "400", description = "채팅 방을 생성하지 못했습니다.",
content = @Content(schema = @Schema(implementation = ErrorResponse.class))),
@ApiResponse(responseCode = "409", description = "올바르지 않은 닉네임, 올바르지 않은 이메일",
content = @Content(schema = @Schema(implementation = ErrorResponse.class)))
})
@GetMapping("/api/webcam/{webcamId}/remote")
public ResponseEntity<WebcamResponseDto.GetRemoteMemberDto> getRemoteMember(@PathVariable(value = "webcamId") Long webcamId) {
WebcamResponseDto.GetRemoteMemberDto response = webcamServcie.getRemoteMemberId(webcamId);
return ResponseEntity.status(HttpStatus.OK).body(response);
}

/**
* offer 정보를 주고받기 - step 5에서 offer를 받고 구독하고 있는 client들에게 전송
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,12 @@ public class WebcamResponseDto {
public static class CreateWebcamDto {
private Long webcamId; //화상채팅 방생성 id
}

@Builder
@Getter
@NoArgsConstructor(access = AccessLevel.PRIVATE)
@AllArgsConstructor(access = AccessLevel.PRIVATE)
public static class GetRemoteMemberDto {
private Long memberId;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@

public interface MemberWebcamRepository extends JpaRepository<MemberWebcam, Long> {
void deleteByWebcam(Webcam webcam);
List<Optional<MemberWebcam>> findByWebcam(Webcam webcam);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
public interface WebcamServcie {
WebcamResponseDto.CreateWebcamDto createWebcamRoom(WebcamRequestDto.CreateWebcamDto request);
void deleteWebcamRoom(WebcamRequestDto.DeleteWebcamDto request);
WebcamResponseDto.GetRemoteMemberDto getRemoteMemberId(Long webcamId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import vom.spring.domain.webcam.repository.WebcamRepository;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Optional;

@Service
@RequiredArgsConstructor
Expand Down Expand Up @@ -43,6 +45,9 @@ public WebcamResponseDto.CreateWebcamDto createWebcamRoom(WebcamRequestDto.Creat
return WebcamResponseDto.CreateWebcamDto.builder().webcamId(newWebcam.getId()).build();
}

/**
* 화상채팅 방 삭제
*/
@Transactional
@Override
public void deleteWebcamRoom(WebcamRequestDto.DeleteWebcamDto request) {
Expand All @@ -55,4 +60,25 @@ public void deleteWebcamRoom(WebcamRequestDto.DeleteWebcamDto request) {
//해당 방 삭제
webcamRepository.deleteById(webcam.getId());
}

/**
* 상대방 정보 조회
*/
@Override
public WebcamResponseDto.GetRemoteMemberDto getRemoteMemberId(Long webcamId) {
String email = SecurityContextHolder.getContext().getAuthentication().getName(); //현재 접속 유저 정보 가져오기
Member currentMember = memberRepository.findByEmail(email).orElseThrow(() -> new RuntimeException("존재하지 않은 유저입니다"));
Webcam webcam = webcamRepository.findById(webcamId).orElseThrow(() -> new IllegalArgumentException("존재하지 않은 webcam 입니다"));
List<Optional<MemberWebcam>> memberWebcams = memberWebcamRepository.findByWebcam(webcam);
Member remoteMember= null;
for (Optional<MemberWebcam> memberWebcam : memberWebcams) {
if (memberWebcam.get().getMember() != currentMember) {
remoteMember = memberWebcam.get().getMember();
}
}
if (remoteMember == null){
throw new IllegalArgumentException("존재하지 않은 유저입니다");
}
return WebcamResponseDto.GetRemoteMemberDto.builder().memberId(remoteMember.getId()).build();
}
}
Loading