Compare commits

..

120 Commits

Author SHA1 Message Date
c823f7578c LH-265: Update client 2022-11-29 13:27:33 +02:00
6cc14cdf30 LH-265: Update documentation and README.md 2022-11-29 13:27:12 +02:00
4bb23def42 Update server 2022-11-29 11:32:03 +02:00
fc745a5879 Update server 2022-11-29 11:09:10 +02:00
742d67f2e3 Update server 2022-11-29 11:08:12 +02:00
e22093d97e Update server 2022-11-29 10:27:55 +02:00
7634a18465 Update server 2022-11-29 10:22:02 +02:00
d17b035526 Update server 2022-11-29 04:03:06 +02:00
a21451e46d Update server 2022-11-29 03:59:42 +02:00
df0cb81a8e Update server 2022-11-29 03:55:34 +02:00
ac8c651a9d Update server 2022-11-29 03:52:15 +02:00
9111c4e245 Update server 2022-11-29 03:50:45 +02:00
7a2d02dcda Update server 2022-11-29 03:44:02 +02:00
39efdd12b7 Update server 2022-11-29 03:41:00 +02:00
0bdc6fac3a Update server 2022-11-29 03:17:28 +02:00
ae7a8ed9ce Update server 2022-11-29 03:16:15 +02:00
9feaebf8a7 Update server 2022-11-29 02:46:12 +02:00
85110b7f5c Update server 2022-11-29 02:44:40 +02:00
d047cdf7d1 Update server 2022-11-29 02:44:01 +02:00
753b476462 Update server 2022-11-29 02:42:13 +02:00
359c7c784e Update server 2022-11-29 02:40:25 +02:00
5169d0d49f Update server 2022-11-29 02:39:11 +02:00
a3b083fe24 Update server 2022-11-29 02:37:55 +02:00
46d3499e3d Update server 2022-11-29 02:34:48 +02:00
38b95d5246 Update server 2022-11-29 02:21:29 +02:00
984b2b892e Update server 2022-11-29 02:20:05 +02:00
e085d22e89 Update server 2022-11-29 02:16:44 +02:00
3bc15fdef1 Update server 2022-11-29 02:09:37 +02:00
67042185c4 Update server 2022-11-29 01:59:53 +02:00
c92dff9bfe Update server 2022-11-28 23:40:56 +02:00
3605ca0468 Update server 2022-11-28 23:40:08 +02:00
1edbcb2179 Merge branch 'LH-265-enable-audio-in-mediasoup' of https://git.safemobile.org/Safemobile/mediasoup into LH-265-enable-audio-in-mediasoup 2022-11-25 10:00:28 +02:00
adbcf6c2bc Update server 2022-11-25 10:00:17 +02:00
c862224ead LH-265: Update client and server 2022-11-25 09:58:53 +02:00
c02a7c7380 Update server 2022-11-24 23:56:42 +02:00
3387a362a6 Update server 2022-11-24 23:30:27 +02:00
21dffefa8c Update server 2022-11-24 23:29:03 +02:00
1369491529 Update server 2022-11-24 23:22:55 +02:00
56bdbca537 Update server 2022-11-24 23:09:18 +02:00
8444809910 Update server 2022-11-24 23:06:02 +02:00
cd84c534ce Update server 2022-11-24 22:27:33 +02:00
038bdb99bc Update server 2022-11-24 22:18:37 +02:00
d94ea12a40 Update server 2022-11-24 17:08:54 +02:00
1148532a9b Update server 2022-11-24 17:01:26 +02:00
3561bb13a6 Update server 2022-11-24 16:59:04 +02:00
22ead926b0 Update server 2022-11-24 16:57:26 +02:00
c6edb2947d Update server 2022-11-24 16:46:00 +02:00
e59f134a68 Update server 2022-11-24 16:37:44 +02:00
aad96b72f2 Update server 2022-11-24 16:36:36 +02:00
3e4c0a32bc Update server 2022-11-24 16:36:00 +02:00
2a7bd42247 Update server 2022-11-24 16:34:54 +02:00
f2c0794bf4 Update server 2022-11-24 16:22:56 +02:00
950298c4f6 Update server 2022-11-24 16:21:22 +02:00
6e74083733 Update server 2022-11-24 13:49:04 +02:00
8ef6c2abb0 Update server 2022-11-24 13:43:33 +02:00
2a86042c80 Update server 2022-11-24 13:41:24 +02:00
56b8e2ea74 Update server 2022-11-24 13:38:28 +02:00
6c42814229 Update server 2022-11-24 13:37:42 +02:00
e65b7e0d7c Update server 2022-11-24 13:36:21 +02:00
aa7c2aea90 Update server 2022-11-24 13:35:32 +02:00
458342c0d2 Update server 2022-11-24 13:32:45 +02:00
fa5a1a5ae7 Update server 2022-11-23 17:56:18 +02:00
9fbe01ae1d Update server 2022-11-23 17:19:55 +02:00
e5bcc6262b Update server 2022-11-23 17:11:09 +02:00
c758a9106c Update server 2022-11-23 16:27:13 +02:00
fcbc28c801 Update server 2022-11-23 16:26:28 +02:00
ba63fb20bf Update server 2022-11-23 16:24:12 +02:00
e8bd6837cf Update server 2022-11-23 16:21:48 +02:00
d386915ff2 Update server 2022-11-23 16:16:17 +02:00
2479f58e21 Update server 2022-11-23 16:09:26 +02:00
d49b8e42ff Update server 2022-11-23 16:03:13 +02:00
a3ae874f8e Update server 2022-11-23 16:01:51 +02:00
c2dbef1918 Update server 2022-11-23 16:00:54 +02:00
b41b8f2d64 Update server 2022-11-23 15:57:27 +02:00
c089e91fba Update server 2022-11-23 13:20:49 +02:00
c63aee83a1 Update server 2022-11-23 13:19:56 +02:00
a97ec24148 Update server 2022-11-23 00:54:03 +02:00
3c23c6791d Update server 2022-11-23 00:34:12 +02:00
1a7b44807d Update server 2022-11-23 00:32:24 +02:00
daa2c556e4 Update server 2022-11-23 00:25:16 +02:00
22656722e8 Update server 2022-11-23 00:22:00 +02:00
f5b9067b7e Update server 2022-11-23 00:21:26 +02:00
0b3a45ae45 Update server 2022-11-23 00:13:56 +02:00
dfe4630839 Update server 2022-11-23 00:11:26 +02:00
d18041cadd Update server 2022-11-23 00:11:16 +02:00
fa42caeeb2 Update server 2022-11-22 23:14:01 +02:00
4dbb7ad554 Update server 2022-11-22 23:12:55 +02:00
d1063803b9 Update server 2022-11-22 23:12:21 +02:00
3cbd31b49c Update server 2022-11-22 23:11:45 +02:00
a39e0eaa17 Update server 2022-11-22 23:11:14 +02:00
b63fb39fd4 Update server 2022-11-22 23:09:33 +02:00
0dfbd296a7 Update server 2022-11-22 20:44:22 +02:00
233f49a998 Update server 2022-11-22 20:43:30 +02:00
127f17cd97 Update server 2022-11-22 20:42:55 +02:00
d1ad8b4d3a Update server 2022-11-22 20:38:16 +02:00
f20e1ad260 Update build 2022-11-22 20:04:43 +02:00
27151a26d1 Update build 2022-11-22 20:03:36 +02:00
544e9e59ab Update build 2022-11-22 20:00:44 +02:00
4e4cd6f893 Update build 2022-11-22 19:55:55 +02:00
e9ff060544 Update build 2022-11-22 19:52:25 +02:00
7d677f4a34 Update build 2022-11-22 19:52:11 +02:00
8f96b8c98b Update build 2022-11-22 19:51:09 +02:00
1084a808c7 Update build 2022-11-22 19:40:02 +02:00
3838f774bf Update build 2022-11-22 19:33:38 +02:00
06bb275f0d Update build 2022-11-22 19:18:48 +02:00
a05f7cc987 Update build 2022-11-22 19:15:34 +02:00
c5c8bc5bb3 Update build 2022-11-22 19:14:50 +02:00
d6bc4e51e5 Update build 2022-11-22 19:11:00 +02:00
4ae02f70d6 Update build 2022-11-22 18:54:22 +02:00
d593d6dc83 Update build 2022-11-22 18:35:36 +02:00
1a1fa9450e Update build 2022-11-22 18:34:12 +02:00
0d24604f2a Update build 2022-11-22 18:33:46 +02:00
1d7c994036 Update build 2022-11-22 18:33:06 +02:00
bc2bf24a65 Update build 2022-11-22 18:32:47 +02:00
cdbfc7891d Update build 2022-11-22 18:30:25 +02:00
c730341674 Update build 2022-11-22 18:28:50 +02:00
b621b76e37 Connect to mediasoup with timeout(fix when it appears offline) 2022-11-22 18:27:56 +02:00
39ad9cad27 Update bundle 2022-11-22 18:10:05 +02:00
8860423e21 LH-265: Update client config 2022-11-22 10:28:45 +02:00
9179a67f64 LH-265: Enable audio on video server 2022-11-21 22:59:41 +02:00
19 changed files with 676 additions and 1030 deletions

