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:
committed by
dermotduffy
parent
bb061a1a55
commit
abcba884e5
@@ -3,6 +3,8 @@ import { mock } from 'vitest-mock-extended';
|
||||
import { INTERNAL_CALLBACK_ACTION } from '../../src/config/schema/actions/custom/internal.js';
|
||||
import { ActionConfig } from '../../src/config/schema/actions/types.js';
|
||||
import {
|
||||
createCallEndAction,
|
||||
createCallStartAction,
|
||||
createCameraAction,
|
||||
createDisplayModeAction,
|
||||
createEffectAction,
|
||||
@@ -358,6 +360,46 @@ describe('createSetReviewAction', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('createCallStartAction', () => {
|
||||
it('should create call start action without a camera', () => {
|
||||
expect(createCallStartAction()).toEqual({
|
||||
action: 'fire-dom-event',
|
||||
advanced_camera_card_action: 'call_start',
|
||||
});
|
||||
});
|
||||
|
||||
it('should create call start action with a camera, stream and cardID', () => {
|
||||
expect(
|
||||
createCallStartAction('camera.front', 'camera.front_doorbell', {
|
||||
cardID: 'card_id',
|
||||
}),
|
||||
).toEqual({
|
||||
action: 'fire-dom-event',
|
||||
advanced_camera_card_action: 'call_start',
|
||||
camera: 'camera.front',
|
||||
stream: 'camera.front_doorbell',
|
||||
card_id: 'card_id',
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('createCallEndAction', () => {
|
||||
it('should create call end action', () => {
|
||||
expect(createCallEndAction()).toEqual({
|
||||
action: 'fire-dom-event',
|
||||
advanced_camera_card_action: 'call_end',
|
||||
});
|
||||
});
|
||||
|
||||
it('should create call end action with a cardID', () => {
|
||||
expect(createCallEndAction({ cardID: 'card_id' })).toEqual({
|
||||
action: 'fire-dom-event',
|
||||
advanced_camera_card_action: 'call_end',
|
||||
card_id: 'card_id',
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('createNotificationAction', () => {
|
||||
it('should create notification action', () => {
|
||||
const notification = { body: { text: 'test' } };
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { mock } from 'vitest-mock-extended';
|
||||
import { hasPopOutAnimationEnded } from '../../src/utils/animation.js';
|
||||
|
||||
describe('hasPopOutAnimationEnded', () => {
|
||||
const element = mock<EventTarget>();
|
||||
|
||||
it('should return true when a pop-out animation ends on the bound element', () => {
|
||||
expect(
|
||||
hasPopOutAnimationEnded({
|
||||
target: element,
|
||||
currentTarget: element,
|
||||
animationName: 'pop-out',
|
||||
}),
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
it('should return false when the event bubbled from a descendant', () => {
|
||||
expect(
|
||||
hasPopOutAnimationEnded({
|
||||
target: mock<EventTarget>(),
|
||||
currentTarget: element,
|
||||
animationName: 'pop-out',
|
||||
}),
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
it('should return false for a different animation', () => {
|
||||
expect(
|
||||
hasPopOutAnimationEnded({
|
||||
target: element,
|
||||
currentTarget: element,
|
||||
animationName: 'pop-in',
|
||||
}),
|
||||
).toBe(false);
|
||||
});
|
||||
});
|
||||
@@ -1,131 +0,0 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import {
|
||||
getStreamCameraID,
|
||||
hasSubstream,
|
||||
removeSubstream,
|
||||
setSubstream,
|
||||
} from '../../src/utils/substream';
|
||||
import { View } from '../../src/view/view';
|
||||
import { createView } from '../test-utils';
|
||||
|
||||
describe('hasSubstream/getStreamCameraID', () => {
|
||||
it('should detect substream', () => {
|
||||
const view = createView({
|
||||
camera: 'camera',
|
||||
context: {
|
||||
live: {
|
||||
overrides: new Map([['camera', 'camera2']]),
|
||||
},
|
||||
},
|
||||
});
|
||||
expect(hasSubstream(view)).toBeTruthy();
|
||||
expect(getStreamCameraID(view)).toBe('camera2');
|
||||
});
|
||||
it('should not detect substream when absent', () => {
|
||||
const view = createView({
|
||||
camera: 'camera',
|
||||
});
|
||||
expect(hasSubstream(view)).toBeFalsy();
|
||||
expect(getStreamCameraID(view)).toBe('camera');
|
||||
});
|
||||
it('should not detect substream when main stream', () => {
|
||||
const view = createView({
|
||||
camera: 'camera',
|
||||
context: {
|
||||
live: {
|
||||
overrides: new Map([['camera', 'camera']]),
|
||||
},
|
||||
},
|
||||
});
|
||||
expect(hasSubstream(view)).toBeFalsy();
|
||||
expect(getStreamCameraID(view)).toBe('camera');
|
||||
});
|
||||
describe('should respect cameraID override', () => {
|
||||
it('should respect cameraID override when present in overrides', () => {
|
||||
const view = createView({
|
||||
camera: 'camera',
|
||||
context: {
|
||||
live: {
|
||||
overrides: new Map([
|
||||
['camera', 'camera2'],
|
||||
['camera3', 'camera4'],
|
||||
]),
|
||||
},
|
||||
},
|
||||
});
|
||||
expect(hasSubstream(view)).toBeTruthy();
|
||||
expect(getStreamCameraID(view, 'camera3')).toBe('camera4');
|
||||
});
|
||||
|
||||
it('should respect cameraID override when not present in overrides', () => {
|
||||
const view = createView();
|
||||
expect(hasSubstream(view)).toBeFalsy();
|
||||
expect(getStreamCameraID(view, 'camera3')).toBe('camera3');
|
||||
});
|
||||
});
|
||||
|
||||
it('should correctly handle null cameras', () => {
|
||||
expect(getStreamCameraID(createView({ camera: null }))).toBeNull();
|
||||
expect(hasSubstream(createView({ camera: null }))).toBeFalsy();
|
||||
});
|
||||
});
|
||||
|
||||
describe('setSubstream', () => {
|
||||
it('should set substream', () => {
|
||||
const view = createView({ camera: 'camera1' });
|
||||
setSubstream(view, 'substream1');
|
||||
expect(view.context?.live?.overrides?.get('camera1')).toBe('substream1');
|
||||
});
|
||||
|
||||
it('should return null without a camera', () => {
|
||||
const view = createView({ camera: null });
|
||||
setSubstream(view, 'foo');
|
||||
expect(view.context).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe('removeSubstream', () => {
|
||||
it('should remove substream that exists', () => {
|
||||
const view = new View({
|
||||
view: 'live',
|
||||
camera: 'camera',
|
||||
context: {
|
||||
live: {
|
||||
overrides: new Map([['camera', 'camera2']]),
|
||||
},
|
||||
},
|
||||
});
|
||||
removeSubstream(view);
|
||||
expect(view.context).toEqual({
|
||||
live: {
|
||||
overrides: new Map(),
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it('should not remove substream that does not exists', () => {
|
||||
const view = new View({
|
||||
view: 'live',
|
||||
camera: 'camera-has-no-overrides',
|
||||
context: {
|
||||
live: {
|
||||
overrides: new Map([['camera', 'camera2']]),
|
||||
},
|
||||
},
|
||||
});
|
||||
removeSubstream(view);
|
||||
expect(view.context).toEqual({
|
||||
live: {
|
||||
overrides: new Map([['camera', 'camera2']]),
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it('should not remove substream without camera', () => {
|
||||
const view = createView({
|
||||
camera: null,
|
||||
});
|
||||
removeSubstream(view);
|
||||
expect(view.context).toBeNull();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user