Compare commits
75 Commits
dtls-test
...
9fbe01ae1d
Author | SHA1 | Date | |
---|---|---|---|
9fbe01ae1d | |||
e5bcc6262b | |||
c758a9106c | |||
fcbc28c801 | |||
ba63fb20bf | |||
e8bd6837cf | |||
d386915ff2 | |||
2479f58e21 | |||
d49b8e42ff | |||
a3ae874f8e | |||
c2dbef1918 | |||
b41b8f2d64 | |||
c089e91fba | |||
c63aee83a1 | |||
a97ec24148 | |||
3c23c6791d | |||
1a7b44807d | |||
daa2c556e4 | |||
22656722e8 | |||
f5b9067b7e | |||
0b3a45ae45 | |||
dfe4630839 | |||
d18041cadd | |||
fa42caeeb2 | |||
4dbb7ad554 | |||
d1063803b9 | |||
3cbd31b49c | |||
a39e0eaa17 | |||
b63fb39fd4 | |||
0dfbd296a7 | |||
233f49a998 | |||
127f17cd97 | |||
d1ad8b4d3a | |||
f20e1ad260 | |||
27151a26d1 | |||
544e9e59ab | |||
4e4cd6f893 | |||
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 | |||
56835d6660 |
4
.env
4
.env
@ -1,3 +1,7 @@
|
||||
PORT=3000
|
||||
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).
|
||||
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
|
||||
/dist
|
||||
|
115
app.js
115
app.js
@ -5,7 +5,7 @@ const app = express();
|
||||
const Server = require('socket.io');
|
||||
const path = require('node:path');
|
||||
const fs = require('node:fs');
|
||||
let https = require('https');
|
||||
let https;
|
||||
try {
|
||||
https = require('node:https');
|
||||
} catch (err) {
|
||||
@ -42,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);
|
||||
@ -59,16 +59,16 @@ const io = new Server(httpsServer, {
|
||||
// const io = new Server(server, { origins: '*:*', allowEIO3: true });
|
||||
|
||||
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 () => {
|
||||
try {
|
||||
worker = await mediasoup.createWorker({
|
||||
rtcMinPort: 2000,
|
||||
rtcMaxPort: 2020,
|
||||
rtcMinPort: parseInt(process.env.RTC_MIN_PORT),
|
||||
rtcMaxPort: parseInt(process.env.RTC_MAX_PORT),
|
||||
})
|
||||
console.log(`[createWorker] worker pid ${worker.pid}`);
|
||||
|
||||
@ -84,13 +84,62 @@ const createWorker = async () => {
|
||||
}
|
||||
|
||||
// We create a Worker as soon as our application starts
|
||||
worker = createWorker()
|
||||
worker = createWorker();
|
||||
|
||||
// This is an Array of RtpCapabilities
|
||||
// https://mediasoup.org/documentation/v3/mediasoup/rtp-parameters-and-capabilities/#RtpCodecCapability
|
||||
// list of media codecs supported by mediasoup ...
|
||||
// https://github.com/versatica/mediasoup/blob/v3/src/supportedRtpCapabilities.ts
|
||||
const mediaCodecs = [
|
||||
const mediaCodecs = [
|
||||
// {
|
||||
// kind : 'audio',
|
||||
// mimeType : 'audio/opus',
|
||||
// clockRate : 48000,
|
||||
// channels : 2
|
||||
// },
|
||||
// {
|
||||
// kind : 'video',
|
||||
// mimeType : 'video/VP8',
|
||||
// clockRate : 90000,
|
||||
// parameters :
|
||||
// {
|
||||
// 'x-google-start-bitrate' : 1000
|
||||
// }
|
||||
// },
|
||||
// {
|
||||
// kind : 'video',
|
||||
// mimeType : 'video/VP9',
|
||||
// clockRate : 90000,
|
||||
// parameters :
|
||||
// {
|
||||
// 'profile-id' : 2,
|
||||
// 'x-google-start-bitrate' : 1000
|
||||
// }
|
||||
// },
|
||||
// {
|
||||
// kind : 'video',
|
||||
// mimeType : 'video/h264',
|
||||
// clockRate : 90000,
|
||||
// parameters :
|
||||
// {
|
||||
// 'packetization-mode' : 1,
|
||||
// 'profile-level-id' : '4d0032',
|
||||
// 'level-asymmetry-allowed' : 1,
|
||||
// 'x-google-start-bitrate' : 1000
|
||||
// }
|
||||
// },
|
||||
// {
|
||||
// kind : 'video',
|
||||
// mimeType : 'video/h264',
|
||||
// clockRate : 90000,
|
||||
// parameters :
|
||||
// {
|
||||
// 'packetization-mode' : 1,
|
||||
// 'profile-level-id' : '42e01f',
|
||||
// 'level-asymmetry-allowed' : 1,
|
||||
// 'x-google-start-bitrate' : 1000
|
||||
// }
|
||||
// }
|
||||
{
|
||||
kind: 'audio',
|
||||
mimeType: 'audio/opus',
|
||||
@ -105,11 +154,11 @@ const mediaCodecs = [
|
||||
'x-google-start-bitrate': 1000,
|
||||
},
|
||||
},
|
||||
]
|
||||
];
|
||||
|
||||
const closeCall = (callId) => {
|
||||
try {
|
||||
if (videoCalls[callId]) {
|
||||
if (callId && videoCalls[callId]) {
|
||||
videoCalls[callId].producer?.close();
|
||||
videoCalls[callId].consumer?.close();
|
||||
videoCalls[callId]?.consumerTransport?.close();
|
||||
@ -124,16 +173,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
|
||||
@ -160,7 +199,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]) {
|
||||
@ -169,12 +210,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);
|
||||
}
|
||||
});
|
||||
|
||||
@ -195,16 +243,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);
|
||||
}
|
||||
});
|
||||
|
||||
@ -215,7 +266,9 @@ peers.on('connection', async socket => {
|
||||
socket.on('transport-connect', async ({ dtlsParameters }) => {
|
||||
try {
|
||||
const callId = socketDetails[socket.id];
|
||||
console.log(`[transport-connect] socket.id ${socket.id} | callId ${callId}`)
|
||||
if (typeof dtlsParameters === 'string') dtlsParameters = JSON.parse(dtlsParameters);
|
||||
|
||||
console.log(`[transport-connect] socket.id ${socket.id} | callId ${callId}`);
|
||||
await videoCalls[callId].producerTransport.connect({ dtlsParameters });
|
||||
} catch (error) {
|
||||
console.log(`ERROR | transport-connect | callId ${socketDetails[socket.id]} | ${error.message}`);
|
||||
@ -227,9 +280,11 @@ peers.on('connection', async socket => {
|
||||
- For the router with the id callId, we make produce on producerTransport
|
||||
- Create the handler on producer at the 'transportclose' event
|
||||
*/
|
||||
socket.on('transport-produce', async ({ kind, rtpParameters, appData }) => {
|
||||
socket.on('transport-produce', async ({ kind, rtpParameters, appData }, callback) => {
|
||||
try {
|
||||
const callId = socketDetails[socket.id];
|
||||
if (typeof rtpParameters === 'string') rtpParameters = JSON.parse(rtpParameters);
|
||||
|
||||
console.log('[transport-produce] | socket.id', socket.id, '| callId', callId);
|
||||
videoCalls[callId].producer = await videoCalls[callId].producerTransport.produce({
|
||||
kind,
|
||||
@ -242,6 +297,11 @@ peers.on('connection', async socket => {
|
||||
console.log('transport for this producer closed', callId)
|
||||
closeCall(callId);
|
||||
});
|
||||
|
||||
// Send back to the client the Producer's id
|
||||
callback && callback({
|
||||
id: videoCalls[callId].producer.id
|
||||
});
|
||||
} catch (error) {
|
||||
console.log(`ERROR | transport-produce | callId ${socketDetails[socket.id]} | ${error.message}`);
|
||||
}
|
||||
@ -290,14 +350,14 @@ peers.on('connection', async socket => {
|
||||
videoCalls[callId].consumer.on('transportclose', () => {
|
||||
const callId = socketDetails[socket.id];
|
||||
console.log('transport close from consumer', callId);
|
||||
closeCall();
|
||||
closeCall(callId);
|
||||
});
|
||||
|
||||
// https://mediasoup.org/documentation/v3/mediasoup/api/#consumer-on-producerclose
|
||||
videoCalls[callId].consumer.on('producerclose', () => {
|
||||
const callId = socketDetails[socket.id];
|
||||
console.log('producer of consumer closed', callId);
|
||||
closeCall();
|
||||
closeCall(callId);
|
||||
});
|
||||
|
||||
// From the consumer extract the following params to send back to the Client
|
||||
@ -312,6 +372,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 -
|
||||
|
||||
|
1304
public/bundle.js
1304
public/bundle.js
File diff suppressed because it is too large
Load Diff
@ -1,5 +1,4 @@
|
||||
module.exports = {
|
||||
hubAddress: 'https://hub.dev.linx.safemobile.com/',
|
||||
mediasoupAddress: 'https://video.safemobile.org/mediasoup',
|
||||
// mediasoupAddress: 'http://localhost:3000/mediasoup',
|
||||
mediasoupAddress: 'https://video.safemobile.org',
|
||||
}
|
232
public/index.js
232
public/index.js
@ -12,92 +12,106 @@ let callId = parseInt(urlParams.get('callId')) || null;
|
||||
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)
|
||||
|
||||
let socket
|
||||
hub = io(config.hubAddress)
|
||||
console.log('🟩 config', config)
|
||||
|
||||
const connectToMediasoup = () => {
|
||||
let socket, hub
|
||||
|
||||
socket = io(config.mediasoupAddress, {
|
||||
reconnection: true,
|
||||
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,
|
||||
})
|
||||
)
|
||||
setTimeout(() => {
|
||||
hub = io(config.hubAddress)
|
||||
|
||||
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;
|
||||
const connectToMediasoup = () => {
|
||||
|
||||
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()
|
||||
}
|
||||
socket = io(config.mediasoupAddress, {
|
||||
reconnection: true,
|
||||
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 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()
|
||||
}
|
||||
|
||||
}, 1600);
|
||||
|
||||
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 rtpCapabilities
|
||||
let producerTransport
|
||||
let consumerTransport
|
||||
let producer
|
||||
let producerVideo
|
||||
let producerAudio
|
||||
let consumer
|
||||
let originAssetId
|
||||
// let originAssetName = 'Adi'
|
||||
// let originAssetTypeName = 'linx'
|
||||
|
||||
// https://mediasoup.org/documentation/v3/mediasoup-client/api/#ProducerOptions
|
||||
// https://mediasoup.org/documentation/v3/mediasoup-client/api/#transport-produce
|
||||
let params = {
|
||||
// mediasoup params
|
||||
let videoParams = {
|
||||
// encodings: [
|
||||
// { scaleResolutionDownBy: 4, maxBitrate: 500000 },
|
||||
// { scaleResolutionDownBy: 2, maxBitrate: 1000000 },
|
||||
// { scaleResolutionDownBy: 1, maxBitrate: 5000000 },
|
||||
// { scalabilityMode: 'S3T3_KEY' }
|
||||
// ],
|
||||
// codecOptions: {
|
||||
// videoGoogleStartBitrate: 1000
|
||||
// }
|
||||
encodings: [
|
||||
{
|
||||
rid: 'r0',
|
||||
@ -121,19 +135,55 @@ let params = {
|
||||
}
|
||||
}
|
||||
|
||||
let audioParams = {
|
||||
codecOptions :
|
||||
{
|
||||
opusStereo : true,
|
||||
opusDtx : true
|
||||
}
|
||||
}
|
||||
|
||||
const streamSuccess = (stream) => {
|
||||
// console.log('[streamSuccess] device', device);
|
||||
// localVideo.srcObject = stream
|
||||
// console.log('stream', stream);
|
||||
// const videoTrack = stream.getVideoTracks()[0]
|
||||
// const audioTrack = stream.getAudioTracks()[0]
|
||||
|
||||
// videoParams = {
|
||||
// track: videoTrack,
|
||||
// // codec : device.rtpCapabilities.codecs.find((codec) => codec.mimeType.toLowerCase() === 'video/vp9'),
|
||||
// // codec : 'video/vp9',
|
||||
// ...videoParams
|
||||
// }
|
||||
|
||||
// audioParams = {
|
||||
// track: audioTrack,
|
||||
// ...audioParams
|
||||
// }
|
||||
|
||||
// console.log('[streamSuccess] videoParams', videoParams, ' | audioParams', audioParams);
|
||||
// goConnect()
|
||||
console.log('[streamSuccess]');
|
||||
localVideo.srcObject = stream
|
||||
const track = stream.getVideoTracks()[0]
|
||||
params = {
|
||||
videoParams = {
|
||||
track,
|
||||
...params
|
||||
...videoParams
|
||||
}
|
||||
goConnect()
|
||||
}
|
||||
|
||||
const getLocalStream = () => {
|
||||
console.log('[getLocalStream]');
|
||||
// navigator.mediaDevices.getUserMedia({
|
||||
// audio: false,
|
||||
// video: {
|
||||
// qvga : { width: { ideal: 320 }, height: { ideal: 240 } },
|
||||
// vga : { width: { ideal: 640 }, height: { ideal: 480 } },
|
||||
// hd : { width: { ideal: 1280 }, height: { ideal: 720 } }
|
||||
// }
|
||||
// })
|
||||
navigator.mediaDevices.getUserMedia({
|
||||
audio: false,
|
||||
video: {
|
||||
@ -167,7 +217,7 @@ const goCreateTransport = () => {
|
||||
// server side to send/recive media
|
||||
const createDevice = async () => {
|
||||
try {
|
||||
console.log('[createDevice]');
|
||||
console.log('[createDevice] 1 device', device);
|
||||
device = new mediasoupClient.Device()
|
||||
|
||||
// https://mediasoup.org/documentation/v3/mediasoup-client/api/#device-load
|
||||
@ -178,7 +228,8 @@ const createDevice = async () => {
|
||||
})
|
||||
|
||||
console.log('Device RTP Capabilities', device.rtpCapabilities)
|
||||
|
||||
console.log('[createDevice] 2 device', device);
|
||||
|
||||
// once the device loads, create transport
|
||||
goCreateTransport()
|
||||
|
||||
@ -207,6 +258,7 @@ const getRtpCapabilities = () => {
|
||||
}
|
||||
|
||||
const createSendTransport = () => {
|
||||
console.log('[createSendTransport');
|
||||
// see server's socket.on('createWebRtcTransport', sender?, ...)
|
||||
// this is a call from Producer, so sender = true
|
||||
socket.emit('createWebRtcTransport', { sender: true, callId }, ({ params }) => {
|
||||
@ -217,7 +269,7 @@ const createSendTransport = () => {
|
||||
return
|
||||
}
|
||||
|
||||
console.log(params)
|
||||
console.log('[createWebRtcTransport] params', params)
|
||||
|
||||
// creates a new WebRTC Transport to send media
|
||||
// based on the server's producer transport params
|
||||
@ -244,7 +296,7 @@ const createSendTransport = () => {
|
||||
})
|
||||
|
||||
producerTransport.on('produce', async (parameters, callback, errback) => {
|
||||
console.log(parameters)
|
||||
console.log('[produce] parameters', parameters)
|
||||
|
||||
try {
|
||||
// tell the server to create a Producer
|
||||
@ -270,22 +322,37 @@ const createSendTransport = () => {
|
||||
}
|
||||
|
||||
const connectSendTransport = async () => {
|
||||
|
||||
console.log('[connectSendTransport] producerTransport');
|
||||
|
||||
// we now call produce() to instruct the producer transport
|
||||
// to send media to the Router
|
||||
// https://mediasoup.org/documentation/v3/mediasoup-client/api/#transport-produce
|
||||
// this action will trigger the 'connect' and 'produce' events above
|
||||
producer = await producerTransport.produce(params)
|
||||
|
||||
producer.on('trackended', () => {
|
||||
producerVideo = await producerTransport.produce(videoParams)
|
||||
console.log('producerVideo', producerVideo);
|
||||
producerVideo.on('trackended', () => {
|
||||
console.log('track ended')
|
||||
// close video track
|
||||
})
|
||||
|
||||
producer.on('transportclose', () => {
|
||||
producerVideo.on('transportclose', () => {
|
||||
console.log('transport ended')
|
||||
// close video track
|
||||
})
|
||||
|
||||
// producerAudio = await producerTransport.produce(audioParams)
|
||||
// console.log('producerAudio', producerAudio);
|
||||
// producerAudio.on('trackended', () => {
|
||||
// console.log('track ended')
|
||||
// // close video track
|
||||
// })
|
||||
|
||||
// producerAudio.on('transportclose', () => {
|
||||
// console.log('transport ended')
|
||||
// // close video track
|
||||
// })
|
||||
|
||||
const answer = {
|
||||
origin_asset_id: ASSET_ID,
|
||||
dest_asset_id: originAssetId || parseInt(urlParams.get('dest_asset_id')),
|
||||
@ -320,7 +387,7 @@ const createRecvTransport = async () => {
|
||||
return
|
||||
}
|
||||
|
||||
console.log(params)
|
||||
console.log('[createRecvTransport] params', params)
|
||||
|
||||
// creates a new WebRTC Transport to receive media
|
||||
// based on server's consumer transport params
|
||||
@ -353,7 +420,8 @@ const resetCallSettings = () => {
|
||||
localVideo.srcObject = null
|
||||
remoteVideo.srcObject = null
|
||||
consumer = null
|
||||
producer = null
|
||||
producerVideo = null
|
||||
producerAudio = null
|
||||
producerTransport = null
|
||||
consumerTransport = null
|
||||
device = undefined
|
||||
|
Reference in New Issue
Block a user