diff --git a/public/index.js b/public/index.js index bd8aa9a..f3b6bfb 100644 --- a/public/index.js +++ b/public/index.js @@ -15,7 +15,10 @@ console.log('[URL] ASSET_ID', ASSET_ID, '| ACCOUNT_ID', ACCOUNT_ID, '| callId', console.log('🟩 config', config) let socket -hub = io(config.hubAddress) + +setTimeout(() => { + hub = io(config.hubAddress) +}, 2000); const connectToMediasoup = () => { @@ -37,41 +40,39 @@ const connectToMediasoup = () => { } if (IS_PRODUCER === true) { - setTimeout(() => { - hub.on('connect', async () => { - console.log(`[HUB]! ${config.hubAddress} | connected: ${hub.connected}`) - connectToMediasoup() - - hub.emit( - 'ars', - JSON.stringify({ - ars: true, - asset_id: ASSET_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('connect', async () => { + console.log(`[HUB]! ${config.hubAddress} | connected: ${hub.connected}`) + connectToMediasoup() + + hub.emit( + 'ars', + JSON.stringify({ + ars: true, + asset_id: ASSET_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() + } }) - }, 2000); + }) hub.on('connect_error', (error) => { console.log('connect_error', error);