From bac6bc0715769ed55a909e83955810b068192403 Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Thu, 3 Dec 2026 10:10:32 +0800 Subject: [PATCH 1/2] =?UTF-8?q?feat:=20=E9=87=8D=E6=9E=84=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E6=96=87=E4=BB=B6=E7=A7=BB=E9=99=A4=20yml=20=E4=BE=9D?= =?UTF-8?q?=E8=B5=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../IMediaMtxService.cs | 4 +- .../MediaMtxCameraOptions.cs | 4 +- .../MediaMtxOptions.cs | 162 ++++++++++++------ .../MediaMtxService.Gateway.cs | 34 ++-- .../MediaMtxService.cs | 6 +- .../MediaMtxWebRtcConfiguration.cs | 149 +++------------- .../README.MediaMtx.md | 104 +++++------ .../skills/bb-mediamtx/SKILL.md | 26 +-- 8 files changed, 220 insertions(+), 269 deletions(-) diff --git a/src/components/BootstrapBlazor.MediaMtx/IMediaMtxService.cs b/src/components/BootstrapBlazor.MediaMtx/IMediaMtxService.cs index f7b64d2e..e4f67cbc 100644 --- a/src/components/BootstrapBlazor.MediaMtx/IMediaMtxService.cs +++ b/src/components/BootstrapBlazor.MediaMtx/IMediaMtxService.cs @@ -34,8 +34,8 @@ public interface IMediaMtxService Task SetGatewayStateAsync(string? apiPassword); /// - /// 登记新路径或更新已有路径的摄像头源配置,返回播放 URL。摄像头 PlayUrl 为 null 时使用 WebRtcPublicUrl 或同机回环地址与 Path 生成地址;空字符串不是有效的播放地址。更新可能中断现有播放;成功不代表源已连通。 - /// Registers a new path or updates the camera source configuration and returns its playback URL. When the camera's PlayUrl is null, builds the URL from WebRtcPublicUrl or the loopback address and Path; an empty string is not a valid playback URL. Updates may interrupt existing playback; success does not verify source connectivity. + /// 登记新路径或更新已有路径的摄像头源配置,返回播放 URL。摄像头 PlayUrl 为 null 时使用 WebRtc.PublicUrl 或同机回环地址与 Path 生成地址;空字符串不是有效的播放地址。更新可能中断现有播放;成功不代表源已连通。 + /// Registers a new path or updates the camera source configuration and returns its playback URL. When the camera's PlayUrl is null, builds the URL from WebRtc.PublicUrl or the loopback address and Path; an empty string is not a valid playback URL. Updates may interrupt existing playback; success does not verify source connectivity. /// 11.0.0 /// /// 由管理 UI 提交的摄像头配置。Camera configuration submitted by the management UI. diff --git a/src/components/BootstrapBlazor.MediaMtx/MediaMtxCameraOptions.cs b/src/components/BootstrapBlazor.MediaMtx/MediaMtxCameraOptions.cs index 72bc1d75..6e64e9b6 100644 --- a/src/components/BootstrapBlazor.MediaMtx/MediaMtxCameraOptions.cs +++ b/src/components/BootstrapBlazor.MediaMtx/MediaMtxCameraOptions.cs @@ -20,8 +20,8 @@ public sealed class MediaMtxCameraOptions public string? Path { get; set; } /// - /// 获得/设置浏览器访问的完整 HTTP 或 HTTPS 播放页面地址,不应包含凭据。为 null 时使用网关 WebRtcPublicUrl 或本机地址与 Path 生成播放地址;空字符串无效。此选项不改变网关监听和 ICE 配置。 - /// Gets or sets the complete browser-facing HTTP or HTTPS player URL without credentials. When null, the URL is built from WebRtcPublicUrl or the loopback address and Path; an empty string is invalid. This option does not change listener or ICE configuration. + /// 获得/设置浏览器访问的完整 HTTP 或 HTTPS 播放页面地址,不应包含凭据。为 null 时使用 WebRtc.PublicUrl 或本机地址与 Path 生成播放地址;空字符串无效。此选项不改变网关监听和 ICE 配置。 + /// Gets or sets the complete browser-facing HTTP or HTTPS player URL without credentials. When null, the URL is built from WebRtc.PublicUrl or the loopback address and Path; an empty string is invalid. This option does not change listener or ICE configuration. /// 11.0.1 /// public string? PlayUrl { get; set; } diff --git a/src/components/BootstrapBlazor.MediaMtx/MediaMtxOptions.cs b/src/components/BootstrapBlazor.MediaMtx/MediaMtxOptions.cs index 413f101b..71d6f26c 100644 --- a/src/components/BootstrapBlazor.MediaMtx/MediaMtxOptions.cs +++ b/src/components/BootstrapBlazor.MediaMtx/MediaMtxOptions.cs @@ -15,39 +15,18 @@ namespace BootstrapBlazor.Components; public sealed class MediaMtxOptions { /// - /// 获得/设置仅供服务端使用的回环 Control API 端口,默认为 9997。 - /// Gets or sets the server-only loopback Control API port. Defaults to 9997. - /// 11.0.0 - /// - public int ApiPort { get; set; } = 9997; - - /// - /// 获得/设置自管网关 Control API 密码。自管模式必填;共享网关的宿主必须配置相同值,并通过安全配置源提供。 - /// Gets or sets the managed gateway Control API password. Required in managed mode; hosts sharing a gateway must use the same value and supply it through a secure configuration source. - /// 11.0.3 - /// - public string? ApiPassword { get; set; } - - /// - /// 获得/设置是否连接由外部管理的本机 MediaMTX 网关。默认值为 false。 - /// Gets or sets whether to connect to an externally managed local MediaMTX gateway. Defaults to false. - /// 11.0.2 + /// 获得/设置网关及控制 API 选项。 + /// Gets or sets the gateway and control API options. + /// 11.0.4 /// - public bool UseExternalGateway { get; set; } - - /// - /// 获得/设置外部网关 Control API 的用户名,默认为 gateway。仅在外部网关模式下使用。 - /// Gets or sets the external gateway Control API user name. Defaults to gateway and is used only in external gateway mode. - /// 11.0.2 - /// - public string ExternalApiUserName { get; set; } = "gateway"; + public MediaMtxGatewayOptions Gateway { get; set; } = new(); /// - /// 获得/设置外部网关 Control API 的密码。仅在外部网关模式下使用,应通过安全配置源提供。 - /// Gets or sets the external gateway Control API password. Used only in external gateway mode; supply it through a secure configuration source. - /// 11.0.2 + /// 获得/设置 WebRTC 播放和 ICE 选项。 + /// Gets or sets the WebRTC playback and ICE options. + /// 11.0.4 /// - public string? ExternalApiPassword { get; set; } + public MediaMtxWebRtcOptions WebRtc { get; set; } = new(); /// /// 获得/设置网关启动或连接外部网关时登记的摄像头,键为播放路径,值中的 Path 和 PlayUrl 被忽略。密码应通过安全配置源提供;环境变量可能被子进程继承。 @@ -55,11 +34,26 @@ public sealed class MediaMtxOptions /// 11.0.0 /// public Dictionary Cameras { get; set; } = new(); +} + +/// +/// MediaMTX 网关选项。 +/// MediaMTX gateway options. +/// 11.0.4 +/// +public sealed class MediaMtxGatewayOptions +{ + /// + /// 获得/设置是否连接由外部管理的本机网关,默认为 false。 + /// Gets or sets whether to connect to an externally managed local gateway. Defaults to false. + /// 11.0.4 + /// + public bool UseExternalGateway { get; set; } /// - /// 获得/设置 MediaMTX 可执行文件路径,默认按当前系统和架构选择应用目录 mediamtx-tools 子目录下的工具。相对路径以应用目录为基准;工具需预先手动部署。 - /// Gets or sets the MediaMTX executable path. Defaults to the current platform's tool under the application's mediamtx-tools directory. Relative paths use the application directory; the tool must be deployed manually in advance. - /// 11.0.0 + /// 获得/设置 MediaMTX 可执行文件路径,默认按当前平台选择应用目录下的工具;相对路径以应用目录为基准。 + /// Gets or sets the MediaMTX executable path. Defaults to the current platform's tool under the application directory; relative paths use that directory. + /// 11.0.4 /// public string MediaMtxPath { get; set; } = Path.Combine("mediamtx-tools", $"{PlatformName}-{RuntimeInformation.OSArchitecture.ToString().ToLowerInvariant()}", @@ -68,52 +62,116 @@ public sealed class MediaMtxOptions private static string PlatformName => OperatingSystem.IsWindows() ? "win" : OperatingSystem.IsMacOS() ? "osx" : "linux"; private static string ExecuteableFileName => OperatingSystem.IsWindows() ? "mediamtx.exe" : "mediamtx"; + /// + /// 获得/设置仅供服务端使用的回环控制 API 端口,默认为 9997。 + /// Gets or sets the server-only loopback control API port. Defaults to 9997. + /// 11.0.4 + /// + public int Port { get; set; } = 9997; /// - /// 获得/设置 WebRTC 播放页面和信令使用的回环 TCP 端口,默认为 8889。 - /// Gets or sets the loopback TCP port for the WebRTC player and signaling. Defaults to 8889. - /// 11.0.0 + /// 获得/设置自管网关控制 API 密码;自管模式必填,共享宿主须配置相同值。 + /// Gets or sets the managed gateway control API password; required in managed mode and identical across hosts sharing a gateway. + /// 11.0.4 /// - public int WebRtcPort { get; set; } = 8889; + public string? Password { get; set; } /// - /// 获得/设置经反向代理访问的 WebRTC 播放基址,例如 https://example.com/mediamtx/。未设置时使用本机回环地址;不改变 ICE 媒体地址。 - /// Gets or sets the reverse-proxied WebRTC player base URL, such as https://example.com/mediamtx/. When unset, the loopback address is used; this does not change the ICE media address. - /// 11.0.0 + /// 获得/设置外部网关控制 API 的用户名,默认为 gateway。 + /// Gets or sets the external gateway control API user name. Defaults to gateway. + /// 11.0.4 /// - public string? WebRtcPublicUrl { get; set; } + public string ExternalUserName { get; set; } = "gateway"; /// - /// 获得/设置 WebRTC 媒体使用的默认回环 UDP 端口,默认为 8189。YAML 片段中的监听地址可覆盖端口。 - /// Gets or sets the default loopback UDP port for WebRTC media. Defaults to 8189. The listener address in the YAML fragment can override the port. - /// 11.0.0 + /// 获得/设置外部网关控制 API 的密码,应通过安全配置源提供。 + /// Gets or sets the external gateway control API password; supply it through a secure configuration source. + /// 11.0.4 /// - public int WebRtcIcePort { get; set; } = 8189; + public string? ExternalPassword { get; set; } +} + +/// +/// MediaMTX WebRTC 播放选项。 +/// MediaMTX WebRTC playback options. +/// 11.0.4 +/// +public sealed class MediaMtxWebRtcOptions +{ + /// + /// 获得/设置 WebRTC 播放页面和信令使用的回环 TCP 端口,默认为 8889。 + /// Gets or sets the loopback TCP port for the WebRTC player and signaling. Defaults to 8889. + /// 11.0.4 + /// + public int Port { get; set; } = 8889; + + /// + /// 获得/设置经反向代理访问的 WebRTC 播放基址;未设置时使用回环地址,不改变 ICE 地址。 + /// Gets or sets the reverse-proxied WebRTC player base URL; defaults to loopback and does not change the ICE address. + /// 11.0.4 + /// + public string? PublicUrl { get; set; } /// - /// 获得/设置自管网关的 WebRTC YAML 片段路径。相对路径以应用目录为准;仅支持文档中列出的 ICE 配置。 - /// Gets or sets the WebRTC YAML fragment path for the managed gateway. Relative paths are resolved against the application directory; only the documented ICE settings are supported. - /// 11.0.3 + /// 获得/设置 WebRTC ICE 选项。 + /// Gets or sets the WebRTC ICE options. + /// 11.0.4 /// - public string? WebRtcConfigPath { get; set; } + public MediaMtxIceOptions Ice { get; set; } = new(); - internal Uri? GetWebRtcPublicUri() + internal Uri? GetPublicUri() { - if (string.IsNullOrWhiteSpace(WebRtcPublicUrl)) + if (string.IsNullOrWhiteSpace(PublicUrl)) { return null; } - if (!Uri.TryCreate(WebRtcPublicUrl, UriKind.Absolute, out var uri) || + if (!Uri.TryCreate(PublicUrl, UriKind.Absolute, out var uri) || !uri.IsWellFormedOriginalString() || uri.Scheme is not ("http" or "https") || uri.UserInfo.Length != 0 || uri.Query.Length != 0 || uri.Fragment.Length != 0) { - throw new ArgumentException("WebRtcPublicUrl must be an absolute HTTP or HTTPS URL without credentials, query or fragment."); + throw new ArgumentException("WebRtc:PublicUrl must be an absolute HTTP or HTTPS URL without credentials, query or fragment."); } return new Uri($"{uri.AbsoluteUri.TrimEnd('/')}/"); } } + +/// +/// MediaMTX WebRTC ICE 选项。 +/// MediaMTX WebRTC ICE options. +/// 11.0.4 +/// +public sealed class MediaMtxIceOptions +{ + /// + /// 获得/设置媒体 UDP 端口,默认为 8189。 + /// Gets or sets the media UDP port. Defaults to 8189. + /// 11.0.4 + /// + public int Port { get; set; } = 8189; + + /// + /// 获得/设置自管网关的 UDP 监听 IP,默认为 127.0.0.1。 + /// Gets or sets the managed gateway's UDP listener IP. Defaults to 127.0.0.1. + /// 11.0.4 + /// + public string Address { get; set; } = "127.0.0.1"; + + /// + /// 获得/设置是否将网络接口地址作为 ICE 候选地址,默认为 false。 + /// Gets or sets whether network interface addresses are advertised as ICE candidates. Defaults to false. + /// 11.0.4 + /// + public bool IpsFromInterfaces { get; set; } + + /// + /// 获得/设置额外公布的 ICE 主机,默认仅包含 127.0.0.1。 + /// Gets or sets additional ICE hosts. Defaults to 127.0.0.1. + /// 11.0.4 + /// + public List? AdditionalHosts { get; set; } +} diff --git a/src/components/BootstrapBlazor.MediaMtx/MediaMtxService.Gateway.cs b/src/components/BootstrapBlazor.MediaMtx/MediaMtxService.Gateway.cs index 2c9bf88c..e7517363 100644 --- a/src/components/BootstrapBlazor.MediaMtx/MediaMtxService.Gateway.cs +++ b/src/components/BootstrapBlazor.MediaMtx/MediaMtxService.Gateway.cs @@ -33,12 +33,8 @@ public async Task EnsureStartedAsync(CancellationToken cancellationToken = defau try { linked.Token.ThrowIfCancellationRequested(); - if (options.Value.UseExternalGateway) + if (options.Value.Gateway.UseExternalGateway) { - if (options.Value.WebRtcConfigPath is not null) - { - throw new InvalidOperationException("WebRtcConfigPath is only supported by the managed gateway."); - } await ConnectExternalGatewayAsync(linked.Token); return; } @@ -71,8 +67,8 @@ public async Task EnsureStartedAsync(CancellationToken cancellationToken = defau private async Task ConnectExternalGatewayAsync(CancellationToken cancellationToken) { var settings = options.Value; - var userName = settings.ExternalApiUserName; - var password = settings.ExternalApiPassword; + var userName = settings.Gateway.ExternalUserName; + var password = settings.Gateway.ExternalPassword; if (string.IsNullOrWhiteSpace(userName) || userName.Contains(':') || string.IsNullOrEmpty(password)) { throw new InvalidOperationException("External MediaMTX gateway credentials are required."); @@ -140,21 +136,21 @@ private async Task StartGatewayAsync(CancellationToken cancellationToken) } var settings = options.Value; - var apiPassword = settings.ApiPassword; + var apiPassword = settings.Gateway.Password; if (string.IsNullOrWhiteSpace(apiPassword)) { - throw new InvalidOperationException("MediaMtxOptions:ApiPassword is required for the managed gateway."); + throw new InvalidOperationException("MediaMtxOptions:Gateway:Password is required for the managed gateway."); } - var executable = Path.GetFullPath(settings.MediaMtxPath, AppContext.BaseDirectory); + var executable = Path.GetFullPath(settings.Gateway.MediaMtxPath, AppContext.BaseDirectory); if (!File.Exists(executable)) { throw new MediaMtxToolNotFoundException(executable); } - var httpAddress = $"{Loopback}:{settings.WebRtcPort}"; - var apiAddress = $"{Loopback}:{settings.ApiPort}"; - var webRtc = await MediaMtxWebRtcConfiguration.LoadAsync(settings.WebRtcConfigPath, settings.WebRtcIcePort, cancellationToken); - var publicUri = settings.GetWebRtcPublicUri(); + var httpAddress = $"{Loopback}:{settings.WebRtc.Port}"; + var apiAddress = $"{Loopback}:{settings.Gateway.Port}"; + var webRtc = MediaMtxWebRtcConfiguration.Create(settings); + var publicUri = settings.WebRtc.GetPublicUri(); var cameraSources = new Dictionary(); var cameras = settings.Cameras.OrderBy(item => item.Key, StringComparer.Ordinal) .ToDictionary(item => item.Key, item => item.Value, StringComparer.Ordinal); @@ -169,8 +165,8 @@ private async Task StartGatewayAsync(CancellationToken cancellationToken) }); var fingerprint = Convert.ToHexString(SHA256.HashData(fingerprintInput)); var directory = MediaMtxSharedGateway.GetDirectory(); - await using var sharedLock = await MediaMtxSharedGateway.AcquireAsync(directory, settings.ApiPort, cancellationToken); - var statePath = Path.Combine(directory, $"{settings.ApiPort}.json"); + await using var sharedLock = await MediaMtxSharedGateway.AcquireAsync(directory, settings.Gateway.Port, cancellationToken); + var statePath = Path.Combine(directory, $"{settings.Gateway.Port}.json"); var state = await MediaMtxSharedGateway.ReadAsync(statePath, cancellationToken); if (state is not null && GetRecordedProcess(state) is { } existing) { @@ -212,8 +208,8 @@ private async Task StartGatewayAsync(CancellationToken cancellationToken) } } - if (!IsPortAvailable(new IPEndPoint(IPAddress.Loopback, settings.WebRtcPort), ProtocolType.Tcp) | - !IsPortAvailable(new IPEndPoint(IPAddress.Loopback, settings.ApiPort), ProtocolType.Tcp) | + if (!IsPortAvailable(new IPEndPoint(IPAddress.Loopback, settings.WebRtc.Port), ProtocolType.Tcp) | + !IsPortAvailable(new IPEndPoint(IPAddress.Loopback, settings.Gateway.Port), ProtocolType.Tcp) | !IsPortAvailable(webRtc.IceEndpoint, ProtocolType.Udp)) { return false; @@ -222,7 +218,7 @@ private async Task StartGatewayAsync(CancellationToken cancellationToken) timeout.CancelAfter(_startupTimeout); Process? process = null; - var configPath = Path.Combine(directory, $"{settings.ApiPort}.yml"); + var configPath = Path.Combine(directory, $"{settings.Gateway.Port}.yml"); try { await File.WriteAllTextAsync(configPath, config, timeout.Token); diff --git a/src/components/BootstrapBlazor.MediaMtx/MediaMtxService.cs b/src/components/BootstrapBlazor.MediaMtx/MediaMtxService.cs index 5eb5909e..01b26e7c 100644 --- a/src/components/BootstrapBlazor.MediaMtx/MediaMtxService.cs +++ b/src/components/BootstrapBlazor.MediaMtx/MediaMtxService.cs @@ -18,7 +18,7 @@ sealed partial class MediaMtxService(IOptions options, ILogger< private readonly HashSet _registeredPaths = new(StringComparer.Ordinal); private readonly HttpClient _client = new(new HttpClientHandler { UseProxy = false, AllowAutoRedirect = false }) { - BaseAddress = new Uri($"http://127.0.0.1:{options.Value.ApiPort}/v3/"), + BaseAddress = new Uri($"http://127.0.0.1:{options.Value.Gateway.Port}/v3/"), Timeout = TimeSpan.FromSeconds(10) }; private string? _apiPassword; @@ -47,7 +47,7 @@ public async Task SetGatewayStateAsync(string? apiPassword) throw new ArgumentException("Camera Path is required.", nameof(camera)); } var source = BuildRtspSourceUrl(camera) ?? throw new ArgumentException("Camera URL must be an absolute RTSP or RTSPS URL.", nameof(camera)); - var playerBaseUrl = options.Value.GetWebRtcPublicUri()?.AbsoluteUri ?? $"http://127.0.0.1:{options.Value.WebRtcPort}/"; + var playerBaseUrl = options.Value.WebRtc.GetPublicUri()?.AbsoluteUri ?? $"http://127.0.0.1:{options.Value.WebRtc.Port}/"; var playerUrl = camera.PlayUrl ?? $"{playerBaseUrl}{path}/"; if (!Uri.TryCreate(playerUrl, UriKind.Absolute, out var player) || player.Scheme is not ("http" or "https") || player.UserInfo.Length != 0) @@ -113,7 +113,7 @@ private async Task SendAsync(HttpMethod method, string route, object? cont { throw new InvalidOperationException("The MediaMTX gateway is not running."); } - var userName = options.Value.UseExternalGateway ? options.Value.ExternalApiUserName : "gateway"; + var userName = options.Value.Gateway.UseExternalGateway ? options.Value.Gateway.ExternalUserName : "gateway"; using var request = _client.CreateAuthorizationRequest(method, route, apiPassword, userName); if (content is not null) { diff --git a/src/components/BootstrapBlazor.MediaMtx/MediaMtxWebRtcConfiguration.cs b/src/components/BootstrapBlazor.MediaMtx/MediaMtxWebRtcConfiguration.cs index be3dd38c..9fa555b5 100644 --- a/src/components/BootstrapBlazor.MediaMtx/MediaMtxWebRtcConfiguration.cs +++ b/src/components/BootstrapBlazor.MediaMtx/MediaMtxWebRtcConfiguration.cs @@ -5,148 +5,45 @@ using System.Net; using System.Net.Sockets; -using System.Text.Json; namespace BootstrapBlazor.Components; sealed class MediaMtxWebRtcConfiguration { - public IPEndPoint IceEndpoint { get; private set; } - public bool IpsFromInterfaces { get; private set; } - public List AdditionalHosts { get; private set; } = ["127.0.0.1"]; + public IPEndPoint IceEndpoint { get; } + public bool IpsFromInterfaces { get; } + public List AdditionalHosts { get; } - private MediaMtxWebRtcConfiguration() + private MediaMtxWebRtcConfiguration(IPEndPoint iceEndpoint, bool ipsFromInterfaces, List additionalHosts) { - IceEndpoint = new IPEndPoint(IPAddress.Loopback, 0); + IceEndpoint = iceEndpoint; + IpsFromInterfaces = ipsFromInterfaces; + AdditionalHosts = additionalHosts; } - public static async Task LoadAsync(string? path, int port, CancellationToken cancellationToken) + public static MediaMtxWebRtcConfiguration Create(MediaMtxOptions options) { - var result = new MediaMtxWebRtcConfiguration(); - if (path is not null) + var ice = options.WebRtc.Ice; + if (!IPAddress.TryParse(ice.Address, out var address) || + address.AddressFamily is not (AddressFamily.InterNetwork or AddressFamily.InterNetworkV6) || + address.Equals(IPAddress.IPv6Any) || + (address.AddressFamily == AddressFamily.InterNetworkV6 && address.ScopeId != 0)) { - if (string.IsNullOrWhiteSpace(path)) - { - throw new ArgumentException("WebRtcConfigPath must not be empty."); - } - var text = await File.ReadAllTextAsync(Path.GetFullPath(path, AppContext.BaseDirectory), cancellationToken); - result.Parse(text); + throw new ArgumentException("WebRtc:Ice:Address must be a supported numeric IP address."); } - if (result.IceEndpoint.Port == 0) + if (ice.Port is < 1 or > 65535) { - result.IceEndpoint = new IPEndPoint(IPAddress.Loopback, port); + throw new ArgumentException("WebRtc:Ice:Port must be between 1 and 65535."); } - return result; - } - - private void Parse(string text) - { - var seen = new HashSet(StringComparer.Ordinal); - var hosts = new List(); - var inHosts = false; - var lineNumber = 0; - using var reader = new StringReader(text); - while (reader.ReadLine() is { } line) - { - lineNumber++; - if (string.IsNullOrWhiteSpace(line) || line.TrimStart().StartsWith('#')) - { - continue; - } - if (line.StartsWith(" - ", StringComparison.Ordinal) && inHosts) - { - var host = ReadScalar(line[4..], lineNumber); - if (Uri.CheckHostName(host) == UriHostNameType.Unknown || host.IndexOfAny(['%', '[', ']']) >= 0) - { - throw Invalid(lineNumber); - } - hosts.Add(host); - continue; - } - if (char.IsWhiteSpace(line[0])) - { - throw Invalid(lineNumber); - } - - var separator = line.IndexOf(':'); - if (separator <= 0) - { - throw Invalid(lineNumber); - } - if (separator + 1 < line.Length && line[separator + 1] != ' ') - { - throw Invalid(lineNumber); - } - var key = line[..separator]; - var value = line[(separator + 1)..].Trim(); - if (!seen.Add(key)) - { - throw Invalid(lineNumber); - } - inHosts = false; - switch (key) - { - case "webrtcLocalUDPAddress": - SetIceEndpoint(ReadScalar(value, lineNumber), lineNumber); - break; - case "webrtcIPsFromInterfaces": - IpsFromInterfaces = value switch - { - "true" => true, - "false" => false, - _ => throw Invalid(lineNumber) - }; - break; - case "webrtcAdditionalHosts" when value.Length == 0: - inHosts = true; - break; - default: - throw Invalid(lineNumber); - } - } - if (seen.Contains("webrtcAdditionalHosts")) - { - if (hosts.Count == 0) - { - throw Invalid(lineNumber); - } - AdditionalHosts = hosts; - } - } - - private void SetIceEndpoint(string value, int lineNumber) - { - if (value.StartsWith(':') || !IPEndPoint.TryParse(value, out var endpoint) || endpoint.Port == 0 || - endpoint.Address.AddressFamily is not (AddressFamily.InterNetwork or AddressFamily.InterNetworkV6) || - endpoint.Address.Equals(IPAddress.IPv6Any) || - (endpoint.Address.AddressFamily == AddressFamily.InterNetworkV6 && endpoint.Address.ScopeId != 0)) + var hosts = ice.AdditionalHosts ?? ["127.0.0.1"]; + if (hosts.Count == 0 || hosts.Any(host => + string.IsNullOrEmpty(host) || Uri.CheckHostName(host) == UriHostNameType.Unknown || + host.IndexOfAny(['%', '[', ']']) >= 0)) { - throw Invalid(lineNumber); + throw new ArgumentException("WebRtc:Ice:AdditionalHosts must contain valid IP addresses or host names."); } - IceEndpoint = endpoint; - } - private static string ReadScalar(string value, int lineNumber) - { - value = value.Trim(); - if (value.StartsWith('"')) - { - try - { - return JsonSerializer.Deserialize(value) is { Length: > 0 } parsed ? parsed : throw Invalid(lineNumber); - } - catch (JsonException) - { - throw Invalid(lineNumber); - } - } - if (value.Length == 0 || value.Any(c => !(c is >= 'a' and <= 'z' or >= 'A' and <= 'Z' or >= '0' and <= '9' or '.' or '-' or ':' or '[' or ']'))) - { - throw Invalid(lineNumber); - } - return value; + return new MediaMtxWebRtcConfiguration(new IPEndPoint(address, ice.Port), + ice.IpsFromInterfaces, [.. hosts]); } - - private static InvalidDataException Invalid(int lineNumber) => - new($"Invalid or unsupported WebRTC YAML fragment at line {lineNumber}."); } diff --git a/src/components/BootstrapBlazor.MediaMtx/README.MediaMtx.md b/src/components/BootstrapBlazor.MediaMtx/README.MediaMtx.md index c34b75f9..1c27aa8d 100644 --- a/src/components/BootstrapBlazor.MediaMtx/README.MediaMtx.md +++ b/src/components/BootstrapBlazor.MediaMtx/README.MediaMtx.md @@ -35,10 +35,16 @@ builder.Services.AddMediaMtxService(); ```json { "MediaMtxOptions": { - "ApiPort": 9997, - "ApiPassword": "", - "WebRtcPort": 8889, - "WebRtcIcePort": 8189, + "Gateway": { + "Port": 9997, + "Password": "" + }, + "WebRtc": { + "Port": 8889, + "Ice": { + "Port": 8189 + } + }, "Cameras": { "hikvision": { "RtspUrl": "rtsp://192.0.2.1:554/Streaming/Channels/101", @@ -50,26 +56,30 @@ builder.Services.AddMediaMtxService(); } ``` -上面的空密码是占位。自管模式必须提供非空白 `ApiPassword`,API 用户名固定为 `gateway`。它与摄像头密码用途不同,强度、存储和轮换由部署方维护;共享网关的宿主应使用相同 API 密码。 +上面的空密码是占位。自管模式必须提供非空白 `Gateway:Password`,API 用户名固定为 `gateway`。它与摄像头密码用途不同,强度、存储和轮换由部署方维护;共享网关的宿主应使用相同 API 密码。 开发环境可使用 User Secrets: ```powershell -dotnet user-secrets set "MediaMtxOptions:ApiPassword" "" +dotnet user-secrets set "MediaMtxOptions:Gateway:Password" "" dotnet user-secrets set "MediaMtxOptions:Cameras:hikvision:Password" "" ``` -生产环境通过部署 Secret 或环境变量提供,例如 `MediaMtxOptions__ApiPassword`、`MediaMtxOptions__Cameras__hikvision__Password`。不要提交实际密码;生产环境默认不加载 `appsettings.Development.json` 或 User Secrets。子进程会接收 API 密码和摄像头源凭据,需限制宿主和子进程的访问权限。 +生产环境通过部署 Secret 或环境变量提供,例如 `MediaMtxOptions__Gateway__Password`、`MediaMtxOptions__Cameras__hikvision__Password`。不要提交实际密码;生产环境默认不加载 `appsettings.Development.json` 或 User Secrets。子进程会接收 API 密码和摄像头源凭据,需限制宿主和子进程的访问权限。 | 选项 | 默认值与用途 | | --- | --- | -| `ApiPort` | `9997`,回环 Control API 的 TCP 端口。 | -| `ApiPassword` | 自管网关必填;用于 API 认证,不是播放密码。 | -| `WebRtcPort` | `8889`,回环播放页面及信令的 TCP 端口,须与 `ApiPort` 不同。 | -| `WebRtcIcePort` | `8189`,默认回环媒体 UDP 端口,可由 YAML 片段覆盖。 | -| `WebRtcPublicUrl` | 可选的 HTTP/HTTPS 播放基址,可带路径前缀,不允许凭据、查询字符串或片段;不配置 ICE。 | -| `WebRtcConfigPath` | 可选的自管网关 WebRTC YAML 片段路径,相对应用目录解析。 | -| `MediaMtxPath` | 默认 `mediamtx-tools\\mediamtx.exe`(Windows)或对应的 `mediamtx`;相对应用目录解析。 | +| `Gateway:Port` | `9997`,回环 Control API 的 TCP 端口。 | +| `Gateway:Password` | 自管网关必填;用于 API 认证,不是播放密码。 | +| `Gateway:UseExternalGateway` | 是否使用外部本机网关,默认为 `false`。 | +| `Gateway:ExternalUserName` / `Gateway:ExternalPassword` | 外部网关控制 API 凭据;用户名默认为 `gateway`。 | +| `WebRtc:Port` | `8889`,回环播放页面及信令的 TCP 端口,须与 `Gateway:Port` 不同。 | +| `WebRtc:Ice:Port` | `8189`,媒体 UDP 端口。 | +| `WebRtc:Ice:Address` | `127.0.0.1`,自管网关的媒体 UDP 监听 IP;公网使用可设为 `0.0.0.0`。 | +| `WebRtc:Ice:IpsFromInterfaces` | `false`,是否将网卡地址作为 ICE 候选地址。 | +| `WebRtc:Ice:AdditionalHosts` | 默认为 `["127.0.0.1"]`,额外公布的 ICE IP 或主机名。 | +| `WebRtc:PublicUrl` | 可选的 HTTP/HTTPS 播放基址,可带路径前缀,不允许凭据、查询字符串或片段;不配置 ICE。 | +| `Gateway:MediaMtxPath` | 默认 `mediamtx-tools\\mediamtx.exe`(Windows)或对应的 `mediamtx`;相对应用目录解析。 | | `Cameras` | 可选的静态摄像头字典,以键作为播放路径,忽略值中的 `Path`、`PlayUrl`。 | 自管网关的完整 YAML 由服务生成,关闭其他协议监听器和 MediaMTX 日志目的地。API 密码和摄像头源通过子进程环境传递,不写入生成的 YAML。 @@ -116,7 +126,7 @@ await mediaMtx.RemoveAsync(camera.Path!, cancellationToken); - `Path` 必须非空。建议调用方限制为小写字母开头,仅包含小写字母、数字和连字符,最长 63 个字符,排除 `all`。 - `RtspUrl` 必须是包含主机名且不含用户信息的绝对 RTSP/RTSPS 地址。`UserName`、`Password` 传原始值,由服务编码;没有用户名时忽略密码。 -- `PlayUrl` 为 `null` 时生成 `//`,未配置公开基址则使用 `http://127.0.0.1://`。非 `null` 时必须是无凭据的绝对 HTTP/HTTPS 地址,空字符串无效;它不改变监听、允许的来源或 ICE。 +- `PlayUrl` 为 `null` 时生成 `//`,未配置公开基址则使用 `http://127.0.0.1://`。非 `null` 时必须是无凭据的绝对 HTTP/HTTPS 地址,空字符串无效;它不改变监听、允许的来源或 ICE。 - 更新、删除同一路径会影响所有观看者。动态配置只保存在网关内存中,网关重启后需重新登记;关闭播放器不删除路径。 播放页默认静音;有声自动播放受浏览器策略限制。音频可使用 G.711 μ-law(PCMU)或 A-law(PCMA)等浏览器支持的编码,不兼容编码需另行转码。 @@ -128,32 +138,20 @@ await mediaMtx.RemoveAsync(camera.Path!, cancellationToken); ```json { "MediaMtxOptions": { - "WebRtcPublicUrl": "https://live.example.com/", - "WebRtcConfigPath": "mediamtx-webrtc.yml" + "WebRtc": { + "PublicUrl": "https://live.example.com/", + "Ice": { + "Address": "0.0.0.0", + "Port": 8189, + "IpsFromInterfaces": false, + "AdditionalHosts": ["服务器公网IP"] + } + } } } ``` -手动在应用目录创建 `mediamtx-webrtc.yml`,服务不会自动生成这个输入文件: - -```yaml -webrtcLocalUDPAddress: "0.0.0.0:8189" -webrtcIPsFromInterfaces: false -webrtcAdditionalHosts: - - "live.example.com" -``` - -在宿主 `.csproj` 中设置构建、发布复制: - -```xml - - - -``` - -`webrtcAdditionalHosts` 应指向 **MediaMTX 服务器可达的公网 IP 或直连域名**,不是摄像头地址;有 CDN 或代理中转时,不能直接使用只代理 HTTP 的地址。 +`WebRtc:Ice:AdditionalHosts` 应指向 **MediaMTX 服务器可达的公网 IP 或直连域名**,不是摄像头地址;有 CDN 或代理中转时,不能直接使用只代理 HTTP 的地址。`WebRtc:Ice:Address` 只接受数字 IP,不支持 IPv6 任意地址及 scope ID;主机列表不能为空。以上设置仅用于自管网关。 ```text 浏览器 → HTTPS nginx → 127.0.0.1:8889:播放页面和 WHEP 信令 @@ -163,13 +161,11 @@ MediaMTX → 摄像头 RTSP 地址:源流 防火墙和云安全组须放行媒体 UDP 端口,有 NAT 时配置对应映射;HTTP 反向代理不会自动转发 UDP。代理需转发完整播放路径、WHEP 请求及会话地址,路径前缀场景还需处理 `Location` 响应头。HTTPS 页面应嵌入 HTTPS 播放地址,代理的嵌入策略须允许 BB 页面。 -**YAML 片段只支持示例中的三个字段**,字段可省略,未设置时保留回环默认。UDP 地址须显式指定数字 IP 和 1–65535 端口;支持 IPv4、具体 IPv6 地址(如 `[::1]:8189`),不支持 `:8189`、`[::]:8189` 或 IPv6 scope ID。片段端口覆盖 `WebRtcIcePort`。 - -`webrtcIPsFromInterfaces` 只接受 `true`/`false`;主机列表须使用示例中的非空块式列表。字符串可不加引号或使用 JSON 风格双引号,支持整行 `#` 注释;不支持单引号、行尾注释、行内列表、锚点或其他字段。文件缺失、重复字段及无效语法都会导致启动失败。需要 TURN 等超出片段范围的配置时,使用外部网关模式。 +媒体 UDP 端口须在 1–65535 范围内。需要 TURN 等超出选项范围的配置时,使用外部网关模式。 ## 进程复用 -同一服务实例的网关仍运行时,`EnsureStartedAsync` 直接返回。新的宿主通过当前系统用户的本机应用数据目录 `BootstrapBlazor\mediamtx-gateways` 及文件锁协调,按 `ApiPort` 查找状态,再核对 PID、启动时间和进程路径。 +同一服务实例的网关仍运行时,`EnsureStartedAsync` 直接返回。新的宿主通过当前系统用户的本机应用数据目录 `BootstrapBlazor\mediamtx-gateways` 及文件锁协调,按 `Gateway:Port` 查找状态,再核对 PID、启动时间和进程路径。 | 情况 | 行为 | | --- | --- | @@ -178,29 +174,33 @@ MediaMTX → 摄像头 RTSP 地址:源流 | 指纹不同、目标路径不同 | 报错,不终止旧进程。 | | 没有有效登记进程 | 预检端口后启动;端口被其他实例占用则报错,不擅自接管。 | -指纹由可执行文件内容、生成的 YAML 和静态摄像头源配置计算 SHA-256,包含摄像头凭据,**不包含 `ApiPassword` 或运行时动态登记**。仅更换 API 密码不会触发自动重启;需先确认并手动停止对应网关,再用新密码启动。共享宿主应保持配置一致,避免反复触发重启。 +指纹由可执行文件内容、生成的 YAML 和静态摄像头源配置计算 SHA-256,包含摄像头凭据,**不包含 `Gateway:Password` 或运行时动态登记**。仅更换 API 密码不会触发自动重启;需先确认并手动停止对应网关,再用新密码启动。共享宿主应保持配置一致,避免反复触发重启。 共享状态只保存进程身份和指纹,不保存 API 密码;不要共享或提交状态文件。宿主释放只关闭自身句柄,网关继续运行。服务不后台守护进程,网关退出后再次调用 `EnsureStartedAsync` 才会尝试启动。启动失败会清理本次启动的进程。 ## 外部本机网关 -由部署方独立启动 MediaMTX,启用 `127.0.0.1:` 的 Control API,设置具有 API 权限的账号,并自行配置 WebRTC、ICE、播放权限和进程守护: +由部署方独立启动 MediaMTX,启用 `127.0.0.1:` 的 Control API,设置具有 API 权限的账号,并自行配置 WebRTC、ICE、播放权限和进程守护: ```json { "MediaMtxOptions": { - "UseExternalGateway": true, - "ApiPort": 9997, - "ExternalApiUserName": "gateway", - "ExternalApiPassword": "", - "WebRtcPublicUrl": "https://live.example.com/" + "Gateway": { + "UseExternalGateway": true, + "Port": 9997, + "ExternalUserName": "gateway", + "ExternalPassword": "" + }, + "WebRtc": { + "PublicUrl": "https://live.example.com/" + } } } ``` -通过安全配置源提供 `ExternalApiPassword`。此模式不使用 `ApiPassword`、不启动或停止进程,不能设置 `WebRtcConfigPath`,也不支持远程 Control API。 +通过安全配置源提供 `Gateway:ExternalPassword`。此模式不使用 `Gateway:Password`、不启动或停止进程,也不支持远程 Control API。 -每次 `EnsureStartedAsync` 检查 `/v3/info`;首次连接、检测到网关重启或失败后重连会重新登记静态 `Cameras`。`WebRtcPublicUrl` 仅用于生成播放地址,不更改外部网关的来源或 ICE 设置。多个宿主须协调路径,失败或取消不回滚已完成的登记。 +每次 `EnsureStartedAsync` 检查 `/v3/info`;首次连接、检测到网关重启或失败后重连会重新登记静态 `Cameras`。`WebRtc:PublicUrl` 仅用于生成播放地址,不更改外部网关的来源或 ICE 设置。多个宿主须协调路径,失败或取消不回滚已完成的登记。 ## 排查与安全 @@ -208,8 +208,8 @@ MediaMTX → 摄像头 RTSP 地址:源流 | 现象 | 检查 | | --- | --- | -| 工具缺失 | `MediaMtxPath`、目标 RID、执行权限及 CLI 警告。 | -| YAML 文件找不到或解析失败 | `WebRtcConfigPath` 相对应用目录,不是源码目录;检查复制设置与受限语法。 | +| 工具缺失 | `Gateway:MediaMtxPath`、目标 RID、执行权限及 CLI 警告。 | +| ICE 配置无效 | 检查 `WebRtc:Ice:Address`、`WebRtc:Ice:Port` 和 `WebRtc:Ice:AdditionalHosts`。 | | HTTP 401/403 | 配置密码是否与运行中网关一致;自管模式认证被拒立即失败。 | | 端口占用、进程退出或就绪超时 | 服务端日志中的 PID、端口、工具版本;启动和复用的 API 就绪检查最多等待 10 秒。 | | 播放页可见但无画面 | 服务器到摄像头的 RTSP、凭据、编码,以及浏览器到 ICE 公网地址的 UDP 连通性。 | diff --git a/src/components/BootstrapBlazor.MediaMtx/skills/bb-mediamtx/SKILL.md b/src/components/BootstrapBlazor.MediaMtx/skills/bb-mediamtx/SKILL.md index f4040fde..bf4db9ec 100644 --- a/src/components/BootstrapBlazor.MediaMtx/skills/bb-mediamtx/SKILL.md +++ b/src/components/BootstrapBlazor.MediaMtx/skills/bb-mediamtx/SKILL.md @@ -5,7 +5,7 @@ description: 提供 BootstrapBlazor.MediaMtx 的配置与 API 参考。适用于 # MediaMTX 使用参考 -先读 [references/llms.txt](references/llms.txt),再查对应 API。部署示例、YAML 语法与排错见 [包内 README](../../README.MediaMtx.md)。以实际引用版本和源码为准,不编造参数。 +先读 [references/llms.txt](references/llms.txt),再查对应 API。部署示例与排错见 [包内 README](../../README.MediaMtx.md)。以实际引用版本和源码为准,不编造参数。 ## 注册与部署 @@ -15,17 +15,17 @@ builder.Services.AddMediaMtxService(); - 主包提供服务端 `IMediaMtxService`,不支持独立 WebAssembly 宿主。DI 默认单例,从 `MediaMtxOptions` 节绑定;可用注册回调覆盖配置,修改后需重启应用。 - 注册不启动网关。先通过 `bb-mediamtx --download --copy --output .\publish` 部署工具;跨平台加 `--rid`。CLI 不修改工程或创建构建规则,运行时不下载工具。 -- `MediaMtxPath` 默认指向应用目录的 `mediamtx-tools\\mediamtx.exe`(Windows)或 `mediamtx`;支持 Windows x64、Linux x64/ARM64/ARMv7、macOS x64/ARM64。CLI 需要 .NET 11。 +- `Gateway:MediaMtxPath` 默认指向应用目录的 `mediamtx-tools\\mediamtx.exe`(Windows)或 `mediamtx`;支持 Windows x64、Linux x64/ARM64/ARMv7、macOS x64/ARM64。CLI 需要 .NET 11。 - CLI 的 `--copy` 只使用缓存;`--force` 覆盖输出工具和许可证,不强制下载。失败以警告报告,不能仅凭退出码判断部署成功。 ## 配置与密码 | 选项 | 约定 | | --- | --- | -| `ApiPort` / `ApiPassword` | 自管 Control API 默认 `127.0.0.1:9997`,用户名 `gateway`;密码必填,由部署方维护。 | -| `WebRtcPort` / `WebRtcIcePort` | 默认回环 TCP `8889` / UDP `8189`;API 与播放 TCP 端口须不同。 | -| `WebRtcPublicUrl` | 浏览器使用的绝对 HTTP/HTTPS 播放基址,无凭据、查询字符串或片段;自管模式同时设置允许的信令来源。 | -| `WebRtcConfigPath` | 自管 WebRTC YAML 片段,相对应用目录解析,文件须自行创建并配置构建、发布复制。 | +| `Gateway:Port` / `Gateway:Password` | 自管 Control API 默认 `127.0.0.1:9997`,用户名 `gateway`;密码必填,由部署方维护。 | +| `WebRtc:Port` / `WebRtc:Ice:Port` | 默认回环 TCP `8889` / UDP `8189`;API 与播放 TCP 端口须不同。 | +| `WebRtc:Ice:Address` / `WebRtc:Ice:IpsFromInterfaces` / `WebRtc:Ice:AdditionalHosts` | 自管网关的 UDP 监听 IP、网卡候选地址开关和额外 ICE 主机;默认分别为 `127.0.0.1`、`false`、`["127.0.0.1"]`。 | +| `WebRtc:PublicUrl` | 浏览器使用的绝对 HTTP/HTTPS 播放基址,无凭据、查询字符串或片段;自管模式同时设置允许的信令来源。 | | `Cameras` | 静态摄像头字典,键为路径;值提供 `RtspUrl`、`UserName`、`Password`,忽略 `Path`、`PlayUrl`。 | API 密码与摄像头密码分开配置,通过 Secret 或环境变量提供,不写入文档、日志或浏览器存储。生产环境默认不加载 Development 配置或 User Secrets;子进程会接收凭据,需限制访问权限。 @@ -37,8 +37,8 @@ await mediaMtx.EnsureStartedAsync(cancellationToken); var playerUrl = await mediaMtx.AddOrUpdateAsync(camera, cancellationToken); ``` -- 同一服务已有存活进程时直接返回。新宿主按当前用户、`ApiPort` 和共享状态核对进程身份;指纹相同且 API 认证通过才复用。 -- 指纹包含可执行文件内容、生成 YAML、静态摄像头源及其凭据,**不包含 `ApiPassword` 或动态登记**。指纹变化且可执行文件路径与当前目标一致时自动停止旧进程并重启,路径不同时报错。共享配置不同可能反复重启,影响所有观看者。 +- 同一服务已有存活进程时直接返回。新宿主按当前用户、`Gateway:Port` 和共享状态核对进程身份;指纹相同且 API 认证通过才复用。 +- 指纹包含可执行文件内容、生成 YAML、静态摄像头源及其凭据,**不包含 `Gateway:Password` 或动态登记**。指纹变化且可执行文件路径与当前目标一致时自动停止旧进程并重启,路径不同时报错。共享配置不同可能反复重启,影响所有观看者。 - 仅更换 API 密码不触发指纹重启,需手动停止对应网关后重新启动。API 认证返回 401/403 时立即失败;其他就绪探测最多等待 10 秒。 - 共享状态位于当前用户本机应用数据目录的 `BootstrapBlazor\mediamtx-gateways`,保存进程身份和指纹,不保存 API 密码。没有有效登记的占用端口实例不会被接管。 - 宿主释放不停止网关、不删除路径。网关崩溃后不后台重启,再次调用 `EnsureStartedAsync` 才尝试启动;启动失败会清理本次启动的进程。 @@ -50,15 +50,15 @@ var playerUrl = await mediaMtx.AddOrUpdateAsync(camera, cancellationToken); - `Path` 非空;建议调用方限制为小写字母开头,仅含小写字母、数字、连字符,最长 63 个字符,排除 `all`。 - `RtspUrl` 是无用户信息的绝对 RTSP/RTSPS 地址,必须包含主机名;用户名、密码传原始值,由服务编码,无用户名时忽略密码。 -- `PlayUrl` 为 `null` 时使用 `WebRtcPublicUrl` 或 `http://127.0.0.1:/` 加 `Path/`;非 `null` 时必须是无凭据的绝对 HTTP/HTTPS 地址,空字符串无效。它不改变来源或 ICE。 -- 公网需同时配置 HTTPS 反向代理和可达的 UDP ICE。YAML 只接受 `webrtcLocalUDPAddress`、`webrtcIPsFromInterfaces`、`webrtcAdditionalHosts`;只支持受限语法,详见 README。 -- 公布的 ICE 地址必须指向 MediaMTX 服务器而非摄像头或仅代理 HTTP 的 CDN;放行 UDP、防火墙及 NAT 映射。普通 nginx HTTP 代理不转发媒体 UDP,`WebRtcPublicUrl` 也不改变 ICE。 +- `PlayUrl` 为 `null` 时使用 `WebRtc:PublicUrl` 或 `http://127.0.0.1:/` 加 `Path/`;非 `null` 时必须是无凭据的绝对 HTTP/HTTPS 地址,空字符串无效。它不改变来源或 ICE。 +- 公网需同时配置 HTTPS 反向代理和可达的 UDP ICE;使用 `WebRtc:Ice:Address`、`WebRtc:Ice:Port` 和 `WebRtc:Ice:AdditionalHosts`,不必维护 YAML。 +- 公布的 ICE 地址必须指向 MediaMTX 服务器而非摄像头或仅代理 HTTP 的 CDN;放行 UDP、防火墙及 NAT 映射。普通 nginx HTTP 代理不转发媒体 UDP,`WebRtc:PublicUrl` 也不改变 ICE。 - MediaMTX 按需 RTSP/TCP 拉流,不转码;编码须与浏览器兼容。播放默认静音,有声自动播放受浏览器限制。 ## 外部网关与安全 -`UseExternalGateway=true` 时只连接 `127.0.0.1:/v3/`,使用 `ExternalApiUserName`(默认 `gateway`)和 `ExternalApiPassword`。不使用 `ApiPassword`,不能设置 `WebRtcConfigPath`;工具、监听、来源、ICE、鉴权与进程守护由部署方负责。 +`Gateway:UseExternalGateway=true` 时只连接 `127.0.0.1:/v3/`,使用 `Gateway:ExternalUserName`(默认 `gateway`)和 `Gateway:ExternalPassword`。不使用 `Gateway:Password`;工具、监听、来源、ICE、鉴权与进程守护由部署方负责。 每次 `EnsureStartedAsync` 检查外部 API,首次连接、检测到重启或失败后重连会登记静态摄像头。服务不停止外部进程,登记失败或取消不回滚已完成操作。 -UI 认证、摄像头级授权、RTSP 目标限制及播放鉴权由调用方实现。API 密码不是播放密码,路径不是访问令牌;不要将 Control API 代理到公网。排错先看服务端异常,区分工具或 YAML 缺失、认证失败、端口冲突与媒体不通。 +UI 认证、摄像头级授权、RTSP 目标限制及播放鉴权由调用方实现。API 密码不是播放密码,路径不是访问令牌;不要将 Control API 代理到公网。排错先看服务端异常,区分工具缺失、认证失败、端口冲突与媒体不通。 From f1cb3014a5cb8ba749ff8abb6f09f1c8788fdb47 Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Thu, 3 Dec 2026 10:10:42 +0800 Subject: [PATCH 2/2] chore: bump version 11.0.4 --- .../BootstrapBlazor.MediaMtx/BootstrapBlazor.MediaMtx.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/BootstrapBlazor.MediaMtx/BootstrapBlazor.MediaMtx.csproj b/src/components/BootstrapBlazor.MediaMtx/BootstrapBlazor.MediaMtx.csproj index e8f05658..f4d79680 100644 --- a/src/components/BootstrapBlazor.MediaMtx/BootstrapBlazor.MediaMtx.csproj +++ b/src/components/BootstrapBlazor.MediaMtx/BootstrapBlazor.MediaMtx.csproj @@ -1,7 +1,7 @@ - 11.0.3 + 11.0.4 bb-mediamtx