Allow microphone state to be used in conditions.
This commit is contained in:
@@ -60,6 +60,7 @@ export class CardElementManager {
|
||||
this._api.getFullscreenManager().initialize();
|
||||
this._api.getExpandManager().initialize();
|
||||
this._api.getMediaLoadedInfoManager().initialize();
|
||||
this._api.getMicrophoneManager().initialize();
|
||||
|
||||
// Whether or not the card is in panel mode on the dashboard.
|
||||
setOrRemoveAttribute(this._element, isCardInPanel(this._element), 'panel');
|
||||
|
||||
@@ -4,6 +4,7 @@ import { copyConfig } from '../config-mgmt';
|
||||
import {
|
||||
FrigateCardCondition,
|
||||
frigateConditionalSchema,
|
||||
MicrophoneConditionState,
|
||||
OverrideConfigurationKey,
|
||||
RawFrigateCardConfig,
|
||||
ViewDisplayMode,
|
||||
@@ -20,6 +21,7 @@ interface ConditionState {
|
||||
displayMode?: ViewDisplayMode;
|
||||
triggered?: Set<string>;
|
||||
interaction?: boolean;
|
||||
microphone?: MicrophoneConditionState;
|
||||
}
|
||||
|
||||
export class ConditionEvaluateRequestEvent extends Event {
|
||||
@@ -254,6 +256,13 @@ export class ConditionsManager {
|
||||
result &&=
|
||||
state.interaction !== undefined && condition.interaction === state.interaction;
|
||||
}
|
||||
if (condition.microphone) {
|
||||
result &&=
|
||||
(condition.microphone.connected === undefined ||
|
||||
state.microphone?.connected === condition.microphone.connected) &&
|
||||
(condition.microphone.muted === undefined ||
|
||||
state.microphone?.muted === condition.microphone.muted);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -29,6 +29,10 @@ export class MicrophoneManager implements ReadonlyMicrophoneManager {
|
||||
this._api = api;
|
||||
}
|
||||
|
||||
public initialize(): void {
|
||||
this._setConditionState();
|
||||
}
|
||||
|
||||
public async connect(): Promise<boolean> {
|
||||
try {
|
||||
this._stream = await navigator.mediaDevices.getUserMedia({
|
||||
@@ -43,13 +47,15 @@ export class MicrophoneManager implements ReadonlyMicrophoneManager {
|
||||
return false;
|
||||
}
|
||||
this._setMute();
|
||||
this._setConditionState();
|
||||
return true;
|
||||
}
|
||||
|
||||
public async disconnect(): Promise<void> {
|
||||
public disconnect(): void {
|
||||
this._stream?.getTracks().forEach((track) => track.stop());
|
||||
|
||||
this._stream = undefined;
|
||||
this._setConditionState();
|
||||
this._api.getCardElementManager().update();
|
||||
}
|
||||
|
||||
@@ -62,6 +68,7 @@ export class MicrophoneManager implements ReadonlyMicrophoneManager {
|
||||
|
||||
this._mute = true;
|
||||
this._setMute();
|
||||
this._setConditionState();
|
||||
|
||||
if (!wasMuted) {
|
||||
this._callListeners('muted');
|
||||
@@ -89,6 +96,7 @@ export class MicrophoneManager implements ReadonlyMicrophoneManager {
|
||||
unmute();
|
||||
}
|
||||
|
||||
this._setConditionState();
|
||||
if (!wasUnmuted) {
|
||||
this._callListeners('unmuted');
|
||||
}
|
||||
@@ -144,4 +152,13 @@ export class MicrophoneManager implements ReadonlyMicrophoneManager {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
protected _setConditionState(): void {
|
||||
this._api.getConditionsManager().setState({
|
||||
microphone: {
|
||||
muted: this.isMuted(),
|
||||
connected: this.isConnected(),
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -104,6 +104,7 @@ export interface CardElementAPI {
|
||||
getFullscreenManager(): FullscreenManager;
|
||||
getInteractionManager(): InteractionManager;
|
||||
getMediaLoadedInfoManager(): MediaLoadedInfoManager;
|
||||
getMicrophoneManager(): MicrophoneManager;
|
||||
getQueryStringManager(): QueryStringManager;
|
||||
}
|
||||
|
||||
@@ -178,6 +179,7 @@ export interface CardMessageAPI {
|
||||
|
||||
export interface CardMicrophoneAPI {
|
||||
getCardElementManager(): CardElementManager;
|
||||
getConditionsManager(): ConditionsManager;
|
||||
getConfigManager(): ConfigManager;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user