调起通话完成
This commit is contained in:
@@ -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 {
|
||||
(ws as any).userInfo = {
|
||||
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);
|
||||
}
|
||||
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对多模式)
|
||||
* @param ws WebSocket连接实例
|
||||
@@ -563,4 +612,6 @@ function onMessage(ws: WebSocket, message: any): void {
|
||||
/**
|
||||
* 导出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 };
|
||||
|
||||
@@ -108,9 +108,9 @@ export default class WSSignaling {
|
||||
case 'host-userInfo':
|
||||
handler.onHostUserInfo(ws, msg.data);
|
||||
break;
|
||||
// case 'invite-call':
|
||||
// handler.onInviteCall(ws, msg.data);
|
||||
// break;
|
||||
case 'invite-call':
|
||||
handler.onInviteCall(ws, msg.data);
|
||||
break;
|
||||
// case 'invite-accepted':
|
||||
// handler.onInviteAccepted(ws, msg.data);
|
||||
// break;
|
||||
|
||||
Reference in New Issue
Block a user