Compare commits
7 Commits
9fbe01ae1d
...
LINXD-2180
Author | SHA1 | Date | |
---|---|---|---|
13829c5e6c | |||
9047e6c47d | |||
77da298944 | |||
c25e34bc37 | |||
9a25f16924 | |||
473f94fcbb | |||
9245373625 |
53
app.js
53
app.js
@ -90,56 +90,7 @@ worker = createWorker();
|
|||||||
// https://mediasoup.org/documentation/v3/mediasoup/rtp-parameters-and-capabilities/#RtpCodecCapability
|
// https://mediasoup.org/documentation/v3/mediasoup/rtp-parameters-and-capabilities/#RtpCodecCapability
|
||||||
// list of media codecs supported by mediasoup ...
|
// list of media codecs supported by mediasoup ...
|
||||||
// https://github.com/versatica/mediasoup/blob/v3/src/supportedRtpCapabilities.ts
|
// 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',
|
kind: 'audio',
|
||||||
mimeType: 'audio/opus',
|
mimeType: 'audio/opus',
|
||||||
@ -203,7 +154,7 @@ peers.on('connection', async socket => {
|
|||||||
try {
|
try {
|
||||||
// We can continue with the room creation process only if we have a callId
|
// 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]) {
|
||||||
console.log('[createRoom] callId', callId);
|
console.log('[createRoom] callId', callId);
|
||||||
videoCalls[callId] = { router: await worker.createRouter({ mediaCodecs }) }
|
videoCalls[callId] = { router: await worker.createRouter({ mediaCodecs }) }
|
||||||
|
4
build.sh
4
build.sh
@ -15,6 +15,7 @@ fi
|
|||||||
## PROJECT NEEDS
|
## PROJECT NEEDS
|
||||||
echo "Building app... from $(git rev-parse --abbrev-ref HEAD)"
|
echo "Building app... from $(git rev-parse --abbrev-ref HEAD)"
|
||||||
#npm run-script build
|
#npm run-script build
|
||||||
|
cp .env.example .env
|
||||||
cp -r {.env,app.js,package.json,server,public} dist/
|
cp -r {.env,app.js,package.json,server,public} dist/
|
||||||
|
|
||||||
#Add version control for pm2
|
#Add version control for pm2
|
||||||
@ -44,5 +45,4 @@ fi
|
|||||||
## POST BUILD
|
## POST BUILD
|
||||||
|
|
||||||
cd -
|
cd -
|
||||||
|
rm .env
|
||||||
|
|
1308
public/bundle.js
1308
public/bundle.js
File diff suppressed because it is too large
Load Diff
@ -1,4 +1,5 @@
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
hubAddress: 'https://hub.dev.linx.safemobile.com/',
|
hubAddress: 'https://hub.dev.linx.safemobile.com/',
|
||||||
mediasoupAddress: 'https://video.safemobile.org',
|
mediasoupAddress: 'https://video.safemobile.org/mediasoup',
|
||||||
|
// mediasoupAddress: 'http://localhost:3000/mediasoup',
|
||||||
}
|
}
|
234
public/index.js
234
public/index.js
@ -12,106 +12,92 @@ 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)
|
||||||
|
|
||||||
console.log('🟩 config', config)
|
let socket
|
||||||
|
hub = io(config.hubAddress)
|
||||||
|
|
||||||
let socket, hub
|
const connectToMediasoup = () => {
|
||||||
|
|
||||||
setTimeout(() => {
|
socket = io(config.mediasoupAddress, {
|
||||||
hub = io(config.hubAddress)
|
reconnection: true,
|
||||||
|
reconnectionDelay: 1000,
|
||||||
const connectToMediasoup = () => {
|
reconnectionDelayMax : 5000,
|
||||||
|
reconnectionAttempts: Infinity
|
||||||
socket = io(config.mediasoupAddress, {
|
})
|
||||||
reconnection: true,
|
|
||||||
reconnectionDelay: 1000,
|
socket.on('connection-success', ({ _socketId, existsProducer }) => {
|
||||||
reconnectionDelayMax : 5000,
|
console.log(`[MEDIA] ${config.mediasoupAddress} | connected: ${socket.connected} | existsProducer: ${existsProducer}`)
|
||||||
reconnectionAttempts: Infinity
|
if (!IS_PRODUCER && existsProducer && consumer === undefined) {
|
||||||
})
|
goConnect()
|
||||||
|
// document.getElementById('btnRecvSendTransport').click();
|
||||||
socket.on('connection-success', ({ _socketId, existsProducer }) => {
|
}
|
||||||
console.log(`[MEDIA] ${config.mediasoupAddress} | connected: ${socket.connected} | existsProducer: ${existsProducer}`)
|
if (IS_PRODUCER && urlParams.get('testing') === 'true') { getLocalStream() }
|
||||||
if (!IS_PRODUCER && existsProducer && consumer === undefined) {
|
})
|
||||||
goConnect()
|
}
|
||||||
// document.getElementById('btnRecvSendTransport').click();
|
|
||||||
}
|
if (IS_PRODUCER === true) {
|
||||||
if (IS_PRODUCER && urlParams.get('testing') === 'true') { getLocalStream() }
|
hub.on('connect', async () => {
|
||||||
})
|
console.log(`[HUB] ${config.hubAddress} | connected: ${hub.connected}`)
|
||||||
}
|
|
||||||
|
|
||||||
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()
|
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 device
|
||||||
let rtpCapabilities
|
let rtpCapabilities
|
||||||
let producerTransport
|
let producerTransport
|
||||||
let consumerTransport
|
let consumerTransport
|
||||||
let producerVideo
|
let producer
|
||||||
let producerAudio
|
|
||||||
let consumer
|
let consumer
|
||||||
let originAssetId
|
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/#ProducerOptions
|
||||||
// https://mediasoup.org/documentation/v3/mediasoup-client/api/#transport-produce
|
// https://mediasoup.org/documentation/v3/mediasoup-client/api/#transport-produce
|
||||||
let videoParams = {
|
let params = {
|
||||||
// encodings: [
|
// mediasoup params
|
||||||
// { scaleResolutionDownBy: 4, maxBitrate: 500000 },
|
|
||||||
// { scaleResolutionDownBy: 2, maxBitrate: 1000000 },
|
|
||||||
// { scaleResolutionDownBy: 1, maxBitrate: 5000000 },
|
|
||||||
// { scalabilityMode: 'S3T3_KEY' }
|
|
||||||
// ],
|
|
||||||
// codecOptions: {
|
|
||||||
// videoGoogleStartBitrate: 1000
|
|
||||||
// }
|
|
||||||
encodings: [
|
encodings: [
|
||||||
{
|
{
|
||||||
rid: 'r0',
|
rid: 'r0',
|
||||||
@ -135,55 +121,19 @@ let videoParams = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let audioParams = {
|
|
||||||
codecOptions :
|
|
||||||
{
|
|
||||||
opusStereo : true,
|
|
||||||
opusDtx : true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const streamSuccess = (stream) => {
|
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]');
|
console.log('[streamSuccess]');
|
||||||
localVideo.srcObject = stream
|
localVideo.srcObject = stream
|
||||||
const track = stream.getVideoTracks()[0]
|
const track = stream.getVideoTracks()[0]
|
||||||
videoParams = {
|
params = {
|
||||||
track,
|
track,
|
||||||
...videoParams
|
...params
|
||||||
}
|
}
|
||||||
goConnect()
|
goConnect()
|
||||||
}
|
}
|
||||||
|
|
||||||
const getLocalStream = () => {
|
const getLocalStream = () => {
|
||||||
console.log('[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({
|
navigator.mediaDevices.getUserMedia({
|
||||||
audio: false,
|
audio: false,
|
||||||
video: {
|
video: {
|
||||||
@ -217,7 +167,7 @@ const goCreateTransport = () => {
|
|||||||
// server side to send/recive media
|
// server side to send/recive media
|
||||||
const createDevice = async () => {
|
const createDevice = async () => {
|
||||||
try {
|
try {
|
||||||
console.log('[createDevice] 1 device', device);
|
console.log('[createDevice]');
|
||||||
device = new mediasoupClient.Device()
|
device = new mediasoupClient.Device()
|
||||||
|
|
||||||
// https://mediasoup.org/documentation/v3/mediasoup-client/api/#device-load
|
// 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('Device RTP Capabilities', device.rtpCapabilities)
|
||||||
console.log('[createDevice] 2 device', device);
|
|
||||||
|
|
||||||
// once the device loads, create transport
|
// once the device loads, create transport
|
||||||
goCreateTransport()
|
goCreateTransport()
|
||||||
|
|
||||||
@ -258,7 +207,6 @@ const getRtpCapabilities = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const createSendTransport = () => {
|
const createSendTransport = () => {
|
||||||
console.log('[createSendTransport');
|
|
||||||
// see server's socket.on('createWebRtcTransport', sender?, ...)
|
// see server's socket.on('createWebRtcTransport', sender?, ...)
|
||||||
// this is a call from Producer, so sender = true
|
// this is a call from Producer, so sender = true
|
||||||
socket.emit('createWebRtcTransport', { sender: true, callId }, ({ params }) => {
|
socket.emit('createWebRtcTransport', { sender: true, callId }, ({ params }) => {
|
||||||
@ -269,7 +217,7 @@ const createSendTransport = () => {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('[createWebRtcTransport] params', params)
|
console.log(params)
|
||||||
|
|
||||||
// creates a new WebRTC Transport to send media
|
// creates a new WebRTC Transport to send media
|
||||||
// based on the server's producer transport params
|
// based on the server's producer transport params
|
||||||
@ -296,7 +244,7 @@ const createSendTransport = () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
producerTransport.on('produce', async (parameters, callback, errback) => {
|
producerTransport.on('produce', async (parameters, callback, errback) => {
|
||||||
console.log('[produce] parameters', parameters)
|
console.log(parameters)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// tell the server to create a Producer
|
// tell the server to create a Producer
|
||||||
@ -322,37 +270,22 @@ const createSendTransport = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const connectSendTransport = async () => {
|
const connectSendTransport = async () => {
|
||||||
|
|
||||||
console.log('[connectSendTransport] producerTransport');
|
|
||||||
|
|
||||||
// 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
|
||||||
producerVideo = await producerTransport.produce(videoParams)
|
producer = await producerTransport.produce(params)
|
||||||
console.log('producerVideo', producerVideo);
|
|
||||||
producerVideo.on('trackended', () => {
|
producer.on('trackended', () => {
|
||||||
console.log('track ended')
|
console.log('track ended')
|
||||||
// close video track
|
// close video track
|
||||||
})
|
})
|
||||||
|
|
||||||
producerVideo.on('transportclose', () => {
|
producer.on('transportclose', () => {
|
||||||
console.log('transport ended')
|
console.log('transport ended')
|
||||||
// close video track
|
// 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 = {
|
const answer = {
|
||||||
origin_asset_id: ASSET_ID,
|
origin_asset_id: ASSET_ID,
|
||||||
dest_asset_id: originAssetId || parseInt(urlParams.get('dest_asset_id')),
|
dest_asset_id: originAssetId || parseInt(urlParams.get('dest_asset_id')),
|
||||||
@ -387,7 +320,7 @@ const createRecvTransport = async () => {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('[createRecvTransport] params', params)
|
console.log(params)
|
||||||
|
|
||||||
// creates a new WebRTC Transport to receive media
|
// creates a new WebRTC Transport to receive media
|
||||||
// based on server's consumer transport params
|
// based on server's consumer transport params
|
||||||
@ -420,8 +353,7 @@ const resetCallSettings = () => {
|
|||||||
localVideo.srcObject = null
|
localVideo.srcObject = null
|
||||||
remoteVideo.srcObject = null
|
remoteVideo.srcObject = null
|
||||||
consumer = null
|
consumer = null
|
||||||
producerVideo = null
|
producer = null
|
||||||
producerAudio = null
|
|
||||||
producerTransport = null
|
producerTransport = null
|
||||||
consumerTransport = null
|
consumerTransport = null
|
||||||
device = undefined
|
device = undefined
|
||||||
|
Reference in New Issue
Block a user