Compare commits
37 Commits
4.00
...
e9ff060544
Author | SHA1 | Date | |
---|---|---|---|
e9ff060544 | |||
7d677f4a34 | |||
8f96b8c98b | |||
1084a808c7 | |||
3838f774bf | |||
06bb275f0d | |||
a05f7cc987 | |||
c5c8bc5bb3 | |||
d6bc4e51e5 | |||
4ae02f70d6 | |||
d593d6dc83 | |||
1a1fa9450e | |||
0d24604f2a | |||
1d7c994036 | |||
bc2bf24a65 | |||
cdbfc7891d | |||
c730341674 | |||
b621b76e37 | |||
39ad9cad27 | |||
8860423e21 | |||
9179a67f64 | |||
75d0e3aee7 | |||
30ac997634 | |||
5aea138f6a | |||
5b01ddc2a8 | |||
084ff36ebe | |||
f4ebf92783 | |||
b59a157b18 | |||
9f8347bec5 | |||
24390c98e5 | |||
1a7371fe18 | |||
be5f97762a | |||
03a11126c4 | |||
fafbee6e4c | |||
bbf23c33d4 | |||
5c2808e75a | |||
2aea7497cc |
4
.env
4
.env
@ -1,3 +1,7 @@
|
|||||||
PORT=3000
|
PORT=3000
|
||||||
IP=0.0.0.0 # Listening IPv4 or IPv6.
|
IP=0.0.0.0 # Listening IPv4 or IPv6.
|
||||||
ANNOUNCED_IP=185.8.154.190 # Announced IPv4 or IPv6 (useful when running mediasoup behind NAT with private IP).
|
ANNOUNCED_IP=185.8.154.190 # Announced IPv4 or IPv6 (useful when running mediasoup behind NAT with private IP).
|
||||||
|
RTC_MIN_PORT=2000
|
||||||
|
RTC_MAX_PORT=2020
|
||||||
|
SERVER_CERT="./server/ssl/cert.pem"
|
||||||
|
SERVER_KEY="./server/ssl/key.pem"
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -1 +1,2 @@
|
|||||||
/node_modules
|
/node_modules
|
||||||
|
/dist
|
||||||
|
57
app.js
57
app.js
@ -5,7 +5,7 @@ const app = express();
|
|||||||
const Server = require('socket.io');
|
const Server = require('socket.io');
|
||||||
const path = require('node:path');
|
const path = require('node:path');
|
||||||
const fs = require('node:fs');
|
const fs = require('node:fs');
|
||||||
let https = require('https');
|
let https;
|
||||||
try {
|
try {
|
||||||
https = require('node:https');
|
https = require('node:https');
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@ -42,8 +42,8 @@ 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('./server/ssl/key.pem', 'utf-8'),
|
key: fs.readFileSync(process.env.SERVER_KEY, 'utf-8'),
|
||||||
cert: fs.readFileSync('./server/ssl/cert.pem', 'utf-8'),
|
cert: fs.readFileSync(process.env.SERVER_CERT, 'utf-8'),
|
||||||
}
|
}
|
||||||
|
|
||||||
const httpsServer = https.createServer(options, app);
|
const httpsServer = https.createServer(options, app);
|
||||||
@ -59,16 +59,16 @@ const io = new Server(httpsServer, {
|
|||||||
// const io = new Server(server, { origins: '*:*', allowEIO3: true });
|
// const io = new Server(server, { origins: '*:*', allowEIO3: true });
|
||||||
|
|
||||||
httpsServer.listen(process.env.PORT, () => {
|
httpsServer.listen(process.env.PORT, () => {
|
||||||
console.log('Video server listening on port:', process.env.PORT)
|
console.log('Video server listening on port:', process.env.PORT);
|
||||||
})
|
});
|
||||||
|
|
||||||
const peers = io.of('/')
|
const peers = io.of('/');
|
||||||
|
|
||||||
const createWorker = async () => {
|
const createWorker = async () => {
|
||||||
try {
|
try {
|
||||||
worker = await mediasoup.createWorker({
|
worker = await mediasoup.createWorker({
|
||||||
rtcMinPort: 2000,
|
rtcMinPort: parseInt(process.env.RTC_MIN_PORT),
|
||||||
rtcMaxPort: 2020,
|
rtcMaxPort: parseInt(process.env.RTC_MAX_PORT),
|
||||||
})
|
})
|
||||||
console.log(`[createWorker] worker pid ${worker.pid}`);
|
console.log(`[createWorker] worker pid ${worker.pid}`);
|
||||||
|
|
||||||
@ -84,7 +84,7 @@ const createWorker = async () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// We create a Worker as soon as our application starts
|
// We create a Worker as soon as our application starts
|
||||||
worker = createWorker()
|
worker = createWorker();
|
||||||
|
|
||||||
// This is an Array of RtpCapabilities
|
// This is an Array of RtpCapabilities
|
||||||
// https://mediasoup.org/documentation/v3/mediasoup/rtp-parameters-and-capabilities/#RtpCodecCapability
|
// https://mediasoup.org/documentation/v3/mediasoup/rtp-parameters-and-capabilities/#RtpCodecCapability
|
||||||
@ -105,11 +105,11 @@ const mediaCodecs = [
|
|||||||
'x-google-start-bitrate': 1000,
|
'x-google-start-bitrate': 1000,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
]
|
];
|
||||||
|
|
||||||
const closeCall = (callId) => {
|
const closeCall = (callId) => {
|
||||||
try {
|
try {
|
||||||
if (videoCalls[callId]) {
|
if (callId && videoCalls[callId]) {
|
||||||
videoCalls[callId].producer?.close();
|
videoCalls[callId].producer?.close();
|
||||||
videoCalls[callId].consumer?.close();
|
videoCalls[callId].consumer?.close();
|
||||||
videoCalls[callId]?.consumerTransport?.close();
|
videoCalls[callId]?.consumerTransport?.close();
|
||||||
@ -124,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
|
- Handlers for WS events
|
||||||
- These are created only when we have a connection with a peer
|
- These are created only when we have a connection with a peer
|
||||||
@ -160,7 +150,9 @@ peers.on('connection', async socket => {
|
|||||||
- If the room already exists, it will not create it, but will only return rtpCapabilities
|
- If the room already exists, it will not create it, but will only return rtpCapabilities
|
||||||
*/
|
*/
|
||||||
socket.on('createRoom', async ({ callId }, callback) => {
|
socket.on('createRoom', async ({ callId }, callback) => {
|
||||||
|
let callbackResponse = null;
|
||||||
try {
|
try {
|
||||||
|
// We can continue with the room creation process only if we have a callId
|
||||||
if (callId) {
|
if (callId) {
|
||||||
console.log(`[createRoom] socket.id ${socket.id} callId ${callId}`);
|
console.log(`[createRoom] socket.id ${socket.id} callId ${callId}`);
|
||||||
if (!videoCalls[callId]) {
|
if (!videoCalls[callId]) {
|
||||||
@ -169,12 +161,19 @@ peers.on('connection', async socket => {
|
|||||||
console.log(`[createRoom] Router ID: ${videoCalls[callId].router.id}`);
|
console.log(`[createRoom] Router ID: ${videoCalls[callId].router.id}`);
|
||||||
}
|
}
|
||||||
socketDetails[socket.id] = callId;
|
socketDetails[socket.id] = callId;
|
||||||
getRtpCapabilities(callId, callback);
|
|
||||||
|
// rtpCapabilities is set for callback
|
||||||
|
console.log('[getRtpCapabilities] callId', callId);
|
||||||
|
callbackResponse = {
|
||||||
|
rtpCapabilities :videoCalls[callId].router.rtpCapabilities
|
||||||
|
};
|
||||||
} else {
|
} else {
|
||||||
console.log(`[createRoom] missing callId ${callId}`);
|
console.log(`[createRoom] missing callId ${callId}`);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(`ERROR | createRoom | callId ${callId} | ${error.message}`);
|
console.log(`ERROR | createRoom | callId ${callId} | ${error.message}`);
|
||||||
|
} finally {
|
||||||
|
callback(callbackResponse);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -195,16 +194,19 @@ peers.on('connection', async socket => {
|
|||||||
videoCalls[callId].producerTransport = await createWebRtcTransportLayer(callId, callback);
|
videoCalls[callId].producerTransport = await createWebRtcTransportLayer(callId, callback);
|
||||||
} else {
|
} else {
|
||||||
console.log(`producerTransport has already been defined | callId ${callId}`);
|
console.log(`producerTransport has already been defined | callId ${callId}`);
|
||||||
|
callback(null);
|
||||||
}
|
}
|
||||||
} else if (!sender) {
|
} else if (!sender) {
|
||||||
if (!videoCalls[callId].consumerTransport) {
|
if (!videoCalls[callId].consumerTransport) {
|
||||||
videoCalls[callId].consumerTransport = await createWebRtcTransportLayer(callId, callback);
|
videoCalls[callId].consumerTransport = await createWebRtcTransportLayer(callId, callback);
|
||||||
} else {
|
} else {
|
||||||
console.log(`consumerTransport has already been defined | callId ${callId}`);
|
console.log(`consumerTransport has already been defined | callId ${callId}`);
|
||||||
|
callback(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(`ERROR | createWebRtcTransport | callId ${socketDetails[socket.id]} | sender ${sender} | ${error.message}`);
|
console.log(`ERROR | createWebRtcTransport | callId ${socketDetails[socket.id]} | sender ${sender} | ${error.message}`);
|
||||||
|
callback(error);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -248,9 +250,9 @@ peers.on('connection', async socket => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Send back to the client the Producer's id
|
// Send back to the client the Producer's id
|
||||||
// callback({
|
callback && callback({
|
||||||
// id: videoCalls[callId].producer.id
|
id: videoCalls[callId].producer.id
|
||||||
// });
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(`ERROR | transport-produce | callId ${socketDetails[socket.id]} | ${error.message}`);
|
console.log(`ERROR | transport-produce | callId ${socketDetails[socket.id]} | ${error.message}`);
|
||||||
}
|
}
|
||||||
@ -299,14 +301,14 @@ peers.on('connection', async socket => {
|
|||||||
videoCalls[callId].consumer.on('transportclose', () => {
|
videoCalls[callId].consumer.on('transportclose', () => {
|
||||||
const callId = socketDetails[socket.id];
|
const callId = socketDetails[socket.id];
|
||||||
console.log('transport close from consumer', callId);
|
console.log('transport close from consumer', callId);
|
||||||
closeCall();
|
closeCall(callId);
|
||||||
});
|
});
|
||||||
|
|
||||||
// https://mediasoup.org/documentation/v3/mediasoup/api/#consumer-on-producerclose
|
// https://mediasoup.org/documentation/v3/mediasoup/api/#consumer-on-producerclose
|
||||||
videoCalls[callId].consumer.on('producerclose', () => {
|
videoCalls[callId].consumer.on('producerclose', () => {
|
||||||
const callId = socketDetails[socket.id];
|
const callId = socketDetails[socket.id];
|
||||||
console.log('producer of consumer closed', callId);
|
console.log('producer of consumer closed', callId);
|
||||||
closeCall();
|
closeCall(callId);
|
||||||
});
|
});
|
||||||
|
|
||||||
// From the consumer extract the following params to send back to the Client
|
// From the consumer extract the following params to send back to the Client
|
||||||
@ -321,6 +323,7 @@ peers.on('connection', async socket => {
|
|||||||
callback({ params });
|
callback({ params });
|
||||||
} else {
|
} else {
|
||||||
console.log(`[canConsume] Can't consume | callId ${callId}`);
|
console.log(`[canConsume] Can't consume | callId ${callId}`);
|
||||||
|
callback(null);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(`ERROR | consume | callId ${socketDetails[socket.id]} | ${error.message}`)
|
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 -
|
||||||
|
|
||||||
|
|
1276
public/bundle.js
1276
public/bundle.js
File diff suppressed because it is too large
Load Diff
@ -1,5 +1,4 @@
|
|||||||
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',
|
||||||
// mediasoupAddress: 'http://localhost:3000/mediasoup',
|
|
||||||
}
|
}
|
204
public/index.js
204
public/index.js
@ -12,83 +12,91 @@ let callId = parseInt(urlParams.get('callId')) || null;
|
|||||||
const IS_PRODUCER = urlParams.get('producer') === 'true' ? true : false
|
const IS_PRODUCER = urlParams.get('producer') === 'true' ? true : false
|
||||||
console.log('[URL] ASSET_ID', ASSET_ID, '| ACCOUNT_ID', ACCOUNT_ID, '| callId', callId, ' | IS_PRODUCER', IS_PRODUCER)
|
console.log('[URL] ASSET_ID', ASSET_ID, '| ACCOUNT_ID', ACCOUNT_ID, '| callId', callId, ' | IS_PRODUCER', IS_PRODUCER)
|
||||||
|
|
||||||
let socket
|
console.log('🟩 config', config)
|
||||||
hub = io(config.hubAddress)
|
|
||||||
|
|
||||||
const connectToMediasoup = () => {
|
let socket, hub
|
||||||
|
|
||||||
socket = io(config.mediasoupAddress, {
|
setTimeout(() => {
|
||||||
reconnection: true,
|
hub = io(config.hubAddress)
|
||||||
reconnectionDelay: 1000,
|
|
||||||
reconnectionDelayMax : 5000,
|
|
||||||
reconnectionAttempts: Infinity
|
|
||||||
})
|
|
||||||
|
|
||||||
socket.on('connection-success', ({ _socketId, existsProducer }) => {
|
|
||||||
console.log(`[MEDIA] ${config.mediasoupAddress} | connected: ${socket.connected} | existsProducer: ${existsProducer}`)
|
|
||||||
if (!IS_PRODUCER && existsProducer && consumer === undefined) {
|
|
||||||
goConnect()
|
|
||||||
// document.getElementById('btnRecvSendTransport').click();
|
|
||||||
}
|
|
||||||
if (IS_PRODUCER && urlParams.get('testing') === 'true') { getLocalStream() }
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
if (IS_PRODUCER === true) {
|
|
||||||
hub.on('connect', async () => {
|
|
||||||
console.log(`[HUB] ${config.hubAddress} | connected: ${hub.connected}`)
|
|
||||||
connectToMediasoup()
|
|
||||||
|
|
||||||
hub.emit(
|
|
||||||
'ars',
|
|
||||||
JSON.stringify({
|
|
||||||
ars: true,
|
|
||||||
asset_id: ASSET_ID,
|
|
||||||
account_id: ACCOUNT_ID,
|
|
||||||
})
|
|
||||||
)
|
|
||||||
|
|
||||||
hub.on('video', (data) => {
|
const connectToMediasoup = () => {
|
||||||
const parsedData = JSON.parse(data);
|
|
||||||
|
|
||||||
if (parsedData.type === 'notify-request') {
|
|
||||||
console.log('video', parsedData)
|
|
||||||
originAssetId = parsedData.origin_asset_id;
|
|
||||||
// originAssetName = parsedData.origin_asset_name;
|
|
||||||
// originAssetTypeName = parsedData.origin_asset_type_name;
|
|
||||||
callId = parsedData.video_call_id;
|
|
||||||
|
|
||||||
console.log('[VIDEO] notify-request | IS_PRODUCER', IS_PRODUCER, 'callId', callId);
|
socket = io(config.mediasoupAddress, {
|
||||||
getLocalStream()
|
reconnection: true,
|
||||||
}
|
reconnectionDelay: 1000,
|
||||||
|
reconnectionDelayMax : 5000,
|
||||||
if (parsedData.type === 'notify-end') {
|
reconnectionAttempts: Infinity
|
||||||
console.log('[VIDEO] notify-end | IS_PRODUCER', IS_PRODUCER, 'callId', callId);
|
|
||||||
resetCallSettings()
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
})
|
|
||||||
|
socket.on('connection-success', ({ _socketId, existsProducer }) => {
|
||||||
|
console.log(`[MEDIA] ${config.mediasoupAddress} | connected: ${socket.connected} | existsProducer: ${existsProducer}`)
|
||||||
|
if (!IS_PRODUCER && existsProducer && consumer === undefined) {
|
||||||
|
goConnect()
|
||||||
|
// document.getElementById('btnRecvSendTransport').click();
|
||||||
|
}
|
||||||
|
if (IS_PRODUCER && urlParams.get('testing') === 'true') { getLocalStream() }
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
if (IS_PRODUCER === true) {
|
||||||
|
hub.on('connect', async () => {
|
||||||
|
console.log(`[HUB]! ${config.hubAddress} | connected: ${hub.connected}`)
|
||||||
|
connectToMediasoup()
|
||||||
|
|
||||||
|
hub.emit(
|
||||||
|
'ars',
|
||||||
|
JSON.stringify({
|
||||||
|
ars: true,
|
||||||
|
asset_id: ASSET_ID,
|
||||||
|
account_id: ACCOUNT_ID,
|
||||||
|
})
|
||||||
|
)
|
||||||
|
|
||||||
|
hub.on('video', (data) => {
|
||||||
|
const parsedData = JSON.parse(data);
|
||||||
|
|
||||||
|
if (parsedData.type === 'notify-request') {
|
||||||
|
console.log('video', parsedData)
|
||||||
|
originAssetId = parsedData.origin_asset_id;
|
||||||
|
// originAssetName = parsedData.origin_asset_name;
|
||||||
|
// originAssetTypeName = parsedData.origin_asset_type_name;
|
||||||
|
callId = parsedData.video_call_id;
|
||||||
|
|
||||||
|
console.log('[VIDEO] notify-request | IS_PRODUCER', IS_PRODUCER, 'callId', callId);
|
||||||
|
getLocalStream()
|
||||||
|
}
|
||||||
|
|
||||||
|
if (parsedData.type === 'notify-end') {
|
||||||
|
console.log('[VIDEO] notify-end | IS_PRODUCER', IS_PRODUCER, 'callId', callId);
|
||||||
|
resetCallSettings()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
hub.on('connect_error', (error) => {
|
||||||
|
console.log('connect_error', error);
|
||||||
|
});
|
||||||
|
|
||||||
|
hub.on('connection', () => {
|
||||||
|
console.log('connection')
|
||||||
|
})
|
||||||
|
|
||||||
|
hub.on('disconnect', () => {
|
||||||
|
console.log('disconnect')
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
connectToMediasoup()
|
||||||
|
}
|
||||||
|
|
||||||
|
}, 2000);
|
||||||
|
|
||||||
hub.on('connect_error', (error) => {
|
|
||||||
console.log('connect_error', error);
|
|
||||||
});
|
|
||||||
|
|
||||||
hub.on('connection', () => {
|
|
||||||
console.log('connection')
|
|
||||||
})
|
|
||||||
|
|
||||||
hub.on('disconnect', () => {
|
|
||||||
console.log('disconnect')
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
connectToMediasoup()
|
|
||||||
}
|
|
||||||
|
|
||||||
let device
|
let device
|
||||||
let rtpCapabilities
|
let rtpCapabilities
|
||||||
let producerTransport
|
let producerTransport
|
||||||
let consumerTransport
|
let consumerTransport
|
||||||
let producer
|
let producerVideo
|
||||||
|
let producerAudio
|
||||||
let consumer
|
let consumer
|
||||||
let originAssetId
|
let originAssetId
|
||||||
// let originAssetName = 'Adi'
|
// let originAssetName = 'Adi'
|
||||||
@ -96,21 +104,18 @@ let originAssetId
|
|||||||
|
|
||||||
// https://mediasoup.org/documentation/v3/mediasoup-client/api/#ProducerOptions
|
// https://mediasoup.org/documentation/v3/mediasoup-client/api/#ProducerOptions
|
||||||
// https://mediasoup.org/documentation/v3/mediasoup-client/api/#transport-produce
|
// https://mediasoup.org/documentation/v3/mediasoup-client/api/#transport-produce
|
||||||
let params = {
|
let videoParams = {
|
||||||
// mediasoup params
|
// mediasoup params
|
||||||
encodings: [
|
encodings: [
|
||||||
{
|
{
|
||||||
rid: 'r0',
|
|
||||||
maxBitrate: 100000,
|
maxBitrate: 100000,
|
||||||
scalabilityMode: 'S1T3',
|
scalabilityMode: 'S1T3',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
rid: 'r1',
|
|
||||||
maxBitrate: 300000,
|
maxBitrate: 300000,
|
||||||
scalabilityMode: 'S1T3',
|
scalabilityMode: 'S1T3',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
rid: 'r2',
|
|
||||||
maxBitrate: 900000,
|
maxBitrate: 900000,
|
||||||
scalabilityMode: 'S1T3',
|
scalabilityMode: 'S1T3',
|
||||||
},
|
},
|
||||||
@ -121,21 +126,51 @@ let params = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const streamSuccess = (stream) => {
|
let audioParams = {
|
||||||
console.log('[streamSuccess]');
|
// mediasoup params
|
||||||
localVideo.srcObject = stream
|
encodings: [
|
||||||
const track = stream.getVideoTracks()[0]
|
{
|
||||||
params = {
|
maxBitrate: 100000,
|
||||||
track,
|
scalabilityMode: 'S1T3',
|
||||||
...params
|
},
|
||||||
|
{
|
||||||
|
maxBitrate: 300000,
|
||||||
|
scalabilityMode: 'S1T3',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
maxBitrate: 900000,
|
||||||
|
scalabilityMode: 'S1T3',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
codecOptions: {
|
||||||
|
opusStereo: true
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const streamSuccess = (stream) => {
|
||||||
|
localVideo.srcObject = stream
|
||||||
|
console.log('stream', stream);
|
||||||
|
const videoTrack = stream.getVideoTracks()[0]
|
||||||
|
const audioTrack = stream.getAudioTracks()[0]
|
||||||
|
|
||||||
|
videoParams = {
|
||||||
|
track: videoTrack,
|
||||||
|
...videoParams
|
||||||
|
}
|
||||||
|
|
||||||
|
audioParams = {
|
||||||
|
track: audioTrack,
|
||||||
|
...audioParams
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('[streamSuccess] videoParams', videoParams, ' | audioParams', audioParams);
|
||||||
goConnect()
|
goConnect()
|
||||||
}
|
}
|
||||||
|
|
||||||
const getLocalStream = () => {
|
const getLocalStream = () => {
|
||||||
console.log('[getLocalStream]');
|
console.log('[getLocalStream]');
|
||||||
navigator.mediaDevices.getUserMedia({
|
navigator.mediaDevices.getUserMedia({
|
||||||
audio: false,
|
audio: true,
|
||||||
video: {
|
video: {
|
||||||
width: {
|
width: {
|
||||||
min: 640,
|
min: 640,
|
||||||
@ -244,7 +279,7 @@ const createSendTransport = () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
producerTransport.on('produce', async (parameters, callback, errback) => {
|
producerTransport.on('produce', async (parameters, callback, errback) => {
|
||||||
console.log(parameters)
|
console.log('[produce] parameters', parameters)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// tell the server to create a Producer
|
// tell the server to create a Producer
|
||||||
@ -270,18 +305,21 @@ const createSendTransport = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const connectSendTransport = async () => {
|
const connectSendTransport = async () => {
|
||||||
|
|
||||||
|
console.log('[connectSendTransport] producerTransport', params);
|
||||||
|
|
||||||
// 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)
|
producerVideo = await producerTransport.produce(videoParams)
|
||||||
|
|
||||||
producer.on('trackended', () => {
|
producerVideo.on('trackended', () => {
|
||||||
console.log('track ended')
|
console.log('track ended')
|
||||||
// close video track
|
// close video track
|
||||||
})
|
})
|
||||||
|
|
||||||
producer.on('transportclose', () => {
|
producerVideo.on('transportclose', () => {
|
||||||
console.log('transport ended')
|
console.log('transport ended')
|
||||||
// close video track
|
// close video track
|
||||||
})
|
})
|
||||||
@ -353,7 +391,7 @@ const resetCallSettings = () => {
|
|||||||
localVideo.srcObject = null
|
localVideo.srcObject = null
|
||||||
remoteVideo.srcObject = null
|
remoteVideo.srcObject = null
|
||||||
consumer = null
|
consumer = null
|
||||||
producer = null
|
producerVideo = null
|
||||||
producerTransport = null
|
producerTransport = null
|
||||||
consumerTransport = null
|
consumerTransport = null
|
||||||
device = undefined
|
device = undefined
|
||||||
|
Reference in New Issue
Block a user