This commit is contained in:
zhangzheng
2026-03-10 19:09:41 +08:00
parent ca23a771b3
commit b4c41e42c9
4 changed files with 73 additions and 46 deletions

View File

@@ -361,8 +361,26 @@ function onCandidate(ws: WebSocket, message: any): void {
// }));
return connectionIds;
}
/**
* 处理chat-message信令
* @param ws WebSocket连接实例
* @param message 消息数据
*/
function onChatMessage(ws: WebSocket, message: any): void {
// 获取连接ID
const connectionId = message.connectionId;
const chatMessage = message.message;
if (connectionPair.has(connectionId)) {
const pair = connectionPair.get(connectionId);
// 找到另一个WebSocket实例
const otherSessionWs = pair[0] == ws ? pair[1] : pair[0];
if (otherSessionWs) {
// 发送chat-message消息
otherSessionWs.send(JSON.stringify({ from: connectionId, to: "", type: "chat-message", data: chatMessage }));
}
}
}
/**
* 导出WebSocket处理器函数
*/
export { reset, add, remove, onConnect, onDisconnect, onOffer, onAnswer, onCandidate, onCallConnectionId, onBroadcast, onGetAllConnectionIds, AddHeartbeat, RemoveHeartbeat };
export { reset, add, remove, onConnect, onDisconnect, onOffer, onAnswer, onCandidate, onCallConnectionId, onBroadcast, onGetAllConnectionIds, AddHeartbeat, RemoveHeartbeat ,onChatMessage};

View File

@@ -108,6 +108,10 @@ export default class WSSignaling {
// 处理callConnectionId信令
handler.onCallConnectionId(ws, msg.data);
break;
case 'chat-message'://接受连接ConnectionId
// 处理chat-message信令
handler.onChatMessage(ws, msg.data);
break;
default:
// 忽略未知消息类型
break;