Compare commits

...

8 Commits

24
app.js
View File

@ -42,7 +42,9 @@ httpsServer.listen(process.env.PORT, () => {
console.log('Listening on port:', process.env.PORT)
})
const io = new Server(httpsServer)
const io = new Server(httpsServer, {
allowEIO3: true
});
// socket.io namespace (could represent a room?)
const peers = io.of('/mediasoup')
@ -149,13 +151,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 +169,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 +179,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 +194,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 +208,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 +280,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({