LINXD-2209: Create rooms in sequence
This commit is contained in:
parent
523945271e
commit
b834016dcb
64
app.js
64
app.js
@ -96,6 +96,36 @@ 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 () => {
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
}, 2000);
|
||||||
|
|
||||||
peers.on('connection', async socket => {
|
peers.on('connection', async socket => {
|
||||||
console.log('[connection] socketId:', socket.id)
|
console.log('[connection] socketId:', socket.id)
|
||||||
socket.emit('connection-success', {
|
socket.emit('connection-success', {
|
||||||
@ -109,26 +139,24 @@ peers.on('connection', async socket => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
socket.on('createRoom', async ({ callId }, callback) => {
|
socket.on('createRoom', async ({ callId }, callback) => {
|
||||||
console.log('[createRoom] callId', callId);
|
// console.log('[createRoom] callId', callId);
|
||||||
console.log('Router length:', Object.keys(router).length);
|
// console.log('Router length:', Object.keys(router).length);
|
||||||
if (router[callId] === undefined) {
|
// if (router[callId] === undefined) {
|
||||||
// worker.createRouter(options)
|
// // worker.createRouter(options)
|
||||||
// options = { mediaCodecs, appData }
|
// // options = { mediaCodecs, appData }
|
||||||
// mediaCodecs -> defined above
|
// // mediaCodecs -> defined above
|
||||||
// appData -> custom application data - we are not supplying any
|
// // appData -> custom application data - we are not supplying any
|
||||||
// none of the two are required
|
// // none of the two are required
|
||||||
router[callId] = await worker.createRouter({ mediaCodecs })
|
// router[callId] = await worker.createRouter({ mediaCodecs })
|
||||||
console.log(`[createRoom] Router ID: ${router[callId].id}`)
|
// 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
|
// Client emits a request to create server side Transport
|
||||||
// We need to differentiate between the producer and consumer transports
|
// We need to differentiate between the producer and consumer transports
|
||||||
|
Loading…
Reference in New Issue
Block a user