Connect to mediasoup with timeout(fix when it appears offline)

This commit is contained in:
Sergiu Toma 2022-11-22 18:27:56 +02:00
parent 39ad9cad27
commit b621b76e37

View File

@ -37,39 +37,41 @@ const connectToMediasoup = () => {
} }
if (IS_PRODUCER === true) { if (IS_PRODUCER === true) {
hub.on('connect', async () => { setTimeout(() => {
console.log(`[HUB] ${config.hubAddress} | connected: ${hub.connected}`) hub.on('connect', async () => {
connectToMediasoup() console.log(`[HUB] ${config.hubAddress} | connected: ${hub.connected}`)
connectToMediasoup()
hub.emit( hub.emit(
'ars', 'ars',
JSON.stringify({ JSON.stringify({
ars: true, ars: true,
asset_id: ASSET_ID, asset_id: ASSET_ID,
account_id: ACCOUNT_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('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()
}
}) })
}) }, 2000);
hub.on('connect_error', (error) => { hub.on('connect_error', (error) => {
console.log('connect_error', error); console.log('connect_error', error);