Skip to content

Commit

Permalink
Merge branch 'develop' into feature/fcm
Browse files Browse the repository at this point in the history
  • Loading branch information
okodeee authored Jun 11, 2024
2 parents 5903d7b + f81c87e commit 011b9f7
Show file tree
Hide file tree
Showing 11 changed files with 169 additions and 138 deletions.
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
7 changes: 5 additions & 2 deletions src/main/java/vom/spring/domain/album/AlbumService.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.io.IOException;
import java.time.LocalDateTime;
import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;

@Service
Expand All @@ -41,19 +42,21 @@ public void setS3Client(AmazonS3Client amazonS3Client) {
@Transactional
public void uploadAlbum(Long memberId, MultipartFile multipartFile) throws IOException {
Homepy homepy = homepyRepository.findByMember_id(memberId);

String originalFilename = multipartFile.getOriginalFilename();
String uniqueFilename = UUID.randomUUID().toString();

ObjectMetadata metadata = new ObjectMetadata();
metadata.setContentLength(multipartFile.getSize());
metadata.setContentType(multipartFile.getContentType());

amazonS3Client.putObject(bucket, originalFilename, multipartFile.getInputStream(), metadata);
amazonS3Client.putObject(bucket, uniqueFilename, multipartFile.getInputStream(), metadata);

albumRepository.save(
Album.builder()
.homepy(homepy)
.name(originalFilename)
.img_url(amazonS3Client.getUrl(bucket, originalFilename).toString())
.img_url(amazonS3Client.getUrl(bucket, uniqueFilename).toString())
.createdAt(LocalDateTime.now())
.build()
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@
import org.springframework.messaging.simp.SimpMessageHeaderAccessor;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.web.ErrorResponse;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import vom.spring.domain.webcam.domain.Message;
import vom.spring.domain.webcam.dto.WebcamRequestDto;
import vom.spring.domain.webcam.dto.WebcamResponseDto;
Expand All @@ -28,15 +25,14 @@

import java.io.IOException;

@Tag(name = "화상채팅(시그널링) API", description = "유저 API 명세서")
@Tag(name = "화상채팅(시그널링) API", description = "화상채팅 API 명세서")
@RestController
@RequiredArgsConstructor
@Slf4j
//db에 webcam 업데이트 로직 필요
public class WebcamController {
private final WebcamServcie webcamServcie;
private final SimpMessagingTemplate messagingTemplate;
private final FcmService fcmService;
// private final SimpMessagingTemplate messagingTemplate;
/**
* 방 생성
*/
Expand All @@ -58,62 +54,61 @@ public ResponseEntity<WebcamResponseDto.CreateWebcamDto> createWebcamRoom(@Reque
* offer 정보를 주고받기 - step 5에서 offer를 받고 구독하고 있는 client들에게 전송
*/
@MessageMapping("/peer/offer/{webcamId}") //해당 경로로 메시지가 날아오면 해당 메서드 실행해서 리턴, /app/~~이런식으로 전달된다
//camKey : 각 요청하는 캠의 key , roomId : 룸 아이디 =>룸 id를 webcam id로 수정
public void PeerHandleOffer(@Payload Message message, SimpMessageHeaderAccessor headerAccessor) {
log.info("offer받은 webcamId:"+ message.getWebcamId()+"offer받은 sender:"+ message.getSender());
messagingTemplate.convertAndSend("/topic/peer/offer/" +message.getWebcamId(), message);
@SendTo("/topic/peer/offer/{webcamId}")
public Message PeerHandleOffer(Message message, @DestinationVariable(value = "webcamId") String webcamId) {
log.info("offer 메세지 왔다, sender: {}, 전달할 webcamId는: {}", message.getSender(),message.getWebcamId());
// messagingTemplate.convertAndSend("/topic/peer/offer/" +message.getWebcamId(), message);
return message;
}

/**
* iceCandidate 정보를 주고 받기 위한 websocket
*/
@MessageMapping("/peer/iceCandidate/{webcamId}")
public void PeerHandleIceCandidate(@Payload Message message, SimpMessageHeaderAccessor headerAccessor) {
log.info("ice받은 webcamId:"+ message.getWebcamId()+"ice받은 sender:"+ message.getSender());
messagingTemplate.convertAndSend("/topic/peer/iceCandidate/" + message.getWebcamId(), message);
@SendTo("/topic/peer/iceCandidate/{webcamId}")
public Message PeerHandleIceCandidate(Message message, @DestinationVariable(value = "webcamId") String webcamId) {
log.info("[ICECANDIDATE] sender: {}, candidate 정보: {}, 전달할 webcamId: {}", message.getSender(), message.getIce(), message.getWebcamId());
// messagingTemplate.convertAndSend("/topic/peer/iceCandidate/" + message.getWebcamId(), message);
return message;
}

/**
* answer 정보 주고받기
*/
@MessageMapping("/peer/answer/{webcamId}")
public void PeerHandleAnswer(@Payload Message message, SimpMessageHeaderAccessor simpMessageHeaderAccessor ) {
log.info("answer받은 webcamId:"+ message.getWebcamId()+"answer받은 sender:"+ message.getSender());
messagingTemplate.convertAndSend("/topic/peer/answer/" + message.getWebcamId(), message);
@SendTo("/topic/peer/answer/{webcamId}")
public Message PeerHandleAnswer(Message message, @DestinationVariable(value = "webcamId") String webcamId) {
log.info("[ANSWER] sender: {}, 전달할 곳 : {} ", message.getSender(), message.getAnswer());
// messagingTemplate.convertAndSend("/topic/peer/answer/" + message.getWebcamId(), message);
return message;
}

// /**
// * camKey 를 받기위해 신호를 보내는 webSocket
// */
// @Operation(summary = "camKey를 받기 위해 신호를 보냄", description = "client의 camKey 정보를 주고 받기 위해 신호를 보냅니다",
// responses = {
// @ApiResponse(responseCode = "201", description = "계정 생성 완료"),
// @ApiResponse(responseCode = "400", description = "존재하지 않은 직업, 존재하지 않은 주소",
// content = @Content(schema = @Schema(implementation = ErrorResponse.class))),
// @ApiResponse(responseCode = "409", description = "올바르지 않은 닉네임, 올바르지 않은 이메일",
// content = @Content(schema = @Schema(implementation = ErrorResponse.class)))
// })
// @MessageMapping("/call/key")
// @SendTo("/topic/call/key")
// public String callKey(@Payload String message) {
// log.info("[Key] : {}", message);
// return message;
// }
//
// /**
// * 자신의 camKey 를 모든 연결된 세션에 보내는 webSocket
// */
// @Operation(summary = "camKey를 모든 연결된 세션에 보냄", description = "client의 camKey를 연결된 모든 peer에게 보냅니다",
// 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)))
// })
// @MessageMapping("/send/key")
// @SendTo("/topic/send/key")
// public String sendKey(@Payload String message) {
// return message;
// }
/**
* leave 정보 주고받기
*/
@MessageMapping("/peer/leaveRoom/{webcamId}")
@SendTo("/topic/peer/leaveRoom/{webcamId}")
public Message PeerHandleLeave(Message message, @DestinationVariable(value = "webcamId") String webcamId) {
log.info("[LEAVE] sender: {}, 전달할 곳 : {} ", message.getSender(), message.getWebcamId());
// messagingTemplate.convertAndSend("/topic/peer/answer/" + message.getWebcamId(), message);
return message;
}

/**
* 방 삭제
*/
@Operation(summary = "화상채팅 방을 삭제합니다", description = "화상채팅 방을 삭제합니다",
responses = {
@ApiResponse(responseCode = "200", description = "화상채팅 방을 삭제했습니다."),
@ApiResponse(responseCode = "400", description = "채팅 방을 삭제하지 못했습니다.",
content = @Content(schema = @Schema(implementation = ErrorResponse.class))),
@ApiResponse(responseCode = "404", description = "채팅 방을 찾지 못했습니다",
content = @Content(schema = @Schema(implementation = ErrorResponse.class)))
})
@DeleteMapping("/api/webcam")
public ResponseEntity<Void> deleteWebcamRoom(@RequestBody WebcamRequestDto.DeleteWebcamDto request) {
System.out.print("방id: " + request.getRoomId());
webcamServcie.deleteWebcamRoom(request);
return ResponseEntity.status(HttpStatus.OK).build();
}
}
2 changes: 1 addition & 1 deletion src/main/java/vom/spring/domain/webcam/domain/Type.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package vom.spring.domain.webcam.domain;

public enum Type {
OFFER, ANSWER, ENTER, ICE
OFFER, ANSWER, ENTER, ICE, LEAVE
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,12 @@ public class WebcamRequestDto {
public static class CreateWebcamDto {
private Long toMemberId; //화상 채팅 요청받은 유저의 id
}

@Builder
@Getter
@NoArgsConstructor(access = AccessLevel.PRIVATE)
@AllArgsConstructor(access = AccessLevel.PRIVATE)
public static class DeleteWebcamDto {
private Long roomId;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

import org.springframework.data.jpa.repository.JpaRepository;
import vom.spring.domain.webcam.domain.MemberWebcam;
import vom.spring.domain.webcam.domain.Webcam;

import java.util.List;
import java.util.Optional;

public interface MemberWebcamRepository extends JpaRepository<MemberWebcam, Long> {

void deleteByWebcam(Webcam webcam);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,11 @@
import org.springframework.data.jpa.repository.JpaRepository;
import vom.spring.domain.webcam.domain.Webcam;

import java.util.Optional;

public interface WebcamRepository extends JpaRepository<Webcam, Long> {

Optional<Webcam> findById(Long webcamId);

void deleteById(Long webcamId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@

public interface WebcamServcie {
WebcamResponseDto.CreateWebcamDto createWebcamRoom(WebcamRequestDto.CreateWebcamDto request);
void deleteWebcamRoom(WebcamRequestDto.DeleteWebcamDto request);
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,17 @@ public WebcamResponseDto.CreateWebcamDto createWebcamRoom(WebcamRequestDto.Creat
memberWebcamRepository.save(toMemberWebcam);
return WebcamResponseDto.CreateWebcamDto.builder().webcamId(newWebcam.getId()).build();
}

@Transactional
@Override
public void deleteWebcamRoom(WebcamRequestDto.DeleteWebcamDto request) {
String email = SecurityContextHolder.getContext().getAuthentication().getName(); //현재 접속 유저 정보 가져오기
Member fromMember = memberRepository.findByEmail(email).orElseThrow(() -> new RuntimeException("존재하지 않은 유저입니다"));
//해당 방 찾기
Webcam webcam = webcamRepository.findById(request.getRoomId()).orElseThrow(() -> new IllegalArgumentException("존재하지 않은 방입니다"));
//해당 방 관련 연관관계 삭제
memberWebcamRepository.deleteByWebcam(webcam);
//해당 방 삭제
webcamRepository.deleteById(webcam.getId());
}
}
Loading

0 comments on commit 011b9f7

Please sign in to comment.