Last active
May 22, 2020 08:05
-
-
Save enricop89/faf8a8d765583a47fa60c9e12003737c to your computer and use it in GitHub Desktop.
Example of Publisher Retry logic
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let currentRetryAttempt = 0; | |
const maxRetryAttempts = 3; | |
const retryAttemptTimeout = 1000; | |
function handleRetryPublisher() { | |
setTimeout(() => { | |
currentRetryAttempt += 1; | |
this.createPublisher(); | |
}, this.retryAttemptTimeout); | |
} | |
function createPublisher(){ | |
const publisher = OT.initPublisher(stream, | |
"container", | |
{...options}, | |
(err) => { | |
if (err && currentRetryAttempt < (this.maxRetryAttempts - 1)) { | |
// Error during subscribe function | |
this.handleRetryPublisher(); | |
// If there is a retry action, do we want to execute the onError props function? | |
// return; | |
} else if (err) { | |
// Retry attempts finished. Show an Error message to the User | |
} else if (!err ) { | |
// Published! | |
} | |
}, | |
); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let currentRetryAttempt = 0; | |
const maxRetryAttempts = 3; | |
const retryAttemptTimeout = 1000; | |
const session, stream; | |
function handleRetrySubscriber() { | |
setTimeout(() => { | |
currentRetryAttempt += 1; | |
this.subscribeToStream(); | |
}, this.retryAttemptTimeout); | |
} | |
function subscribeToStream(){ | |
const subscriber = session.subscribe(stream, | |
"container", | |
{...options}, | |
(err) => { | |
if (err && currentRetryAttempt < (this.maxRetryAttempts - 1)) { | |
// Error during subscribe function | |
this.handleRetrySubscriber(); | |
// return; | |
} else if (err) { | |
// Retry attempts finished. Show an Error message to the User | |
} else if (!err ) { | |
// subscribed! | |
} | |
}, | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment