LINXD-2209: Identify the callId from dictionary

This commit is contained in:
Sergiu Toma 2022-09-15 09:19:04 +03:00
parent b85ba68c9c
commit 41b50d2a11

26
app.js
View File

@ -36,6 +36,7 @@ let worker
* *
**/ **/
let videoCalls = {} let videoCalls = {}
let socketDetails = {}
app.get('/', (_req, res) => { app.get('/', (_req, res) => {
res.send('Hello from mediasoup app!') res.send('Hello from mediasoup app!')
@ -112,16 +113,18 @@ peers.on('connection', async socket => {
socket.on('disconnect', () => { socket.on('disconnect', () => {
// do some cleanup // do some cleanup
console.log('peer disconnected') console.log('peer disconnected | socket.id', socket.id)
delete socketDetails[socket.id];
}) })
socket.on('createRoom', async ({ callId }, callback) => { socket.on('createRoom', async ({ callId }, callback) => {
if (videoCalls[callId].router === undefined) { if (videoCalls[callId].router === undefined) {
console.log('[createRoom] callId', callId); console.log('[createRoom] callId', callId);
videoCalls[callId].router = await worker.createRouter({ mediaCodecs }) videoCalls[callId].router = await worker.createRouter({ mediaCodecs });
console.log(`[createRoom] Router ID: ${videoCalls[callId].router.id}`) console.log(`[createRoom] Router ID: ${videoCalls[callId].router.id}`)
} }
getRtpCapabilities(callId, callback) socketDetails[socket.id] = callId;
getRtpCapabilities(callId, callback);
}) })
// Client emits a request to create server side Transport // Client emits a request to create server side Transport
@ -137,13 +140,16 @@ peers.on('connection', async socket => {
}) })
// see client's socket.emit('transport-connect', ...) // see client's socket.emit('transport-connect', ...)
socket.on('transport-connect', async ({ dtlsParameters, callId }) => { socket.on('transport-connect', async ({ dtlsParameters }) => {
console.log('[transport-connect] DTLS PARAMS... ', { dtlsParameters }) const callId = socketDetails[socket.id];
console.log(`[transport-connect] socket.id ${socket.id} | callId ${callId} | DTLS PARAMS... ${dtlsParameters}`)
await videoCalls[callId].producerTransport.connect({ dtlsParameters }) await videoCalls[callId].producerTransport.connect({ dtlsParameters })
}) })
// see client's socket.emit('transport-produce', ...) // see client's socket.emit('transport-produce', ...)
socket.on('transport-produce', async ({ kind, rtpParameters, appData, callId }) => { socket.on('transport-produce', async ({ kind, rtpParameters, appData }) => {
const callId = socketDetails[socket.id];
console.log('[transport-produce] | socket.id', socket.id, '| callId', callId);
// call produce based on the prameters from the client // call produce based on the prameters from the client
videoCalls[callId].producer = await videoCalls[callId].producerTransport.produce({ videoCalls[callId].producer = await videoCalls[callId].producerTransport.produce({
kind, kind,
@ -164,12 +170,14 @@ peers.on('connection', async socket => {
}) })
// see client's socket.emit('transport-recv-connect', ...) // see client's socket.emit('transport-recv-connect', ...)
socket.on('transport-recv-connect', async ({ dtlsParameters, callId }) => { socket.on('transport-recv-connect', async ({ dtlsParameters }) => {
console.log(`[transport-recv-connect] DTLS PARAMS: ${dtlsParameters}`) const callId = socketDetails[socket.id];
console.log(`[transport-recv-connect] socket.id ${socket.id} | callId ${callId} | DTLS PARAMS: ${dtlsParameters}`);
await videoCalls[callId].consumerTransport.connect({ dtlsParameters }) await videoCalls[callId].consumerTransport.connect({ dtlsParameters })
}) })
socket.on('consume', async ({ rtpCapabilities, callId }, callback) => { socket.on('consume', async ({ rtpCapabilities }, callback) => {
const callId = socketDetails[socket.id];
console.log('[consume] callId', callId); console.log('[consume] callId', callId);
try { try {
// console.log('consume', rtpCapabilities, callId); // console.log('consume', rtpCapabilities, callId);