Refactor code; Added logs; Added env variables
This commit is contained in:
@ -20651,22 +20651,45 @@ yeast.decode = decode;
|
||||
module.exports = yeast;
|
||||
|
||||
},{}],95:[function(require,module,exports){
|
||||
module.exports = {
|
||||
hubAddress: 'https://hub.dev.linx.safemobile.com/',
|
||||
mediasoupAddress: 'https://localhost:3000/mediasoup',
|
||||
}
|
||||
},{}],96:[function(require,module,exports){
|
||||
const io = require('socket.io-client')
|
||||
const mediasoupClient = require('mediasoup-client')
|
||||
const urlParams = new URLSearchParams(location.search);
|
||||
const config = require('./config')
|
||||
console.log('[CONFIG]', config);
|
||||
|
||||
const ASSET_ID = parseInt(urlParams.get('assetId')) || null;
|
||||
const ACCOUNT_ID = parseInt(urlParams.get('accountId')) || null;
|
||||
let callId = parseInt(urlParams.get('callId')) || null;
|
||||
const IS_PRODUCER = urlParams.get('producer') === 'true' ? true : false
|
||||
console.log('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)
|
||||
|
||||
let socket
|
||||
hub = io('https://hub.dev.linx.safemobile.com/')
|
||||
hub = io(config.hubAddress)
|
||||
|
||||
const connectToMediasoup = () => {
|
||||
|
||||
socket = io(config.mediasoupAddress)
|
||||
|
||||
socket.on('connection-success', ({ _socketId, existsProducer }) => {
|
||||
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() }
|
||||
})
|
||||
}
|
||||
|
||||
if (IS_PRODUCER === true) {
|
||||
hub.on('connect', async () => {
|
||||
console.log('hub.connected', hub.connected);
|
||||
console.log(`[HUB] ${config.hubAddress} | connected: ${hub.connected}`)
|
||||
connectToMediasoup()
|
||||
|
||||
hub.emit(
|
||||
'ars',
|
||||
JSON.stringify({
|
||||
@ -20689,11 +20712,6 @@ if (IS_PRODUCER === true) {
|
||||
if (parsedData.type === 'notify-request' && IS_PRODUCER) {
|
||||
getLocalStream()
|
||||
}
|
||||
|
||||
// setTimeout(() => {
|
||||
// !IS_PRODUCER && goConnect()
|
||||
// }, 1000);
|
||||
// getRtpCapabilities()
|
||||
})
|
||||
})
|
||||
|
||||
@ -20708,23 +20726,10 @@ if (IS_PRODUCER === true) {
|
||||
hub.on('disconnect', () => {
|
||||
console.log('disconnect')
|
||||
})
|
||||
} else {
|
||||
connectToMediasoup()
|
||||
}
|
||||
|
||||
|
||||
socket = io('https://localhost:3000/mediasoup')
|
||||
|
||||
socket.on('connection-success', ({ socketId, existsProducer }) => {
|
||||
console.log(socketId, existsProducer)
|
||||
// if (IS_PRODUCER) { getLocalStream() }
|
||||
// setInterval(() => {
|
||||
// if (!IS_PRODUCER && existsProducer) { goConnect() }
|
||||
|
||||
// }, 5000);
|
||||
if (!IS_PRODUCER && existsProducer && consumer === undefined) { goConnect() }
|
||||
})
|
||||
|
||||
|
||||
|
||||
let device
|
||||
let rtpCapabilities
|
||||
let producerTransport
|
||||
@ -20769,11 +20774,11 @@ const streamSuccess = (stream) => {
|
||||
track,
|
||||
...params
|
||||
}
|
||||
|
||||
goConnect()
|
||||
}
|
||||
|
||||
const getLocalStream = () => {
|
||||
console.log('[getLocalStream]');
|
||||
navigator.mediaDevices.getUserMedia({
|
||||
audio: false,
|
||||
video: {
|
||||
@ -20925,7 +20930,7 @@ const connectSendTransport = async () => {
|
||||
|
||||
const answer = {
|
||||
origin_asset_id: ASSET_ID,
|
||||
dest_asset_id: originAssetId,
|
||||
dest_asset_id: originAssetId || parseInt(urlParams.get('dest_asset_id')),
|
||||
type: 'notify-answer',
|
||||
origin_asset_priority: 1,
|
||||
origin_asset_type_name: originAssetTypeName,
|
||||
@ -20978,7 +20983,6 @@ const createRecvTransport = async () => {
|
||||
errback(error)
|
||||
}
|
||||
})
|
||||
|
||||
connectRecvTransport()
|
||||
})
|
||||
}
|
||||
@ -20997,7 +21001,6 @@ const connectRecvTransport = async () => {
|
||||
return
|
||||
}
|
||||
|
||||
console.log(params)
|
||||
// then consume with the local consumer transport
|
||||
// which creates a consumer
|
||||
consumer = await consumerTransport.consume({
|
||||
@ -21010,16 +21013,16 @@ const connectRecvTransport = async () => {
|
||||
// destructure and retrieve the video track from the producer
|
||||
const { track } = consumer
|
||||
|
||||
const stream = new MediaStream([track])
|
||||
let stream = new MediaStream()
|
||||
stream.addTrack(track)
|
||||
// stream.removeTrack(track)
|
||||
remoteVideo.srcObject = stream
|
||||
|
||||
// the server consumer started with media paused
|
||||
// so we need to inform the server to resume
|
||||
socket.emit('consumer-resume')
|
||||
console.log('consumer', consumer);
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
btnLocalVideo.addEventListener('click', getLocalStream)
|
||||
btnRecvSendTransport.addEventListener('click', goConnect)
|
||||
},{"mediasoup-client":67,"socket.io-client":83}]},{},[95]);
|
||||
},{"./config":95,"mediasoup-client":67,"socket.io-client":83}]},{},[96]);
|
||||
|
4
public/config.js
Normal file
4
public/config.js
Normal file
@ -0,0 +1,4 @@
|
||||
module.exports = {
|
||||
hubAddress: 'https://hub.dev.linx.safemobile.com/',
|
||||
mediasoupAddress: 'https://localhost:3000/mediasoup',
|
||||
}
|
@ -55,6 +55,9 @@
|
||||
<button id="btnRecvSendTransport">Consume</button>
|
||||
</div>
|
||||
</td>
|
||||
<td class="remoteColumn">
|
||||
<div id="videoContainer"></div>
|
||||
</td>
|
||||
</tr>
|
||||
<!-- <tr>
|
||||
<td colspan="2">
|
||||
|
@ -1,19 +1,37 @@
|
||||
const io = require('socket.io-client')
|
||||
const mediasoupClient = require('mediasoup-client')
|
||||
const urlParams = new URLSearchParams(location.search);
|
||||
const config = require('./config')
|
||||
console.log('[CONFIG]', config);
|
||||
|
||||
const ASSET_ID = parseInt(urlParams.get('assetId')) || null;
|
||||
const ACCOUNT_ID = parseInt(urlParams.get('accountId')) || null;
|
||||
let callId = parseInt(urlParams.get('callId')) || null;
|
||||
const IS_PRODUCER = urlParams.get('producer') === 'true' ? true : false
|
||||
console.log('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)
|
||||
|
||||
let socket
|
||||
hub = io('https://hub.dev.linx.safemobile.com/')
|
||||
hub = io(config.hubAddress)
|
||||
|
||||
const connectToMediasoup = () => {
|
||||
|
||||
socket = io(config.mediasoupAddress)
|
||||
|
||||
socket.on('connection-success', ({ _socketId, existsProducer }) => {
|
||||
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() }
|
||||
})
|
||||
}
|
||||
|
||||
if (IS_PRODUCER === true) {
|
||||
hub.on('connect', async () => {
|
||||
console.log('hub.connected', hub.connected);
|
||||
console.log(`[HUB] ${config.hubAddress} | connected: ${hub.connected}`)
|
||||
connectToMediasoup()
|
||||
|
||||
hub.emit(
|
||||
'ars',
|
||||
JSON.stringify({
|
||||
@ -36,11 +54,6 @@ if (IS_PRODUCER === true) {
|
||||
if (parsedData.type === 'notify-request' && IS_PRODUCER) {
|
||||
getLocalStream()
|
||||
}
|
||||
|
||||
// setTimeout(() => {
|
||||
// !IS_PRODUCER && goConnect()
|
||||
// }, 1000);
|
||||
// getRtpCapabilities()
|
||||
})
|
||||
})
|
||||
|
||||
@ -55,23 +68,10 @@ if (IS_PRODUCER === true) {
|
||||
hub.on('disconnect', () => {
|
||||
console.log('disconnect')
|
||||
})
|
||||
} else {
|
||||
connectToMediasoup()
|
||||
}
|
||||
|
||||
|
||||
socket = io('https://localhost:3000/mediasoup')
|
||||
|
||||
socket.on('connection-success', ({ socketId, existsProducer }) => {
|
||||
console.log(socketId, existsProducer)
|
||||
// if (IS_PRODUCER) { getLocalStream() }
|
||||
// setInterval(() => {
|
||||
// if (!IS_PRODUCER && existsProducer) { goConnect() }
|
||||
|
||||
// }, 5000);
|
||||
if (!IS_PRODUCER && existsProducer && consumer === undefined) { goConnect() }
|
||||
})
|
||||
|
||||
|
||||
|
||||
let device
|
||||
let rtpCapabilities
|
||||
let producerTransport
|
||||
@ -116,11 +116,11 @@ const streamSuccess = (stream) => {
|
||||
track,
|
||||
...params
|
||||
}
|
||||
|
||||
goConnect()
|
||||
}
|
||||
|
||||
const getLocalStream = () => {
|
||||
console.log('[getLocalStream]');
|
||||
navigator.mediaDevices.getUserMedia({
|
||||
audio: false,
|
||||
video: {
|
||||
@ -272,7 +272,7 @@ const connectSendTransport = async () => {
|
||||
|
||||
const answer = {
|
||||
origin_asset_id: ASSET_ID,
|
||||
dest_asset_id: originAssetId,
|
||||
dest_asset_id: originAssetId || parseInt(urlParams.get('dest_asset_id')),
|
||||
type: 'notify-answer',
|
||||
origin_asset_priority: 1,
|
||||
origin_asset_type_name: originAssetTypeName,
|
||||
@ -325,7 +325,6 @@ const createRecvTransport = async () => {
|
||||
errback(error)
|
||||
}
|
||||
})
|
||||
|
||||
connectRecvTransport()
|
||||
})
|
||||
}
|
||||
@ -344,7 +343,6 @@ const connectRecvTransport = async () => {
|
||||
return
|
||||
}
|
||||
|
||||
console.log(params)
|
||||
// then consume with the local consumer transport
|
||||
// which creates a consumer
|
||||
consumer = await consumerTransport.consume({
|
||||
@ -357,13 +355,13 @@ const connectRecvTransport = async () => {
|
||||
// destructure and retrieve the video track from the producer
|
||||
const { track } = consumer
|
||||
|
||||
const stream = new MediaStream([track])
|
||||
let stream = new MediaStream()
|
||||
stream.addTrack(track)
|
||||
// stream.removeTrack(track)
|
||||
remoteVideo.srcObject = stream
|
||||
|
||||
// the server consumer started with media paused
|
||||
// so we need to inform the server to resume
|
||||
socket.emit('consumer-resume')
|
||||
console.log('consumer', consumer);
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user