Skip to content

Commit

Permalink
[mirotalk] - allow join room without webcam
Browse files Browse the repository at this point in the history
  • Loading branch information
miroslavpejic85 committed Jul 10, 2022
1 parent 0f4ad36 commit dc51c1c
Show file tree
Hide file tree
Showing 4 changed files with 537 additions and 225 deletions.
101 changes: 57 additions & 44 deletions app/src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -426,8 +426,8 @@ server.listen(port, null, () => {
* information. After all of that happens, they'll finally be able to complete
* the peer connection and will be in streaming audio/video between eachother.
*/
io.sockets.on('connect', (socket) => {
log.debug('[' + socket.id + '] connection accepted');
io.sockets.on('connect', async (socket) => {
log.debug('[' + socket.id + '] connection accepted', { host: socket.handshake.headers.host.split(':')[0] });

socket.channels = {};
sockets[socket.id] = socket;
Expand All @@ -446,9 +446,9 @@ io.sockets.on('connect', (socket) => {
/**
* On peer diconnected
*/
socket.on('disconnect', (reason) => {
socket.on('disconnect', async (reason) => {
for (let channel in socket.channels) {
removePeerFrom(channel);
await removePeerFrom(channel);
}
log.debug('[' + socket.id + '] disconnected', { reason: reason });
delete sockets[socket.id];
Expand All @@ -457,7 +457,8 @@ io.sockets.on('connect', (socket) => {
/**
* On peer join
*/
socket.on('join', (config) => {
socket.on('join', async (config) => {
// log.debug('Join room', config);
log.debug('[' + socket.id + '] join ', config);

let channel = config.channel;
Expand Down Expand Up @@ -495,13 +496,13 @@ io.sockets.on('connect', (socket) => {
};
log.debug('connected peers grp by roomId', peers);

addPeerTo(channel);
await addPeerTo(channel);

channels[channel][socket.id] = socket;
socket.channels[channel] = channel;

// Send some server info to joined peer
sendToPeer(socket.id, sockets, 'serverInfo', { peers_count: Object.keys(peers[channel]).length });
await sendToPeer(socket.id, sockets, 'serverInfo', { peers_count: Object.keys(peers[channel]).length });
});

/**
Expand Down Expand Up @@ -562,15 +563,15 @@ io.sockets.on('connect', (socket) => {
/**
* Relay ICE to peers
*/
socket.on('relayICE', (config) => {
socket.on('relayICE', async (config) => {
let peer_id = config.peer_id;
let ice_candidate = config.ice_candidate;

// log.debug('[' + socket.id + '] relay ICE-candidate to [' + peer_id + '] ', {
// address: config.ice_candidate,
// });

sendToPeer(peer_id, sockets, 'iceCandidate', {
await sendToPeer(peer_id, sockets, 'iceCandidate', {
peer_id: socket.id,
ice_candidate: ice_candidate,
});
Expand All @@ -579,15 +580,15 @@ io.sockets.on('connect', (socket) => {
/**
* Relay SDP to peers
*/
socket.on('relaySDP', (config) => {
socket.on('relaySDP', async (config) => {
let peer_id = config.peer_id;
let session_description = config.session_description;

log.debug('[' + socket.id + '] relay SessionDescription to [' + peer_id + '] ', {
type: session_description.type,
});

sendToPeer(peer_id, sockets, 'sessionDescription', {
await sendToPeer(peer_id, sockets, 'sessionDescription', {
peer_id: socket.id,
session_description: session_description,
});
Expand All @@ -596,7 +597,7 @@ io.sockets.on('connect', (socket) => {
/**
* Handle Room action
*/
socket.on('roomAction', (config) => {
socket.on('roomAction', async (config) => {
//log.debug('[' + socket.id + '] Room action:', config);
let room_is_locked = false;
let room_id = config.room_id;
Expand All @@ -609,7 +610,7 @@ io.sockets.on('connect', (socket) => {
case 'lock':
peers[room_id]['lock'] = true;
peers[room_id]['password'] = password;
sendToRoom(room_id, socket.id, 'roomAction', {
await sendToRoom(room_id, socket.id, 'roomAction', {
peer_name: peer_name,
action: action,
});
Expand All @@ -618,7 +619,7 @@ io.sockets.on('connect', (socket) => {
case 'unlock':
delete peers[room_id]['lock'];
delete peers[room_id]['password'];
sendToRoom(room_id, socket.id, 'roomAction', {
await sendToRoom(room_id, socket.id, 'roomAction', {
peer_name: peer_name,
action: action,
});
Expand All @@ -629,7 +630,7 @@ io.sockets.on('connect', (socket) => {
action: action,
password: password == peers[room_id]['password'] ? 'OK' : 'KO',
};
sendToPeer(socket.id, sockets, 'roomAction', config);
await sendToPeer(socket.id, sockets, 'roomAction', config);
break;
}
} catch (err) {
Expand All @@ -641,7 +642,8 @@ io.sockets.on('connect', (socket) => {
/**
* Relay NAME to peers
*/
socket.on('peerName', (config) => {
socket.on('peerName', async (config) => {
// log.debug('Peer name', config);
let room_id = config.room_id;
let peer_name_old = config.peer_name_old;
let peer_name_new = config.peer_name_new;
Expand All @@ -660,7 +662,7 @@ io.sockets.on('connect', (socket) => {
peer_name: peer_name_new,
});

sendToRoom(room_id, socket.id, 'peerName', {
await sendToRoom(room_id, socket.id, 'peerName', {
peer_id: peer_id_to_update,
peer_name: peer_name_new,
});
Expand All @@ -670,7 +672,8 @@ io.sockets.on('connect', (socket) => {
/**
* Relay Audio Video Hand ... Status to peers
*/
socket.on('peerStatus', (config) => {
socket.on('peerStatus', async (config) => {
// log.debug('Peer status', config);
let room_id = config.room_id;
let peer_name = config.peer_name;
let element = config.element;
Expand Down Expand Up @@ -701,7 +704,7 @@ io.sockets.on('connect', (socket) => {
status: status,
});

sendToRoom(room_id, socket.id, 'peerStatus', {
await sendToRoom(room_id, socket.id, 'peerStatus', {
peer_id: socket.id,
peer_name: peer_name,
element: element,
Expand All @@ -715,52 +718,61 @@ io.sockets.on('connect', (socket) => {
/**
* Relay actions to peers or specific peer in the same room
*/
socket.on('peerAction', (config) => {
socket.on('peerAction', async (config) => {
// log.debug('Peer action', config);
let room_id = config.room_id;
let peer_id = config.peer_id;
let peer_name = config.peer_name;
let peer_use_video = config.peer_use_video;
let peer_action = config.peer_action;
let peer_id = config.peer_id;

if (peer_id) {
log.debug('[' + socket.id + '] emit peerAction to [' + peer_id + '] from room_id [' + room_id + ']');
let send_to_all = config.send_to_all;

sendToPeer(peer_id, sockets, 'peerAction', {
if (send_to_all) {
log.debug('[' + socket.id + '] emit peerAction to [room_id: ' + room_id + ']', {
peer_id: socket.id,
peer_name: peer_name,
peer_action: peer_action,
peer_use_video: peer_use_video,
});
} else {
log.debug('[' + socket.id + '] emit peerAction to [room_id: ' + room_id + ']', {
peer_id: socket.id,

await sendToRoom(room_id, socket.id, 'peerAction', {
peer_id: peer_id,
peer_name: peer_name,
peer_action: peer_action,
peer_use_video: peer_use_video,
});
} else {
log.debug('[' + socket.id + '] emit peerAction to [' + peer_id + '] from room_id [' + room_id + ']');

sendToRoom(room_id, socket.id, 'peerAction', {
await sendToPeer(peer_id, sockets, 'peerAction', {
peer_id: peer_id,
peer_name: peer_name,
peer_action: peer_action,
peer_use_video: peer_use_video,
});
}
});

/**
* Relay Kick out peer from room
*/
socket.on('kickOut', (config) => {
socket.on('kickOut', async (config) => {
let room_id = config.room_id;
let peer_id = config.peer_id;
let peer_name = config.peer_name;

log.debug('[' + socket.id + '] kick out peer [' + peer_id + '] from room_id [' + room_id + ']');

sendToPeer(peer_id, sockets, 'kickOut', {
await sendToPeer(peer_id, sockets, 'kickOut', {
peer_name: peer_name,
});
});

/**
* Relay File info
*/
socket.on('fileInfo', (config) => {
socket.on('fileInfo', async (config) => {
// log.debug('File info', config);
let room_id = config.room_id;
let peer_name = config.peer_name;
let peer_id = config.peer_id;
Expand All @@ -785,27 +797,28 @@ io.sockets.on('connect', (socket) => {
});

if (broadcast) {
sendToRoom(room_id, socket.id, 'fileInfo', file);
await sendToRoom(room_id, socket.id, 'fileInfo', file);
} else {
sendToPeer(peer_id, sockets, 'fileInfo', file);
await sendToPeer(peer_id, sockets, 'fileInfo', file);
}
});

/**
* Abort file sharing
*/
socket.on('fileAbort', (config) => {
socket.on('fileAbort', async (config) => {
let room_id = config.room_id;
let peer_name = config.peer_name;

log.debug('[' + socket.id + '] Peer [' + peer_name + '] send fileAbort to room_id [' + room_id + ']');
sendToRoom(room_id, socket.id, 'fileAbort');
await sendToRoom(room_id, socket.id, 'fileAbort');
});

/**
* Relay video player action
*/
socket.on('videoPlayer', (config) => {
socket.on('videoPlayer', async (config) => {
// log.debug('Video player', config);
let room_id = config.room_id;
let peer_name = config.peer_name;
let video_action = config.video_action;
Expand All @@ -830,27 +843,27 @@ io.sockets.on('connect', (socket) => {
logMe,
);

sendToPeer(peer_id, sockets, 'videoPlayer', sendConfig);
await sendToPeer(peer_id, sockets, 'videoPlayer', sendConfig);
} else {
log.debug('[' + socket.id + '] emit videoPlayer to [room_id: ' + room_id + ']', logMe);

sendToRoom(room_id, socket.id, 'videoPlayer', sendConfig);
await sendToRoom(room_id, socket.id, 'videoPlayer', sendConfig);
}
});

/**
* Whiteboard actions for all user in the same room
*/
socket.on('wbCanvasToJson', (config) => {
let room_id = config.room_id;
socket.on('wbCanvasToJson', async (config) => {
// log.debug('Whiteboard send canvas', config);
sendToRoom(room_id, socket.id, 'wbCanvasToJson', config);
let room_id = config.room_id;
await sendToRoom(room_id, socket.id, 'wbCanvasToJson', config);
});

socket.on('whiteboardAction', (config) => {
socket.on('whiteboardAction', async (config) => {
log.debug('Whiteboard', config);
let room_id = config.room_id;
sendToRoom(room_id, socket.id, 'whiteboardAction', config);
await sendToRoom(room_id, socket.id, 'whiteboardAction', config);
});
}); // end [sockets.on-connect]

Expand Down
9 changes: 8 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mirotalk",
"version": "1.0.0",
"version": "1.0.1",
"description": "A free WebRTC browser-based video call",
"main": "server.js",
"scripts": {
Expand All @@ -12,6 +12,13 @@
"type": "git",
"url": "git+https://github.com/miroslavpejic85/mirotalk"
},
"keywords": [
"webrtc",
"socket.io",
"p2p",
"nodejs",
"video"
],
"author": "Miroslav Pejic",
"license": "AGPL-3.0",
"homepage": "https://github.com/miroslavpejic85/mirotalk",
Expand Down

0 comments on commit dc51c1c

Please sign in to comment.