Compare commits
10 Commits
fix-branch
...
4.04
Author | SHA1 | Date | |
---|---|---|---|
75d0e3aee7 | |||
30ac997634 | |||
5aea138f6a | |||
5b01ddc2a8 | |||
084ff36ebe | |||
f4ebf92783 | |||
b59a157b18 | |||
9f8347bec5 | |||
24390c98e5 | |||
1a7371fe18 |
1
.gitignore
vendored
1
.gitignore
vendored
@ -1 +1,2 @@
|
||||
/node_modules
|
||||
/dist
|
||||
|
49
app.js
49
app.js
@ -5,7 +5,12 @@ const app = express();
|
||||
const Server = require('socket.io');
|
||||
const path = require('node:path');
|
||||
const fs = require('node:fs');
|
||||
const https = require('https');
|
||||
let https;
|
||||
try {
|
||||
https = require('node:https');
|
||||
} catch (err) {
|
||||
console.log('https support is disabled!');
|
||||
}
|
||||
const mediasoup = require('mediasoup');
|
||||
|
||||
let worker
|
||||
@ -37,8 +42,8 @@ app.use('/sfu', express.static(path.join(__dirname, 'public')))
|
||||
|
||||
// SSL cert for HTTPS access
|
||||
const options = {
|
||||
key: fs.readFileSync('./server/ssl/key.pem', 'utf-8'),
|
||||
cert: fs.readFileSync('./server/ssl/cert.pem', 'utf-8'),
|
||||
key: fs.readFileSync(process.env.SERVER_KEY, 'utf-8'),
|
||||
cert: fs.readFileSync(process.env.SERVER_CERT, 'utf-8'),
|
||||
}
|
||||
|
||||
const httpsServer = https.createServer(options, app);
|
||||
@ -58,13 +63,12 @@ httpsServer.listen(process.env.PORT, () => {
|
||||
});
|
||||
|
||||
const peers = io.of('/');
|
||||
console.log('process.env.RTC_MIN_PORT', process.env.RTC_MIN_PORT);
|
||||
console.log('process.env.RTC_MAX_PORT', process.env.RTC_MAX_PORT, process.env.RTC_MAX_PORT.length);
|
||||
|
||||
const createWorker = async () => {
|
||||
try {
|
||||
worker = await mediasoup.createWorker({
|
||||
rtcMinPort: process.env.RTC_MIN_PORT,
|
||||
rtcMaxPort: process.env.RTC_MAX_PORT,
|
||||
rtcMinPort: parseInt(process.env.RTC_MIN_PORT),
|
||||
rtcMaxPort: parseInt(process.env.RTC_MAX_PORT),
|
||||
})
|
||||
console.log(`[createWorker] worker pid ${worker.pid}`);
|
||||
|
||||
@ -120,16 +124,6 @@ const closeCall = (callId) => {
|
||||
}
|
||||
}
|
||||
|
||||
const getRtpCapabilities = (callId, callback) => {
|
||||
try {
|
||||
console.log('[getRtpCapabilities] callId', callId);
|
||||
const rtpCapabilities = videoCalls[callId].router.rtpCapabilities;
|
||||
callback({ rtpCapabilities });
|
||||
} catch (error) {
|
||||
console.log(`ERROR | getRtpCapabilities | callId ${callId} | ${error.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
- Handlers for WS events
|
||||
- These are created only when we have a connection with a peer
|
||||
@ -156,7 +150,9 @@ peers.on('connection', async socket => {
|
||||
- If the room already exists, it will not create it, but will only return rtpCapabilities
|
||||
*/
|
||||
socket.on('createRoom', async ({ callId }, callback) => {
|
||||
let callbackResponse = null;
|
||||
try {
|
||||
// We can continue with the room creation process only if we have a callId
|
||||
if (callId) {
|
||||
console.log(`[createRoom] socket.id ${socket.id} callId ${callId}`);
|
||||
if (!videoCalls[callId]) {
|
||||
@ -165,12 +161,19 @@ peers.on('connection', async socket => {
|
||||
console.log(`[createRoom] Router ID: ${videoCalls[callId].router.id}`);
|
||||
}
|
||||
socketDetails[socket.id] = callId;
|
||||
getRtpCapabilities(callId, callback);
|
||||
|
||||
// rtpCapabilities is set for callback
|
||||
console.log('[getRtpCapabilities] callId', callId);
|
||||
callbackResponse = {
|
||||
rtpCapabilities :videoCalls[callId].router.rtpCapabilities
|
||||
};
|
||||
} else {
|
||||
console.log(`[createRoom] missing callId ${callId}`);
|
||||
}
|
||||
} catch (error) {
|
||||
console.log(`ERROR | createRoom | callId ${callId} | ${error.message}`);
|
||||
} finally {
|
||||
callback(callbackResponse);
|
||||
}
|
||||
});
|
||||
|
||||
@ -191,16 +194,19 @@ peers.on('connection', async socket => {
|
||||
videoCalls[callId].producerTransport = await createWebRtcTransportLayer(callId, callback);
|
||||
} else {
|
||||
console.log(`producerTransport has already been defined | callId ${callId}`);
|
||||
callback(null);
|
||||
}
|
||||
} else if (!sender) {
|
||||
if (!videoCalls[callId].consumerTransport) {
|
||||
videoCalls[callId].consumerTransport = await createWebRtcTransportLayer(callId, callback);
|
||||
} else {
|
||||
console.log(`consumerTransport has already been defined | callId ${callId}`);
|
||||
callback(null);
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.log(`ERROR | createWebRtcTransport | callId ${socketDetails[socket.id]} | sender ${sender} | ${error.message}`);
|
||||
callback(error);
|
||||
}
|
||||
});
|
||||
|
||||
@ -244,9 +250,9 @@ peers.on('connection', async socket => {
|
||||
});
|
||||
|
||||
// Send back to the client the Producer's id
|
||||
// callback({
|
||||
// id: videoCalls[callId].producer.id
|
||||
// });
|
||||
callback && callback({
|
||||
id: videoCalls[callId].producer.id
|
||||
});
|
||||
} catch (error) {
|
||||
console.log(`ERROR | transport-produce | callId ${socketDetails[socket.id]} | ${error.message}`);
|
||||
}
|
||||
@ -317,6 +323,7 @@ peers.on('connection', async socket => {
|
||||
callback({ params });
|
||||
} else {
|
||||
console.log(`[canConsume] Can't consume | callId ${callId}`);
|
||||
callback(null);
|
||||
}
|
||||
} catch (error) {
|
||||
console.log(`ERROR | consume | callId ${socketDetails[socket.id]} | ${error.message}`)
|
||||
|
48
build.sh
Executable file
48
build.sh
Executable file
@ -0,0 +1,48 @@
|
||||
#/!bin/bash
|
||||
## PREBUILD PROCESS
|
||||
# check dist dir to be present and empty
|
||||
if [ ! -d "dist" ]; then
|
||||
## MAKE DIR
|
||||
mkdir "dist"
|
||||
echo "Directory dist created."
|
||||
else
|
||||
## CLEANUP
|
||||
rm -fr dist/*
|
||||
fi
|
||||
# Install dependencies
|
||||
#npm install
|
||||
|
||||
## PROJECT NEEDS
|
||||
echo "Building app... from $(git rev-parse --abbrev-ref HEAD)"
|
||||
#npm run-script build
|
||||
cp -r {.env,app.js,package.json,server,public} dist/
|
||||
|
||||
#Add version control for pm2
|
||||
cd dist
|
||||
#Add version control for pm2
|
||||
version=$(git describe)
|
||||
file_pkg="package.json"
|
||||
key=" \"version\": \""
|
||||
|
||||
count=$(echo ${version%%-*} | grep -o "\." | wc -l)
|
||||
if (( $count > 1 )); then
|
||||
version=${version%%-*}
|
||||
else
|
||||
version="${version%%-*}.0"
|
||||
fi
|
||||
if [ -f "$file_pkg" ] && [ ! -z "$version" ]; then
|
||||
version=" \"version\": \"$version\","
|
||||
sed -i "s|^.*$key.*|${version//\//\\/}|g" $file_pkg
|
||||
text=$(cat $file_pkg | grep -c "$version")
|
||||
if [ $text -eq 0 ]; then
|
||||
echo "Version couldn't be set"
|
||||
else
|
||||
echo "Version $version successfully applied to App"
|
||||
fi
|
||||
fi
|
||||
|
||||
## POST BUILD
|
||||
|
||||
cd -
|
||||
|
||||
|
Reference in New Issue
Block a user