mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-03-11 02:47:37 +03:00
Some checks failed
CI / AMD64 Build (push) Has been cancelled
CI / ARM Build (push) Has been cancelled
CI / Jetson Jetpack 6 (push) Has been cancelled
CI / AMD64 Extra Build (push) Has been cancelled
CI / ARM Extra Build (push) Has been cancelled
CI / Synaptics Build (push) Has been cancelled
CI / Assemble and push default build (push) Has been cancelled
* Fix jetson stats reading * Return result * Avoid unknown class for cover image * fix double encoding of passwords in camera wizard * formatting * empty homekit config fixes * add locks to jina v1 embeddings protect tokenizer and feature extractor in jina_v1_embedding with per-instance thread lock to avoid the "Already borrowed" RuntimeError during concurrent tokenization * Capitalize correctly * replace deprecated google-generativeai with google-genai update gemini genai provider with new calls from SDK provider_options specifies any http options suppress unneeded info logging * fix attribute area on detail stream hover --------- Co-authored-by: Josh Hawkins <32435876+hawkeye217@users.noreply.github.com>
151 lines
3.9 KiB
TypeScript
151 lines
3.9 KiB
TypeScript
import { baseUrl } from "@/api/baseUrl";
|
|
import { generateFixedHash, isValidId } from "./stringUtil";
|
|
import type { LiveStreamMetadata } from "@/types/live";
|
|
|
|
/**
|
|
* Processes a user-entered camera name and returns both the final camera name
|
|
* and friendly name for Frigate configuration.
|
|
*
|
|
* @param userInput - The name entered by the user (could be display name)
|
|
* @returns Object with finalCameraName and friendlyName
|
|
*/
|
|
export function processCameraName(userInput: string): {
|
|
finalCameraName: string;
|
|
friendlyName?: string;
|
|
} {
|
|
const normalizedInput = userInput.replace(/\s+/g, "_").toLowerCase();
|
|
|
|
if (isValidId(normalizedInput)) {
|
|
return {
|
|
finalCameraName: normalizedInput,
|
|
friendlyName: userInput.includes(" ") ? userInput : undefined,
|
|
};
|
|
}
|
|
|
|
return {
|
|
finalCameraName: generateFixedHash(userInput, "cam"),
|
|
friendlyName: userInput,
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Detect Reolink camera capabilities and recommend optimal protocol
|
|
*
|
|
* Calls the Frigate backend API which queries the Reolink camera to determine
|
|
* its resolution and recommends either http-flv (for 5MP and below) or rtsp
|
|
* (for higher resolutions).
|
|
*
|
|
* @param host - Camera IP address or hostname
|
|
* @param username - Camera username
|
|
* @param password - Camera password
|
|
* @returns The recommended protocol key ("http-flv" or "rtsp"), or null if detection failed
|
|
*/
|
|
export async function detectReolinkCamera(
|
|
host: string,
|
|
username: string,
|
|
password: string,
|
|
): Promise<"http-flv" | "rtsp" | null> {
|
|
try {
|
|
const params = new URLSearchParams({
|
|
host,
|
|
username,
|
|
password,
|
|
});
|
|
|
|
const response = await fetch(
|
|
`${baseUrl}api/reolink/detect?${params.toString()}`,
|
|
{
|
|
method: "GET",
|
|
},
|
|
);
|
|
|
|
if (!response.ok) {
|
|
return null;
|
|
}
|
|
|
|
const data = await response.json();
|
|
|
|
if (data.success && data.protocol) {
|
|
return data.protocol;
|
|
}
|
|
|
|
return null;
|
|
} catch (error) {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Mask credentials in RTSP URIs for display
|
|
*/
|
|
export function maskUri(uri: string): string {
|
|
try {
|
|
// Handle RTSP URLs with user:pass@host format
|
|
// Use greedy match for password to handle passwords with @
|
|
const rtspMatch = uri.match(/rtsp:\/\/([^:]+):(.+)@(.+)/);
|
|
if (rtspMatch) {
|
|
return `rtsp://${rtspMatch[1]}:${"*".repeat(4)}@${rtspMatch[3]}`;
|
|
}
|
|
|
|
// Handle HTTP/HTTPS URLs with password query parameter
|
|
const urlObj = new URL(uri);
|
|
if (urlObj.searchParams.has("password")) {
|
|
urlObj.searchParams.set("password", "*".repeat(4));
|
|
return urlObj.toString();
|
|
}
|
|
} catch (e) {
|
|
// ignore
|
|
}
|
|
return uri;
|
|
}
|
|
|
|
/**
|
|
* Represents the audio features supported by a camera stream
|
|
*/
|
|
export type CameraAudioFeatures = {
|
|
twoWayAudio: boolean;
|
|
audioOutput: boolean;
|
|
};
|
|
|
|
/**
|
|
* Detects camera audio features from go2rtc stream metadata.
|
|
* Checks for two-way audio (backchannel) and audio output capabilities.
|
|
*
|
|
* @param metadata - The LiveStreamMetadata from go2rtc stream
|
|
* @param requireSecureContext - If true, two-way audio requires secure context (default: true)
|
|
* @returns CameraAudioFeatures object with detected capabilities
|
|
*/
|
|
export function detectCameraAudioFeatures(
|
|
metadata: LiveStreamMetadata | null | undefined,
|
|
requireSecureContext: boolean = true,
|
|
): CameraAudioFeatures {
|
|
if (!metadata) {
|
|
return {
|
|
twoWayAudio: false,
|
|
audioOutput: false,
|
|
};
|
|
}
|
|
|
|
const twoWayAudio =
|
|
(!requireSecureContext || window.isSecureContext) &&
|
|
metadata.producers.find(
|
|
(prod) =>
|
|
prod.medias &&
|
|
prod.medias.find((media) => media.includes("audio, sendonly")) !=
|
|
undefined,
|
|
) != undefined;
|
|
|
|
const audioOutput =
|
|
metadata.producers.find(
|
|
(prod) =>
|
|
prod.medias &&
|
|
prod.medias.find((media) => media.includes("audio, recvonly")) !=
|
|
undefined,
|
|
) != undefined;
|
|
|
|
return {
|
|
twoWayAudio: !!twoWayAudio,
|
|
audioOutput: !!audioOutput,
|
|
};
|
|
}
|