Compare commits
27 Commits
4.06
...
a31e646e2b
Author | SHA1 | Date | |
---|---|---|---|
a31e646e2b | |||
fe792f93b6 | |||
dafbc486ad | |||
b606a72030 | |||
c174e92e3c | |||
449724537e | |||
9634aac153 | |||
e0bc4642cb | |||
f950142188 | |||
5ba1f76585 | |||
dc9c91fccc | |||
5abcddc115 | |||
bf65221664 | |||
5687569bc1 | |||
44c8d9b8ee | |||
0a6985f9b9 | |||
d29def364c | |||
acd6025f59 | |||
4b0c06e0b0 | |||
c1fe524ec7 | |||
f8fcfb3165 | |||
d324528d52 | |||
d1eb7afc3a | |||
695964d342 | |||
3ca555ef9e | |||
92fbecc36a | |||
d633eec92f |
38
app.js
38
app.js
@ -13,40 +13,40 @@ try {
|
|||||||
}
|
}
|
||||||
const mediasoup = require('mediasoup');
|
const mediasoup = require('mediasoup');
|
||||||
|
|
||||||
let worker;
|
let worker
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* videoCalls - Dictionary of Object(s)
|
* videoCalls - Dictionary of Object(s)
|
||||||
* '<callId>': {
|
* '<callId>': {
|
||||||
* router: Router,
|
* router: Router, router
|
||||||
* initiatorAudioProducer: Producer,
|
* initiatorAudioProducer: Producer,
|
||||||
* initiatorVideoProducer: Producer,
|
* initiatorVideoProducer: Producer,
|
||||||
* receiverVideoProducer: Producer,
|
* receiverVideoProducer: Producer, producerVideo
|
||||||
* receiverAudioProducer: Producer,
|
* receiverAudioProducer: Producer, producerAudio
|
||||||
* initiatorProducerTransport: Producer Transport,
|
* initiatorProducerTransport: Producer Transport,
|
||||||
* receiverProducerTransport: Producer Transport,
|
* receiverProducerTransport: Producer Transport, producerTransport
|
||||||
* initiatorConsumerVideo: Consumer,
|
* initiatorConsumerVideo: Consumer, consumerVideo
|
||||||
* initiatorConsumerAudio: Consumer,
|
* initiatorConsumerAudio: Consumer, consumerAudio
|
||||||
* initiatorConsumerTransport: Consumer Transport
|
* initiatorConsumerTransport: Consumer Transport consumerTransport
|
||||||
* initiatorSockerId
|
* initiatorSockerId
|
||||||
* receiverSocketId
|
* receiverSocketId
|
||||||
* }
|
* }
|
||||||
*
|
*
|
||||||
**/
|
**/
|
||||||
let videoCalls = {};
|
let videoCalls = {}
|
||||||
let socketDetails = {};
|
let socketDetails = {}
|
||||||
|
|
||||||
app.get('/', (_req, res) => {
|
app.get('/', (_req, res) => {
|
||||||
res.send('Hello from mediasoup app!')
|
res.send('Hello from mediasoup app!')
|
||||||
});
|
})
|
||||||
|
|
||||||
app.use('/sfu', express.static(path.join(__dirname, 'public')));
|
app.use('/sfu', express.static(path.join(__dirname, 'public')))
|
||||||
|
|
||||||
// SSL cert for HTTPS access
|
// SSL cert for HTTPS access
|
||||||
const options = {
|
const options = {
|
||||||
key: fs.readFileSync(process.env.SERVER_KEY, 'utf-8'),
|
key: fs.readFileSync(process.env.SERVER_KEY, 'utf-8'),
|
||||||
cert: fs.readFileSync(process.env.SERVER_CERT, 'utf-8'),
|
cert: fs.readFileSync(process.env.SERVER_CERT, 'utf-8'),
|
||||||
};
|
}
|
||||||
|
|
||||||
const httpsServer = https.createServer(options, app);
|
const httpsServer = https.createServer(options, app);
|
||||||
|
|
||||||
@ -225,6 +225,7 @@ peers.on('connection', async socket => {
|
|||||||
*/
|
*/
|
||||||
socket.on('createWebRtcTransport', async ({ sender }, callback) => {
|
socket.on('createWebRtcTransport', async ({ sender }, callback) => {
|
||||||
try {
|
try {
|
||||||
|
console.log('🟥', socket.id, JSON.stringify(sender));
|
||||||
const callId = socketDetails[socket.id];
|
const callId = socketDetails[socket.id];
|
||||||
console.log(`[createWebRtcTransport] socket ${socket.id} | sender ${sender} | callId ${callId}`);
|
console.log(`[createWebRtcTransport] socket ${socket.id} | sender ${sender} | callId ${callId}`);
|
||||||
if (sender) {
|
if (sender) {
|
||||||
@ -427,8 +428,7 @@ peers.on('connection', async socket => {
|
|||||||
callback({ videoParams, audioParams });
|
callback({ videoParams, audioParams });
|
||||||
} else if (!canConsumeVideo && canConsumeAudio) {
|
} else if (!canConsumeVideo && canConsumeAudio) {
|
||||||
const audioParams = await consumeAudio(callId, socket.id, rtpCapabilities)
|
const audioParams = await consumeAudio(callId, socket.id, rtpCapabilities)
|
||||||
const data = { videoParams: null, audioParams };
|
callback({ videoParams: null, audioParams });
|
||||||
callback(data);
|
|
||||||
} else {
|
} else {
|
||||||
console.log(`[consume] Can't consume | callId ${callId}`);
|
console.log(`[consume] Can't consume | callId ${callId}`);
|
||||||
callback(null);
|
callback(null);
|
||||||
@ -449,14 +449,14 @@ peers.on('connection', async socket => {
|
|||||||
console.log(`[consumer-resume] callId ${callId}`)
|
console.log(`[consumer-resume] callId ${callId}`)
|
||||||
|
|
||||||
if (isInitiator(callId, socket.id)) {
|
if (isInitiator(callId, socket.id)) {
|
||||||
console.log(`[consumer-resume] isInitiator true`);
|
|
||||||
await videoCalls[callId].initiatorConsumerVideo.resume();
|
await videoCalls[callId].initiatorConsumerVideo.resume();
|
||||||
await videoCalls[callId].initiatorConsumerAudio.resume();
|
await videoCalls[callId].initiatorConsumerAudio.resume();
|
||||||
} else {
|
} else {
|
||||||
console.log(`[consumer-resume] isInitiator false`);
|
await videoCalls[callId].receiverConsumerVideo.resume();
|
||||||
(videoCalls[callId].receiverConsumerVideo) && await videoCalls[callId].receiverConsumerVideo.resume();
|
await videoCalls[callId].receiverConsumerAudio.resume();
|
||||||
(videoCalls[callId].receiverConsumerVideo) && await videoCalls[callId].receiverConsumerAudio.resume();
|
|
||||||
}
|
}
|
||||||
|
// await videoCalls[callId].consumerVideo.resume();
|
||||||
|
// await videoCalls[callId].consumerAudio.resume();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(`ERROR | consumer-resume | callId ${socketDetails[socket.id]} | ${error.message}`);
|
console.log(`ERROR | consumer-resume | callId ${socketDetails[socket.id]} | ${error.message}`);
|
||||||
}
|
}
|
||||||
|
170
public/bundle.js
170
public/bundle.js
@ -20368,24 +20368,10 @@ const ASSET_NAME = urlParams.get('assetName') || null;
|
|||||||
const ASSET_TYPE = urlParams.get('assetType') || null;
|
const ASSET_TYPE = urlParams.get('assetType') || null;
|
||||||
let callId = parseInt(urlParams.get('callId')) || null;
|
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
|
||||||
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('[URL] ASSET_ID', ASSET_ID, '| ACCOUNT_ID', ACCOUNT_ID, '| callId', callId, ' | IS_PRODUCER', IS_PRODUCER)
|
||||||
|
|
||||||
console.log('🟩 config', config)
|
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 socket, hub
|
||||||
let device
|
let device
|
||||||
let rtpCapabilities
|
let rtpCapabilities
|
||||||
@ -20395,21 +20381,6 @@ let producerVideo
|
|||||||
let producerAudio
|
let producerAudio
|
||||||
let consumer
|
let consumer
|
||||||
let originAssetId
|
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/#ProducerOptions
|
||||||
// https://mediasoup.org/documentation/v3/mediasoup-client/api/#transport-produce
|
// https://mediasoup.org/documentation/v3/mediasoup-client/api/#transport-produce
|
||||||
@ -20531,7 +20502,7 @@ const streamSuccess = (stream) => {
|
|||||||
const getLocalStream = () => {
|
const getLocalStream = () => {
|
||||||
console.log('[getLocalStream]');
|
console.log('[getLocalStream]');
|
||||||
navigator.mediaDevices.getUserMedia({
|
navigator.mediaDevices.getUserMedia({
|
||||||
audio: produceAudio ? true : false,
|
audio: true,
|
||||||
video: {
|
video: {
|
||||||
qvga : { width: { ideal: 320 }, height: { ideal: 240 } },
|
qvga : { width: { ideal: 320 }, height: { ideal: 240 } },
|
||||||
vga : { width: { ideal: 640 }, height: { ideal: 480 } },
|
vga : { width: { ideal: 640 }, height: { ideal: 480 } },
|
||||||
@ -20680,36 +20651,34 @@ const connectSendTransport = async () => {
|
|||||||
// this action will trigger the 'connect' and 'produce' events above
|
// this action will trigger the 'connect' and 'produce' events above
|
||||||
|
|
||||||
// Produce video
|
// Produce video
|
||||||
let producerVideoHandler = await producerTransport.produce(videoParams)
|
producerVideo = await producerTransport.produce(videoParams)
|
||||||
console.log('videoParams', videoParams);
|
console.log('videoParams', videoParams);
|
||||||
console.log('producerVideo', producerVideo);
|
console.log('producerVideo', producerVideo);
|
||||||
|
|
||||||
producerVideoHandler.on('trackended', () => {
|
producerVideo.on('trackended', () => {
|
||||||
console.log('track ended')
|
console.log('track ended')
|
||||||
// close video track
|
// close video track
|
||||||
})
|
})
|
||||||
|
|
||||||
producerVideoHandler.on('transportclose', () => {
|
producerVideo.on('transportclose', () => {
|
||||||
console.log('transport ended')
|
console.log('transport ended')
|
||||||
// close video track
|
// close video track
|
||||||
})
|
})
|
||||||
|
|
||||||
// Produce audio
|
// Produce audio
|
||||||
if (produceAudio) {
|
producerAudio = await producerTransport.produce(audioParams)
|
||||||
let producerAudioHandler = await producerTransport.produce(audioParams)
|
console.log('audioParams', audioParams);
|
||||||
console.log('audioParams', audioParams);
|
console.log('producerAudio', producerAudio);
|
||||||
console.log('producerAudio', producerAudio);
|
|
||||||
|
producerAudio.on('trackended', () => {
|
||||||
producerAudioHandler.on('trackended', () => {
|
console.log('track ended')
|
||||||
console.log('track ended')
|
// close audio track
|
||||||
// close audio track
|
})
|
||||||
})
|
|
||||||
|
producerAudio.on('transportclose', () => {
|
||||||
producerAudioHandler.on('transportclose', () => {
|
console.log('transport ended')
|
||||||
console.log('transport ended')
|
// close audio track
|
||||||
// close audio track
|
})
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
const answer = {
|
const answer = {
|
||||||
origin_asset_id: ASSET_ID,
|
origin_asset_id: ASSET_ID,
|
||||||
@ -20793,95 +20762,36 @@ const connectRecvTransport = async () => {
|
|||||||
await socket.emit('consume', {
|
await socket.emit('consume', {
|
||||||
rtpCapabilities: device.rtpCapabilities,
|
rtpCapabilities: device.rtpCapabilities,
|
||||||
callId
|
callId
|
||||||
}, async ({videoParams, audioParams}) => {
|
}, async ({ params }) => {
|
||||||
console.log(`[consume] 🟩 videoParams`, videoParams)
|
// if (params.error) {
|
||||||
console.log(`[consume] 🟩 audioParams`, audioParams)
|
// console.log('Cannot Consume')
|
||||||
console.log('[consume] 🟩 consumerTransport', consumerTransport)
|
// return
|
||||||
|
// }
|
||||||
|
|
||||||
|
console.log(`[connectRecvTransport] consume params ${params}`);
|
||||||
|
|
||||||
|
// 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()
|
let stream = new MediaStream()
|
||||||
|
stream.addTrack(track)
|
||||||
// Maybe the unit does not produce video or audio, so we must only consume what is produced
|
// stream.removeTrack(track)
|
||||||
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')
|
|
||||||
|
|
||||||
remoteVideo.srcObject = stream
|
remoteVideo.srcObject = stream
|
||||||
remoteVideo.setAttribute('autoplay', true)
|
socket.emit('consumer-resume')
|
||||||
|
console.log('consumer', consumer);
|
||||||
|
|
||||||
remoteVideo.play()
|
|
||||||
.then(() => {
|
|
||||||
console.log('remoteVideo PLAY')
|
|
||||||
})
|
|
||||||
.catch((error) => {
|
|
||||||
displayError(`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
|
|
||||||
})
|
|
||||||
|
|
||||||
consumerVideo.on('transportclose', () => {
|
|
||||||
console.log('transport closed so consumer closed')
|
|
||||||
})
|
|
||||||
|
|
||||||
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 = () => {
|
const closeCall = () => {
|
||||||
console.log('closeCall');
|
console.log('closeCall');
|
||||||
|
|
||||||
|
@ -34,9 +34,6 @@
|
|||||||
<body>
|
<body>
|
||||||
<body>
|
<body>
|
||||||
<div id="video">
|
<div id="video">
|
||||||
<legend>Client options:</legend>
|
|
||||||
<input type="checkbox" id="produceAudio" name="produceAudio">
|
|
||||||
<label for="produceAudio">Produce audio</label><br>
|
|
||||||
<table>
|
<table>
|
||||||
<thead>
|
<thead>
|
||||||
<th>Local Video</th>
|
<th>Local Video</th>
|
||||||
@ -46,24 +43,12 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
<div id="sharedBtns">
|
<div id="sharedBtns">
|
||||||
<video
|
<video id="localVideo" autoplay class="video" muted></video>
|
||||||
id="localVideo"
|
|
||||||
class="video"
|
|
||||||
autoplay
|
|
||||||
muted
|
|
||||||
playsinline
|
|
||||||
></video>
|
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<div id="sharedBtns">
|
<div id="sharedBtns">
|
||||||
<video
|
<video id="remoteVideo" autoplay class="video" ></video>
|
||||||
id="remoteVideo"
|
|
||||||
class="video"
|
|
||||||
autoplay
|
|
||||||
muted
|
|
||||||
playsinline
|
|
||||||
></video>
|
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
@ -76,10 +61,33 @@
|
|||||||
<td>
|
<td>
|
||||||
<div id="sharedBtns">
|
<div id="sharedBtns">
|
||||||
<button id="btnRecvSendTransport">Consume</button>
|
<button id="btnRecvSendTransport">Consume</button>
|
||||||
<button id="remoteSoundControl">Unmute</button>
|
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</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>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
<div id="closeCallBtn">
|
<div id="closeCallBtn">
|
||||||
|
170
public/index.js
170
public/index.js
@ -10,24 +10,10 @@ const ASSET_NAME = urlParams.get('assetName') || null;
|
|||||||
const ASSET_TYPE = urlParams.get('assetType') || null;
|
const ASSET_TYPE = urlParams.get('assetType') || null;
|
||||||
let callId = parseInt(urlParams.get('callId')) || null;
|
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
|
||||||
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('[URL] ASSET_ID', ASSET_ID, '| ACCOUNT_ID', ACCOUNT_ID, '| callId', callId, ' | IS_PRODUCER', IS_PRODUCER)
|
||||||
|
|
||||||
console.log('🟩 config', config)
|
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 socket, hub
|
||||||
let device
|
let device
|
||||||
let rtpCapabilities
|
let rtpCapabilities
|
||||||
@ -37,21 +23,6 @@ let producerVideo
|
|||||||
let producerAudio
|
let producerAudio
|
||||||
let consumer
|
let consumer
|
||||||
let originAssetId
|
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/#ProducerOptions
|
||||||
// https://mediasoup.org/documentation/v3/mediasoup-client/api/#transport-produce
|
// https://mediasoup.org/documentation/v3/mediasoup-client/api/#transport-produce
|
||||||
@ -173,7 +144,7 @@ const streamSuccess = (stream) => {
|
|||||||
const getLocalStream = () => {
|
const getLocalStream = () => {
|
||||||
console.log('[getLocalStream]');
|
console.log('[getLocalStream]');
|
||||||
navigator.mediaDevices.getUserMedia({
|
navigator.mediaDevices.getUserMedia({
|
||||||
audio: produceAudio ? true : false,
|
audio: true,
|
||||||
video: {
|
video: {
|
||||||
qvga : { width: { ideal: 320 }, height: { ideal: 240 } },
|
qvga : { width: { ideal: 320 }, height: { ideal: 240 } },
|
||||||
vga : { width: { ideal: 640 }, height: { ideal: 480 } },
|
vga : { width: { ideal: 640 }, height: { ideal: 480 } },
|
||||||
@ -322,36 +293,34 @@ const connectSendTransport = async () => {
|
|||||||
// this action will trigger the 'connect' and 'produce' events above
|
// this action will trigger the 'connect' and 'produce' events above
|
||||||
|
|
||||||
// Produce video
|
// Produce video
|
||||||
let producerVideoHandler = await producerTransport.produce(videoParams)
|
producerVideo = await producerTransport.produce(videoParams)
|
||||||
console.log('videoParams', videoParams);
|
console.log('videoParams', videoParams);
|
||||||
console.log('producerVideo', producerVideo);
|
console.log('producerVideo', producerVideo);
|
||||||
|
|
||||||
producerVideoHandler.on('trackended', () => {
|
producerVideo.on('trackended', () => {
|
||||||
console.log('track ended')
|
console.log('track ended')
|
||||||
// close video track
|
// close video track
|
||||||
})
|
})
|
||||||
|
|
||||||
producerVideoHandler.on('transportclose', () => {
|
producerVideo.on('transportclose', () => {
|
||||||
console.log('transport ended')
|
console.log('transport ended')
|
||||||
// close video track
|
// close video track
|
||||||
})
|
})
|
||||||
|
|
||||||
// Produce audio
|
// Produce audio
|
||||||
if (produceAudio) {
|
producerAudio = await producerTransport.produce(audioParams)
|
||||||
let producerAudioHandler = await producerTransport.produce(audioParams)
|
console.log('audioParams', audioParams);
|
||||||
console.log('audioParams', audioParams);
|
console.log('producerAudio', producerAudio);
|
||||||
console.log('producerAudio', producerAudio);
|
|
||||||
|
producerAudio.on('trackended', () => {
|
||||||
producerAudioHandler.on('trackended', () => {
|
console.log('track ended')
|
||||||
console.log('track ended')
|
// close audio track
|
||||||
// close audio track
|
})
|
||||||
})
|
|
||||||
|
producerAudio.on('transportclose', () => {
|
||||||
producerAudioHandler.on('transportclose', () => {
|
console.log('transport ended')
|
||||||
console.log('transport ended')
|
// close audio track
|
||||||
// close audio track
|
})
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
const answer = {
|
const answer = {
|
||||||
origin_asset_id: ASSET_ID,
|
origin_asset_id: ASSET_ID,
|
||||||
@ -435,95 +404,36 @@ const connectRecvTransport = async () => {
|
|||||||
await socket.emit('consume', {
|
await socket.emit('consume', {
|
||||||
rtpCapabilities: device.rtpCapabilities,
|
rtpCapabilities: device.rtpCapabilities,
|
||||||
callId
|
callId
|
||||||
}, async ({videoParams, audioParams}) => {
|
}, async ({ params }) => {
|
||||||
console.log(`[consume] 🟩 videoParams`, videoParams)
|
// if (params.error) {
|
||||||
console.log(`[consume] 🟩 audioParams`, audioParams)
|
// console.log('Cannot Consume')
|
||||||
console.log('[consume] 🟩 consumerTransport', consumerTransport)
|
// return
|
||||||
|
// }
|
||||||
|
|
||||||
|
console.log(`[connectRecvTransport] consume params ${params}`);
|
||||||
|
|
||||||
|
// 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()
|
let stream = new MediaStream()
|
||||||
|
stream.addTrack(track)
|
||||||
// Maybe the unit does not produce video or audio, so we must only consume what is produced
|
// stream.removeTrack(track)
|
||||||
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')
|
|
||||||
|
|
||||||
remoteVideo.srcObject = stream
|
remoteVideo.srcObject = stream
|
||||||
remoteVideo.setAttribute('autoplay', true)
|
socket.emit('consumer-resume')
|
||||||
|
console.log('consumer', consumer);
|
||||||
|
|
||||||
remoteVideo.play()
|
|
||||||
.then(() => {
|
|
||||||
console.log('remoteVideo PLAY')
|
|
||||||
})
|
|
||||||
.catch((error) => {
|
|
||||||
displayError(`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
|
|
||||||
})
|
|
||||||
|
|
||||||
consumerVideo.on('transportclose', () => {
|
|
||||||
console.log('transport closed so consumer closed')
|
|
||||||
})
|
|
||||||
|
|
||||||
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 = () => {
|
const closeCall = () => {
|
||||||
console.log('closeCall');
|
console.log('closeCall');
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user