Compare commits
7 Commits
8ef6c2abb0
...
fix-branch
Author | SHA1 | Date | |
---|---|---|---|
2e336a429e | |||
b14e82fd87 | |||
c4f72eddd5 | |||
6e4ceb9977 | |||
2c00de1dd0 | |||
f96fd24e03 | |||
fce2f30648 |
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,2 +1 @@
|
||||
/node_modules
|
||||
/dist
|
||||
|
120
app.js
120
app.js
@ -5,12 +5,7 @@ const app = express();
|
||||
const Server = require('socket.io');
|
||||
const path = require('node:path');
|
||||
const fs = require('node:fs');
|
||||
let https;
|
||||
try {
|
||||
https = require('node:https');
|
||||
} catch (err) {
|
||||
console.log('https support is disabled!');
|
||||
}
|
||||
const https = require('https');
|
||||
const mediasoup = require('mediasoup');
|
||||
|
||||
let worker
|
||||
@ -42,8 +37,8 @@ app.use('/sfu', express.static(path.join(__dirname, 'public')))
|
||||
|
||||
// SSL cert for HTTPS access
|
||||
const options = {
|
||||
key: fs.readFileSync(process.env.SERVER_KEY, 'utf-8'),
|
||||
cert: fs.readFileSync(process.env.SERVER_CERT, 'utf-8'),
|
||||
key: fs.readFileSync('./server/ssl/key.pem', 'utf-8'),
|
||||
cert: fs.readFileSync('./server/ssl/cert.pem', 'utf-8'),
|
||||
}
|
||||
|
||||
const httpsServer = https.createServer(options, app);
|
||||
@ -63,12 +58,13 @@ 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: parseInt(process.env.RTC_MIN_PORT),
|
||||
rtcMaxPort: parseInt(process.env.RTC_MAX_PORT),
|
||||
rtcMinPort: process.env.RTC_MIN_PORT,
|
||||
rtcMaxPort: process.env.RTC_MAX_PORT,
|
||||
})
|
||||
console.log(`[createWorker] worker pid ${worker.pid}`);
|
||||
|
||||
@ -90,70 +86,21 @@ worker = createWorker();
|
||||
// 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: '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/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',
|
||||
// clockRate: 48000,
|
||||
// channels: 2,
|
||||
// },
|
||||
// {
|
||||
// kind: 'video',
|
||||
// mimeType: 'video/VP8',
|
||||
// clockRate: 90000,
|
||||
// parameters: {
|
||||
// 'x-google-start-bitrate': 1000,
|
||||
// },
|
||||
// },
|
||||
];
|
||||
|
||||
const closeCall = (callId) => {
|
||||
@ -173,6 +120,16 @@ 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
|
||||
@ -199,9 +156,7 @@ 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]) {
|
||||
@ -210,19 +165,12 @@ peers.on('connection', async socket => {
|
||||
console.log(`[createRoom] Router ID: ${videoCalls[callId].router.id}`);
|
||||
}
|
||||
socketDetails[socket.id] = callId;
|
||||
|
||||
// rtpCapabilities is set for callback
|
||||
console.log('[getRtpCapabilities] callId', callId);
|
||||
callbackResponse = {
|
||||
rtpCapabilities :videoCalls[callId].router.rtpCapabilities
|
||||
};
|
||||
getRtpCapabilities(callId, callback);
|
||||
} else {
|
||||
console.log(`[createRoom] missing callId ${callId}`);
|
||||
}
|
||||
} catch (error) {
|
||||
console.log(`ERROR | createRoom | callId ${callId} | ${error.message}`);
|
||||
} finally {
|
||||
callback(callbackResponse);
|
||||
}
|
||||
});
|
||||
|
||||
@ -243,19 +191,16 @@ 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);
|
||||
}
|
||||
});
|
||||
|
||||
@ -299,9 +244,9 @@ peers.on('connection', async socket => {
|
||||
});
|
||||
|
||||
// Send back to the client the Producer's id
|
||||
callback && callback({
|
||||
id: videoCalls[callId].producer.id
|
||||
});
|
||||
// callback({
|
||||
// id: videoCalls[callId].producer.id
|
||||
// });
|
||||
} catch (error) {
|
||||
console.log(`ERROR | transport-produce | callId ${socketDetails[socket.id]} | ${error.message}`);
|
||||
}
|
||||
@ -372,7 +317,6 @@ 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
48
build.sh
@ -1,48 +0,0 @@
|
||||
#/!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 -
|
||||
|
||||
|
1364
public/bundle.js
1364
public/bundle.js
File diff suppressed because it is too large
Load Diff
@ -1,4 +1,5 @@
|
||||
module.exports = {
|
||||
hubAddress: 'https://hub.dev.linx.safemobile.com/',
|
||||
mediasoupAddress: 'https://video.safemobile.org',
|
||||
mediasoupAddress: 'https://video.safemobile.org/mediasoup',
|
||||
// mediasoupAddress: 'http://localhost:3000/mediasoup',
|
||||
}
|
@ -43,7 +43,7 @@
|
||||
<tr>
|
||||
<td>
|
||||
<div id="sharedBtns">
|
||||
<video id="localVideo" autoplay class="video" muted></video>
|
||||
<video id="localVideo" autoplay class="video" ></video>
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
|
290
public/index.js
290
public/index.js
@ -12,191 +12,141 @@ 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)
|
||||
|
||||
console.log('🟩 config', config)
|
||||
let socket
|
||||
hub = io(config.hubAddress)
|
||||
|
||||
let socket, hub
|
||||
const connectToMediasoup = () => {
|
||||
|
||||
setTimeout(() => {
|
||||
hub = io(config.hubAddress)
|
||||
|
||||
const connectToMediasoup = () => {
|
||||
|
||||
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 {
|
||||
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()
|
||||
}
|
||||
|
||||
}, 1600);
|
||||
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()
|
||||
}
|
||||
|
||||
let device
|
||||
let rtpCapabilities
|
||||
let producerTransport
|
||||
let consumerTransport
|
||||
let producerVideo
|
||||
let producerAudio
|
||||
let producer
|
||||
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 videoParams = {
|
||||
let params = {
|
||||
// mediasoup params
|
||||
encodings: [
|
||||
{ scaleResolutionDownBy: 4, maxBitrate: 500000 },
|
||||
{ scaleResolutionDownBy: 2, maxBitrate: 1000000 },
|
||||
{ scaleResolutionDownBy: 1, maxBitrate: 5000000 },
|
||||
{ scalabilityMode: 'S3T3_KEY' }
|
||||
{
|
||||
rid: 'r0',
|
||||
maxBitrate: 100000,
|
||||
scalabilityMode: 'S1T3',
|
||||
},
|
||||
{
|
||||
rid: 'r1',
|
||||
maxBitrate: 300000,
|
||||
scalabilityMode: 'S1T3',
|
||||
},
|
||||
{
|
||||
rid: 'r2',
|
||||
maxBitrate: 900000,
|
||||
scalabilityMode: 'S1T3',
|
||||
},
|
||||
],
|
||||
// https://mediasoup.org/documentation/v3/mediasoup-client/api/#ProducerCodecOptions
|
||||
codecOptions: {
|
||||
videoGoogleStartBitrate: 1000
|
||||
}
|
||||
// encodings: [
|
||||
// {
|
||||
// rid: 'r0',
|
||||
// maxBitrate: 100000,
|
||||
// scalabilityMode: 'S1T3',
|
||||
// },
|
||||
// {
|
||||
// rid: 'r1',
|
||||
// maxBitrate: 300000,
|
||||
// scalabilityMode: 'S1T3',
|
||||
// },
|
||||
// {
|
||||
// rid: 'r2',
|
||||
// maxBitrate: 900000,
|
||||
// scalabilityMode: 'S1T3',
|
||||
// },
|
||||
// ],
|
||||
// // https://mediasoup.org/documentation/v3/mediasoup-client/api/#ProducerCodecOptions
|
||||
// codecOptions: {
|
||||
// videoGoogleStartBitrate: 1000
|
||||
// }
|
||||
}
|
||||
|
||||
let audioParams = {
|
||||
codecOptions :
|
||||
{
|
||||
opusStereo : true,
|
||||
opusDtx : true
|
||||
}
|
||||
}
|
||||
|
||||
const streamSuccess = (stream) => {
|
||||
console.log('[streamSuccess] device', device);
|
||||
console.log('[streamSuccess]');
|
||||
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
|
||||
const track = stream.getVideoTracks()[0]
|
||||
params = {
|
||||
track,
|
||||
...params
|
||||
}
|
||||
|
||||
audioParams = {
|
||||
track: audioTrack,
|
||||
...audioParams
|
||||
}
|
||||
|
||||
console.log('[streamSuccess] videoParams', videoParams, ' | audioParams', audioParams);
|
||||
goConnect()
|
||||
// console.log('[streamSuccess]');
|
||||
// localVideo.srcObject = stream
|
||||
// const track = stream.getVideoTracks()[0]
|
||||
// videoParams = {
|
||||
// track,
|
||||
// ...videoParams
|
||||
// }
|
||||
// goConnect()
|
||||
}
|
||||
|
||||
const getLocalStream = () => {
|
||||
console.log('[getLocalStream]');
|
||||
navigator.mediaDevices.getUserMedia({
|
||||
audio: true,
|
||||
audio: false,
|
||||
video: {
|
||||
qvga : { width: { ideal: 320 }, height: { ideal: 240 } },
|
||||
vga : { width: { ideal: 640 }, height: { ideal: 480 } },
|
||||
hd : { width: { ideal: 1280 }, height: { ideal: 720 } }
|
||||
width: {
|
||||
min: 640,
|
||||
max: 1920,
|
||||
},
|
||||
height: {
|
||||
min: 400,
|
||||
max: 1080,
|
||||
}
|
||||
}
|
||||
})
|
||||
// navigator.mediaDevices.getUserMedia({
|
||||
// audio: false,
|
||||
// video: {
|
||||
// width: {
|
||||
// min: 640,
|
||||
// max: 1920,
|
||||
// },
|
||||
// height: {
|
||||
// min: 400,
|
||||
// max: 1080,
|
||||
// }
|
||||
// }
|
||||
// })
|
||||
.then(streamSuccess)
|
||||
.catch(error => {
|
||||
console.log(error.message)
|
||||
@ -217,7 +167,7 @@ const goCreateTransport = () => {
|
||||
// server side to send/recive media
|
||||
const createDevice = async () => {
|
||||
try {
|
||||
console.log('[createDevice] 1 device', device);
|
||||
console.log('[createDevice]');
|
||||
device = new mediasoupClient.Device()
|
||||
|
||||
// https://mediasoup.org/documentation/v3/mediasoup-client/api/#device-load
|
||||
@ -228,8 +178,7 @@ const createDevice = async () => {
|
||||
})
|
||||
|
||||
console.log('Device RTP Capabilities', device.rtpCapabilities)
|
||||
console.log('[createDevice] 2 device', device);
|
||||
|
||||
|
||||
// once the device loads, create transport
|
||||
goCreateTransport()
|
||||
|
||||
@ -258,7 +207,6 @@ 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 }) => {
|
||||
@ -269,7 +217,7 @@ const createSendTransport = () => {
|
||||
return
|
||||
}
|
||||
|
||||
console.log('[createWebRtcTransport] params', params)
|
||||
console.log(params)
|
||||
|
||||
// creates a new WebRTC Transport to send media
|
||||
// based on the server's producer transport params
|
||||
@ -296,7 +244,7 @@ const createSendTransport = () => {
|
||||
})
|
||||
|
||||
producerTransport.on('produce', async (parameters, callback, errback) => {
|
||||
console.log('[produce] parameters', parameters)
|
||||
console.log(parameters)
|
||||
|
||||
try {
|
||||
// tell the server to create a Producer
|
||||
@ -322,33 +270,18 @@ 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
|
||||
producerVideo = await producerTransport.produce(videoParams)
|
||||
console.log('producerVideo', producerVideo);
|
||||
producerVideo.on('trackended', () => {
|
||||
producer = await producerTransport.produce(params)
|
||||
|
||||
producer.on('trackended', () => {
|
||||
console.log('track ended')
|
||||
// close video track
|
||||
})
|
||||
|
||||
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', () => {
|
||||
producer.on('transportclose', () => {
|
||||
console.log('transport ended')
|
||||
// close video track
|
||||
})
|
||||
@ -387,7 +320,7 @@ const createRecvTransport = async () => {
|
||||
return
|
||||
}
|
||||
|
||||
console.log('[createRecvTransport] params', params)
|
||||
console.log(params)
|
||||
|
||||
// creates a new WebRTC Transport to receive media
|
||||
// based on server's consumer transport params
|
||||
@ -420,8 +353,7 @@ const resetCallSettings = () => {
|
||||
localVideo.srcObject = null
|
||||
remoteVideo.srcObject = null
|
||||
consumer = null
|
||||
producerVideo = null
|
||||
producerAudio = null
|
||||
producer = null
|
||||
producerTransport = null
|
||||
consumerTransport = null
|
||||
device = undefined
|
||||
|
Reference in New Issue
Block a user