Compare commits
23 Commits
LINXD-2270
...
LAPI-675-g
Author | SHA1 | Date | |
---|---|---|---|
26345bd22b | |||
9b4e0186ac | |||
eece7d2ee3 | |||
ad4c1f27e7 | |||
b2128c4754 | |||
af53dc1610 | |||
f48fe4f9aa | |||
6fd6ca9755 | |||
1b72941a32 | |||
c037240f47 | |||
9716bddd71 | |||
e6c08a2c1d | |||
1342e812e6 | |||
d8405eccc7 | |||
5bf31d452f | |||
c034610471 | |||
df5b3eab90 | |||
b0293230b6 | |||
391e8eb6f0 | |||
3139a625a2 | |||
9d43b7ec0c | |||
342d09c3e6 | |||
b3409de3ba |
125
app.js
@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
8
build.sh
@ -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
|
||||||
|
BIN
doc/[video] Call waiting.png
Normal file
After Width: | Height: | Size: 614 KiB |
BIN
doc/[video] Client Android-iOS closed.png
Normal file
After Width: | Height: | Size: 354 KiB |
BIN
doc/[video] Dispatcher closed.png
Normal file
After Width: | Height: | Size: 462 KiB |
BIN
doc/[video] HUB - Dispatcher close call before accept_reject.png
Normal file
After Width: | Height: | Size: 252 KiB |
BIN
doc/[video] HUB - Dispatcher close call.png
Normal file
After Width: | Height: | Size: 346 KiB |
BIN
doc/[video] HUB - Dispatcher dieconnect.png
Normal file
After Width: | Height: | Size: 407 KiB |
BIN
doc/[video] Video Window closed.png
Normal file
After Width: | Height: | Size: 439 KiB |
@ -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
|
||||||
}
|
}
|
||||||
|
Before Width: | Height: | Size: 4.2 KiB |
Before Width: | Height: | Size: 493 B |
Before Width: | Height: | Size: 418 B |
@ -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
|
||||||
}
|
}
|
||||||
|