feat: Allow 2-way audio detection to be skipped and timed (#2355)
- For #2313
This commit is contained in:
@@ -85,15 +85,13 @@ export class Camera {
|
||||
): Promise<Capabilities> {
|
||||
const rawCapabilities = await this._getRawCapabilities(options);
|
||||
const config = this.getConfig();
|
||||
const has2WayAudio = await liveProviderSupports2WayAudio(
|
||||
options.hass,
|
||||
config,
|
||||
this._getGo2RTCMetadataEndpoint(),
|
||||
this.getProxyConfig(),
|
||||
);
|
||||
const has2WayAudio = await this._has2WayAudioCapability(options.hass);
|
||||
|
||||
return new Capabilities(
|
||||
{ ...rawCapabilities, '2-way-audio': has2WayAudio },
|
||||
{
|
||||
...rawCapabilities,
|
||||
'2-way-audio': has2WayAudio,
|
||||
},
|
||||
{
|
||||
disable: config.capabilities?.disable,
|
||||
disableExcept: config.capabilities?.disable_except,
|
||||
@@ -101,6 +99,26 @@ export class Camera {
|
||||
);
|
||||
}
|
||||
|
||||
protected async _has2WayAudioCapability(hass: HomeAssistant): Promise<boolean> {
|
||||
if (this._config.capabilities?.disable?.includes('2-way-audio')) {
|
||||
return false;
|
||||
}
|
||||
const disableExcept = this._config.capabilities?.disable_except;
|
||||
if (disableExcept?.length && !disableExcept.includes('2-way-audio')) {
|
||||
return false;
|
||||
}
|
||||
if (this._config.capabilities?.force?.includes('2-way-audio')) {
|
||||
return true;
|
||||
}
|
||||
return await liveProviderSupports2WayAudio(
|
||||
hass,
|
||||
this.getConfig(),
|
||||
this.getConfig().go2rtc.metadata_fetch_timeout_seconds,
|
||||
this._getGo2RTCMetadataEndpoint(),
|
||||
this.getProxyConfig(),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get raw capabilities for this camera. Subclasses should override
|
||||
* and call super._getRawCapabilities() to extend defaults.
|
||||
|
||||
@@ -6,18 +6,14 @@ import { errorToConsole } from '../../../utils/basic';
|
||||
import { CameraProxyConfig } from '../../types';
|
||||
import { Go2RTCStreamInfo, go2RTCStreamInfoSchema } from './types';
|
||||
|
||||
// Allow generous amount of time to fetch metadata (timeout matches that used in
|
||||
// the Frigate frontend for the same call).
|
||||
// See: https://github.com/dermotduffy/advanced-camera-card/issues/2313
|
||||
const GO2RTC_METADATA_TIMEOUT_SECONDS = 10;
|
||||
|
||||
const getGo2RTCStreamMetadata = async (
|
||||
hass: HomeAssistant,
|
||||
endpoint: Endpoint,
|
||||
timeoutSeconds: number,
|
||||
): Promise<Go2RTCStreamInfo | null> => {
|
||||
try {
|
||||
return await homeAssistantSignAndFetch(hass, endpoint, go2RTCStreamInfoSchema, {
|
||||
timeoutSeconds: GO2RTC_METADATA_TIMEOUT_SECONDS,
|
||||
timeoutSeconds,
|
||||
});
|
||||
} catch (e) {
|
||||
errorToConsole(e as Error);
|
||||
@@ -53,6 +49,7 @@ const streamSupports2WayAudio = (streamInfo: Go2RTCStreamInfo | null): boolean =
|
||||
*/
|
||||
export const supports2WayAudio = async (
|
||||
hass: HomeAssistant,
|
||||
metadataFetchTimeoutSeconds: number,
|
||||
go2rtcMetadataEndpoint?: Endpoint | null,
|
||||
proxyConfig?: CameraProxyConfig,
|
||||
): Promise<boolean> => {
|
||||
@@ -67,6 +64,10 @@ export const supports2WayAudio = async (
|
||||
{ context: 'live', openLimit: 1 },
|
||||
);
|
||||
|
||||
const streamInfo = await getGo2RTCStreamMetadata(hass, endpoint);
|
||||
const streamInfo = await getGo2RTCStreamMetadata(
|
||||
hass,
|
||||
endpoint,
|
||||
metadataFetchTimeoutSeconds,
|
||||
);
|
||||
return streamSupports2WayAudio(streamInfo);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user