1
0
Fork 0
mirror of https://gitlab.com/futo-org/fcast.git synced 2025-08-22 15:22:50 +00:00

Receiver: Add pausing and resuming showDuration timer

This commit is contained in:
Michael Hollister 2025-06-18 11:06:16 -05:00
parent 205ec8bf23
commit c12e1aff58
2 changed files with 147 additions and 119 deletions

View file

@ -15,3 +15,55 @@ export function mediaItemFromPlayMessage(message: PlayMessage) {
null, null, message.headers, message.metadata
) : new MediaItem("");
}
export class Timer {
private handle: number;
private callback: () => void;
private delay: number;
private startTime: number;
private remainingTime: number;
constructor(callback: () => void, delay: number, autoStart: boolean = true) {
this.handle = null;
this.callback = callback;
this.delay = delay;
if (autoStart) {
this.start();
}
}
public start(delay?: number) {
this.delay = delay ? delay : this.delay;
if (this.handle) {
window.clearTimeout(this.handle);
}
this.startTime = Date.now();
this.remainingTime = null;
this.handle = window.setTimeout(this.callback, this.delay);
}
public pause() {
if (this.handle) {
window.clearTimeout(this.handle);
this.handle = null;
this.remainingTime = this.delay - (Date.now() - this.startTime);
}
}
public resume() {
if (this.remainingTime) {
this.start(this.remainingTime);
}
}
public stop() {
if (this.handle) {
window.clearTimeout(this.handle);
this.handle = null;
this.remainingTime = null;
}
}
}