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
@@ -294,6 +294,81 @@ describe('MicrophoneActionsController', () => {
});
});
describe('on call state change', () => {
it('should unmute on call start when call is a configured unmute condition', () => {
const microphoneManager = createMicrophoneManager();
const controller = new MicrophoneActionsController();
controller.setOptions({
microphoneManager,
autoUnmuteConditions: ['call' as const],
});
controller.setCallActive(false);
controller.setCallActive(true);
expect(microphoneManager.unmute).toBeCalledTimes(1);
});
it('should unmute when the call is already active on first notification', () => {
const microphoneManager = createMicrophoneManager();
const controller = new MicrophoneActionsController();
controller.setOptions({
microphoneManager,
autoUnmuteConditions: ['call' as const],
});
// `setCallActive(true)` is the first call-state signal, with no preceding
// `false` -- as for a live view that mounts while a call is already
// active. The initial state must not be swallowed as a baseline.
controller.setCallActive(true);
expect(microphoneManager.unmute).toBeCalledTimes(1);
});
it('should mute on call end when call is a configured mute condition', () => {
const microphoneManager = createMicrophoneManager();
const controller = new MicrophoneActionsController();
controller.setOptions({
microphoneManager,
autoMuteConditions: ['call' as const],
});
controller.setCallActive(true);
controller.setCallActive(false);
expect(microphoneManager.mute).toBeCalledTimes(1);
});
it('should not act on the initial call state', () => {
const microphoneManager = createMicrophoneManager();
const controller = new MicrophoneActionsController();
controller.setOptions({
microphoneManager,
autoMuteConditions: ['call' as const],
autoUnmuteConditions: ['call' as const],
});
controller.setCallActive(false);
expect(microphoneManager.mute).not.toBeCalled();
expect(microphoneManager.unmute).not.toBeCalled();
});
it('should not act on call start when call is not a configured condition', () => {
const microphoneManager = createMicrophoneManager();
const controller = new MicrophoneActionsController();
controller.setOptions({
microphoneManager,
autoUnmuteConditions: [],
});
controller.setCallActive(false);
controller.setCallActive(true);
expect(microphoneManager.unmute).not.toBeCalled();
});
});
describe('lifecycle', () => {
it('should be idempotent on setRoot for the same element', () => {
const controller = new MicrophoneActionsController();