Compare commits
120 Commits
develop
...
LH-265-ena
Author | SHA1 | Date | |
---|---|---|---|
c823f7578c | |||
6cc14cdf30 | |||
4bb23def42 | |||
fc745a5879 | |||
742d67f2e3 | |||
e22093d97e | |||
7634a18465 | |||
d17b035526 | |||
a21451e46d | |||
df0cb81a8e | |||
ac8c651a9d | |||
9111c4e245 | |||
7a2d02dcda | |||
39efdd12b7 | |||
0bdc6fac3a | |||
ae7a8ed9ce | |||
9feaebf8a7 | |||
85110b7f5c | |||
d047cdf7d1 | |||
753b476462 | |||
359c7c784e | |||
5169d0d49f | |||
a3b083fe24 | |||
46d3499e3d | |||
38b95d5246 | |||
984b2b892e | |||
e085d22e89 | |||
3bc15fdef1 | |||
67042185c4 | |||
c92dff9bfe | |||
3605ca0468 | |||
1edbcb2179 | |||
adbcf6c2bc | |||
c862224ead | |||
c02a7c7380 | |||
3387a362a6 | |||
21dffefa8c | |||
1369491529 | |||
56bdbca537 | |||
8444809910 | |||
cd84c534ce | |||
038bdb99bc | |||
d94ea12a40 | |||
1148532a9b | |||
3561bb13a6 | |||
22ead926b0 | |||
c6edb2947d | |||
e59f134a68 | |||
aad96b72f2 | |||
3e4c0a32bc | |||
2a7bd42247 | |||
f2c0794bf4 | |||
950298c4f6 | |||
6e74083733 | |||
8ef6c2abb0 | |||
2a86042c80 | |||
56b8e2ea74 | |||
6c42814229 | |||
e65b7e0d7c | |||
aa7c2aea90 | |||
458342c0d2 | |||
fa5a1a5ae7 | |||
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 |
@ -22,17 +22,20 @@
|
||||
2. Run the `npm start:prod` command to start the server in production mode.
|
||||
(To connect to the terminal, use `pm2 log video-server`)
|
||||
|
||||
---
|
||||
|
||||
### Web client
|
||||
|
||||
- The server will start by default on port 3000, and the ssl certificates will have to be configured
|
||||
- The web client can be accessed using the /sfu path
|
||||
ex: http://localhost:3000/sfu/?assetId=1&&accountId=1&producer=true&assetName=Adi&assetType=linx
|
||||
ex: https://HOST/sfu/?assetId=1&&accountId=1&producer=true&dest_asset_id=75&assetName=Adi
|
||||
assetId = asset id of the unit on which you are doing the test
|
||||
accountId = account id of the unit on which you are doing the test
|
||||
producer = it will always be true because you are the producer
|
||||
(it's possible to put false, but then you have to have another client with producer true)
|
||||
assetName = asset name of the unit on which you are doing the test
|
||||
assetType = asset type of the unit on which you are doing the test
|
||||
dest_asset_id= the addressee with whom the call is made
|
||||
- To make a call using this client, you need a microphone and permission to use it
|
||||
- For any changes related to the client, the command `npm run watch' will have to be used to generate the bundle.js used by the web client
|
||||
|
||||
### Demo project
|
||||
The demo project used initially and then modified for our needs `https://github.com/jamalag/mediasoup2`
|
||||
|
215
app.js
215
app.js
@ -95,23 +95,76 @@ const mediaCodecs = [
|
||||
kind : 'audio',
|
||||
mimeType : 'audio/opus',
|
||||
clockRate : 48000,
|
||||
channels: 2,
|
||||
channels : 2
|
||||
},
|
||||
{
|
||||
kind : 'video',
|
||||
mimeType : 'video/VP8',
|
||||
clockRate : 90000,
|
||||
parameters: {
|
||||
'x-google-start-bitrate': 1000,
|
||||
parameters :
|
||||
{
|
||||
'x-google-start-bitrate' : 1000
|
||||
},
|
||||
channels : 2
|
||||
},
|
||||
{
|
||||
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) => {
|
||||
try {
|
||||
if (callId && videoCalls[callId]) {
|
||||
videoCalls[callId].producer?.close();
|
||||
videoCalls[callId].consumer?.close();
|
||||
videoCalls[callId].producerVideo?.close();
|
||||
videoCalls[callId].producerAudio?.close();
|
||||
videoCalls[callId].consumerVideo?.close();
|
||||
videoCalls[callId].consumerAudio?.close();
|
||||
|
||||
videoCalls[callId]?.consumerTransport?.close();
|
||||
videoCalls[callId]?.producerTransport?.close();
|
||||
videoCalls[callId]?.router?.close();
|
||||
@ -236,14 +289,20 @@ peers.on('connection', async socket => {
|
||||
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({
|
||||
console.log(`[transport-produce] kind: ${kind} | socket.id: ${socket.id} | callId: ${callId}`);
|
||||
console.log('kind', kind);
|
||||
console.log('rtpParameters', rtpParameters);
|
||||
|
||||
if (kind === 'video') {
|
||||
videoCalls[callId].producerVideo = await videoCalls[callId].producerTransport.produce({
|
||||
kind,
|
||||
rtpParameters,
|
||||
});
|
||||
console.log(`[transport-produce] Producer ID: ${videoCalls[callId].producer.id} | kind: ${videoCalls[callId].producer.kind}`);
|
||||
|
||||
videoCalls[callId].producer.on('transportclose', () => {
|
||||
|
||||
console.log(`[transport-produce] Producer ID: ${videoCalls[callId].producerVideo.id} | kind: ${videoCalls[callId].producerVideo.kind}`);
|
||||
|
||||
videoCalls[callId].producerVideo.on('transportclose', () => {
|
||||
const callId = socketDetails[socket.id];
|
||||
console.log('transport for this producer closed', callId)
|
||||
closeCall(callId);
|
||||
@ -251,8 +310,27 @@ peers.on('connection', async socket => {
|
||||
|
||||
// Send back to the client the Producer's id
|
||||
callback && callback({
|
||||
id: videoCalls[callId].producer.id
|
||||
id: videoCalls[callId].producerVideo.id
|
||||
});
|
||||
} else if (kind === 'audio') {
|
||||
videoCalls[callId].producerAudio = await videoCalls[callId].producerTransport.produce({
|
||||
kind,
|
||||
rtpParameters,
|
||||
});
|
||||
|
||||
console.log(`[transport-produce] Producer ID: ${videoCalls[callId].producerAudio.id} | kind: ${videoCalls[callId].producerAudio.kind}`);
|
||||
|
||||
videoCalls[callId].producerAudio.on('transportclose', () => {
|
||||
const callId = socketDetails[socket.id];
|
||||
console.log('transport for this producer closed', callId)
|
||||
closeCall(callId);
|
||||
});
|
||||
|
||||
// Send back to the client the Producer's id
|
||||
callback && callback({
|
||||
id: videoCalls[callId].producerAudio.id
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
console.log(`ERROR | transport-produce | callId ${socketDetails[socket.id]} | ${error.message}`);
|
||||
}
|
||||
@ -281,48 +359,36 @@ peers.on('connection', async socket => {
|
||||
*/
|
||||
socket.on('consume', async ({ rtpCapabilities }, callback) => {
|
||||
try {
|
||||
console.log(`[consume] rtpCapabilities: ${JSON.stringify(rtpCapabilities)}`);
|
||||
|
||||
const callId = socketDetails[socket.id];
|
||||
console.log('[consume] callId', callId);
|
||||
|
||||
// Check if the router can consume the specified producer
|
||||
if (videoCalls[callId].router.canConsume({
|
||||
producerId: videoCalls[callId].producer.id,
|
||||
const canConsumeVideo = !!videoCalls[callId].producerVideo && !!videoCalls[callId].router.canConsume({
|
||||
producerId: videoCalls[callId].producerVideo.id,
|
||||
rtpCapabilities
|
||||
})) {
|
||||
console.log('[consume] Can consume', callId);
|
||||
// Transport can now consume and return a consumer
|
||||
videoCalls[callId].consumer = await videoCalls[callId].consumerTransport.consume({
|
||||
producerId: videoCalls[callId].producer.id,
|
||||
rtpCapabilities,
|
||||
paused: true,
|
||||
});
|
||||
})
|
||||
|
||||
// https://mediasoup.org/documentation/v3/mediasoup/api/#consumer-on-transportclose
|
||||
videoCalls[callId].consumer.on('transportclose', () => {
|
||||
const callId = socketDetails[socket.id];
|
||||
console.log('transport close from consumer', callId);
|
||||
closeCall(callId);
|
||||
});
|
||||
const canConsumeAudio = !!videoCalls[callId].producerAudio && !!videoCalls[callId].router.canConsume({
|
||||
producerId: videoCalls[callId].producerAudio.id,
|
||||
rtpCapabilities
|
||||
})
|
||||
|
||||
// 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(callId);
|
||||
});
|
||||
console.log('[consume] canConsumeVideo', canConsumeVideo);
|
||||
console.log('[consume] canConsumeAudio', canConsumeAudio);
|
||||
|
||||
// From the consumer extract the following params to send back to the Client
|
||||
const params = {
|
||||
id: videoCalls[callId].consumer.id,
|
||||
producerId: videoCalls[callId].producer.id,
|
||||
kind: videoCalls[callId].consumer.kind,
|
||||
rtpParameters: videoCalls[callId].consumer.rtpParameters,
|
||||
};
|
||||
|
||||
// Send the parameters to the client
|
||||
callback({ params });
|
||||
if (canConsumeVideo && !canConsumeAudio) {
|
||||
console.log('1');
|
||||
const videoParams = await consumeVideo(callId, rtpCapabilities)
|
||||
console.log('videoParams', videoParams);
|
||||
callback({ videoParams, audioParams: null });
|
||||
} else if (canConsumeVideo && canConsumeAudio) {
|
||||
console.log('2');
|
||||
const videoParams = await consumeVideo(callId, rtpCapabilities)
|
||||
const audioParams = await consumeAudio(callId, rtpCapabilities)
|
||||
callback({ videoParams, audioParams });
|
||||
} else {
|
||||
console.log(`[canConsume] Can't consume | callId ${callId}`);
|
||||
console.log(`[consume] Can't consume | callId ${callId}`);
|
||||
callback(null);
|
||||
}
|
||||
} catch (error) {
|
||||
@ -339,13 +405,71 @@ peers.on('connection', async socket => {
|
||||
try {
|
||||
const callId = socketDetails[socket.id];
|
||||
console.log(`[consumer-resume] callId ${callId}`)
|
||||
await videoCalls[callId].consumer.resume();
|
||||
await videoCalls[callId].consumerVideo.resume();
|
||||
await videoCalls[callId].consumerAudio.resume();
|
||||
} catch (error) {
|
||||
console.log(`ERROR | consumer-resume | callId ${socketDetails[socket.id]} | ${error.message}`);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
const consumeVideo = async (callId, rtpCapabilities) => {
|
||||
videoCalls[callId].consumerVideo = await videoCalls[callId].consumerTransport.consume({
|
||||
producerId: videoCalls[callId].producerVideo.id,
|
||||
rtpCapabilities,
|
||||
paused: true,
|
||||
});
|
||||
|
||||
// https://mediasoup.org/documentation/v3/mediasoup/api/#consumer-on-transportclose
|
||||
videoCalls[callId].consumerVideo.on('transportclose', () => {
|
||||
const callId = socketDetails[socket.id];
|
||||
console.log('transport close from consumer', callId);
|
||||
closeCall(callId);
|
||||
});
|
||||
|
||||
// https://mediasoup.org/documentation/v3/mediasoup/api/#consumer-on-producerclose
|
||||
videoCalls[callId].consumerVideo.on('producerclose', () => {
|
||||
const callId = socketDetails[socket.id];
|
||||
console.log('producer of consumer closed', callId);
|
||||
closeCall(callId);
|
||||
});
|
||||
|
||||
return {
|
||||
id: videoCalls[callId].consumerVideo.id,
|
||||
producerId: videoCalls[callId].producerVideo.id,
|
||||
kind: 'video',
|
||||
rtpParameters: videoCalls[callId].consumerVideo.rtpParameters,
|
||||
}
|
||||
}
|
||||
|
||||
const consumeAudio = async (callId, rtpCapabilities) => {
|
||||
videoCalls[callId].consumerAudio = await videoCalls[callId].consumerTransport.consume({
|
||||
producerId: videoCalls[callId].producerAudio.id,
|
||||
rtpCapabilities,
|
||||
paused: true,
|
||||
});
|
||||
|
||||
// https://mediasoup.org/documentation/v3/mediasoup/api/#consumer-on-transportclose
|
||||
videoCalls[callId].consumerAudio.on('transportclose', () => {
|
||||
const callId = socketDetails[socket.id];
|
||||
console.log('transport close from consumer', callId);
|
||||
closeCall(callId);
|
||||
});
|
||||
|
||||
// https://mediasoup.org/documentation/v3/mediasoup/api/#consumer-on-producerclose
|
||||
videoCalls[callId].consumerAudio.on('producerclose', () => {
|
||||
const callId = socketDetails[socket.id];
|
||||
console.log('producer of consumer closed', callId);
|
||||
closeCall(callId);
|
||||
});
|
||||
return {
|
||||
id: videoCalls[callId].consumerAudio.id,
|
||||
producerId: videoCalls[callId].producerAudio.id,
|
||||
kind: 'audio',
|
||||
rtpParameters: videoCalls[callId].consumerAudio.rtpParameters,
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
- Called from at event 'createWebRtcTransport' and assigned to the consumer or producer transport
|
||||
- It will return parameters, these are required for the client to create the RecvTransport
|
||||
@ -393,6 +517,7 @@ const createWebRtcTransportLayer = async (callId, callback) => {
|
||||
dtlsParameters: transport.dtlsParameters,
|
||||
};
|
||||
|
||||
console.log('[createWebRtcTransportLayer] callback params', params);
|
||||
// Send back to the client the params
|
||||
callback({ params });
|
||||
|
||||
|
1076
public/bundle.js
1076
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',
|
||||
}
|
@ -43,7 +43,7 @@
|
||||
<tr>
|
||||
<td>
|
||||
<div id="sharedBtns">
|
||||
<video id="localVideo" autoplay class="video" ></video>
|
||||
<video id="localVideo" autoplay class="video" muted></video>
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
|
180
public/index.js
180
public/index.js
@ -12,7 +12,41 @@ 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
|
||||
console.log('🟩 config', config)
|
||||
|
||||
let socket, hub
|
||||
let device
|
||||
let rtpCapabilities
|
||||
let producerTransport
|
||||
let consumerTransport
|
||||
let producerVideo
|
||||
let producerAudio
|
||||
let consumer
|
||||
let originAssetId
|
||||
|
||||
// https://mediasoup.org/documentation/v3/mediasoup-client/api/#ProducerOptions
|
||||
// https://mediasoup.org/documentation/v3/mediasoup-client/api/#transport-produce
|
||||
let videoParams = {
|
||||
encodings: [
|
||||
{ scaleResolutionDownBy: 4, maxBitrate: 500000 },
|
||||
{ scaleResolutionDownBy: 2, maxBitrate: 1000000 },
|
||||
{ scaleResolutionDownBy: 1, maxBitrate: 5000000 },
|
||||
{ scalabilityMode: 'S3T3_KEY' }
|
||||
],
|
||||
codecOptions: {
|
||||
videoGoogleStartBitrate: 1000
|
||||
}
|
||||
}
|
||||
|
||||
let audioParams = {
|
||||
codecOptions :
|
||||
{
|
||||
opusStereo : true,
|
||||
opusDtx : true
|
||||
}
|
||||
}
|
||||
|
||||
setTimeout(() => {
|
||||
hub = io(config.hubAddress)
|
||||
|
||||
const connectToMediasoup = () => {
|
||||
@ -36,7 +70,7 @@ const connectToMediasoup = () => {
|
||||
|
||||
if (IS_PRODUCER === true) {
|
||||
hub.on('connect', async () => {
|
||||
console.log(`[HUB] ${config.hubAddress} | connected: ${hub.connected}`)
|
||||
console.log(`[HUB]! ${config.hubAddress} | connected: ${hub.connected}`)
|
||||
connectToMediasoup()
|
||||
|
||||
hub.emit(
|
||||
@ -84,73 +118,51 @@ if (IS_PRODUCER === true) {
|
||||
connectToMediasoup()
|
||||
}
|
||||
|
||||
let device
|
||||
let rtpCapabilities
|
||||
let producerTransport
|
||||
let consumerTransport
|
||||
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 params = {
|
||||
// mediasoup params
|
||||
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
|
||||
}
|
||||
}
|
||||
}, 1600);
|
||||
|
||||
const streamSuccess = (stream) => {
|
||||
console.log('[streamSuccess]');
|
||||
console.log('[streamSuccess] device', device);
|
||||
localVideo.srcObject = stream
|
||||
const track = stream.getVideoTracks()[0]
|
||||
params = {
|
||||
track,
|
||||
...params
|
||||
console.log('stream', stream);
|
||||
const videoTrack = stream.getVideoTracks()[0]
|
||||
const audioTrack = stream.getAudioTracks()[0]
|
||||
|
||||
videoParams = {
|
||||
track: videoTrack,
|
||||
...videoParams
|
||||
}
|
||||
|
||||
audioParams = {
|
||||
track: audioTrack,
|
||||
...audioParams
|
||||
}
|
||||
|
||||
console.log('[streamSuccess] videoParams', videoParams, ' | audioParams', audioParams);
|
||||
goConnect()
|
||||
}
|
||||
|
||||
const getLocalStream = () => {
|
||||
console.log('[getLocalStream]');
|
||||
navigator.mediaDevices.getUserMedia({
|
||||
audio: false,
|
||||
audio: true,
|
||||
video: {
|
||||
width: {
|
||||
min: 640,
|
||||
max: 1920,
|
||||
},
|
||||
height: {
|
||||
min: 400,
|
||||
max: 1080,
|
||||
}
|
||||
qvga : { width: { ideal: 320 }, height: { ideal: 240 } },
|
||||
vga : { width: { ideal: 640 }, height: { ideal: 480 } },
|
||||
hd : { width: { ideal: 1280 }, height: { ideal: 720 } }
|
||||
}
|
||||
})
|
||||
.then(streamSuccess)
|
||||
.catch(error => {
|
||||
console.log(error.message)
|
||||
})
|
||||
|
||||
navigator.permissions.query(
|
||||
{ name: 'microphone' }
|
||||
).then((permissionStatus) =>{
|
||||
console.log('🟨 [PERMISSION] permissionStatus', permissionStatus); // granted, denied, prompt
|
||||
// It will block the code from execution and display "Permission denied" if we don't have microphone permissions
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
const goConnect = () => {
|
||||
@ -167,7 +179,6 @@ const goCreateTransport = () => {
|
||||
// server side to send/recive media
|
||||
const createDevice = async () => {
|
||||
try {
|
||||
console.log('[createDevice]');
|
||||
device = new mediasoupClient.Device()
|
||||
|
||||
// https://mediasoup.org/documentation/v3/mediasoup-client/api/#device-load
|
||||
@ -178,6 +189,7 @@ const createDevice = async () => {
|
||||
})
|
||||
|
||||
console.log('Device RTP Capabilities', device.rtpCapabilities)
|
||||
console.log('[createDevice] device', device);
|
||||
|
||||
// once the device loads, create transport
|
||||
goCreateTransport()
|
||||
@ -207,18 +219,20 @@ 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 }) => {
|
||||
socket.emit('createWebRtcTransport', { sender: true, callId }, (value) => {
|
||||
|
||||
console.log(`[createWebRtcTransport] value: ${JSON.stringify(value)}`);
|
||||
|
||||
const params = value.params;
|
||||
// The server sends back params needed
|
||||
// to create Send Transport on the client side
|
||||
if (params.error) {
|
||||
console.log(params.error)
|
||||
return
|
||||
}
|
||||
|
||||
console.log(params)
|
||||
|
||||
// creates a new WebRTC Transport to send media
|
||||
// based on the server's producer transport params
|
||||
// https://mediasoup.org/documentation/v3/mediasoup-client/api/#TransportOptions
|
||||
@ -244,10 +258,10 @@ 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
|
||||
// Tell the server to create a Producer
|
||||
// with the following parameters and produce
|
||||
// and expect back a server side producer id
|
||||
// see server's socket.on('transport-produce', ...)
|
||||
@ -270,22 +284,44 @@ const createSendTransport = () => {
|
||||
}
|
||||
|
||||
const connectSendTransport = async () => {
|
||||
// we now call produce() to instruct the producer transport
|
||||
|
||||
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', () => {
|
||||
// Produce video
|
||||
producerVideo = await producerTransport.produce(videoParams)
|
||||
console.log('videoParams', 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
|
||||
})
|
||||
|
||||
// Produce audio
|
||||
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,
|
||||
dest_asset_id: originAssetId || parseInt(urlParams.get('dest_asset_id')),
|
||||
@ -294,7 +330,7 @@ const connectSendTransport = async () => {
|
||||
origin_asset_type_name: ASSET_TYPE,
|
||||
origin_asset_name: ASSET_NAME,
|
||||
video_call_id: callId,
|
||||
answer: 'accepted', // answer: 'rejected'
|
||||
answer: 'accepted', // answer: accepted/rejected
|
||||
};
|
||||
console.log('SEND answer', answer);
|
||||
|
||||
@ -310,7 +346,7 @@ const connectSendTransport = async () => {
|
||||
|
||||
const createRecvTransport = async () => {
|
||||
console.log('createRecvTransport');
|
||||
// see server's socket.on('consume', sender?, ...)
|
||||
// See server's socket.on('consume', sender?, ...)
|
||||
// this is a call from Consumer, so sender = false
|
||||
await socket.emit('createWebRtcTransport', { sender: false, callId }, ({ params }) => {
|
||||
// The server sends back params needed
|
||||
@ -320,15 +356,15 @@ const createRecvTransport = async () => {
|
||||
return
|
||||
}
|
||||
|
||||
console.log(params)
|
||||
console.log('[createRecvTransport] params', params)
|
||||
|
||||
// creates a new WebRTC Transport to receive media
|
||||
// Creates a new WebRTC Transport to receive media
|
||||
// based on server's consumer transport params
|
||||
// https://mediasoup.org/documentation/v3/mediasoup-client/api/#device-createRecvTransport
|
||||
consumerTransport = device.createRecvTransport(params)
|
||||
|
||||
// https://mediasoup.org/documentation/v3/communication-between-client-and-server/#producing-media
|
||||
// this event is raised when a first call to transport.produce() is made
|
||||
// This event is raised when a first call to transport.produce() is made
|
||||
// see connectRecvTransport() below
|
||||
consumerTransport.on('connect', async ({ dtlsParameters }, callback, errback) => {
|
||||
try {
|
||||
@ -353,7 +389,8 @@ const resetCallSettings = () => {
|
||||
localVideo.srcObject = null
|
||||
remoteVideo.srcObject = null
|
||||
consumer = null
|
||||
producer = null
|
||||
producerVideo = null
|
||||
producerAudio = null
|
||||
producerTransport = null
|
||||
consumerTransport = null
|
||||
device = undefined
|
||||
@ -361,7 +398,7 @@ const resetCallSettings = () => {
|
||||
|
||||
const connectRecvTransport = async () => {
|
||||
console.log('connectRecvTransport');
|
||||
// for consumer, we need to tell the server first
|
||||
// For consumer, we need to tell the server first
|
||||
// to create a consumer based on the rtpCapabilities and consume
|
||||
// if the router can consume, it will send back a set of params as below
|
||||
await socket.emit('consume', {
|
||||
@ -373,7 +410,7 @@ const connectRecvTransport = async () => {
|
||||
return
|
||||
}
|
||||
|
||||
// then consume with the local consumer transport
|
||||
// Then consume with the local consumer transport
|
||||
// which creates a consumer
|
||||
consumer = await consumerTransport.consume({
|
||||
id: params.id,
|
||||
@ -416,6 +453,7 @@ const closeCall = () => {
|
||||
resetCallSettings()
|
||||
}
|
||||
|
||||
|
||||
btnLocalVideo.addEventListener('click', getLocalStream)
|
||||
btnRecvSendTransport.addEventListener('click', goConnect)
|
||||
btnCloseCall.addEventListener('click', closeCall)
|
Loading…
Reference in New Issue
Block a user