forked from dremin/twilio-voice.js
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
VBLOCKS-1718 | Remove default node modules (twilio#167)
* VBLOCKS-1716 | Convert JS pipeline to TS * Update npmignore * adding browser events and removing backoff * Adding backoff module * Use new backoff in call class * Use new backoff in wstransport * lint * fix tsdocs * Adding changelog * Adding tests * adding test file * Updating changelog
- Loading branch information
1 parent
d2b59bc
commit 5fd3bbe
Showing
9 changed files
with
274 additions
and
76 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,25 @@ | ||
.circleci | ||
.deepsource.toml | ||
.env | ||
.github | ||
.idea | ||
.nyc_output | ||
.nycrc | ||
.release.json | ||
BUILD.md | ||
build.yaml | ||
config.example.yaml | ||
config.yaml | ||
coverage | ||
docs | ||
extension | ||
lib | ||
karma.conf.ts | ||
karma.network.conf.ts | ||
node_modules | ||
nodemon.json | ||
PREFLIGHT.md | ||
scripts | ||
server.js | ||
templates | ||
tests | ||
tslint.json |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/** | ||
* @packageDocumentation | ||
* @internalapi | ||
*/ | ||
// @ts-nocheck | ||
// NOTE (csantos): This file was taken directly from twilio-video and has been renamed from JS to TS only. | ||
// It needs to be re-written as part of the overall updating of the files to TS. | ||
import { EventEmitter } from 'events'; | ||
|
||
class Backoff extends EventEmitter { | ||
/** | ||
* Construct a {@link Backoff}. | ||
* @param {object} options | ||
* @property {number} min - Initial timeout in milliseconds [100] | ||
* @property {number} max - Max timeout [10000] | ||
* @property {boolean} jitter - Apply jitter [0] | ||
* @property {number} factor - Multiplication factor for Backoff operation [2] | ||
*/ | ||
constructor(options) { | ||
super(); | ||
Object.defineProperties(this, { | ||
_attempts: { | ||
value: 0, | ||
writable: true, | ||
}, | ||
_duration: { | ||
enumerable: false, | ||
get() { | ||
let ms = this._min * Math.pow(this._factor, this._attempts); | ||
if (this._jitter) { | ||
const rand = Math.random(); | ||
const deviation = Math.floor(rand * this._jitter * ms); | ||
// tslint:disable-next-line | ||
ms = (Math.floor(rand * 10) & 1) === 0 ? ms - deviation : ms + deviation; | ||
} | ||
// tslint:disable-next-line | ||
return Math.min(ms, this._max) | 0; | ||
}, | ||
}, | ||
_factor: { value: options.factor || 2 }, | ||
_jitter: { value: options.jitter > 0 && options.jitter <= 1 ? options.jitter : 0 }, | ||
_max: { value: options.max || 10000 }, | ||
_min: { value: options.min || 100 }, | ||
_timeoutID: { | ||
value: null, | ||
writable: true, | ||
}, | ||
}); | ||
} | ||
|
||
backoff() { | ||
const duration = this._duration; | ||
if (this._timeoutID) { | ||
clearTimeout(this._timeoutID); | ||
this._timeoutID = null; | ||
} | ||
|
||
this.emit('backoff', this._attempts, duration); | ||
this._timeoutID = setTimeout(() => { | ||
this.emit('ready', this._attempts, duration); | ||
this._attempts++; | ||
}, duration); | ||
} | ||
|
||
reset() { | ||
this._attempts = 0; | ||
if (this._timeoutID) { | ||
clearTimeout(this._timeoutID); | ||
this._timeoutID = null; | ||
} | ||
} | ||
} | ||
|
||
export default Backoff; |
This file contains 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
This file contains 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
This file contains 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
Oops, something went wrong.