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

dev -> main #174

Merged
merged 3 commits into from
May 12, 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
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,18 @@ public void endCodingTest(
);
}

@MessageMapping("/chat/volume")
public void volume(
MessageRequest messageRequestDto,
@Header("Authorization") String authorization
) {
chatService.volume(
messageRequestDto.getRoomShortUuid(),
tempParseMemberIdFromHeader(authorization),
messageRequestDto.getMessage()
);
}

@MessageExceptionHandler
public String exception() {
return "Error has occurred.";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,12 @@ public static MessageResponse endCoding(Long memberId) {
null
);
}

public static MessageResponse volume(Long memberId, String message) {
return new MessageResponse(
memberId,
MessageType.VOLUME,
message
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ public enum MessageType {
UNREADY_ROOM("unready"),
CHANGE_HOST("change-host"),
START_CODING("start-coding"),
END_CODING("end-coding");
END_CODING("end-coding"),
VOLUME("volume");

@JsonValue
private final String value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@ public interface ChatService {
void startCodingTest(String roomShortUuid, Long memberId);

void endCodingTest(String roomShortUuid, Long memberId);

void volume(String roomShortUuid, Long memberId, String message);
}
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ public void endCodingTest(String roomShortUuid, Long memberId) {
messageService.sendMessage(roomShortUuid, MessageResponse.endCoding(memberId));
}

@Override
public void volume(String roomShortUuid, Long memberId, String message) {
messageService.sendMessage(roomShortUuid, MessageResponse.volume(memberId, message));
}

private void checkMemberIsHost(String roomShortUuid, Long memberId) {
roomMemberService.validateHost(roomShortUuid, memberId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ public Message<?> preSend(Message<?> message, MessageChannel channel) {
accessor.getCommand() == StompCommand.SEND) {
try {
String token = extractToken(accessor);
if (token == null || !jwtProvider.validateToken(token)) {
log.warn("토큰 null or 유효하지 않은 토큰");
if (!jwtProvider.validateToken(token)) {
log.warn("jwtProvider에서 validate 하지 못한 값");
throw new IllegalArgumentException("Invalid token");
}
} catch (Exception e) {
Expand All @@ -42,8 +42,12 @@ public Message<?> preSend(Message<?> message, MessageChannel channel) {

private String extractToken(StompHeaderAccessor accessor) {
String authorization = accessor.getFirstNativeHeader(AUTHORIZATION_HEADER);
if (authorization == null || !authorization.startsWith(BEARER_PREFIX)) {
throw new IllegalArgumentException("Invalid token");
if (authorization == null) {
log.warn("토큰이 null 입니다.");
throw new IllegalArgumentException("token is null");
} else if (!authorization.startsWith(BEARER_PREFIX)) {
log.warn("Bearer 로 시작하지 않는 토큰입니다.");
throw new IllegalArgumentException("invalid token");
}
return authorization.substring(BEARER_PREFIX.length());
}
Expand Down
Loading