diff --git a/examples/master.js b/examples/master.js index 29abb53..47869cd 100644 --- a/examples/master.js +++ b/examples/master.js @@ -228,18 +228,27 @@ registerMasterSignalingClientCallbacks = (signalingClient, formValues, onStatsRe // If in WebRTC ingestion mode, retry if no connection was established within 30 seconds. // Note: This is an interim setting - the viewer application will retry after 30 seconds if the connection through the WebRTC Ingestion mode is not successful. if (master.channelHelper.isIngestionEnabled()) { - setTimeout(function () { - // We check that it's not failed because if the state transitioned to failed, - // the state change callback would handle this already - if ( - answerer.getPeerConnection().connectionState !== 'connected' && - answerer.getPeerConnection().connectionState !== 'failed' && - answerer.getPeerConnection().connectionState !== 'closed' - ) { - console.error(`[${role}] Connection was not successful - Will retry after 30 seconds.`); - onPeerConnectionFailed(remoteClientId, false, false); - } - }, 30000); + const CHECK_INTERVAL_SECONDS = 5; + const RETRY_TIMEOUT_SECONDS = 30; + + for (let i = CHECK_INTERVAL_SECONDS; i <= RETRY_TIMEOUT_SECONDS; i += CHECK_INTERVAL_SECONDS) { + setTimeout(function () { + // check the state each 5 seconds + //enter retry if still connecting after 30 seconds + if ( + answerer.getPeerConnection().connectionState !== 'connected' && + answerer.getPeerConnection().connectionState !== 'failed' && + answerer.getPeerConnection().connectionState !== 'closed' + ) { + if (i < RETRY_TIMEOUT_SECONDS) { + console.log(`[${role}] Still connecting after ${i} seconds.`); + } else { + console.error(`[${role}] Connection was not successful - Will retry after ${RETRY_TIMEOUT_SECONDS} seconds.`); + onPeerConnectionFailed(remoteClientId, false, false); + } + } + }, i * 1000); + } } });