Compare commits

..

23 Commits

Author SHA1 Message Date
26345bd22b LAPI-675: Comment code<DEBUG> 2023-01-13 18:42:34 +02:00
9b4e0186ac LAPI-675: Update server go emit new-producer; Update client to handle this event 2023-01-13 18:32:11 +02:00
eece7d2ee3 LAPI-675: Added handler for new transport/newproducer/newconsumer 2023-01-13 13:27:59 +02:00
ad4c1f27e7 Merge pull request 'LAPI-674: Parse transport-recv-connect and consume param' (#23) from LAPI-674-change-events-for-consumer-in-mediasoup-server into develop
Reviewed-on: #23
Reviewed-by: Cristi Ene <cristi.ene@safemobile.com>
2023-01-13 07:52:27 +00:00
b2128c4754 fix build 2023-01-12 16:42:44 +00:00
af53dc1610 fix build 2023-01-12 16:30:39 +00:00
f48fe4f9aa LAPI-674: Parse transport-recv-connect and consume param 2023-01-12 16:23:30 +02:00
6fd6ca9755 Merge pull request 'comsume-undefined' (#22) from comsume-undefined into develop
Reviewed-on: #22
Reviewed-by: Cristi Ene <cristi.ene@safemobile.com>
2023-01-12 13:31:46 +00:00
1b72941a32 Moved callId in consumer-resume 2023-01-12 15:09:21 +02:00
c037240f47 Refactor consumer-resume 2023-01-12 14:32:48 +02:00
9716bddd71 Added log 2023-01-12 12:50:40 +02:00
e6c08a2c1d Refactor consumer-resume v3 2023-01-12 12:46:46 +02:00
1342e812e6 Refactor consumer-resume 2023-01-12 12:45:23 +02:00
d8405eccc7 Refactor consumer-resume 2023-01-12 12:44:11 +02:00
5bf31d452f Check for initiatorConsumerAudio before resume() 2023-01-12 12:38:40 +02:00
c034610471 Rollback 2023-01-12 12:38:01 +02:00
df5b3eab90 Check for initiatorConsumerAudio before resume() 2023-01-12 12:31:52 +02:00
b0293230b6 Merge pull request 'add-diagrams-doc' (#21) from add-diagrams-doc into develop
Reviewed-on: #21
Reviewed-by: Cristi Ene <cristi.ene@safemobile.com>
2023-01-10 17:51:05 +00:00
391e8eb6f0 Added diagram for close call before accept/reject 2023-01-10 13:17:57 +02:00
3139a625a2 Added workflow diagrams 2023-01-10 12:05:29 +02:00
9d43b7ec0c Merge pull request 'LINXD-2270: Allow server and web client to have full duplex' (#20) from LINXD-2270-full-duplex into develop
Reviewed-on: #20
Reviewed-by: Cristi Ene <cristi.ene@safemobile.com>
2022-12-27 11:12:38 +00:00
342d09c3e6 LINXD-2270: Removed console logs; Update commented code 2022-12-27 13:11:06 +02:00
b3409de3ba LINXD-2270: Allow server and web client to have full duplex 2022-12-19 19:31:33 +02:00
14 changed files with 145 additions and 98 deletions

125
app.js
View File

@ -13,40 +13,40 @@ try {
} }
const mediasoup = require('mediasoup'); const mediasoup = require('mediasoup');
let worker let worker;
/** /**
* *
* videoCalls - Dictionary of Object(s) * videoCalls - Dictionary of Object(s)
* '<callId>': { * '<callId>': {
* router: Router, router * router: Router,
* initiatorAudioProducer: Producer, * initiatorAudioProducer: Producer,
* initiatorVideoProducer: Producer, * initiatorVideoProducer: Producer,
* receiverVideoProducer: Producer, producerVideo * receiverVideoProducer: Producer,
* receiverAudioProducer: Producer, producerAudio * receiverAudioProducer: Producer,
* initiatorProducerTransport: Producer Transport, * initiatorProducerTransport: Producer Transport,
* receiverProducerTransport: Producer Transport, producerTransport * receiverProducerTransport: Producer Transport,
* initiatorConsumerVideo: Consumer, consumerVideo * initiatorConsumerVideo: Consumer,
* initiatorConsumerAudio: Consumer, consumerAudio * initiatorConsumerAudio: Consumer,
* initiatorConsumerTransport: Consumer Transport consumerTransport * initiatorConsumerTransport: Consumer Transport
* initiatorSockerId * initiatorSocket
* receiverSocketId * receiverSocket
* } * }
* *
**/ **/
let videoCalls = {} let videoCalls = {};
let socketDetails = {} let socketDetails = {};
app.get('/', (_req, res) => { app.get('/', (_req, res) => {
res.send('Hello from mediasoup app!') res.send('Hello from mediasoup app!')
}) });
app.use('/sfu', express.static(path.join(__dirname, 'public'))) app.use('/sfu', express.static(path.join(__dirname, 'public')));
// SSL cert for HTTPS access // SSL cert for HTTPS access
const options = { const options = {
key: fs.readFileSync(process.env.SERVER_KEY, 'utf-8'), key: fs.readFileSync(process.env.SERVER_KEY, 'utf-8'),
cert: fs.readFileSync(process.env.SERVER_CERT, 'utf-8'), cert: fs.readFileSync(process.env.SERVER_CERT, 'utf-8'),
} };
const httpsServer = https.createServer(options, app); const httpsServer = https.createServer(options, app);
@ -193,11 +193,11 @@ peers.on('connection', async socket => {
console.log(`[createRoom] socket.id ${socket.id} callId ${callId}`); console.log(`[createRoom] socket.id ${socket.id} callId ${callId}`);
if (!videoCalls[callId]) { if (!videoCalls[callId]) {
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].receiverSocketId = socket.id videoCalls[callId].receiverSocket = socket;
} else { } else {
videoCalls[callId].initiatorSockerId = socket.id videoCalls[callId].initiatorSocket = socket;
} }
socketDetails[socket.id] = callId; socketDetails[socket.id] = callId;
// rtpCapabilities is set for callback // rtpCapabilities is set for callback
@ -225,7 +225,6 @@ peers.on('connection', async socket => {
*/ */
socket.on('createWebRtcTransport', async ({ sender }, callback) => { socket.on('createWebRtcTransport', async ({ sender }, callback) => {
try { try {
console.log('🟥', socket.id, JSON.stringify(sender));
const callId = socketDetails[socket.id]; const callId = socketDetails[socket.id];
console.log(`[createWebRtcTransport] socket ${socket.id} | sender ${sender} | callId ${callId}`); console.log(`[createWebRtcTransport] socket ${socket.id} | sender ${sender} | callId ${callId}`);
if (sender) { if (sender) {
@ -281,6 +280,72 @@ peers.on('connection', async socket => {
if (typeof rtpParameters === 'string') rtpParameters = JSON.parse(rtpParameters); if (typeof rtpParameters === 'string') rtpParameters = JSON.parse(rtpParameters);
console.log(`[transport-produce] kind: ${kind} | socket: ${socket.id} | callId: ${callId}`); console.log(`[transport-produce] kind: ${kind} | socket: ${socket.id} | callId: ${callId}`);
// const router = videoCalls[callId].router;
// router.observer.on("newtransport", (transport) => {
// transport.observer.on("newproducer", (producer) => {
// console.log(
// "new producer created [worker.pid:%d, router.id:%s, transport.id:%s, producer.id:%s]",
// worker.pid, router.id, transport.id, producer.id
// );
// if (!isInitiator(callId, socket.id)) {
// console.log('🟥 Emit to initiatorSocket');
// initiatorSocket.emit('new-producer', {
// callId
// });
// } else {
// console.log('🟥 Emit to receiverSocket');
// receiverSocket.emit('new-producer', {
// callId
// });
// }
// });
// });
if (kind === 'video') { if (kind === 'video') {
if (!isInitiator(callId, socket.id)) { if (!isInitiator(callId, socket.id)) {
videoCalls[callId].receiverVideoProducer = await videoCalls[callId].receiverProducerTransport.produce({ videoCalls[callId].receiverVideoProducer = await videoCalls[callId].receiverProducerTransport.produce({
@ -370,6 +435,7 @@ peers.on('connection', async socket => {
try { try {
const callId = socketDetails[socket.id]; const callId = socketDetails[socket.id];
console.log(`[transport-recv-connect] socket ${socket.id} | callId ${callId}`); console.log(`[transport-recv-connect] socket ${socket.id} | callId ${callId}`);
if (typeof dtlsParameters === 'string') dtlsParameters = JSON.parse(dtlsParameters);
// await videoCalls[callId].consumerTransport.connect({ dtlsParameters }); // await videoCalls[callId].consumerTransport.connect({ dtlsParameters });
if(!isInitiator(callId, socket.id)) { if(!isInitiator(callId, socket.id)) {
await videoCalls[callId].receiverConsumerTransport.connect({ dtlsParameters }); await videoCalls[callId].receiverConsumerTransport.connect({ dtlsParameters });
@ -393,6 +459,8 @@ peers.on('connection', async socket => {
const callId = socketDetails[socket.id]; const callId = socketDetails[socket.id];
console.log(`[consume] socket ${socket.id} | callId ${callId} | rtpCapabilities: ${JSON.stringify(rtpCapabilities)}`); console.log(`[consume] socket ${socket.id} | callId ${callId} | rtpCapabilities: ${JSON.stringify(rtpCapabilities)}`);
if (typeof rtpCapabilities === 'string') rtpCapabilities = JSON.parse(rtpCapabilities);
console.log('[consume] callId', callId); console.log('[consume] callId', callId);
let canConsumeVideo, canConsumeAudio; let canConsumeVideo, canConsumeAudio;
if (isInitiator(callId, socket.id)) { if (isInitiator(callId, socket.id)) {
@ -429,7 +497,6 @@ peers.on('connection', async socket => {
} else if (!canConsumeVideo && canConsumeAudio) { } else if (!canConsumeVideo && canConsumeAudio) {
const audioParams = await consumeAudio(callId, socket.id, rtpCapabilities) const audioParams = await consumeAudio(callId, socket.id, rtpCapabilities)
const data = { videoParams: null, audioParams }; const data = { videoParams: null, audioParams };
console.log('-----------======= data', data);
callback(data); callback(data);
} else { } else {
console.log(`[consume] Can't consume | callId ${callId}`); console.log(`[consume] Can't consume | callId ${callId}`);
@ -444,23 +511,19 @@ peers.on('connection', async socket => {
/* /*
- Event sent by the consumer after consuming to resume the pause - Event sent by the consumer after consuming to resume the pause
- When consuming on consumerTransport, it is initially done with paused: true, here we will resume - When consuming on consumerTransport, it is initially done with paused: true, here we will resume
- For the initiator we resume the initiatorConsumerAUDIO/VIDEO and for receiver the receiverConsumerAUDIO/VIDEO
*/ */
socket.on('consumer-resume', async () => { socket.on('consumer-resume',() => {
try { try {
const callId = socketDetails[socket.id]; const callId = socketDetails[socket.id];
console.log(`[consumer-resume] callId ${callId}`) console.log(`[consumer-resume] callId ${callId}`)
if (isInitiator(callId, socket.id)) { if (isInitiator(callId, socket.id)) {
console.log(`[consumer-resume] isInitiator true`); videoCalls[callId]?.initiatorConsumerVideo?.resume();
await videoCalls[callId].initiatorConsumerVideo.resume(); videoCalls[callId]?.initiatorConsumerAudio?.resume();
await videoCalls[callId].initiatorConsumerAudio.resume();
} else { } else {
console.log(`[consumer-resume] isInitiator false`); videoCalls[callId]?.receiverConsumerVideo?.resume();
(videoCalls[callId].receiverConsumerVideo) && await videoCalls[callId].receiverConsumerVideo.resume(); videoCalls[callId]?.receiverConsumerAudio?.resume();
(videoCalls[callId].receiverConsumerVideo) && await videoCalls[callId].receiverConsumerAudio.resume();
} }
// await videoCalls[callId].consumerVideo.resume();
// await videoCalls[callId].consumerAudio.resume();
} catch (error) { } catch (error) {
console.log(`ERROR | consumer-resume | callId ${socketDetails[socket.id]} | ${error.message}`); console.log(`ERROR | consumer-resume | callId ${socketDetails[socket.id]} | ${error.message}`);
} }
@ -581,7 +644,7 @@ const consumeAudio = async (callId, socketId, rtpCapabilities) => {
} }
const isInitiator = (callId, socketId) => { const isInitiator = (callId, socketId) => {
return (videoCalls[callId].initiatorSockerId === socketId); return (videoCalls[callId].initiatorSocket.id === socketId);
} }
/* /*

View File

@ -9,13 +9,19 @@ else
## CLEANUP ## CLEANUP
rm -fr dist/* rm -fr dist/*
fi fi
if [ -d "node_modules" ]; then
rm -fr node_modules
fi
# Install dependencies # Install dependencies
#npm install #npm install
## PROJECT NEEDS ## PROJECT NEEDS
echo "Building app... from $(git rev-parse --abbrev-ref HEAD)" echo "Building app... from $(git rev-parse --abbrev-ref HEAD)"
#npm run-script build #npm run-script build
cp -r {.env,app.js,package.json,server,public} dist/ #cp -r {.env,app.js,package.json,server,public} dist/
cp -r ./* dist/
#Add version control for pm2 #Add version control for pm2
cd dist cd dist

Binary file not shown.

After

Width:  |  Height:  |  Size: 614 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 354 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 462 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 252 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 346 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 407 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 439 KiB

View File

@ -20811,28 +20811,15 @@ const connectRecvTransport = async () => {
if (audioParams) { if (audioParams) {
console.log('❗ Have AUDIO stream to consume'); console.log('❗ Have AUDIO stream to consume');
let audioTrack = await getAudioTrask(audioParams) let audioTrack = await getAudioTrask(audioParams)
console.log('audioTrack', audioTrack);
stream.addTrack(audioTrack) stream.addTrack(audioTrack)
} else { } else {
console.log('❗ Don\'t have AUDIO stream to consume'); console.log('❗ Don\'t have AUDIO stream to consume');
} }
console.log('----------stream', stream);
console.log('stream.getAudioTracks()', stream.getAudioTracks());
socket.emit('consumer-resume') socket.emit('consumer-resume')
remoteVideo.srcObject = stream remoteVideo.srcObject = stream
// remoteVideo.autoplay = true remoteVideo.setAttribute('autoplay', true)
remoteVideo.controls = true;
remoteVideo.muted = true;
remoteVideo.loop = true;
remoteVideo.setAttribute('playsinline', '');
remoteVideo.src = stream;
remoteVideo.volume = 1.0;
// window.localStream = stream; // A
// window.localAudio.srcObject = stream; // B
// window.localAudio.autoplay = true; // C
remoteVideo.play() remoteVideo.play()
.then(() => { .then(() => {
@ -20873,24 +20860,24 @@ const getAudioTrask = async (audioParams) => {
const audioTrack = consumerAudio.track const audioTrack = consumerAudio.track
// audioTrack.applyConstraints({ audioTrack.applyConstraints({
// audio: { audio: {
// advanced: [ advanced: [
// { {
// echoCancellation: {exact: true} echoCancellation: {exact: true}
// }, },
// { {
// autoGainControl: {exact: true} autoGainControl: {exact: true}
// }, },
// { {
// noiseSuppression: {exact: true} noiseSuppression: {exact: true}
// }, },
// { {
// highpassFilter: {exact: true} highpassFilter: {exact: true}
// } }
// ] ]
// } }
// }) })
return audioTrack return audioTrack
} }

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 493 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 418 B

View File

@ -95,6 +95,10 @@ setTimeout(() => {
} }
if (IS_PRODUCER && urlParams.get('testing') === 'true') { getLocalStream() } if (IS_PRODUCER && urlParams.get('testing') === 'true') { getLocalStream() }
}) })
// socket.on('new-producer', ({ callId }) => {
// console.log(`🟥 new-producer | callId: ${callId}`);
// })
} }
if (IS_PRODUCER === true) { if (IS_PRODUCER === true) {
@ -453,28 +457,15 @@ const connectRecvTransport = async () => {
if (audioParams) { if (audioParams) {
console.log('❗ Have AUDIO stream to consume'); console.log('❗ Have AUDIO stream to consume');
let audioTrack = await getAudioTrask(audioParams) let audioTrack = await getAudioTrask(audioParams)
console.log('audioTrack', audioTrack);
stream.addTrack(audioTrack) stream.addTrack(audioTrack)
} else { } else {
console.log('❗ Don\'t have AUDIO stream to consume'); console.log('❗ Don\'t have AUDIO stream to consume');
} }
console.log('----------stream', stream);
console.log('stream.getAudioTracks()', stream.getAudioTracks());
socket.emit('consumer-resume') socket.emit('consumer-resume')
remoteVideo.srcObject = stream remoteVideo.srcObject = stream
// remoteVideo.autoplay = true remoteVideo.setAttribute('autoplay', true)
remoteVideo.controls = true;
remoteVideo.muted = true;
remoteVideo.loop = true;
remoteVideo.setAttribute('playsinline', '');
remoteVideo.src = stream;
remoteVideo.volume = 1.0;
// window.localStream = stream; // A
// window.localAudio.srcObject = stream; // B
// window.localAudio.autoplay = true; // C
remoteVideo.play() remoteVideo.play()
.then(() => { .then(() => {
@ -515,24 +506,24 @@ const getAudioTrask = async (audioParams) => {
const audioTrack = consumerAudio.track const audioTrack = consumerAudio.track
// audioTrack.applyConstraints({ audioTrack.applyConstraints({
// audio: { audio: {
// advanced: [ advanced: [
// { {
// echoCancellation: {exact: true} echoCancellation: {exact: true}
// }, },
// { {
// autoGainControl: {exact: true} autoGainControl: {exact: true}
// }, },
// { {
// noiseSuppression: {exact: true} noiseSuppression: {exact: true}
// }, },
// { {
// highpassFilter: {exact: true} highpassFilter: {exact: true}
// } }
// ] ]
// } }
// }) })
return audioTrack return audioTrack
} }