feat: Add 'call' support to improve 2-way audio experience (#2486)

Draws significant inspiration (and direct styling) from
https://github.com/dermotduffy/advanced-camera-card/pull/2447 . Thank
you @Maudfer !

BREAKING CHANGE:

The microphone condition previously bundled two unrelated signals —
whether a two-way-audio session was connected and whether the microphone
was muted. Connection state is now its own dedicated call condition, and
microphone is reserved purely for mute state. Configs are upgraded
automatically (the card rewrites affected conditions under overrides,
elements, and automations). If you maintain config by hand, convert as
follows:

If you only used connected:

# Before
```yaml
condition: microphone
connected: true
```

# After
```yaml
condition: call
call: true
```
If you used both connected and muted — they must be split into two
conditions, since they no longer live together:

# Before
```yaml
condition: microphone
connected: true
muted: false
```

# After
```yaml
condition: and
conditions:
  - condition: call
    call: true
  - condition: microphone
    muted: false
```
This commit is contained in:
Dermot Duffy
2026-06-30 17:45:13 -07:00
committed by dermotduffy
parent bb061a1a55
commit abcba884e5
116 changed files with 3871 additions and 845 deletions
+52
View File
@@ -791,6 +791,42 @@ const frigateCardToAdvancedCameraCardTransform = (
return modified;
};
/**
* Migrate a `condition: microphone` condition with the (removed) `connected`
* field into a `condition: call` node. Operates on a single condition object in
* place. When both `connected` and `muted` are present, splits into a
* two-condition `and` (the only way to preserve both semantics now that
* `connected` no longer lives on `microphone`).
*
* @returns `true` if the node was modified.
*/
const microphoneConnectedToCallTransform = (data: unknown): boolean => {
if (typeof data !== 'object' || !data || data['condition'] !== 'microphone') {
return false;
}
const connected = data['connected'];
if (typeof connected !== 'boolean') {
return false;
}
const muted = data['muted'];
for (const key of Object.keys(data)) {
delete data[key];
}
if (typeof muted === 'boolean') {
data['condition'] = 'and';
data['conditions'] = [
{ condition: 'call', call: connected },
{ condition: 'microphone', muted: muted },
];
} else {
data['condition'] = 'call';
data['call'] = connected;
}
return true;
};
const frigateCardToAdvancedCameraCardStyleTransform = (data: unknown): unknown => {
if (typeof data !== 'object' || !data || Array.isArray(data)) {
return data;
@@ -999,4 +1035,20 @@ const UPGRADES = [
CONF_CAMERAS,
upgradeWithOverrides('ptz', ptzIncorrectDataToWebRTCDataTransform),
),
// microphone.connected → call condition migration. Conditions live under
// overrides, elements, and automations.
upgradeArrayOfObjects(CONF_OVERRIDES, (override) =>
upgradeObjectRecursively(microphoneConnectedToCallTransform)(override),
),
(data: unknown): boolean => {
return upgradeObjectRecursively(microphoneConnectedToCallTransform)(
typeof data === 'object' && data ? data[CONF_ELEMENTS] : {},
);
},
(data: unknown): boolean => {
return upgradeObjectRecursively(microphoneConnectedToCallTransform)(
typeof data === 'object' && data ? data[CONF_AUTOMATIONS] : {},
);
},
];