View File

@ -1,2 +0,0 @@
node_modules
doc

View File

@ -1,25 +1,11 @@
FROM ubuntu:22.04
WORKDIR /app
FROM ubuntu
RUN apt-get update && \
apt-get install -y build-essential pip net-tools iputils-ping iproute2 curl
RUN curl -fsSL https://deb.nodesource.com/setup_18.x | bash -
RUN curl -fsSL https://deb.nodesource.com/setup_16.x | bash -
RUN apt-get install -y nodejs
RUN npm install -g watchify
COPY . /app/
RUN npm install
EXPOSE 3000/tcp
EXPOSE 2000-2200/udp
CMD node app.js
#docker build -t linx-video .
# docker run -it -d --restart always -p 3000:3000/tcp -p 2000-2200:2000-2200/udp linx-video
#Run under host network
# docker run -it -d --network host --restart always -p 3000:3000/tcp -p 2000-2200:2000-2200/udp linx-video
#https://docs.docker.com/config/containers/resource_constraints/
#docker run -it -d --network host --cpus="0.25" --memory="512m" --restart always -p 3000:3000/tcp -p 2000-2200:2000-2200/udp linx-video
EXPOSE 3000
EXPOSE 2000-2020
EXPOSE 10000-10100

View File

@ -39,3 +39,4 @@ dest_asset_id= the addressee with whom the call is made
### Demo project
The demo project used initially and then modified for our needs `https://github.com/jamalag/mediasoup2`

