Skip to content

Commit afb6893

Browse files
committed
#90 chatforyou 서버 scaleout 대응 :: fallback 로직 수정 및 전체 코드 정리
1 parent 57577b7 commit afb6893

File tree

15 files changed

+46
-59
lines changed

15 files changed

+46
-59
lines changed

nodejs-frontend/static/js/rtc/dataChannelChatting.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
const dataChannelChatting = {
55
$element: $('.floating-chat'),
66
$sendMessageBtn : $('#sendMessageBtn'),
7-
$userTextInput : $('.text-box'),
7+
$userTextInput : $('#userTextInput'),
88
$messagesContainer : $('.messages'),
99
isCheckMinioPage : false,
1010
init: function() {
@@ -24,13 +24,16 @@ const dataChannelChatting = {
2424
self.$userTextInput.on('keydown', function(event) {
2525
if (event.shiftKey && event.which === 13) {
2626
// shift + enter 사용 시 한줄 띄우기
27-
} else if (event.which === 13) {
27+
} else if (event.which === 13 && self.$userTextInput.text().trim() !== '') {
2828
event.preventDefault(); // 기본 동작(한줄 띄우기)을 방지
2929
dataChannel.showNewMessage(self.parseMessage(self.$userTextInput), 'self');
3030
}
3131
});
3232

33-
this.$sendMessageBtn.on("click", function(){
33+
self.$sendMessageBtn.on("click", function(){
34+
if(self.$userTextInput.text().trim() === ''){
35+
return;
36+
}
3437
dataChannel.showNewMessage(self.parseMessage(self.$userTextInput), 'self');
3538
});
3639

nodejs-frontend/static/js/rtc/kurento-service.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,6 @@ function register() {
226226
// 방 정보를 서버에서 조회
227227
const url = window.__CONFIG__.API_BASE_URL + '/chat/room/' + new URLSearchParams(window.location.search).get('roomId');
228228
const successCallback = (response) => {
229-
debugger;
230229
if(response.result === 'REDIRECT_ROOM'){
231230
console.log('room redirect to : ', response.data.roomId);
232231
location.reload();

nodejs-frontend/templates/kurentoroom.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,8 @@ <h2 class="justify-content-md-center" id="room-header"></h2>
158158
<input type="file" id="file" style="display: none;"/>
159159
</div>
160160
</div>
161-
<div class="text-box" contenteditable="true" disabled="true"></div>
162-
<button id="sendMessage">send</button>
161+
<div class="text-box" id="userTextInput" contenteditable="true" disabled="true"></div>
162+
<button id="sendMessageBtn">send</button>
163163
</div>
164164
</div>
165165
</div>

springboot-backend/src/main/java/webChat/controller/ChatRoomController.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,9 @@
1010
import org.springframework.security.core.annotation.AuthenticationPrincipal;
1111
import org.springframework.ui.Model;
1212
import org.springframework.web.bind.annotation.*;
13-
import webChat.model.redis.DataType;
14-
import webChat.model.redis.RedisKeyPrefix;
1513
import webChat.model.response.ChatForYouResponseResult;
1614
import webChat.model.routing.RoomRoutingInfo;
1715
import webChat.model.routing.RoutingCookie;
18-
import webChat.service.redis.RedisService;
1916
import webChat.model.response.common.ChatForYouResponse;
2017
import webChat.model.room.ChatRoom;
2118
import webChat.model.room.RoomState;
@@ -40,7 +37,6 @@ public class ChatRoomController {
4037
private final ChatRoomService chatRoomService;
4138
private final RoutingService routingService;
4239
private final RoutingInstanceProvider instanceProvider;
43-
private final RedisService redisService;
4440

4541
// 채팅방 생성
4642
@PostMapping("/room")
@@ -77,13 +73,14 @@ public ResponseEntity<ChatForYouResponse> joinRoom(
7773
ChatRoom chatRoom = chatRoomService.findRoomById(roomId);
7874

7975
if (StringUtil.isNullOrEmpty(chatRoom.getInstanceId()) || !instanceProvider.isHealthy(chatRoom.getInstanceId())){
80-
// TODO 서버가 죽었을때 예외처리 필요 :: 임시 조치로 메인 대시보드로 이동
76+
// TODO 서버가 죽었을때 예외처리 필요 :: 방 삭제 및 임시 조치로 메인 대시보드로 이동
77+
chatRoomService.delChatRoom(roomId);
8178
return ResponseEntity.ok(ChatForYouResponse.ofRedirectRoom(chatRoom, ChatForYouResponseResult.REDIRECT_DASHBOARD));
8279
}
8380

8481

8582
if (!instanceProvider.getInstanceId().equals(chatRoom.getInstanceId())) {
86-
RoomRoutingInfo roomRoutingInfo = redisService.getRedisDataByDataType(RedisKeyPrefix.ROOM_ROUTING_PREFIX.getPrefix()+roomId, DataType.ROOM_ROUTING, RoomRoutingInfo.class);
83+
RoomRoutingInfo roomRoutingInfo = routingService.getRoomRoutingInfoByRoomId(roomId);
8784
int redirectCount = routingService.getRedirectCount(request);
8885
if(redirectCount > 3){
8986
return ResponseEntity.ok(ChatForYouResponse.ofRedirectRoom(chatRoom, ChatForYouResponseResult.REDIRECT_DASHBOARD));

springboot-backend/src/main/java/webChat/controller/HealthController.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package webChat.controller;
22

3-
import jakarta.servlet.http.HttpServletRequest;
43
import jakarta.servlet.http.HttpServletResponse;
54
import lombok.RequiredArgsConstructor;
65
import lombok.extern.slf4j.Slf4j;
@@ -12,7 +11,6 @@
1211
import webChat.model.routing.RoutingCookie;
1312
import webChat.service.routing.CookieCheckEvent;
1413
import webChat.service.routing.RoutingInstanceProvider;
15-
import webChat.service.routing.RoutingService;
1614
import webChat.utils.StringUtil;
1715

1816
/**
@@ -25,7 +23,6 @@
2523
public class HealthController {
2624
private final RoutingInstanceProvider instanceProvider;
2725
private final CookieCheckEvent cookieCheckEvent;
28-
private final RoutingService routingService;
2926

3027
@Value("${cookie.check.domain:}")
3128
private String cookieCheckDomain;
@@ -36,7 +33,7 @@ public class HealthController {
3633
* @return
3734
*/
3835
@GetMapping("/cookie")
39-
public ResponseEntity<String> cookieHealth(HttpServletRequest request, HttpServletResponse response) {
36+
public ResponseEntity<String> cookieHealth(HttpServletResponse response) {
4037
if (StringUtil.isNullOrEmpty(cookieCheckDomain)) { // 운영환경은 세팅, 로컬은 빈값
4138
response.addCookie(new jakarta.servlet.http.Cookie(RoutingCookie.CHATFORYOU_SERVER_COOKIE.getName(), instanceProvider.getInstanceId()));
4239
}

springboot-backend/src/main/java/webChat/controller/LoginController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import org.springframework.web.bind.annotation.RestController;
77

88
@RestController
9-
@RequestMapping("/chatforyou/api/file")
9+
@RequestMapping("/chatforyou/api/login")
1010
public class LoginController {
1111

1212
@GetMapping("/chatlogin")
Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package webChat.model.kafka;
22

3-
import com.fasterxml.jackson.annotation.JsonIgnore;
43
import lombok.AllArgsConstructor;
54
import lombok.Getter;
65
import lombok.NoArgsConstructor;
@@ -12,14 +11,4 @@
1211
@SuperBuilder
1312
public abstract class KafkaEvent {
1413
private long publishedAt;
15-
16-
// TODO 공통화 처리 필요
17-
// @JsonIgnore
18-
// public static KafkaServerEvent of(KafkaEvent event){
19-
// return (KafkaServerEvent) event;
20-
// }
21-
// @JsonIgnore
22-
// public static KafkaRoomEvent of(KafkaEvent event){
23-
// return (KafkaRoomEvent) event;
24-
// }
2514
}
Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
package webChat.model.kafka;
22

3-
import lombok.Getter;
4-
5-
// 키는 파티셔닝 전략에 맞게 명명
63
public class KafkaSendKey {
74
public static final String EVENT_TYPE = "event-type";
85
}

springboot-backend/src/main/java/webChat/model/kafka/KafkaServerEvent.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,6 @@ public static KafkaServerEvent createCookieDiscovered(String instanceId, String
7878
.build();
7979
}
8080

81-
public String getEventId() {
82-
return instanceId + "_" + eventType + "_" + getPublishedAt();
83-
}
84-
8581
/**
8682
* 쿠키 관련 이벤트인지 확인
8783
*/

springboot-backend/src/main/java/webChat/service/chatroom/ChatRoomService.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import org.springframework.stereotype.Service;
1010
import webChat.model.redis.RedisKeyPrefix;
1111
import webChat.model.routing.RoomRoutingInfo;
12-
import webChat.service.routing.InstanceProvider;
1312
import webChat.controller.ExceptionController;
1413
import webChat.model.chat.ChatType;
1514
import webChat.model.redis.DataType;

0 commit comments

Comments
 (0)