调起通话完成

This commit is contained in:
2026-05-18 23:29:48 +08:00
parent 85c0b0226d
commit 52b5faf5a7
2 changed files with 55 additions and 4 deletions

View File

@@ -378,6 +378,11 @@ function onCallConnectionId(ws: WebSocket, message: any): void {
}); });
} }
} }
/**
* 处理host-userInfo消息更新host的用户信息
* @param ws WebSocket连接实例
* @param message 消息数据
*/
function onHostUserInfo(ws: WebSocket, message: any): void { function onHostUserInfo(ws: WebSocket, message: any): void {
(ws as any).userInfo = { (ws as any).userInfo = {
id: message.id || '', id: message.id || '',
@@ -387,7 +392,51 @@ function onHostUserInfo(ws: WebSocket, message: any): void {
log(LogLevel.log, 'Updated current ws userInfo:', (ws as any).userInfo); log(LogLevel.log, 'Updated current ws userInfo:', (ws as any).userInfo);
} }
function onInviteCall(ws: WebSocket, message: any): void {
const connectionId = message.connectionId as string;
const targetSocketId = message.targetSocketId as string;
const targetUserId = message.targetUserId as string;
let targetWs: WebSocket = null;
clients.forEach((_connectionIds, clientWs) => {
if (targetWs || clientWs === ws) {
return;
}
const userInfo = ((clientWs as any).userInfo || {}) as UserInfo;
if ((targetSocketId && (clientWs as any).socketId === targetSocketId) ||
(targetUserId && userInfo.id === targetUserId)) {
targetWs = clientWs;
}
});
if (!targetWs) {
ws.send(JSON.stringify({
type: 'invite-failed',
data: {
connectionId,
reason: 'target-offline'
}
}));
log(LogLevel.warn, `invite-call target not found: socketId=${targetSocketId}, userId=${targetUserId}`);
return;
}
targetWs.send(JSON.stringify({
type: 'invite-call',
data: {
connectionId,
inviterSocketId: (ws as any).socketId || '',
inviterUserId: message.inviterUserId || (((ws as any).userInfo || {}) as UserInfo).id || '',
inviterName: message.inviterName || (((ws as any).userInfo || {}) as UserInfo).name || '邀请方',
inviterAvatar: message.inviterAvatar || (((ws as any).userInfo || {}) as UserInfo).avatar || '',
targetSocketId: targetSocketId || '',
targetUserId: targetUserId || ''
}
}));
log(LogLevel.log, `Forwarded invite-call to socketId=${targetSocketId}, userId=${targetUserId}, connectionId=${connectionId}`);
}
/** /**
* 处理广播消息请求1对多模式 * 处理广播消息请求1对多模式
* @param ws WebSocket连接实例 * @param ws WebSocket连接实例
@@ -563,4 +612,6 @@ function onMessage(ws: WebSocket, message: any): void {
/** /**
* 导出WebSocket处理器函数 * 导出WebSocket处理器函数
*/ */
export { reset, add, remove, onConnect, onDisconnect, onOffer, onAnswer, onCandidate, onCallConnectionId, onBroadcast, onGetAllConnectionIds, onGetOnlineUsers, AddHeartbeat, RemoveHeartbeat, onMessage, isHost, broadcastToGroup, connectionGroup, onHostUserInfo }; export { reset, add, remove, onConnect, onDisconnect, onOffer, onAnswer, onCandidate, onCallConnectionId,
onBroadcast, onGetAllConnectionIds, onGetOnlineUsers, AddHeartbeat, RemoveHeartbeat, onMessage, isHost,
broadcastToGroup, connectionGroup, onHostUserInfo, onInviteCall };

View File

@@ -108,9 +108,9 @@ export default class WSSignaling {
case 'host-userInfo': case 'host-userInfo':
handler.onHostUserInfo(ws, msg.data); handler.onHostUserInfo(ws, msg.data);
break; break;
// case 'invite-call': case 'invite-call':
// handler.onInviteCall(ws, msg.data); handler.onInviteCall(ws, msg.data);
// break; break;
// case 'invite-accepted': // case 'invite-accepted':
// handler.onInviteAccepted(ws, msg.data); // handler.onInviteAccepted(ws, msg.data);
// break; // break;