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
@@ -1,5 +1,6 @@
|
||||
import { StyleInfo } from 'lit/directives/style-map';
|
||||
import { CameraManager } from '../camera-manager/manager';
|
||||
import { CallManager } from '../card-controller/call/manager';
|
||||
import { FoldersManager } from '../card-controller/folders/manager';
|
||||
import { FullscreenManager } from '../card-controller/fullscreen/fullscreen-manager';
|
||||
import { MediaPlayerManager } from '../card-controller/media-player-manager';
|
||||
@@ -17,6 +18,8 @@ import { HomeAssistant } from '../ha/types';
|
||||
import { localize } from '../localize/localize.js';
|
||||
import { MediaLoadedInfo } from '../types';
|
||||
import {
|
||||
createCallEndAction,
|
||||
createCallStartAction,
|
||||
createCameraAction,
|
||||
createDisplayModeAction,
|
||||
createGeneralAction,
|
||||
@@ -30,8 +33,8 @@ import {
|
||||
import { arrayify, isTruthy } from '../utils/basic';
|
||||
import { isBeingCasted } from '../utils/casting';
|
||||
import { getPTZTarget } from '../utils/ptz';
|
||||
import { getStreamCameraID, hasSubstream } from '../utils/substream';
|
||||
import { ViewItemClassifier } from '../view/item-classifier';
|
||||
import { getStreamCameraID, hasSubstream } from '../view/substream';
|
||||
import { resolveViewName } from '../view/utils/resolve-default';
|
||||
import { View } from '../view/view';
|
||||
import {
|
||||
@@ -40,6 +43,7 @@ import {
|
||||
} from '../view/view-support';
|
||||
|
||||
export interface MenuButtonControllerOptions {
|
||||
callManager?: CallManager | null;
|
||||
currentMediaLoadedInfo?: MediaLoadedInfo | null;
|
||||
showCameraUIButton?: boolean;
|
||||
fullscreenManager?: FullscreenManager | null;
|
||||
@@ -94,11 +98,13 @@ export class MenuButtonController {
|
||||
this._getInfoButton(config, cameraManager, options?.view),
|
||||
this._getSetReviewButton(config, options?.view),
|
||||
this._getCameraUIButton(config, options?.showCameraUIButton),
|
||||
this._getCallButton(config, cameraManager, options?.callManager, options?.view),
|
||||
this._getMicrophoneButton(
|
||||
config,
|
||||
cameraManager,
|
||||
options?.view,
|
||||
options?.microphoneManager,
|
||||
options?.callManager,
|
||||
),
|
||||
this._getExpandButton(config, options?.inExpandedMode),
|
||||
this._getFullscreenButton(config, options?.fullscreenManager),
|
||||
@@ -480,17 +486,91 @@ export class MenuButtonController {
|
||||
: null;
|
||||
}
|
||||
|
||||
private _getCallButton(
|
||||
config: AdvancedCameraCardConfig,
|
||||
cameraManager: CameraManager,
|
||||
callManager?: CallManager | null,
|
||||
view?: View | null,
|
||||
): MenuItem | null {
|
||||
if (!view?.camera || !view.is('live')) {
|
||||
return null;
|
||||
}
|
||||
const cameraID = view.camera;
|
||||
|
||||
// The call targets: the selected camera and/or any 2-way-audio-capable
|
||||
// dependency.
|
||||
const targets = [
|
||||
...cameraManager.getStore().getAllDependentCameras(cameraID, '2-way-audio'),
|
||||
];
|
||||
if (!targets.length) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// In a call: a single hang-up button, regardless of target count.
|
||||
if (callManager?.isActive()) {
|
||||
return {
|
||||
icon: 'mdi:phone-hangup',
|
||||
title: localize('config.live.controls.call.end'),
|
||||
style: this._getEmphasizedStyle(true),
|
||||
...config.menu.buttons.call,
|
||||
type: 'custom:advanced-camera-card-menu-icon',
|
||||
tap_action: createCallEndAction(),
|
||||
};
|
||||
}
|
||||
|
||||
// Idle, single target: a plain button (`call_start` resolves the default).
|
||||
if (targets.length === 1) {
|
||||
return {
|
||||
icon: 'mdi:phone',
|
||||
title: localize('config.live.controls.call.start'),
|
||||
...config.menu.buttons.call,
|
||||
type: 'custom:advanced-camera-card-menu-icon',
|
||||
tap_action: createCallStartAction(),
|
||||
};
|
||||
}
|
||||
|
||||
// Idle, multiple targets: a submenu, one entry per stream.
|
||||
const menuItems = targets.map((streamID) => {
|
||||
const metadata = cameraManager.getCameraMetadata(streamID) ?? undefined;
|
||||
return {
|
||||
enabled: true,
|
||||
icon: metadata?.icon.icon,
|
||||
entity: metadata?.icon.entity,
|
||||
state_color: true,
|
||||
title: metadata?.title,
|
||||
tap_action: createCallStartAction(
|
||||
cameraID,
|
||||
streamID === cameraID ? undefined : streamID,
|
||||
),
|
||||
};
|
||||
});
|
||||
|
||||
return {
|
||||
icon: 'mdi:phone',
|
||||
title: localize('config.live.controls.call.start'),
|
||||
...config.menu.buttons.call,
|
||||
type: 'custom:advanced-camera-card-menu-submenu',
|
||||
items: menuItems,
|
||||
};
|
||||
}
|
||||
|
||||
private _getMicrophoneButton(
|
||||
config: AdvancedCameraCardConfig,
|
||||
cameraManager: CameraManager,
|
||||
view?: View | null,
|
||||
microphoneManager?: MicrophoneManager | null,
|
||||
callManager?: CallManager | null,
|
||||
): MenuItem | null {
|
||||
const streamCameraID = view ? getStreamCameraID(view) : null;
|
||||
if (!streamCameraID) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// The microphone only transmits during an active call.
|
||||
if (!callManager?.isActive()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const capabilities = cameraManager.getCameraCapabilities(streamCameraID);
|
||||
|
||||
if (microphoneManager && capabilities?.has('2-way-audio')) {
|
||||
|
||||
Reference in New Issue
Block a user