Compare commits

...

19 Commits

Author SHA1 Message Date
031a7bc4c5 LINXD-2209: Remove console.logs 2022-09-13 21:05:24 +03:00
d7486d0fd6 LINXD-2209: Add 10ms delay between room creation 2022-09-13 21:04:42 +03:00
38931f0654 LINXD-2209: Add 50ms delay between room creation 2022-09-13 21:02:29 +03:00
bb684ca4db LINXD-2209: Add 300ms delay 2022-09-13 20:59:55 +03:00
25a76c343b LINXD-2209: Move getRtpCapa outside of room creation 2022-09-13 20:59:12 +03:00
817a49204d LINXD-2209: Added logs 2022-09-13 20:58:06 +03:00
91b4db1982 LINXD-2209: Added logs 2022-09-13 20:54:35 +03:00
8562f6c58c LINXD-2209: Added logs 2022-09-13 20:49:40 +03:00
5abc309502 LINXD-2209: Added logs 2022-09-13 20:28:07 +03:00
ecb5a88a2c LINXD-2209: Update port 2022-09-13 20:10:34 +03:00
782b749ea3 LINXD-2209: Check queue length 2022-09-13 20:09:25 +03:00
b834016dcb LINXD-2209: Create rooms in sequence 2022-09-13 19:56:06 +03:00
523945271e Remove callback with producer id from transport-produce 2022-08-31 17:06:54 +03:00
0af7ddd786 Remove callback with producer id from transport-produce 2022-08-31 16:53:08 +03:00
ba5add489d Remove callback with producer id from transport-produce 2022-08-31 16:49:23 +03:00
d5cb144799 Remove callback with producer id from transport-produce 2022-08-31 16:47:54 +03:00
4e92f6cdd3 Remove callback with producer id from transport-produce 2022-08-31 16:43:59 +03:00
aaa1c5cea4 Remove callback with producer id from transport-produce 2022-08-31 16:40:38 +03:00
4f302570a2 Remove callback with producer id from transport-produce 2022-08-31 16:24:21 +03:00

84
app.js
View File

@ -96,6 +96,38 @@ const mediaCodecs = [
},
]
let queue = []
// queue.push({
// callId: 1,
// callback: () => console.log('callback')
// })
// queue.push({
// callId: 2,
// callback: () => console.log('callback')
// })
// queue.push({
// callId: 3,
// callback: () => console.log('callback')
// })
const getRtpCapabilities = (callId, callback) => {
const rtpCapabilities = router[callId].rtpCapabilities
callback({ rtpCapabilities })
}
setInterval(async () => {
if (queue.length > 0) {
const { callId, callback } = queue.shift();
if (router[callId] === undefined) {
router[callId] = await worker.createRouter({ mediaCodecs })
console.log(`[createRoom] Router ID: ${router[callId].id}`)
}
getRtpCapabilities(callId, callback)
}
}, 1);
peers.on('connection', async socket => {
console.log('[connection] socketId:', socket.id)
socket.emit('connection-success', {
@ -110,26 +142,24 @@ peers.on('connection', async socket => {
socket.on('createRoom', async ({ callId }, callback) => {
console.log('[createRoom] callId', callId);
console.log('Router length:', Object.keys(router).length);
if (router[callId] === undefined) {
// worker.createRouter(options)
// options = { mediaCodecs, appData }
// mediaCodecs -> defined above
// appData -> custom application data - we are not supplying any
// none of the two are required
router[callId] = await worker.createRouter({ mediaCodecs })
console.log(`[createRoom] Router ID: ${router[callId].id}`)
}
// console.log('Router length:', Object.keys(router).length);
// if (router[callId] === undefined) {
// // worker.createRouter(options)
// // options = { mediaCodecs, appData }
// // mediaCodecs -> defined above
// // appData -> custom application data - we are not supplying any
// // none of the two are required
// router[callId] = await worker.createRouter({ mediaCodecs })
// console.log(`[createRoom] Router ID: ${router[callId].id}`)
// }
getRtpCapabilities(callId, callback)
// getRtpCapabilities(callId, callback)
queue.push({
callId,
callback
})
})
const getRtpCapabilities = (callId, callback) => {
const rtpCapabilities = router[callId].rtpCapabilities
callback({ rtpCapabilities })
}
// Client emits a request to create server side Transport
// We need to differentiate between the producer and consumer transports
socket.on('createWebRtcTransport', async ({ sender, callId }, callback) => {
@ -149,13 +179,12 @@ peers.on('connection', async socket => {
})
// see client's socket.emit('transport-produce', ...)
socket.on('transport-produce', async ({ kind, rtpParameters, appData }, callback) => {
socket.on('transport-produce', async ({ kind, rtpParameters, appData }) => {
// call produce based on the prameters from the client
producer = await producerTransport.produce({
kind,
rtpParameters,
})
console.log(`[transport-produce] Producer ID: ${producer.id} | kind: ${producer.kind}`)
producer.on('transportclose', () => {
@ -168,11 +197,6 @@ peers.on('connection', async socket => {
router[callId].close()
delete router[callId]
})
// Send back to the client the Producer's id
callback({
id: producer.id
})
})
// see client's socket.emit('transport-recv-connect', ...)
@ -183,7 +207,7 @@ peers.on('connection', async socket => {
socket.on('consume', async ({ rtpCapabilities, callId }, callback) => {
try {
console.log('consume', rtpCapabilities, callId);
// console.log('consume', rtpCapabilities, callId);
// check if the router can consume the specified producer
if (router[callId].canConsume({
producerId: producer.id,
@ -198,8 +222,12 @@ peers.on('connection', async socket => {
consumer.on('transportclose', () => {
console.log('transport close from consumer', callId)
// closeRoom(callId)
// https://mediasoup.org/documentation/v3/mediasoup/api/#router-close
router[callId].close()
delete router[callId]
producer.close()
consumer.close()
})
consumer.on('producerclose', () => {
@ -208,6 +236,8 @@ peers.on('connection', async socket => {
// https://mediasoup.org/documentation/v3/mediasoup/api/#router-close
router[callId].close()
delete router[callId]
producer.close()
consumer.close()
})
// from the consumer extract the following params
@ -278,7 +308,7 @@ const createWebRtcTransportLayer = async (callId, callback) => {
dtlsParameters: transport.dtlsParameters,
}
console.log('params', params);
// console.log('params', params);
// send back to the client the following prameters
callback({