debugging eingebaut, deploy gefixt
All checks were successful
Deploy SingleChat / deploy (push) Successful in 25s

This commit is contained in:
Torsten Schulz (local)
2026-06-17 16:37:40 +02:00
parent c46e64367d
commit 0d24fcd9e5
7 changed files with 187 additions and 26 deletions

View File

@@ -418,9 +418,19 @@ function buildVideoCallPayloadForUser(session, userName) {
function emitVideoCallEventToUser(userName, eventName, session) {
const client = getClientByUserName(userName);
if (!isClientOnline(client)) return;
console.log('[video] emit', eventName, {
to: userName,
callId: session.callId,
withUserName: getOtherParticipant(session, userName),
status: session.status
});
client.socket.emit(eventName, buildVideoCallPayloadForUser(session, userName));
}
function logVideo(message, details = {}) {
console.log('[video]', message, details);
}
function emitVideoCapacityToUser(userName) {
const client = getClientByUserName(userName);
if (!isClientOnline(client)) return;
@@ -503,6 +513,7 @@ function finalizeVideoSession(session) {
}
function sendVideoCallError(socket, code, message, details = {}) {
logVideo('error', { code, message, ...details });
socket.emit('videoCall:error', {
code,
message,
@@ -1874,6 +1885,7 @@ export function setupBroadcast(io, __dirname) {
function handleVideoCallInvite(socket, client, data) {
const withUserName = String(data?.withUserName || '').trim();
logVideo('invite:request', { from: client.userName, withUserName });
if (!withUserName || withUserName === client.userName) {
sendVideoCallError(socket, 'VIDEO_INVALID_PARTNER', 'Ungültiger Gesprächspartner.');
return;
@@ -1916,6 +1928,7 @@ export function setupBroadcast(io, __dirname) {
const session = createVideoSession(client.userName, withUserName);
registerVideoSession(session);
logVideo('invite:created', { callId: session.callId, from: client.userName, withUserName, status: session.status });
emitVideoCallEventToUser(client.userName, 'videoCall:invite', session);
emitVideoCallEventToUser(withUserName, 'videoCall:incoming', session);
@@ -1926,6 +1939,7 @@ export function setupBroadcast(io, __dirname) {
function handleVideoCallAccept(socket, client, data) {
const callId = String(data?.callId || '').trim();
const session = videoSessions.get(callId);
logVideo('accept:request', { from: client.userName, callId });
if (!session || session.status !== 'ringing' || !session.participants.includes(client.userName)) {
sendVideoCallError(socket, 'VIDEO_CALL_NOT_FOUND', 'Videoanruf nicht gefunden.', { callId });
@@ -1955,6 +1969,7 @@ export function setupBroadcast(io, __dirname) {
}
touchVideoSession(session, 'connecting');
logVideo('accept:connecting', { callId: session.callId, participants: session.participants });
emitVideoCallEventToUser(session.participants[0], 'videoCall:start', session);
emitVideoCallEventToUser(session.participants[1], 'videoCall:start', session);
emitVideoCapacityToUser(session.participants[0]);
@@ -2044,6 +2059,7 @@ export function setupBroadcast(io, __dirname) {
const callId = String(data?.callId || '').trim();
const signalType = String(data?.signalType || '').trim();
const session = videoSessions.get(callId);
logVideo('signal:received', { from: client.userName, callId, signalType });
if (!session || !ACTIVE_VIDEO_SESSION_STATUSES.has(session.status) || !session.participants.includes(client.userName)) {
sendVideoCallError(socket, 'VIDEO_CALL_NOT_FOUND', 'Videoanruf nicht gefunden.', { callId });
@@ -2061,6 +2077,7 @@ export function setupBroadcast(io, __dirname) {
const description = data?.description;
const descriptionType = String(description?.type || '').trim();
const sdp = String(description?.sdp || '').trim();
logVideo('signal:description', { from: client.userName, to: otherUserName, callId, descriptionType, sdpLength: sdp.length });
if (!descriptionType || !sdp || !['offer', 'answer'].includes(descriptionType)) {
sendVideoCallError(socket, 'VIDEO_SIGNAL_INVALID_DESCRIPTION', 'Ungültige Video-Signalisierung.', { callId });
return;
@@ -2077,6 +2094,13 @@ export function setupBroadcast(io, __dirname) {
if (signalType === 'candidate') {
const candidate = data?.candidate;
logVideo('signal:candidate', {
from: client.userName,
to: otherUserName,
callId,
candidateType: candidate?.type || null,
candidateSnippet: String(candidate?.candidate || '').slice(0, 120)
});
if (!isRelayIceCandidate(candidate)) {
sendVideoCallError(socket, 'VIDEO_SIGNAL_NON_RELAY_CANDIDATE', 'Nur Relay-Kandidaten sind für Videochat erlaubt.', { callId });
return;
@@ -2092,6 +2116,7 @@ export function setupBroadcast(io, __dirname) {
const callId = String(data?.callId || '').trim();
const nextState = String(data?.connectionState || '').trim().toLowerCase();
const session = videoSessions.get(callId);
logVideo('connection-state', { from: client.userName, callId, nextState });
if (!session || !ACTIVE_VIDEO_SESSION_STATUSES.has(session.status) || !session.participants.includes(client.userName)) {
sendVideoCallError(socket, 'VIDEO_CALL_NOT_FOUND', 'Videoanruf nicht gefunden.', { callId });
@@ -2117,6 +2142,7 @@ export function setupBroadcast(io, __dirname) {
session.participants.every((participant) => session.connectionStates[participant] === 'connected')
) {
touchVideoSession(session, 'active');
logVideo('connection-state:active', { callId: session.callId, participants: session.participants });
}
emitVideoCallUpdateToParticipants(session);