Add http action type and Sonar mute toggle (chatCapture, media channels)

This commit is contained in:
2026-08-25 02:41:02 +02:00
parent 9797cd7e79
commit a6dc2b6230
8 changed files with 227 additions and 33 deletions
@@ -0,0 +1,60 @@
using System.Net.Http;
using System.Text.Json;
public class SonarToggleMuteAction : IAction
{
private static readonly HttpClient Client = CreateClient();
private readonly string _address;
private readonly string _channel;
private bool? _lastKnownMuted;
public SonarToggleMuteAction(string address, string channel)
{
_address = address;
_channel = channel;
}
public void Execute()
{
_ = ToggleAsync();
}
private async Task ToggleAsync()
{
try
{
// Première pression : on part du principe qu'on est démuté, donc on mute.
// Ensuite, on se base sur l'état réel renvoyé par Sonar à chaque appel.
var desiredMuted = !(_lastKnownMuted ?? false);
var url = $"http://{_address}/volumeSettings/classic/{_channel}/Mute/{(desiredMuted ? "true" : "false")}";
var response = await Client.PutAsync(url, new StringContent(""));
var body = await response.Content.ReadAsStringAsync();
using var doc = JsonDocument.Parse(body);
var actualMuted = doc.RootElement
.GetProperty("devices")
.GetProperty(_channel)
.GetProperty("classic")
.GetProperty("muted")
.GetBoolean();
_lastKnownMuted = actualMuted;
Console.WriteLine($"[SonarToggleMute] {_channel} -> muted={actualMuted}");
}
catch (Exception ex)
{
Console.WriteLine($"[SonarToggleMute] Erreur : {ex.Message}");
}
}
private static HttpClient CreateClient()
{
var handler = new HttpClientHandler
{
ServerCertificateCustomValidationCallback = (msg, cert, chain, errors) => true
};
return new HttpClient(handler);
}
}