解决打包失败问题,去掉print
This commit is contained in:
@@ -1,14 +1,18 @@
|
|||||||
package com.ttstd.signaling;
|
package com.ttstd.signaling;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
public class WebRtcSignalingApplication {
|
public class WebRtcSignalingApplication {
|
||||||
|
|
||||||
|
static Logger logger = LoggerFactory.getLogger(WebRtcSignalingApplication.class);
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
SpringApplication.run(WebRtcSignalingApplication.class, args);
|
SpringApplication.run(WebRtcSignalingApplication.class, args);
|
||||||
System.out.println("✅ WebRTC信令服务器启动成功!WebSocket连接地址:ws://localhost:2310/ws/rtc?userId=xxx");
|
logger.info("✅ WebRTC信令服务器启动成功!WebSocket连接地址:ws://localhost:2310/ws/rtc?userId=xxx");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ package com.ttstd.signaling.handler;
|
|||||||
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.ttstd.signaling.entity.RtcSignalMessage;
|
import com.ttstd.signaling.entity.RtcSignalMessage;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.web.socket.CloseStatus;
|
import org.springframework.web.socket.CloseStatus;
|
||||||
import org.springframework.web.socket.TextMessage;
|
import org.springframework.web.socket.TextMessage;
|
||||||
@@ -19,6 +21,8 @@ import java.util.concurrent.ConcurrentHashMap;
|
|||||||
@Component
|
@Component
|
||||||
public class WebRtcSignalHandler extends TextWebSocketHandler {
|
public class WebRtcSignalHandler extends TextWebSocketHandler {
|
||||||
|
|
||||||
|
Logger logger = LoggerFactory.getLogger(WebRtcSignalHandler.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 核心:维护在线用户的WebSocket会话映射
|
* 核心:维护在线用户的WebSocket会话映射
|
||||||
* key: 用户ID(userId)
|
* key: 用户ID(userId)
|
||||||
@@ -41,7 +45,7 @@ public class WebRtcSignalHandler extends TextWebSocketHandler {
|
|||||||
if (userId != null && !userId.isEmpty()) {
|
if (userId != null && !userId.isEmpty()) {
|
||||||
// 将用户会话存入在线列表
|
// 将用户会话存入在线列表
|
||||||
ONLINE_USER_SESSIONS.put(userId, session);
|
ONLINE_USER_SESSIONS.put(userId, session);
|
||||||
System.out.println("用户[" + userId + "] 上线,当前在线人数:" + ONLINE_USER_SESSIONS.size());
|
logger.info("用户[" + userId + "] 上线,当前在线人数:" + ONLINE_USER_SESSIONS.size());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,7 +71,7 @@ public class WebRtcSignalHandler extends TextWebSocketHandler {
|
|||||||
if (targetSession != null && targetSession.isOpen()) {
|
if (targetSession != null && targetSession.isOpen()) {
|
||||||
// 将信令消息原样转发给目标用户
|
// 将信令消息原样转发给目标用户
|
||||||
targetSession.sendMessage(new TextMessage(objectMapper.writeValueAsString(signalMessage)));
|
targetSession.sendMessage(new TextMessage(objectMapper.writeValueAsString(signalMessage)));
|
||||||
System.out.println("信令中转成功:[" + fromUserId + "] -> [" + toUserId + "] 类型:" + signalType);
|
logger.info("信令中转成功:[" + fromUserId + "] -> [" + toUserId + "] 类型:" + signalType);
|
||||||
} else {
|
} else {
|
||||||
// 目标用户不在线/连接已关闭
|
// 目标用户不在线/连接已关闭
|
||||||
sendErrorMessage(session, "目标用户[" + toUserId + "] 不在线或连接已断开");
|
sendErrorMessage(session, "目标用户[" + toUserId + "] 不在线或连接已断开");
|
||||||
@@ -82,7 +86,7 @@ public class WebRtcSignalHandler extends TextWebSocketHandler {
|
|||||||
String userId = getUserIdFromSession(session);
|
String userId = getUserIdFromSession(session);
|
||||||
if (userId != null) {
|
if (userId != null) {
|
||||||
ONLINE_USER_SESSIONS.remove(userId);
|
ONLINE_USER_SESSIONS.remove(userId);
|
||||||
System.out.println("用户[" + userId + "] 下线,当前在线人数:" + ONLINE_USER_SESSIONS.size());
|
logger.info("用户[" + userId + "] 下线,当前在线人数:" + ONLINE_USER_SESSIONS.size());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -94,7 +98,7 @@ public class WebRtcSignalHandler extends TextWebSocketHandler {
|
|||||||
String userId = getUserIdFromSession(session);
|
String userId = getUserIdFromSession(session);
|
||||||
if (userId != null) {
|
if (userId != null) {
|
||||||
ONLINE_USER_SESSIONS.remove(userId);
|
ONLINE_USER_SESSIONS.remove(userId);
|
||||||
System.out.println("用户[" + userId + "] 连接异常,已移除会话,异常信息:" + exception.getMessage());
|
logger.error("用户[" + userId + "] 连接异常,已移除会话,异常信息:" + exception.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
spring.application.name=WebRTCSignaling
|
spring.application.name=WebRTCSignaling
|
||||||
server.port=2310
|
server.port=5156
|
||||||
Reference in New Issue
Block a user