1128
app.js

File diff suppressed because it is too large Load Diff

View File

@ -1,40 +1,4 @@
#/!bin/bash
## FUNCTIONS
function getGitVersion(){
version=$(git describe)
count=$(echo ${version%%-*} | grep -o "\." | wc -l)
if (( $count > 1 )); then
version=${version%%-*}
elif (( $count == 0 ));then
echo -e "Error: Git version \"${version%%-*}\" not respecting Safemobile standard.\n Must be like 4.xx or 4.xx.xx"
version="0.0.0"
else
if [[ "$1" == "dev" ]];then
cleanprefix=${version#*-} # remove everything before `-` including `-`
cleansuffix=${cleanprefix%-*} # remove everything after `-` including `-`
version="${version%%-*}.${cleansuffix}"
else
version="${version%%-*}.0" # one `%` remove everything after last `-`, two `%%` remove everything after all `-`
fi
fi
}
function addVersionPm2(){
file_pkg="package.json"
key=" \"version\": \""
if [ -f "$file_pkg" ] && [ ! -z "$version" ]; then
versionApp=" \"version\": \"$version\","
sed -i "s|^.*$key.*|${versionApp//\//\\/}|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
}
## PREBUILD PROCESS
# check dist dir to be present and empty
if [ ! -d "dist" ]; then
@ -45,31 +9,40 @@ else
## CLEANUP
rm -fr dist/*
fi
if [ -d "node_modules" ]; then
rm -fr node_modules
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,doc,Dockerfile} dist/
#cp -r ./* dist/
cp -r {.env,app.js,package.json,server,public} dist/
# Generate Git log
dateString=$(date +"%Y%m%d-%H%M%S")
git log --pretty=format:"%ad%x09%an%x09%s" --no-merges -20 > "dist/git-$dateString.log"
# Get Git version control
getGitVersion $1
# Add version control for pm2
#Add version control for pm2
cd dist
addVersionPm2
#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 -

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 419 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.0 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 606 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 349 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 412 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 421 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 567 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 660 KiB

BIN
doc/[video] Workflow.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 571 KiB

View File

@ -20353,7 +20353,7 @@ module.exports = yeast;
},{}],94:[function(require,module,exports){
module.exports = {
hubAddress: 'https://hub.dev.linx.safemobile.com/',
mediasoupAddress: 'https://testing.video.safemobile.org/',
mediasoupAddress: 'https://video.safemobile.org',
}
},{}],95:[function(require,module,exports){
const io = require('socket.io-client')
@ -20368,24 +20368,10 @@ const ASSET_NAME = urlParams.get('assetName') || null;
const ASSET_TYPE = urlParams.get('assetType') || null;
let callId = parseInt(urlParams.get('callId')) || null;
const IS_PRODUCER = urlParams.get('producer') === 'true' ? true : false
let remoteVideo = document.getElementById('remoteVideo')
remoteVideo.defaultMuted = true
let produceAudio = false
console.log('[URL] ASSET_ID', ASSET_ID, '| ACCOUNT_ID', ACCOUNT_ID, '| callId', callId, ' | IS_PRODUCER', IS_PRODUCER)
console.log('🟩 config', config)
produceAudioSelector = document.getElementById('produceAudio');
produceAudioSelector.addEventListener('change', e => {
if(e.target.checked) {
produceAudio = true
console.log('produce audio');
} else {
produceAudio = false
}
});
let socket, hub
let device
let rtpCapabilities
@ -20395,21 +20381,6 @@ let producerVideo
let producerAudio
let consumer
let originAssetId
let consumerVideo // local consumer video(consumer not transport)
let consumerAudio // local consumer audio(consumer not transport)
const remoteSoundControl = document.getElementById('remoteSoundControl');
remoteSoundControl.addEventListener('click', function handleClick() {
console.log('remoteSoundControl.textContent', remoteSoundControl.textContent);
if (remoteSoundControl.textContent === 'Unmute') {
remoteVideo.muted = false
remoteSoundControl.textContent = 'Mute';
} else {
remoteVideo.muted = true
remoteSoundControl.textContent = 'Unmute';
}
});
// https://mediasoup.org/documentation/v3/mediasoup-client/api/#ProducerOptions
// https://mediasoup.org/documentation/v3/mediasoup-client/api/#transport-produce
@ -20449,23 +20420,10 @@ setTimeout(() => {
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() }
})
socket.on('new-producer', ({ callId, kind }) => {
console.log(`🟢 new-producer | callId: ${callId} | kind: ${kind} | Ready to consume`);
connectRecvTransport();
})
socket.on('close-producer', ({ callId, kind }) => {
console.log(`🔴 close-producer | callId: ${callId} | kind: ${kind}`);
if (kind === 'video') {
consumerVideo.close()
remoteVideo.srcObject = null
}
else if (kind === 'audio') consumerAudio.close()
})
}
if (IS_PRODUCER === true) {
@ -20544,7 +20502,7 @@ const streamSuccess = (stream) => {
const getLocalStream = () => {
console.log('[getLocalStream]');
navigator.mediaDevices.getUserMedia({
audio: produceAudio ? true : false,
audio: true,
video: {
qvga : { width: { ideal: 320 }, height: { ideal: 240 } },
vga : { width: { ideal: 640 }, height: { ideal: 480 } },
@ -20622,7 +20580,7 @@ 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 }, (value) => {
socket.emit('createWebRtcTransport', { sender: true, callId }, (value) => {
console.log(`[createWebRtcTransport] value: ${JSON.stringify(value)}`);
@ -20693,36 +20651,34 @@ const connectSendTransport = async () => {
// this action will trigger the 'connect' and 'produce' events above
// Produce video
let producerVideoHandler = await producerTransport.produce(videoParams)
producerVideo = await producerTransport.produce(videoParams)
console.log('videoParams', videoParams);
console.log('producerVideo', producerVideo);
producerVideoHandler.on('trackended', () => {
producerVideo.on('trackended', () => {
console.log('track ended')
// close video track
})
producerVideoHandler.on('transportclose', () => {
producerVideo.on('transportclose', () => {
console.log('transport ended')
// close video track
})
// Produce audio
if (produceAudio) {
let producerAudioHandler = await producerTransport.produce(audioParams)
console.log('audioParams', audioParams);
console.log('producerAudio', producerAudio);
producerAudioHandler.on('trackended', () => {
console.log('track ended')
// close audio track
})
producerAudioHandler.on('transportclose', () => {
console.log('transport ended')
// close audio track
})
}
producerAudio = await producerTransport.produce(audioParams)
console.log('audioParams', audioParams);
console.log('producerAudio', producerAudio);
producerAudio.on('trackended', () => {
console.log('track ended')
// close audio track
})
producerAudio.on('transportclose', () => {
console.log('transport ended')
// close audio track
})
const answer = {
origin_asset_id: ASSET_ID,
@ -20744,8 +20700,6 @@ const connectSendTransport = async () => {
// Enable Close call button
const closeCallBtn = document.getElementById('btnCloseCall');
closeCallBtn.removeAttribute('disabled');
createRecvTransport();
}
const createRecvTransport = async () => {
@ -20785,8 +20739,7 @@ const createRecvTransport = async () => {
errback(error)
}
})
// We call it in new-rpoducer, we don't need it here anymore
// connectRecvTransport()
connectRecvTransport()
})
}
@ -20809,91 +20762,34 @@ const connectRecvTransport = async () => {
await socket.emit('consume', {
rtpCapabilities: device.rtpCapabilities,
callId
}, async ({videoParams, audioParams}) => {
console.log(`[consume] 🟩 videoParams`, videoParams)
console.log(`[consume] 🟩 audioParams`, audioParams)
console.log('[consume] 🟩 consumerTransport', consumerTransport)
}, async ({ params }) => {
if (params.error) {
console.log('Cannot Consume')
return
}
// Then consume with the local consumer transport
// which creates a consumer
consumer = await consumerTransport.consume({
id: params.id,
producerId: params.producerId,
kind: params.kind,
rtpParameters: params.rtpParameters
})
// destructure and retrieve the video track from the producer
const { track } = consumer
let stream = new MediaStream()
// Maybe the unit does not produce video or audio, so we must only consume what is produced
if (videoParams) {
console.log('❗ Have VIDEO stream to consume');
stream.addTrack(await getVideoTrask(videoParams))
} else {
console.log('❗ Don\'t have VIDEO stream to consume');
}
if (audioParams) {
console.log('❗ Have AUDIO stream to consume');
let audioTrack = await getAudioTrask(audioParams)
stream.addTrack(audioTrack)
} else {
console.log('❗ Don\'t have AUDIO stream to consume');
}
socket.emit('consumer-resume')
stream.addTrack(track)
// stream.removeTrack(track)
remoteVideo.srcObject = stream
remoteVideo.setAttribute('autoplay', true)
socket.emit('consumer-resume')
console.log('consumer', consumer);
remoteVideo.play()
.then(() => {
console.log('remoteVideo PLAY')
})
.catch((error) => {
console.error(`remoteVideo PLAY ERROR | ${error.message}`)
})
})
}
const getVideoTrask = async (videoParams) => {
consumerVideo = await consumerTransport.consume({
id: videoParams.id,
producerId: videoParams.producerId,
kind: videoParams.kind,
rtpParameters: videoParams.rtpParameters
})
return consumerVideo.track
}
const getAudioTrask = async (audioParams) => {
consumerAudio = await consumerTransport.consume({
id: audioParams.id,
producerId: audioParams.producerId,
kind: audioParams.kind,
rtpParameters: audioParams.rtpParameters
})
consumerAudio.on('transportclose', () => {
console.log('transport closed so consumer closed')
})
const audioTrack = consumerAudio.track
audioTrack.applyConstraints({
audio: {
advanced: [
{
echoCancellation: {exact: true}
},
{
autoGainControl: {exact: true}
},
{
noiseSuppression: {exact: true}
},
{
highpassFilter: {exact: true}
}
]
}
})
return audioTrack
}
const closeCall = () => {
console.log('closeCall');
@ -20915,31 +20811,8 @@ const closeCall = () => {
resetCallSettings()
}
// const consume = async (kind) => {
// console.log(`[consume] kind: ${kind}`)
// console.log('createRecvTransport Consumer')
// await socket.emit('createWebRtcTransport', { sender: false, callId, dispatcher: true }, ({ params }) => {
// if (params.error) {
// console.log('createRecvTransport | createWebRtcTransport | Error', params.error)
// return
// }
// consumerTransport = device.createRecvTransport(params)
// consumerTransport.on('connect', async ({ dtlsParameters }, callback, errback) => {
// try {
// await socket.emit('transport-recv-connect', {
// dtlsParameters,
// })
// callback()
// } catch (error) {
// errback(error)
// }
// })
// connectRecvTransport()
// })
// }
btnLocalVideo.addEventListener('click', getLocalStream)
// btnRecvSendTransport.addEventListener('click', consume)
btnRecvSendTransport.addEventListener('click', goConnect)
btnCloseCall.addEventListener('click', closeCall)
},{"./config":94,"mediasoup-client":66,"socket.io-client":82}]},{},[95]);

View File

@ -1,4 +1,4 @@
module.exports = {
hubAddress: 'https://hub.dev.linx.safemobile.com/',
mediasoupAddress: 'https://testing.video.safemobile.org/',
mediasoupAddress: 'https://video.safemobile.org',
}

View File

@ -34,9 +34,6 @@
<body>
<body>
<div id="video">
<legend>Client options:</legend>
<input type="checkbox" id="produceAudio" name="produceAudio">
<label for="produceAudio">Produce audio</label><br>
<table>
<thead>
<th>Local Video</th>
@ -46,24 +43,12 @@
<tr>
<td>
<div id="sharedBtns">
<video
id="localVideo"
class="video"
autoplay
muted
playsinline
></video>
<video id="localVideo" autoplay class="video" muted></video>
</div>
</td>
<td>
<div id="sharedBtns">
<video
id="remoteVideo"
class="video"
autoplay
muted
playsinline
></video>
<video id="remoteVideo" autoplay class="video" ></video>
</div>
</td>
</tr>
@ -75,11 +60,34 @@
</td>
<td>
<div id="sharedBtns">
<!-- <button id="btnRecvSendTransport">Consume</button> -->
<button id="remoteSoundControl">Unmute</button>
<button id="btnRecvSendTransport">Consume</button>
</div>
</td>
</tr>
<!-- <tr>
<td colspan="2">
<div id="sharedBtns">
<button id="btnRtpCapabilities">2. Get Rtp Capabilities</button>
<br />
<button id="btnDevice">3. Create Device</button>
</div>
</td>
</tr>
<tr>
<td>
<div id="sharedBtns">
<button id="btnCreateSendTransport">4. Create Send Transport</button>
<br />
<button id="btnConnectSendTransport">5. Connect Send Transport & Produce</button></td>
</div>
<td>
<div id="sharedBtns">
<button id="btnRecvSendTransport">6. Create Recv Transport</button>
<br />
<button id="btnConnectRecvTransport">7. Connect Recv Transport & Consume</button>
</div>
</td>
</tr> -->
</tbody>
</table>
<div id="closeCallBtn">

View File

@ -10,24 +10,10 @@ const ASSET_NAME = urlParams.get('assetName') || null;
const ASSET_TYPE = urlParams.get('assetType') || null;
let callId = parseInt(urlParams.get('callId')) || null;
const IS_PRODUCER = urlParams.get('producer') === 'true' ? true : false
let remoteVideo = document.getElementById('remoteVideo')
remoteVideo.defaultMuted = true
let produceAudio = false
console.log('[URL] ASSET_ID', ASSET_ID, '| ACCOUNT_ID', ACCOUNT_ID, '| callId', callId, ' | IS_PRODUCER', IS_PRODUCER)
console.log('🟩 config', config)
produceAudioSelector = document.getElementById('produceAudio');
produceAudioSelector.addEventListener('change', e => {
if(e.target.checked) {
produceAudio = true
console.log('produce audio');
} else {
produceAudio = false
}
});
let socket, hub
let device
let rtpCapabilities
@ -37,21 +23,6 @@ let producerVideo
let producerAudio
let consumer
let originAssetId
let consumerVideo // local consumer video(consumer not transport)
let consumerAudio // local consumer audio(consumer not transport)
const remoteSoundControl = document.getElementById('remoteSoundControl');
remoteSoundControl.addEventListener('click', function handleClick() {
console.log('remoteSoundControl.textContent', remoteSoundControl.textContent);
if (remoteSoundControl.textContent === 'Unmute') {
remoteVideo.muted = false
remoteSoundControl.textContent = 'Mute';
} else {
remoteVideo.muted = true
remoteSoundControl.textContent = 'Unmute';
}
});
// https://mediasoup.org/documentation/v3/mediasoup-client/api/#ProducerOptions
// https://mediasoup.org/documentation/v3/mediasoup-client/api/#transport-produce
@ -91,23 +62,10 @@ setTimeout(() => {
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() }
})
socket.on('new-producer', ({ callId, kind }) => {
console.log(`🟢 new-producer | callId: ${callId} | kind: ${kind} | Ready to consume`);
connectRecvTransport();
})
socket.on('close-producer', ({ callId, kind }) => {
console.log(`🔴 close-producer | callId: ${callId} | kind: ${kind}`);
if (kind === 'video') {
consumerVideo.close()
remoteVideo.srcObject = null
}
else if (kind === 'audio') consumerAudio.close()
})
}
if (IS_PRODUCER === true) {
@ -186,7 +144,7 @@ const streamSuccess = (stream) => {
const getLocalStream = () => {
console.log('[getLocalStream]');
navigator.mediaDevices.getUserMedia({
audio: produceAudio ? true : false,
audio: true,
video: {
qvga : { width: { ideal: 320 }, height: { ideal: 240 } },
vga : { width: { ideal: 640 }, height: { ideal: 480 } },
@ -264,7 +222,7 @@ 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 }, (value) => {
socket.emit('createWebRtcTransport', { sender: true, callId }, (value) => {
console.log(`[createWebRtcTransport] value: ${JSON.stringify(value)}`);
@ -335,36 +293,34 @@ const connectSendTransport = async () => {
// this action will trigger the 'connect' and 'produce' events above
// Produce video
let producerVideoHandler = await producerTransport.produce(videoParams)
producerVideo = await producerTransport.produce(videoParams)
console.log('videoParams', videoParams);
console.log('producerVideo', producerVideo);
producerVideoHandler.on('trackended', () => {
producerVideo.on('trackended', () => {
console.log('track ended')
// close video track
})
producerVideoHandler.on('transportclose', () => {
producerVideo.on('transportclose', () => {
console.log('transport ended')
// close video track
})
// Produce audio
if (produceAudio) {
let producerAudioHandler = await producerTransport.produce(audioParams)
console.log('audioParams', audioParams);
console.log('producerAudio', producerAudio);
producerAudioHandler.on('trackended', () => {
console.log('track ended')
// close audio track
})
producerAudioHandler.on('transportclose', () => {
console.log('transport ended')
// close audio track
})
}
producerAudio = await producerTransport.produce(audioParams)
console.log('audioParams', audioParams);
console.log('producerAudio', producerAudio);
producerAudio.on('trackended', () => {
console.log('track ended')
// close audio track
})
producerAudio.on('transportclose', () => {
console.log('transport ended')
// close audio track
})
const answer = {
origin_asset_id: ASSET_ID,
@ -386,8 +342,6 @@ const connectSendTransport = async () => {
// Enable Close call button
const closeCallBtn = document.getElementById('btnCloseCall');
closeCallBtn.removeAttribute('disabled');
createRecvTransport();
}
const createRecvTransport = async () => {
@ -427,8 +381,7 @@ const createRecvTransport = async () => {
errback(error)
}
})
// We call it in new-rpoducer, we don't need it here anymore
// connectRecvTransport()
connectRecvTransport()
})
}
@ -451,91 +404,34 @@ const connectRecvTransport = async () => {
await socket.emit('consume', {
rtpCapabilities: device.rtpCapabilities,
callId
}, async ({videoParams, audioParams}) => {
console.log(`[consume] 🟩 videoParams`, videoParams)
console.log(`[consume] 🟩 audioParams`, audioParams)
console.log('[consume] 🟩 consumerTransport', consumerTransport)
}, async ({ params }) => {
if (params.error) {
console.log('Cannot Consume')
return
}
// Then consume with the local consumer transport
// which creates a consumer
consumer = await consumerTransport.consume({
id: params.id,
producerId: params.producerId,
kind: params.kind,
rtpParameters: params.rtpParameters
})
// destructure and retrieve the video track from the producer
const { track } = consumer
let stream = new MediaStream()
// Maybe the unit does not produce video or audio, so we must only consume what is produced
if (videoParams) {
console.log('❗ Have VIDEO stream to consume');
stream.addTrack(await getVideoTrask(videoParams))
} else {
console.log('❗ Don\'t have VIDEO stream to consume');
}
if (audioParams) {
console.log('❗ Have AUDIO stream to consume');
let audioTrack = await getAudioTrask(audioParams)
stream.addTrack(audioTrack)
} else {
console.log('❗ Don\'t have AUDIO stream to consume');
}
socket.emit('consumer-resume')
stream.addTrack(track)
// stream.removeTrack(track)
remoteVideo.srcObject = stream
remoteVideo.setAttribute('autoplay', true)
socket.emit('consumer-resume')
console.log('consumer', consumer);
remoteVideo.play()
.then(() => {
console.log('remoteVideo PLAY')
})
.catch((error) => {
console.error(`remoteVideo PLAY ERROR | ${error.message}`)
})
})
}
const getVideoTrask = async (videoParams) => {
consumerVideo = await consumerTransport.consume({
id: videoParams.id,
producerId: videoParams.producerId,
kind: videoParams.kind,
rtpParameters: videoParams.rtpParameters
})
return consumerVideo.track
}
const getAudioTrask = async (audioParams) => {
consumerAudio = await consumerTransport.consume({
id: audioParams.id,
producerId: audioParams.producerId,
kind: audioParams.kind,
rtpParameters: audioParams.rtpParameters
})
consumerAudio.on('transportclose', () => {
console.log('transport closed so consumer closed')
})
const audioTrack = consumerAudio.track
audioTrack.applyConstraints({
audio: {
advanced: [
{
echoCancellation: {exact: true}
},
{
autoGainControl: {exact: true}
},
{
noiseSuppression: {exact: true}
},
{
highpassFilter: {exact: true}
}
]
}
})
return audioTrack
}
const closeCall = () => {
console.log('closeCall');
@ -557,30 +453,7 @@ const closeCall = () => {
resetCallSettings()
}
// const consume = async (kind) => {
// console.log(`[consume] kind: ${kind}`)
// console.log('createRecvTransport Consumer')
// await socket.emit('createWebRtcTransport', { sender: false, callId, dispatcher: true }, ({ params }) => {
// if (params.error) {
// console.log('createRecvTransport | createWebRtcTransport | Error', params.error)
// return
// }
// consumerTransport = device.createRecvTransport(params)
// consumerTransport.on('connect', async ({ dtlsParameters }, callback, errback) => {
// try {
// await socket.emit('transport-recv-connect', {
// dtlsParameters,
// })
// callback()
// } catch (error) {
// errback(error)
// }
// })
// connectRecvTransport()
// })
// }
btnLocalVideo.addEventListener('click', getLocalStream)
// btnRecvSendTransport.addEventListener('click', consume)
btnRecvSendTransport.addEventListener('click', goConnect)
btnCloseCall.addEventListener('click', closeCall)