Add play/pause/mute/unmute Frigate card commands.

This commit is contained in:
Dermot Duffy
2023-05-11 20:25:40 -07:00
parent 2e5b86d6c9
commit 8365b43c04
23 changed files with 435 additions and 49 deletions
+17 -1
View File
@@ -5,11 +5,21 @@ export class CachedValueController<T> implements ReactiveController {
protected _host: ReactiveControllerHost;
protected _timerSeconds: number;
protected _callback: () => T;
protected _timerStartCallback?: () => void;
protected _timerStopCallback?: () => void;
protected _timerID?: number;
constructor(host: ReactiveControllerHost, timerSeconds: number, callback: () => T) {
constructor(
host: ReactiveControllerHost,
timerSeconds: number,
callback: () => T,
timerStartCallback?: () => void,
timerStopCallback?: () => void,
) {
this._timerSeconds = timerSeconds;
this._callback = callback;
this._timerStartCallback = timerStartCallback;
this._timerStopCallback = timerStopCallback;
(this._host = host).addController(this);
}
@@ -48,6 +58,7 @@ export class CachedValueController<T> implements ReactiveController {
public stopTimer(): void {
if (this._timerID !== undefined) {
window.clearInterval(this._timerID);
this._timerStopCallback?.();
}
this._timerID = undefined;
}
@@ -59,6 +70,7 @@ export class CachedValueController<T> implements ReactiveController {
this.stopTimer();
if (this._timerSeconds > 0) {
this._timerStartCallback?.();
this._timerID = window.setInterval(() => {
this.updateValue();
this._host.requestUpdate();
@@ -66,6 +78,10 @@ export class CachedValueController<T> implements ReactiveController {
}
}
public hasTimer(): boolean {
return !!this._timerID;
}
/**
* Host has connected to the cache.
*/