[call-me] - improve handle screen status

This commit is contained in:
Miroslav Pejic
2025-08-25 13:28:10 +02:00
parent 6c1ceb58bd
commit f31a215a8e
4 changed files with 112 additions and 91 deletions
+34 -9
View File
@@ -404,13 +404,14 @@ function handleConnection(socket) {
if (!users.has(name)) {
users.set(name, socket);
socket.username = name;
// Initialize user media status (default: both enabled)
// Initialize user media status (default: both enabled, no screen sharing)
userMediaStatus.set(name, {
video: true,
audio: true
audio: true,
screenSharing: false,
});
log.debug('User signed in:', name);
sendMsgTo(socket, { type: 'signIn', success: true });
broadcastConnectedUsers();
@@ -437,7 +438,7 @@ function handleConnection(socket) {
const callerMediaStatus = userMediaStatus.get(socket.username);
const offerData = {
...data,
callerMediaStatus: callerMediaStatus
callerMediaStatus: callerMediaStatus,
};
sendMsgTo(recipientSocket, offerData);
} else {
@@ -461,21 +462,45 @@ function handleConnection(socket) {
// Function to handle media status updates
function handleMediaStatus(data) {
const { video, audio } = data;
const { video, audio, screenSharing } = data;
const username = socket.username;
if (username && userMediaStatus.has(username)) {
const currentStatus = userMediaStatus.get(username);
const newStatus = {
video: video !== undefined ? video : currentStatus.video,
audio: audio !== undefined ? audio : currentStatus.audio
audio: audio !== undefined ? audio : currentStatus.audio,
screenSharing: screenSharing !== undefined ? screenSharing : currentStatus.screenSharing,
};
userMediaStatus.set(username, newStatus);
log.debug('Updated media status for', username, newStatus);
// Broadcast screen sharing status change to other connected users if it changed
if (screenSharing !== undefined && screenSharing !== currentStatus.screenSharing) {
broadcastScreenSharingStatus(username, screenSharing);
}
}
}
// Function to broadcast screen sharing status to connected users
function broadcastScreenSharingStatus(username, isScreenSharing) {
const message = {
type: 'remoteScreenShare',
from: username,
screenSharing: isScreenSharing,
};
log.debug('Broadcasting screen sharing status:', message);
// Send to all other connected users
users.forEach((userSocket, userName) => {
if (userName !== username) {
sendMsgTo(userSocket, message);
}
});
}
// Function to handle signaling messages (offer, answer, candidate, leave)
function handleSignalingMessage(data) {
const { type, name } = data;