【m】聊天消息接入

This commit is contained in:
zhangzheng
2026-03-12 12:10:40 +08:00
parent b4c41e42c9
commit e9f7b3ad5c
7 changed files with 425 additions and 359 deletions

View File

@@ -366,7 +366,7 @@ function onCandidate(ws: WebSocket, message: any): void {
* @param ws WebSocket连接实例
* @param message 消息数据
*/
function onChatMessage(ws: WebSocket, message: any): void {
function onMessage(ws: WebSocket, message: any): void {
// 获取连接ID
const connectionId = message.connectionId;
const chatMessage = message.message;
@@ -376,11 +376,11 @@ function onCandidate(ws: WebSocket, message: any): void {
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 }));
otherSessionWs.send(JSON.stringify({ from: connectionId, to: "", type: "on-message", data: chatMessage }));
}
}
}
/**
* 导出WebSocket处理器函数
*/
export { reset, add, remove, onConnect, onDisconnect, onOffer, onAnswer, onCandidate, onCallConnectionId, onBroadcast, onGetAllConnectionIds, AddHeartbeat, RemoveHeartbeat ,onChatMessage};
export { reset, add, remove, onConnect, onDisconnect, onOffer, onAnswer, onCandidate, onCallConnectionId, onBroadcast, onGetAllConnectionIds, AddHeartbeat, RemoveHeartbeat ,onMessage};

View File

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