Skip to content

Commit

Permalink
Merge pull request TeamMajorLink#53 from kimdavid0521/feat#50
Browse files Browse the repository at this point in the history
화상채팅 기능 구현(WebRTC + websocket)
  • Loading branch information
kimdavid0521 authored Aug 19, 2024
2 parents 2e70dc3 + ff8aab0 commit 4c5d792
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 1 deletion.
3 changes: 3 additions & 0 deletions majorLink/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ dependencies {

// iamport 결제
implementation 'com.github.iamport:iamport-rest-client-java:0.2.23'

//web rtc 화상채팅
implementation 'com.fasterxml.jackson.core:jackson-databind'
}

tasks.named('test') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ public class WebConfig implements WebMvcConfigurer {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedOrigins("http://localhost:3000", "http://localhost:3007","http://localhost:3008") //프론트 테스트 url입니다.
.allowedOrigins("http://localhost:3000",
"http://localhost:3007","http://localhost:3008",
"http://localhost:59923",
"http://localhost:3003",
"http://localhost:3004"
) //프론트 테스트 url입니다.
.allowedMethods("POST", "GET", "DELETE", "PUT", "PATCH")
.allowedHeaders("*");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.example.majorLink.global.config;

import com.example.majorLink.handler.VideoChatWebSocketHandler;
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;

@Configuration
@EnableWebSocket
public class WebSocketLiveConfig implements WebSocketConfigurer {

//화상채팅
@Override
public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
registry.addHandler(new VideoChatWebSocketHandler(), "/ws/video-chat").setAllowedOrigins("*");

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.example.majorLink.handler;

import org.springframework.web.socket.CloseStatus;
import org.springframework.web.socket.TextMessage;
import org.springframework.web.socket.WebSocketSession;
import org.springframework.web.socket.handler.TextWebSocketHandler;

import java.util.HashSet;
import java.util.Set;

public class VideoChatWebSocketHandler extends TextWebSocketHandler {

private final Set<WebSocketSession> sessions = new HashSet<>();

@Override
public void afterConnectionEstablished(WebSocketSession session) throws Exception {
sessions.add(session);
}

@Override
public void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception {
for (WebSocketSession webSocketSession : sessions) {
if(webSocketSession.isOpen() && !webSocketSession.equals(session)) {
webSocketSession.sendMessage(message);
}
}
}

@Override
public void afterConnectionClosed(WebSocketSession session, CloseStatus status) throws Exception {
sessions.remove(session);
}
}

0 comments on commit 4c5d792

Please sign in to comment.