Compare commits
1 Commits
8ef6c2abb0
...
LH-265-ena
Author | SHA1 | Date | |
---|---|---|---|
df3482ac15 |
55
app.js
55
app.js
@ -95,65 +95,16 @@ const mediaCodecs = [
|
|||||||
kind: 'audio',
|
kind: 'audio',
|
||||||
mimeType: 'audio/opus',
|
mimeType: 'audio/opus',
|
||||||
clockRate: 48000,
|
clockRate: 48000,
|
||||||
channels : 2
|
channels: 2,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
kind: 'video',
|
kind: 'video',
|
||||||
mimeType: 'video/VP8',
|
mimeType: 'video/VP8',
|
||||||
clockRate: 90000,
|
clockRate: 90000,
|
||||||
parameters :
|
parameters: {
|
||||||
{
|
'x-google-start-bitrate': 1000,
|
||||||
'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) => {
|
const closeCall = (callId) => {
|
||||||
|
1060
public/bundle.js
1060
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',
|
||||||
}
|
}
|
@ -43,7 +43,7 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
<div id="sharedBtns">
|
<div id="sharedBtns">
|
||||||
<video id="localVideo" autoplay class="video" muted></video>
|
<video id="localVideo" autoplay class="video" ></video>
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
|
158
public/index.js
158
public/index.js
@ -12,11 +12,7 @@ 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
|
||||||
|
|
||||||
let socket, hub
|
|
||||||
|
|
||||||
setTimeout(() => {
|
|
||||||
hub = io(config.hubAddress)
|
hub = io(config.hubAddress)
|
||||||
|
|
||||||
const connectToMediasoup = () => {
|
const connectToMediasoup = () => {
|
||||||
@ -40,7 +36,7 @@ setTimeout(() => {
|
|||||||
|
|
||||||
if (IS_PRODUCER === true) {
|
if (IS_PRODUCER === true) {
|
||||||
hub.on('connect', async () => {
|
hub.on('connect', async () => {
|
||||||
console.log(`[HUB]! ${config.hubAddress} | connected: ${hub.connected}`)
|
console.log(`[HUB] ${config.hubAddress} | connected: ${hub.connected}`)
|
||||||
connectToMediasoup()
|
connectToMediasoup()
|
||||||
|
|
||||||
hub.emit(
|
hub.emit(
|
||||||
@ -88,90 +84,52 @@ setTimeout(() => {
|
|||||||
connectToMediasoup()
|
connectToMediasoup()
|
||||||
}
|
}
|
||||||
|
|
||||||
}, 1600);
|
|
||||||
|
|
||||||
|
|
||||||
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 = {
|
||||||
|
// mediasoup params
|
||||||
encodings: [
|
encodings: [
|
||||||
{ scaleResolutionDownBy: 4, maxBitrate: 500000 },
|
{
|
||||||
{ scaleResolutionDownBy: 2, maxBitrate: 1000000 },
|
rid: 'r0',
|
||||||
{ scaleResolutionDownBy: 1, maxBitrate: 5000000 },
|
maxBitrate: 100000,
|
||||||
{ scalabilityMode: 'S3T3_KEY' }
|
scalabilityMode: 'S1T3',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
rid: 'r1',
|
||||||
|
maxBitrate: 300000,
|
||||||
|
scalabilityMode: 'S1T3',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
rid: 'r2',
|
||||||
|
maxBitrate: 900000,
|
||||||
|
scalabilityMode: 'S1T3',
|
||||||
|
},
|
||||||
],
|
],
|
||||||
|
// https://mediasoup.org/documentation/v3/mediasoup-client/api/#ProducerCodecOptions
|
||||||
codecOptions: {
|
codecOptions: {
|
||||||
videoGoogleStartBitrate: 1000
|
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) => {
|
const streamSuccess = (stream) => {
|
||||||
console.log('[streamSuccess] device', device);
|
console.log('[streamSuccess]');
|
||||||
localVideo.srcObject = stream
|
localVideo.srcObject = stream
|
||||||
console.log('stream', stream);
|
const track = stream.getVideoTracks()[0]
|
||||||
const videoTrack = stream.getVideoTracks()[0]
|
params = {
|
||||||
const audioTrack = stream.getAudioTracks()[0]
|
track,
|
||||||
|
...params
|
||||||
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()
|
goConnect()
|
||||||
// console.log('[streamSuccess]');
|
|
||||||
// localVideo.srcObject = stream
|
|
||||||
// const track = stream.getVideoTracks()[0]
|
|
||||||
// videoParams = {
|
|
||||||
// track,
|
|
||||||
// ...videoParams
|
|
||||||
// }
|
|
||||||
// goConnect()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const getLocalStream = () => {
|
const getLocalStream = () => {
|
||||||
@ -179,24 +137,16 @@ const getLocalStream = () => {
|
|||||||
navigator.mediaDevices.getUserMedia({
|
navigator.mediaDevices.getUserMedia({
|
||||||
audio: true,
|
audio: true,
|
||||||
video: {
|
video: {
|
||||||
qvga : { width: { ideal: 320 }, height: { ideal: 240 } },
|
width: {
|
||||||
vga : { width: { ideal: 640 }, height: { ideal: 480 } },
|
min: 640,
|
||||||
hd : { width: { ideal: 1280 }, height: { ideal: 720 } }
|
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)
|
.then(streamSuccess)
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
console.log(error.message)
|
console.log(error.message)
|
||||||
@ -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,7 +178,6 @@ 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,33 +270,18 @@ 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')
|
|
||||||
// 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')
|
console.log('transport ended')
|
||||||
// close video track
|
// close video track
|
||||||
})
|
})
|
||||||
@ -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