WIP: router-close-connections #2
23
app.js
23
app.js
@ -149,7 +149,7 @@ peers.on('connection', async socket => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
// see client's socket.emit('transport-produce', ...)
|
// see client's socket.emit('transport-produce', ...)
|
||||||
socket.on('transport-produce', async ({ kind, rtpParameters, appData }) => {
|
socket.on('transport-produce', async ({ kind, rtpParameters, appData }, callback) => {
|
||||||
// call produce based on the prameters from the client
|
// call produce based on the prameters from the client
|
||||||
producer = await producerTransport.produce({
|
producer = await producerTransport.produce({
|
||||||
kind,
|
kind,
|
||||||
@ -157,6 +157,10 @@ peers.on('connection', async socket => {
|
|||||||
})
|
})
|
||||||
console.log(`[transport-produce] Producer ID: ${producer.id} | kind: ${producer.kind}`)
|
console.log(`[transport-produce] Producer ID: ${producer.id} | kind: ${producer.kind}`)
|
||||||
|
|
||||||
|
// If we have multiple producers/consumers on the same room
|
||||||
|
// We need to notify all the consumers of the room
|
||||||
|
// --- code ---
|
||||||
|
|
||||||
producer.on('transportclose', () => {
|
producer.on('transportclose', () => {
|
||||||
console.log('transport for this producer closed', callId)
|
console.log('transport for this producer closed', callId)
|
||||||
|
|
||||||
@ -167,6 +171,15 @@ peers.on('connection', async socket => {
|
|||||||
router[callId].close()
|
router[callId].close()
|
||||||
delete router[callId]
|
delete router[callId]
|
||||||
})
|
})
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Send back to the client the Producer's id
|
||||||
|
callback({
|
||||||
|
id: producer.id
|
||||||
|
})
|
||||||
|
} catch (error) {
|
||||||
|
|||||||
|
console.log(`ERROR | transport-produce | ${error}`)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
// see client's socket.emit('transport-recv-connect', ...)
|
// see client's socket.emit('transport-recv-connect', ...)
|
||||||
@ -196,8 +209,8 @@ peers.on('connection', async socket => {
|
|||||||
// https://mediasoup.org/documentation/v3/mediasoup/api/#router-close
|
// https://mediasoup.org/documentation/v3/mediasoup/api/#router-close
|
||||||
router[callId].close()
|
router[callId].close()
|
||||||
delete router[callId]
|
delete router[callId]
|
||||||
producer.close()
|
// producer.close()
|
||||||
consumer.close()
|
// consumer.close()
|
||||||
})
|
})
|
||||||
|
|
||||||
consumer.on('producerclose', () => {
|
consumer.on('producerclose', () => {
|
||||||
@ -206,8 +219,8 @@ peers.on('connection', async socket => {
|
|||||||
// https://mediasoup.org/documentation/v3/mediasoup/api/#router-close
|
// https://mediasoup.org/documentation/v3/mediasoup/api/#router-close
|
||||||
router[callId].close()
|
router[callId].close()
|
||||||
delete router[callId]
|
delete router[callId]
|
||||||
producer.close()
|
// producer.close()
|
||||||
consumer.close()
|
// consumer.close()
|
||||||
})
|
})
|
||||||
|
|
||||||
// from the consumer extract the following params
|
// from the consumer extract the following params
|
||||||
|
@ -20653,8 +20653,8 @@ module.exports = yeast;
|
|||||||
},{}],95:[function(require,module,exports){
|
},{}],95:[function(require,module,exports){
|
||||||
module.exports = {
|
module.exports = {
|
||||||
hubAddress: 'https://hub.dev.linx.safemobile.com/',
|
hubAddress: 'https://hub.dev.linx.safemobile.com/',
|
||||||
// mediasoupAddress: 'https://video.safemobile.org/mediasoup',
|
mediasoupAddress: 'https://video.safemobile.org/mediasoup',
|
||||||
mediasoupAddress: 'http://localhost:3000/mediasoup',
|
// mediasoupAddress: 'http://localhost:3000/mediasoup',
|
||||||
}
|
}
|
||||||
},{}],96:[function(require,module,exports){
|
},{}],96:[function(require,module,exports){
|
||||||
const io = require('socket.io-client')
|
const io = require('socket.io-client')
|
||||||
@ -20866,6 +20866,7 @@ const getRtpCapabilities = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const createSendTransport = () => {
|
const createSendTransport = () => {
|
||||||
|
|
||||||
// see server's socket.on('createWebRtcTransport', sender?, ...)
|
// see server's socket.on('createWebRtcTransport', sender?, ...)
|
||||||
// this is a call from Producer, so sender = true
|
// this is a call from Producer, so sender = true
|
||||||
socket.emit('createWebRtcTransport', { sender: true, callId }, ({ params }) => {
|
socket.emit('createWebRtcTransport', { sender: true, callId }, ({ params }) => {
|
||||||
@ -20876,7 +20877,7 @@ const createSendTransport = () => {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(params)
|
console.log('params', params)
|
||||||
|
|
||||||
// creates a new WebRTC Transport to send media
|
// creates a new WebRTC Transport to send media
|
||||||
// based on the server's producer transport params
|
// based on the server's producer transport params
|
||||||
@ -20903,7 +20904,7 @@ const createSendTransport = () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
producerTransport.on('produce', async (parameters, callback, errback) => {
|
producerTransport.on('produce', async (parameters, callback, errback) => {
|
||||||
console.log(parameters)
|
console.log('produce', parameters)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// tell the server to create a Producer
|
// tell the server to create a Producer
|
||||||
@ -20915,56 +20916,59 @@ const createSendTransport = () => {
|
|||||||
rtpParameters: parameters.rtpParameters,
|
rtpParameters: parameters.rtpParameters,
|
||||||
appData: parameters.appData,
|
appData: parameters.appData,
|
||||||
}, ({ id }) => {
|
}, ({ id }) => {
|
||||||
|
console.log('[transport-produce] callback | id', id);
|
||||||
// Tell the transport that parameters were transmitted and provide it with the
|
// Tell the transport that parameters were transmitted and provide it with the
|
||||||
// server side producer's id.
|
// server side producer's id.
|
||||||
callback({ id })
|
callback({ id })
|
||||||
})
|
})
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
console.log('ERROR | produce |', error);
|
||||||
errback(error)
|
errback(error)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
connectSendTransport()
|
connectSendTransport()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const connectSendTransport = async () => {
|
const connectSendTransport = async () => {
|
||||||
|
console.log('[connectSendTransport]');
|
||||||
// we now call produce() to instruct the producer transport
|
// we now call produce() to instruct the producer transport
|
||||||
// to send media to the Router
|
// to send media to the Router
|
||||||
// https://mediasoup.org/documentation/v3/mediasoup-client/api/#transport-produce
|
// https://mediasoup.org/documentation/v3/mediasoup-client/api/#transport-produce
|
||||||
// this action will trigger the 'connect' and 'produce' events above
|
// this action will trigger the 'connect' and 'produce' events above
|
||||||
producer = await producerTransport.produce(params)
|
producer = await producerTransport.produce(params)
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
producer.on('trackended', () => {
|
||||||
|
console.log('track ended')
|
||||||
|
// close video track
|
||||||
|
})
|
||||||
|
|
||||||
|
producer.on('transportclose', () => {
|
||||||
|
console.log('transport ended')
|
||||||
|
// close video track
|
||||||
|
})
|
||||||
|
|
||||||
|
// Enable Close call button
|
||||||
|
const closeCallBtn = document.getElementById('btnCloseCall');
|
||||||
|
closeCallBtn.removeAttribute('disabled');
|
||||||
|
|
||||||
producer.on('trackended', () => {
|
const answer = {
|
||||||
console.log('track ended')
|
origin_asset_id: ASSET_ID,
|
||||||
// close video track
|
dest_asset_id: originAssetId || parseInt(urlParams.get('dest_asset_id')),
|
||||||
})
|
type: 'notify-answer',
|
||||||
|
origin_asset_priority: 1,
|
||||||
producer.on('transportclose', () => {
|
origin_asset_type_name: ASSET_TYPE,
|
||||||
console.log('transport ended')
|
origin_asset_name: ASSET_NAME,
|
||||||
// close video track
|
video_call_id: callId,
|
||||||
})
|
answer: 'accepted', // answer: 'rejected'
|
||||||
|
};
|
||||||
const answer = {
|
console.log('SEND answer', answer);
|
||||||
origin_asset_id: ASSET_ID,
|
hub.emit(
|
||||||
dest_asset_id: originAssetId || parseInt(urlParams.get('dest_asset_id')),
|
'video',
|
||||||
type: 'notify-answer',
|
JSON.stringify(answer)
|
||||||
origin_asset_priority: 1,
|
);
|
||||||
origin_asset_type_name: ASSET_TYPE,
|
}, 7000);
|
||||||
origin_asset_name: ASSET_NAME,
|
|
||||||
video_call_id: callId,
|
|
||||||
answer: 'accepted', // answer: 'rejected'
|
|
||||||
};
|
|
||||||
console.log('SEND answer', answer);
|
|
||||||
|
|
||||||
hub.emit(
|
|
||||||
'video',
|
|
||||||
JSON.stringify(answer)
|
|
||||||
);
|
|
||||||
|
|
||||||
// Enable Close call button
|
|
||||||
const closeCallBtn = document.getElementById('btnCloseCall');
|
|
||||||
closeCallBtn.removeAttribute('disabled');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const createRecvTransport = async () => {
|
const createRecvTransport = async () => {
|
||||||
@ -21009,7 +21013,6 @@ const createRecvTransport = async () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const resetCallSettings = () => {
|
const resetCallSettings = () => {
|
||||||
socket.emit('transportclose', { callId })
|
|
||||||
localVideo.srcObject = null
|
localVideo.srcObject = null
|
||||||
remoteVideo.srcObject = null
|
remoteVideo.srcObject = null
|
||||||
consumer = null
|
consumer = null
|
||||||
@ -21057,12 +21060,12 @@ const connectRecvTransport = async () => {
|
|||||||
|
|
||||||
const closeCall = () => {
|
const closeCall = () => {
|
||||||
console.log('closeCall');
|
console.log('closeCall');
|
||||||
|
|
||||||
// Emit 'notify-end' to Hub so the consumer will know to close the video
|
// Emit 'notify-end' to Hub so the consumer will know to close the video
|
||||||
const notifyEnd = {
|
const notifyEnd = {
|
||||||
origin_asset_id: ASSET_ID,
|
origin_asset_id: ASSET_ID,
|
||||||
dest_asset_id: originAssetId || parseInt(urlParams.get('dest_asset_id')),
|
dest_asset_id: originAssetId || parseInt(urlParams.get('dest_asset_id')),
|
||||||
type: 'notify-end',
|
type: 'notify-end',
|
||||||
video_call_id: callId
|
video_call_id: callId
|
||||||
}
|
}
|
||||||
console.log('notifyEnd', notifyEnd)
|
console.log('notifyEnd', notifyEnd)
|
||||||
@ -21072,7 +21075,7 @@ const closeCall = () => {
|
|||||||
const closeCallBtn = document.getElementById('btnCloseCall')
|
const closeCallBtn = document.getElementById('btnCloseCall')
|
||||||
closeCallBtn.setAttribute('disabled', '')
|
closeCallBtn.setAttribute('disabled', '')
|
||||||
|
|
||||||
// Reset settings and send closeTransport to video server
|
// Reset settings
|
||||||
resetCallSettings()
|
resetCallSettings()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -207,6 +207,7 @@ const getRtpCapabilities = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const createSendTransport = () => {
|
const createSendTransport = () => {
|
||||||
|
|
||||||
// see server's socket.on('createWebRtcTransport', sender?, ...)
|
// see server's socket.on('createWebRtcTransport', sender?, ...)
|
||||||
// this is a call from Producer, so sender = true
|
// this is a call from Producer, so sender = true
|
||||||
socket.emit('createWebRtcTransport', { sender: true, callId }, ({ params }) => {
|
socket.emit('createWebRtcTransport', { sender: true, callId }, ({ params }) => {
|
||||||
@ -217,7 +218,7 @@ const createSendTransport = () => {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(params)
|
console.log('params', params)
|
||||||
|
|
||||||
// creates a new WebRTC Transport to send media
|
// creates a new WebRTC Transport to send media
|
||||||
// based on the server's producer transport params
|
// based on the server's producer transport params
|
||||||
@ -244,7 +245,7 @@ const createSendTransport = () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
producerTransport.on('produce', async (parameters, callback, errback) => {
|
producerTransport.on('produce', async (parameters, callback, errback) => {
|
||||||
console.log(parameters)
|
console.log('produce', parameters)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// tell the server to create a Producer
|
// tell the server to create a Producer
|
||||||
@ -256,56 +257,59 @@ const createSendTransport = () => {
|
|||||||
rtpParameters: parameters.rtpParameters,
|
rtpParameters: parameters.rtpParameters,
|
||||||
appData: parameters.appData,
|
appData: parameters.appData,
|
||||||
}, ({ id }) => {
|
}, ({ id }) => {
|
||||||
|
console.log('[transport-produce] callback | id', id);
|
||||||
// Tell the transport that parameters were transmitted and provide it with the
|
// Tell the transport that parameters were transmitted and provide it with the
|
||||||
// server side producer's id.
|
// server side producer's id.
|
||||||
callback({ id })
|
callback({ id })
|
||||||
})
|
})
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
console.log('ERROR | produce |', error);
|
||||||
errback(error)
|
errback(error)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
connectSendTransport()
|
connectSendTransport()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const connectSendTransport = async () => {
|
const connectSendTransport = async () => {
|
||||||
|
console.log('[connectSendTransport]');
|
||||||
// we now call produce() to instruct the producer transport
|
// we now call produce() to instruct the producer transport
|
||||||
// to send media to the Router
|
// to send media to the Router
|
||||||
// https://mediasoup.org/documentation/v3/mediasoup-client/api/#transport-produce
|
// https://mediasoup.org/documentation/v3/mediasoup-client/api/#transport-produce
|
||||||
// this action will trigger the 'connect' and 'produce' events above
|
// this action will trigger the 'connect' and 'produce' events above
|
||||||
producer = await producerTransport.produce(params)
|
producer = await producerTransport.produce(params)
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
producer.on('trackended', () => {
|
||||||
|
console.log('track ended')
|
||||||
|
// close video track
|
||||||
|
})
|
||||||
|
|
||||||
|
producer.on('transportclose', () => {
|
||||||
|
console.log('transport ended')
|
||||||
|
// close video track
|
||||||
|
})
|
||||||
|
|
||||||
|
// Enable Close call button
|
||||||
|
const closeCallBtn = document.getElementById('btnCloseCall');
|
||||||
|
closeCallBtn.removeAttribute('disabled');
|
||||||
|
|
||||||
producer.on('trackended', () => {
|
const answer = {
|
||||||
console.log('track ended')
|
origin_asset_id: ASSET_ID,
|
||||||
// close video track
|
dest_asset_id: originAssetId || parseInt(urlParams.get('dest_asset_id')),
|
||||||
})
|
type: 'notify-answer',
|
||||||
|
origin_asset_priority: 1,
|
||||||
producer.on('transportclose', () => {
|
origin_asset_type_name: ASSET_TYPE,
|
||||||
console.log('transport ended')
|
origin_asset_name: ASSET_NAME,
|
||||||
// close video track
|
video_call_id: callId,
|
||||||
})
|
answer: 'accepted', // answer: 'rejected'
|
||||||
|
};
|
||||||
const answer = {
|
console.log('SEND answer', answer);
|
||||||
origin_asset_id: ASSET_ID,
|
hub.emit(
|
||||||
dest_asset_id: originAssetId || parseInt(urlParams.get('dest_asset_id')),
|
'video',
|
||||||
type: 'notify-answer',
|
JSON.stringify(answer)
|
||||||
origin_asset_priority: 1,
|
);
|
||||||
origin_asset_type_name: ASSET_TYPE,
|
}, 7000);
|
||||||
origin_asset_name: ASSET_NAME,
|
|
||||||
video_call_id: callId,
|
|
||||||
answer: 'accepted', // answer: 'rejected'
|
|
||||||
};
|
|
||||||
console.log('SEND answer', answer);
|
|
||||||
|
|
||||||
hub.emit(
|
|
||||||
'video',
|
|
||||||
JSON.stringify(answer)
|
|
||||||
);
|
|
||||||
|
|
||||||
// Enable Close call button
|
|
||||||
const closeCallBtn = document.getElementById('btnCloseCall');
|
|
||||||
closeCallBtn.removeAttribute('disabled');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const createRecvTransport = async () => {
|
const createRecvTransport = async () => {
|
||||||
|
Loading…
Reference in New Issue
Block a user
Isn't the
producer
a global variable?What should the client do with the producer id? Looks below that is sent back to server, why?