Add socket info

This commit is contained in:
Sergiu Toma 2022-12-13 10:28:45 +02:00
parent 8a9c370f02
commit d633eec92f

48
app.js
View File

@ -15,19 +15,21 @@ const mediasoup = require('mediasoup');
let worker let worker
/** /**
* videoCalls
* |-> Router
* |-> Producer
* |-> Consumer
* |-> Producer Transport
* |-> Consumer Transport
* *
* videoCalls - Dictionary of Object(s)
* '<callId>': { * '<callId>': {
* router: Router, * router: Router, router
* producer: Producer, * initiatorAudioProducer: Producer,
* producerTransport: Producer Transport, * initiatorVideoProducer: Producer,
* consumer: Consumer, * receiverVideoProducer: Producer, producerVideo
* consumerTransport: Consumer Transport * receiverAudioProducer: Producer, producerAudio
* initiatorProducerTransport: Producer Transport,
* receiverProducerTransport: Producer Transport, producerTransport
* initiatorConsumerVideo: Consumer, consumerVideo
* initiatorConsumerAudio: Consumer, consumerAudio
* initiatorConsumerTransport: Consumer Transport consumerTransport
* initiatorSockerId
* receiverSocketId
* } * }
* *
**/ **/
@ -141,20 +143,6 @@ const mediaCodecs = [
'x-google-start-bitrate' : 1000 'x-google-start-bitrate' : 1000
} }
} }
// {
// kind: 'audio',
// mimeType: 'audio/opus',
// clockRate: 48000,
// channels: 2,
// },
// {
// kind: 'video',
// mimeType: 'video/VP8',
// clockRate: 90000,
// parameters: {
// 'x-google-start-bitrate': 1000,
// },
// },
]; ];
const closeCall = (callId) => { const closeCall = (callId) => {
@ -212,9 +200,11 @@ peers.on('connection', async socket => {
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}`);
videoCalls[callId].initiatorSockerId = socket.id
} else {
videoCalls[callId].receiverSocketId = socket.id
} }
socketDetails[socket.id] = callId; socketDetails[socket.id] = callId;
// rtpCapabilities is set for callback // rtpCapabilities is set for callback
console.log('[getRtpCapabilities] callId', callId); console.log('[getRtpCapabilities] callId', callId);
callbackResponse = { callbackResponse = {
@ -223,6 +213,7 @@ peers.on('connection', async socket => {
} else { } else {
console.log(`[createRoom] missing callId ${callId}`); console.log(`[createRoom] missing callId ${callId}`);
} }
console.log('🔴 isInitiator(callId, socket.id)', isInitiator(callId, socket.id));
} catch (error) { } catch (error) {
console.log(`ERROR | createRoom | callId ${callId} | ${error.message}`); console.log(`ERROR | createRoom | callId ${callId} | ${error.message}`);
} finally { } finally {
@ -470,6 +461,11 @@ const consumeAudio = async (callId, rtpCapabilities) => {
} }
} }
const isInitiator = async (callId, socketId) => {
if (videoCalls[callId].initiatorSockerId === socketId) return true;
else return false
}
/* /*
- Called from at event 'createWebRtcTransport' and assigned to the consumer or producer transport - Called from at event 'createWebRtcTransport' and assigned to the consumer or producer transport
- It will return parameters, these are required for the client to create the RecvTransport - It will return parameters, these are required for the client to create the RecvTransport