Skip to content

Instantly share code, notes, and snippets.

@enricop89
Last active May 22, 2020 08:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save enricop89/faf8a8d765583a47fa60c9e12003737c to your computer and use it in GitHub Desktop.
Save enricop89/faf8a8d765583a47fa60c9e12003737c to your computer and use it in GitHub Desktop.
Example of Publisher Retry logic
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!
}
},
);
}
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