2023-08-25 18:48:17 -04:00
|
|
|
import { Component, ComponentNames } from '.';
|
2023-08-13 18:47:58 -04:00
|
|
|
|
|
|
|
export class NetworkUpdateable extends Component {
|
2023-09-02 16:40:46 -04:00
|
|
|
static DEFAULT_UPDATE_JITTER_MS = 30;
|
|
|
|
static DEFAULT_THRESHOLD_TIME_MS = 20;
|
|
|
|
|
|
|
|
public updateThreshold: number;
|
|
|
|
public jitter: number;
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
updateThreshold = NetworkUpdateable.DEFAULT_THRESHOLD_TIME_MS,
|
|
|
|
jitter = NetworkUpdateable.DEFAULT_UPDATE_JITTER_MS
|
|
|
|
) {
|
2023-08-13 18:47:58 -04:00
|
|
|
super(ComponentNames.NetworkUpdateable);
|
2023-09-02 16:40:46 -04:00
|
|
|
|
|
|
|
this.updateThreshold = updateThreshold;
|
|
|
|
this.jitter = jitter;
|
|
|
|
}
|
|
|
|
|
|
|
|
public getNextUpdateTime() {
|
|
|
|
return Math.random() * this.jitter + this.updateThreshold;
|
2023-08-13 18:47:58 -04:00
|
|
|
}
|
|
|
|
}
|