Skip to content

Commit

Permalink
[BE] setting: webRTC 세팅 (#30)
Browse files Browse the repository at this point in the history
Signed-off-by: EunJiJung <[email protected]>
  • Loading branch information
bianbbc87 committed Feb 9, 2025
1 parent e9911d8 commit bf88a46
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/backend/signaling-server/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,20 @@ dependencies {
// mysql
runtimeOnly 'com.mysql:mysql-connector-j'
implementation 'org.springframework.boot:spring-boot-starter-data-redis'

// WebSocket
implementation 'org.springframework.boot:spring-boot-starter-websocket'

// sockjs
implementation 'org.webjars:sockjs-client:1.5.1'
// stomp
implementation 'org.webjars:stomp-websocket:2.3.4'
// gson
implementation 'com.google.code.gson:gson:2.9.0'

/* Kurento 미디어 서버 관련 2개 */
// https://mvnrepository.com/artifact/org.kurento/kurento-client
implementation group: 'org.kurento', name: 'kurento-client', version: '6.18.0'
}

dependencyManagement {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.asyncgate.signaling_server.config;

import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;
import org.springframework.web.socket.server.standard.ServletServerContainerFactoryBean;
import sun.misc.SignalHandler;

@Configuration
@EnableWebSocket // 웹 소켓에 대해 자동 설정
@RequiredArgsConstructor
public class WebRTCConfig implements WebSocketConfigurer {
// WebRTC 시그널링을 처리할 핸들러
private final SignalHandler signalHandler;

// WebSocket 핸들러 등록
@Override
public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
registry.addHandler(signalHandler, "/signal")
.setAllowedOrigins("*");
}

// WebSocket 텍스트 및 바이너리 버퍼 크기 설정
@Bean
public ServletServerContainerFactoryBean createWebSocketContainer() {
ServletServerContainerFactoryBean container = new ServletServerContainerFactoryBean();
container.setMaxTextMessageBufferSize(32768);
container.setMaxBinaryMessageBufferSize(32768);
return container;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.asyncgate.signaling_server.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.messaging.simp.config.MessageBrokerRegistry;
import org.springframework.web.socket.config.annotation.*;

@Configuration
@EnableWebSocketMessageBroker // 문자 채팅용
public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {

// 웹 소켓 연결을 위한 엔드포인트 설정 및 stomp sub/pub 엔드포인트 설정
@Override
public void registerStompEndpoints(StompEndpointRegistry registry) {
// stomp 접속 주소 url => /ws-stomp
registry.addEndpoint("/ws-stomp") // 연결될 엔드포인트
.withSockJS(); // SocketJS 를 연결한다는 설정
}

@Override
public void configureMessageBroker(MessageBrokerRegistry registry) {
// 메시지를 구독하는 요청 url => 즉 메시지 받을 때
registry.enableSimpleBroker("/sub");

// 메시지를 발행하는 요청 url => 즉 메시지 보낼 때
registry.setApplicationDestinationPrefixes("/pub");
}

}

0 comments on commit bf88a46

Please sign in to comment.