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 socketDetails = {}
app.get('/', (_req, res) => {
res.send('Hello from mediasoup app!')
@ -112,16 +113,18 @@ peers.on('connection', async socket => {
socket.on('disconnect', () => {
// 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) => {
if (videoCalls[callId].router === undefined) {
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}`)
}
getRtpCapabilities(callId, callback)
socketDetails[socket.id] = callId;
getRtpCapabilities(callId, callback);
})
// 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', ...)
socket.on('transport-connect', async ({ dtlsParameters, callId }) => {
console.log('[transport-connect] DTLS PARAMS... ', { dtlsParameters })
socket.on('transport-connect', async ({ 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 })
})
// 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
videoCalls[callId].producer = await videoCalls[callId].producerTransport.produce({
kind,
@ -164,12 +170,14 @@ peers.on('connection', async socket => {
})
// see client's socket.emit('transport-recv-connect', ...)
socket.on('transport-recv-connect', async ({ dtlsParameters, callId }) => {
console.log(`[transport-recv-connect] DTLS PARAMS: ${dtlsParameters}`)
socket.on('transport-recv-connect', async ({ 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 })
})
socket.on('consume', async ({ rtpCapabilities, callId }, callback) => {
socket.on('consume', async ({ rtpCapabilities }, callback) => {
const callId = socketDetails[socket.id];
console.log('[consume] callId', callId);
try {
// console.log('consume', rtpCapabilities, callId);