From 775d3c8f815c2fa19648b9d60d39845d14ab95e8 Mon Sep 17 00:00:00 2001 From: DataNext Date: Fri, 25 Apr 2025 22:46:32 +0200 Subject: [PATCH 01/12] Added ChatMix manager --- SteelSeriesAPI.Sample/Program.cs | 6 +-- SteelSeriesAPI.Tests/Program.cs | 6 +-- .../Exceptions/ChatMixBalanceException.cs | 8 ++++ .../Exceptions/ChatMixDisabledException.cs | 8 ++++ SteelSeriesAPI/Sonar/Http/SonarHttpCommand.cs | 15 +----- .../Sonar/Http/SonarHttpProvider.cs | 27 ----------- .../Sonar/Interfaces/ISonarCommandHandler.cs | 7 --- .../Sonar/Interfaces/ISonarDataProvider.cs | 12 ----- .../Interfaces/Managers/IChatMixManager.cs | 23 ++++++++++ .../Sonar/Managers/ChatMixManager.cs | 46 +++++++++++++++++++ SteelSeriesAPI/Sonar/SonarBridge.cs | 17 +------ 11 files changed, 94 insertions(+), 81 deletions(-) create mode 100644 SteelSeriesAPI/Sonar/Exceptions/ChatMixBalanceException.cs create mode 100644 SteelSeriesAPI/Sonar/Exceptions/ChatMixDisabledException.cs create mode 100644 SteelSeriesAPI/Sonar/Interfaces/Managers/IChatMixManager.cs create mode 100644 SteelSeriesAPI/Sonar/Managers/ChatMixManager.cs diff --git a/SteelSeriesAPI.Sample/Program.cs b/SteelSeriesAPI.Sample/Program.cs index 377e5bd..005cbae 100644 --- a/SteelSeriesAPI.Sample/Program.cs +++ b/SteelSeriesAPI.Sample/Program.cs @@ -57,10 +57,10 @@ static void Main(string[] args) sonarManager.Configurations.SetConfig(currentConfig); // Or you can just directly give the config // Get ChatMix info - double chatMixBalance = sonarManager.GetChatMixBalance(); // The ChatMix value between -1 and 1 - bool chatMixState = sonarManager.GetChatMixState(); // If ChatMix is usable or not + double chatMixBalance = sonarManager.ChatMix.GetBalance(); // The ChatMix value between -1 and 1 + bool chatMixState = sonarManager.ChatMix.GetState(); // If ChatMix is usable or not // Change ChatMix value - sonarManager.SetChatMixBalance(0.5); // 0.5 is halfway to Chat + sonarManager.ChatMix.SetBalance(0.5); // 0.5 is halfway to Chat // Get playback devices (Windows devices) List inputDevices = sonarManager.PlaybackDevices.GetPlaybackDevices(DataFlow.INPUT).ToList(); // Input devices (Mics...) diff --git a/SteelSeriesAPI.Tests/Program.cs b/SteelSeriesAPI.Tests/Program.cs index a745607..d67f076 100644 --- a/SteelSeriesAPI.Tests/Program.cs +++ b/SteelSeriesAPI.Tests/Program.cs @@ -112,8 +112,8 @@ void GetTest(SonarBridge sonarManager) Console.WriteLine("----Channel from config ID----------"); Console.WriteLine(sonarManager.Configurations.GetAudioConfiguration("29ae2c02-792b-4487-863c-dc3e11a7a469").AssociatedChannel); Console.WriteLine("--------ChatMix---------"); - Console.WriteLine(sonarManager.GetChatMixBalance()); - Console.WriteLine(sonarManager.GetChatMixState()); + Console.WriteLine(sonarManager.ChatMix.GetBalance()); + Console.WriteLine(sonarManager.ChatMix.GetState()); Console.WriteLine("-----Redirection Devices-----------"); Console.WriteLine("---Output---"); @@ -223,7 +223,7 @@ void SetTest(SonarBridge sonarManager){ string configId = sonarManager.Configurations.GetAudioConfigurations(Channel.MEDIA).FirstOrDefault(config => config.Name == "Default")?.Id; sonarManager.Configurations.SetConfig(configId); sonarManager.Configurations.SetConfigByName(Channel.MEDIA, "Default"); - sonarManager.SetChatMixBalance(0.5); + sonarManager.ChatMix.SetBalance(0.5); var redirectionDevices = sonarManager.PlaybackDevices.GetPlaybackDevices(DataFlow.INPUT); redirectionDevices.GetEnumerator().MoveNext(); diff --git a/SteelSeriesAPI/Sonar/Exceptions/ChatMixBalanceException.cs b/SteelSeriesAPI/Sonar/Exceptions/ChatMixBalanceException.cs new file mode 100644 index 0000000..b00a8dc --- /dev/null +++ b/SteelSeriesAPI/Sonar/Exceptions/ChatMixBalanceException.cs @@ -0,0 +1,8 @@ +namespace SteelSeriesAPI.Sonar.Exceptions; + +public class ChatMixBalanceException : Exception +{ + public ChatMixBalanceException() : base("ChatMix balance out of range.") { } + public ChatMixBalanceException(string message) : base(message) { } + public ChatMixBalanceException(string message, Exception innerException) : base(message, innerException) { } +} \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/Exceptions/ChatMixDisabledException.cs b/SteelSeriesAPI/Sonar/Exceptions/ChatMixDisabledException.cs new file mode 100644 index 0000000..be52eff --- /dev/null +++ b/SteelSeriesAPI/Sonar/Exceptions/ChatMixDisabledException.cs @@ -0,0 +1,8 @@ +namespace SteelSeriesAPI.Sonar.Exceptions; + +public class ChatMixDisabledException : Exception +{ + public ChatMixDisabledException() : base("ChatMix is not enabled.") { } + public ChatMixDisabledException(string message) : base(message) { } + public ChatMixDisabledException(string message, Exception innerException) : base(message, innerException) { } +} \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/Http/SonarHttpCommand.cs b/SteelSeriesAPI/Sonar/Http/SonarHttpCommand.cs index 6dad7c4..683ae8c 100644 --- a/SteelSeriesAPI/Sonar/Http/SonarHttpCommand.cs +++ b/SteelSeriesAPI/Sonar/Http/SonarHttpCommand.cs @@ -21,20 +21,7 @@ public void SetMode(Mode mode) Thread.Sleep(100); // Prevent bugs/freezes/crashes } - public void SetChatMixBalance(double balance) - { - if (!_sonarBridge.GetChatMixState()) - { - throw new Exception("Can't change the value of the balance of the ChatMix when it is not enabled"); - } - - if (balance > 1 || balance < -1) - { - throw new Exception("ChatMix balance can't be less than -1 and greater than 1"); - } - - new HttpFetcher().Put("chatMix?balance=" + balance.ToString("0.00", CultureInfo.InvariantCulture)); - } + public void SetRedirectionState(bool newState, Channel channel, Mix mix) { diff --git a/SteelSeriesAPI/Sonar/Http/SonarHttpProvider.cs b/SteelSeriesAPI/Sonar/Http/SonarHttpProvider.cs index e4ee8cf..8a602e5 100644 --- a/SteelSeriesAPI/Sonar/Http/SonarHttpProvider.cs +++ b/SteelSeriesAPI/Sonar/Http/SonarHttpProvider.cs @@ -16,33 +16,6 @@ public Mode GetMode() return (Mode)ModeExtensions.FromDictKey(mode, ModeMapChoice.StreamDict); } - #region ChatMix - - public double GetChatMixBalance() - { - JsonDocument chatMix = new HttpFetcher().Provide("chatMix"); - - return chatMix.RootElement.GetProperty("balance").GetDouble(); - } - - public bool GetChatMixState() - { - JsonDocument chatMix = new HttpFetcher().Provide("chatMix"); - string cState = chatMix.RootElement.GetProperty("state").ToString(); - if (cState == "enabled") - { - return true; - } - else if (cState == "differentDeviceSelected") - { - return false; - } - - return false; - } - - #endregion - public bool GetRedirectionState(Channel channel, Mix mix) { if (channel == Channel.MASTER) diff --git a/SteelSeriesAPI/Sonar/Interfaces/ISonarCommandHandler.cs b/SteelSeriesAPI/Sonar/Interfaces/ISonarCommandHandler.cs index 69f47c9..775efe7 100644 --- a/SteelSeriesAPI/Sonar/Interfaces/ISonarCommandHandler.cs +++ b/SteelSeriesAPI/Sonar/Interfaces/ISonarCommandHandler.cs @@ -9,13 +9,6 @@ public interface ISonarCommandHandler /// /// The you want to set void SetMode(Mode mode); - - /// - /// Set the balance of the ChatMix - /// - /// -1 to balance to Game channel
1 to balance to Chat channel
- /// A between -1 and 1 - void SetChatMixBalance(double balance); /// /// Enable or disable the Redirection of the chosen Sonar of the chosen Sonar diff --git a/SteelSeriesAPI/Sonar/Interfaces/ISonarDataProvider.cs b/SteelSeriesAPI/Sonar/Interfaces/ISonarDataProvider.cs index 01d296e..edce5d6 100644 --- a/SteelSeriesAPI/Sonar/Interfaces/ISonarDataProvider.cs +++ b/SteelSeriesAPI/Sonar/Interfaces/ISonarDataProvider.cs @@ -11,18 +11,6 @@ public interface ISonarDataProvider /// A , either Classic or Streamer Mode GetMode(); - /// - /// Get the actual ChatMix balance value - /// - /// A double between -1 and 1 - double GetChatMixBalance(); - - /// - /// Get the actual state of the ChatMix - /// - /// True if ChatMix is enabled
False if ChatMix is disabled
- bool GetChatMixState(); - /// /// Get the mute state of the Redirection of the chosen Sonar of the chosen Sonar /// diff --git a/SteelSeriesAPI/Sonar/Interfaces/Managers/IChatMixManager.cs b/SteelSeriesAPI/Sonar/Interfaces/Managers/IChatMixManager.cs new file mode 100644 index 0000000..6e3dc1f --- /dev/null +++ b/SteelSeriesAPI/Sonar/Interfaces/Managers/IChatMixManager.cs @@ -0,0 +1,23 @@ +namespace SteelSeriesAPI.Sonar.Interfaces.Managers; + +public interface IChatMixManager +{ + /// + /// Get the actual ChatMix balance value + /// + /// A double between -1 and 1 + double GetBalance(); + + /// + /// Get the actual state of the ChatMix + /// + /// True if ChatMix is enabled
False if ChatMix is disabled
+ bool GetState(); + + /// + /// Set the balance of the ChatMix + /// + /// -1 to balance to Game channel
1 to balance to Chat channel
+ /// A between -1 and 1 + void SetBalance(double balance); +} \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/Managers/ChatMixManager.cs b/SteelSeriesAPI/Sonar/Managers/ChatMixManager.cs new file mode 100644 index 0000000..f288615 --- /dev/null +++ b/SteelSeriesAPI/Sonar/Managers/ChatMixManager.cs @@ -0,0 +1,46 @@ +using SteelSeriesAPI.Sonar.Exceptions; +using SteelSeriesAPI.Sonar.Interfaces.Managers; +using SteelSeriesAPI.Sonar.Http; + +using System.Text.Json; +using System.Globalization; + +namespace SteelSeriesAPI.Sonar.Managers; + +public class ChatMixManager : IChatMixManager +{ + public double GetBalance() + { + JsonDocument chatMix = new HttpFetcher().Provide("chatMix"); + + return chatMix.RootElement.GetProperty("balance").GetDouble(); + } + + public bool GetState() + { + JsonDocument chatMix = new HttpFetcher().Provide("chatMix"); + string cState = chatMix.RootElement.GetProperty("state").ToString(); + + if (cState == "enabled") + { + return true; + } + + return false; + } + + public void SetBalance(double balance) + { + if (!GetState()) + { + throw new ChatMixDisabledException(); + } + + if (balance > 1 || balance < -1) + { + throw new ChatMixBalanceException(); + } + + new HttpFetcher().Put("chatMix?balance=" + balance.ToString("0.00", CultureInfo.InvariantCulture)); + } +} \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/SonarBridge.cs b/SteelSeriesAPI/Sonar/SonarBridge.cs index 0a0441e..8e05db0 100644 --- a/SteelSeriesAPI/Sonar/SonarBridge.cs +++ b/SteelSeriesAPI/Sonar/SonarBridge.cs @@ -20,6 +20,7 @@ public class SonarBridge : ISonarBridge private ISonarSocket _sonarSocket; public readonly VolumeSettingsManager VolumeSettings; + public readonly ChatMixManager ChatMix; public readonly ConfigurationManager Configurations; public readonly PlaybackDeviceManager PlaybackDevices; public readonly EventManager Events; @@ -29,6 +30,7 @@ public SonarBridge() _sonarCommand = new SonarHttpCommand(this); _sonarProvider = new SonarHttpProvider(); VolumeSettings = new VolumeSettingsManager(); + ChatMix = new ChatMixManager(); Configurations = new ConfigurationManager(); PlaybackDevices = new PlaybackDeviceManager(); Events = new EventManager(); @@ -102,16 +104,6 @@ public Mode GetMode() { return _sonarProvider.GetMode(); } - - public double GetChatMixBalance() - { - return _sonarProvider.GetChatMixBalance(); - } - - public bool GetChatMixState() - { - return _sonarProvider.GetChatMixState(); - } public bool GetRedirectionState(Channel channel, Mix mix) { @@ -136,11 +128,6 @@ public void SetMode(Mode mode) { _sonarCommand.SetMode(mode); } - - public void SetChatMixBalance(double balance) - { - _sonarCommand.SetChatMixBalance(balance); - } public void SetRedirectionState(bool newState, Channel channel, Mix mix) { From c03092479d5c8780fa3424224620bc2cb23f6a6a Mon Sep 17 00:00:00 2001 From: DataNext Date: Fri, 25 Apr 2025 22:48:24 +0200 Subject: [PATCH 02/12] Forgot "Exception" at the end of the exceptions name --- SteelSeriesAPI/Sonar/Exceptions/ConfigNotFound.cs | 8 -------- .../Sonar/Exceptions/ConfigNotFoundException.cs | 8 ++++++++ .../Sonar/Exceptions/MasterChannelNotSupported.cs | 8 -------- .../Exceptions/MasterChannelNotSupportedException.cs | 8 ++++++++ SteelSeriesAPI/Sonar/Exceptions/MicChannelSupportOnly.cs | 8 -------- .../Sonar/Exceptions/MicChannelSupportOnlyException.cs | 8 ++++++++ .../Sonar/Exceptions/SonarListenerNotConnected.cs | 8 -------- .../Exceptions/SonarListenerNotConnectedException.cs | 8 ++++++++ SteelSeriesAPI/Sonar/Http/SonarHttpCommand.cs | 2 +- SteelSeriesAPI/Sonar/Http/SonarHttpProvider.cs | 4 ++-- SteelSeriesAPI/Sonar/Managers/ConfigurationManager.cs | 6 +++--- SteelSeriesAPI/Sonar/Managers/PlaybackDeviceManager.cs | 6 +++--- SteelSeriesAPI/Sonar/SonarSocket.cs | 2 +- 13 files changed, 42 insertions(+), 42 deletions(-) delete mode 100644 SteelSeriesAPI/Sonar/Exceptions/ConfigNotFound.cs create mode 100644 SteelSeriesAPI/Sonar/Exceptions/ConfigNotFoundException.cs delete mode 100644 SteelSeriesAPI/Sonar/Exceptions/MasterChannelNotSupported.cs create mode 100644 SteelSeriesAPI/Sonar/Exceptions/MasterChannelNotSupportedException.cs delete mode 100644 SteelSeriesAPI/Sonar/Exceptions/MicChannelSupportOnly.cs create mode 100644 SteelSeriesAPI/Sonar/Exceptions/MicChannelSupportOnlyException.cs delete mode 100644 SteelSeriesAPI/Sonar/Exceptions/SonarListenerNotConnected.cs create mode 100644 SteelSeriesAPI/Sonar/Exceptions/SonarListenerNotConnectedException.cs diff --git a/SteelSeriesAPI/Sonar/Exceptions/ConfigNotFound.cs b/SteelSeriesAPI/Sonar/Exceptions/ConfigNotFound.cs deleted file mode 100644 index 4632d17..0000000 --- a/SteelSeriesAPI/Sonar/Exceptions/ConfigNotFound.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace SteelSeriesAPI.Sonar.Exceptions; - -public class ConfigNotFound : Exception -{ - public ConfigNotFound() : base("No audio configuration found.") { } - public ConfigNotFound(string message) : base(message) { } - public ConfigNotFound(string message, Exception innerException) : base(message, innerException) { } -} \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/Exceptions/ConfigNotFoundException.cs b/SteelSeriesAPI/Sonar/Exceptions/ConfigNotFoundException.cs new file mode 100644 index 0000000..1084652 --- /dev/null +++ b/SteelSeriesAPI/Sonar/Exceptions/ConfigNotFoundException.cs @@ -0,0 +1,8 @@ +namespace SteelSeriesAPI.Sonar.Exceptions; + +public class ConfigNotFoundException : Exception +{ + public ConfigNotFoundException() : base("No audio configuration found.") { } + public ConfigNotFoundException(string message) : base(message) { } + public ConfigNotFoundException(string message, Exception innerException) : base(message, innerException) { } +} \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/Exceptions/MasterChannelNotSupported.cs b/SteelSeriesAPI/Sonar/Exceptions/MasterChannelNotSupported.cs deleted file mode 100644 index f16c9a8..0000000 --- a/SteelSeriesAPI/Sonar/Exceptions/MasterChannelNotSupported.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace SteelSeriesAPI.Sonar.Exceptions; - -public class MasterChannelNotSupported : Exception -{ - public MasterChannelNotSupported() : base("Master Channel is not supported in this case.") { } - public MasterChannelNotSupported(string message) : base(message) { } - public MasterChannelNotSupported(string message, Exception innerException) : base(message, innerException) { } -} \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/Exceptions/MasterChannelNotSupportedException.cs b/SteelSeriesAPI/Sonar/Exceptions/MasterChannelNotSupportedException.cs new file mode 100644 index 0000000..91b8755 --- /dev/null +++ b/SteelSeriesAPI/Sonar/Exceptions/MasterChannelNotSupportedException.cs @@ -0,0 +1,8 @@ +namespace SteelSeriesAPI.Sonar.Exceptions; + +public class MasterChannelNotSupportedException : Exception +{ + public MasterChannelNotSupportedException() : base("Master Channel is not supported in this case.") { } + public MasterChannelNotSupportedException(string message) : base(message) { } + public MasterChannelNotSupportedException(string message, Exception innerException) : base(message, innerException) { } +} \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/Exceptions/MicChannelSupportOnly.cs b/SteelSeriesAPI/Sonar/Exceptions/MicChannelSupportOnly.cs deleted file mode 100644 index 32fdc11..0000000 --- a/SteelSeriesAPI/Sonar/Exceptions/MicChannelSupportOnly.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace SteelSeriesAPI.Sonar.Exceptions; - -public class MicChannelSupportOnly : Exception -{ - public MicChannelSupportOnly() : base("Only the Mic Channel is supported in this case.") { } - public MicChannelSupportOnly(string message) : base(message) { } - public MicChannelSupportOnly(string message, Exception innerException) : base(message, innerException) { } -} \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/Exceptions/MicChannelSupportOnlyException.cs b/SteelSeriesAPI/Sonar/Exceptions/MicChannelSupportOnlyException.cs new file mode 100644 index 0000000..ab83946 --- /dev/null +++ b/SteelSeriesAPI/Sonar/Exceptions/MicChannelSupportOnlyException.cs @@ -0,0 +1,8 @@ +namespace SteelSeriesAPI.Sonar.Exceptions; + +public class MicChannelSupportOnlyException : Exception +{ + public MicChannelSupportOnlyException() : base("Only the Mic Channel is supported in this case.") { } + public MicChannelSupportOnlyException(string message) : base(message) { } + public MicChannelSupportOnlyException(string message, Exception innerException) : base(message, innerException) { } +} \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/Exceptions/SonarListenerNotConnected.cs b/SteelSeriesAPI/Sonar/Exceptions/SonarListenerNotConnected.cs deleted file mode 100644 index cbce5b9..0000000 --- a/SteelSeriesAPI/Sonar/Exceptions/SonarListenerNotConnected.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace SteelSeriesAPI.Sonar.Exceptions; - -public class SonarListenerNotConnected : Exception -{ - public SonarListenerNotConnected() : base("Listener need to be connected before listening") { } - public SonarListenerNotConnected(string message) : base(message) { } - public SonarListenerNotConnected(string message, Exception innerException) : base(message, innerException) { } -} \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/Exceptions/SonarListenerNotConnectedException.cs b/SteelSeriesAPI/Sonar/Exceptions/SonarListenerNotConnectedException.cs new file mode 100644 index 0000000..03294b7 --- /dev/null +++ b/SteelSeriesAPI/Sonar/Exceptions/SonarListenerNotConnectedException.cs @@ -0,0 +1,8 @@ +namespace SteelSeriesAPI.Sonar.Exceptions; + +public class SonarListenerNotConnectedException : Exception +{ + public SonarListenerNotConnectedException() : base("Listener need to be connected before listening") { } + public SonarListenerNotConnectedException(string message) : base(message) { } + public SonarListenerNotConnectedException(string message, Exception innerException) : base(message, innerException) { } +} \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/Http/SonarHttpCommand.cs b/SteelSeriesAPI/Sonar/Http/SonarHttpCommand.cs index 683ae8c..bd92157 100644 --- a/SteelSeriesAPI/Sonar/Http/SonarHttpCommand.cs +++ b/SteelSeriesAPI/Sonar/Http/SonarHttpCommand.cs @@ -38,7 +38,7 @@ public void SetProcessToDeviceRouting(int pId, Channel channel) { if (channel == Channel.MASTER) { - throw new MasterChannelNotSupported(); + throw new MasterChannelNotSupportedException(); } JsonDocument audioDeviceRouting = new HttpFetcher().Provide("AudioDeviceRouting"); diff --git a/SteelSeriesAPI/Sonar/Http/SonarHttpProvider.cs b/SteelSeriesAPI/Sonar/Http/SonarHttpProvider.cs index 8a602e5..c754e7c 100644 --- a/SteelSeriesAPI/Sonar/Http/SonarHttpProvider.cs +++ b/SteelSeriesAPI/Sonar/Http/SonarHttpProvider.cs @@ -20,7 +20,7 @@ public bool GetRedirectionState(Channel channel, Mix mix) { if (channel == Channel.MASTER) { - throw new MasterChannelNotSupported(); + throw new MasterChannelNotSupportedException(); } JsonDocument streamRedirections = new HttpFetcher().Provide("streamRedirections"); @@ -62,7 +62,7 @@ public IEnumerable GetRoutedProcess(Channel channel) { if (channel == Channel.MASTER) { - throw new MasterChannelNotSupported(); + throw new MasterChannelNotSupportedException(); } JsonDocument audioDeviceRoutings = new HttpFetcher().Provide("AudioDeviceRouting"); diff --git a/SteelSeriesAPI/Sonar/Managers/ConfigurationManager.cs b/SteelSeriesAPI/Sonar/Managers/ConfigurationManager.cs index abf221c..b78df4e 100644 --- a/SteelSeriesAPI/Sonar/Managers/ConfigurationManager.cs +++ b/SteelSeriesAPI/Sonar/Managers/ConfigurationManager.cs @@ -28,7 +28,7 @@ public IEnumerable GetAudioConfigurations(Channel chann { if (channel == Channel.MASTER) { - throw new MasterChannelNotSupported(); + throw new MasterChannelNotSupportedException(); } IEnumerable configs = GetAllAudioConfigurations(); @@ -66,7 +66,7 @@ public SonarAudioConfiguration GetSelectedAudioConfiguration(Channel channel) { if (channel == Channel.MASTER) { - throw new MasterChannelNotSupported(); + throw new MasterChannelNotSupportedException(); } JsonDocument selectedConfigs = new HttpFetcher().Provide("configs/selected"); @@ -90,7 +90,7 @@ public SonarAudioConfiguration GetSelectedAudioConfiguration(Channel channel) public void SetConfig(string configId) { - if (string.IsNullOrEmpty(configId)) throw new ConfigNotFound($"No audio configuration found with this id: {configId}"); + if (string.IsNullOrEmpty(configId)) throw new ConfigNotFoundException($"No audio configuration found with this id: {configId}"); new HttpFetcher().Put("configs/" + configId + "/select"); } diff --git a/SteelSeriesAPI/Sonar/Managers/PlaybackDeviceManager.cs b/SteelSeriesAPI/Sonar/Managers/PlaybackDeviceManager.cs index 10cee6b..2607dcd 100644 --- a/SteelSeriesAPI/Sonar/Managers/PlaybackDeviceManager.cs +++ b/SteelSeriesAPI/Sonar/Managers/PlaybackDeviceManager.cs @@ -66,7 +66,7 @@ public PlaybackDevice GetClassicPlaybackDevice(Channel channel) { if (channel == Channel.MASTER) { - throw new MasterChannelNotSupported(); + throw new MasterChannelNotSupportedException(); } JsonDocument classicRedirections = new HttpFetcher().Provide("classicRedirections"); @@ -127,7 +127,7 @@ public PlaybackDevice GetStreamerPlaybackDevice(Channel channel = Channel.MIC) { if (channel != Channel.MIC) { - throw new MicChannelSupportOnly(); + throw new MicChannelSupportOnlyException(); } JsonDocument streamRedirections = new HttpFetcher().Provide("streamRedirections"); @@ -199,7 +199,7 @@ public void SetStreamerPlaybackDevice(string deviceId, Channel channel = Channel { if (channel != Channel.MIC) { - throw new MicChannelSupportOnly(); + throw new MicChannelSupportOnlyException(); } new HttpFetcher().Put("streamRedirections/" + channel.ToDictKey(ChannelMapChoice.ChannelDict) +"/deviceId/" + deviceId); diff --git a/SteelSeriesAPI/Sonar/SonarSocket.cs b/SteelSeriesAPI/Sonar/SonarSocket.cs index 6bd5631..4d28201 100644 --- a/SteelSeriesAPI/Sonar/SonarSocket.cs +++ b/SteelSeriesAPI/Sonar/SonarSocket.cs @@ -48,7 +48,7 @@ public bool Listen() { if (!IsConnected) { - throw new SonarListenerNotConnected(); + throw new SonarListenerNotConnectedException(); } _listenerThread.Start(); From 9e16e258a2664d6adf70d2f38881e52ac09a58d1 Mon Sep 17 00:00:00 2001 From: DataNext Date: Fri, 25 Apr 2025 22:57:33 +0200 Subject: [PATCH 03/12] Added Manager for routed processes --- SteelSeriesAPI.Tests/Program.cs | 4 +- SteelSeriesAPI/Sonar/Http/SonarHttpCommand.cs | 27 ------- .../Sonar/Http/SonarHttpProvider.cs | 36 --------- .../Sonar/Interfaces/ISonarCommandHandler.cs | 7 -- .../Sonar/Interfaces/ISonarDataProvider.cs | 7 -- .../Managers/IRoutedProcessManager.cs | 21 ++++++ .../Sonar/Managers/RoutedProcessManager.cs | 75 +++++++++++++++++++ SteelSeriesAPI/Sonar/SonarBridge.cs | 12 +-- 8 files changed, 100 insertions(+), 89 deletions(-) create mode 100644 SteelSeriesAPI/Sonar/Interfaces/Managers/IRoutedProcessManager.cs create mode 100644 SteelSeriesAPI/Sonar/Managers/RoutedProcessManager.cs diff --git a/SteelSeriesAPI.Tests/Program.cs b/SteelSeriesAPI.Tests/Program.cs index d67f076..85b529d 100644 --- a/SteelSeriesAPI.Tests/Program.cs +++ b/SteelSeriesAPI.Tests/Program.cs @@ -207,7 +207,7 @@ void GetTest(SonarBridge sonarManager) } Console.WriteLine("-- " + device); - foreach (var routed in sonarManager.GetRoutedProcess(device)) + foreach (var routed in sonarManager.RoutedProcesses.GetRoutedProcesses(device)) { Console.WriteLine(routed.Id + ", " + routed.ProcessName + ", " + routed.PId + ", " + routed.State + ", " + routed.DisplayName); @@ -232,7 +232,7 @@ void SetTest(SonarBridge sonarManager){ sonarManager.SetRedirectionState(true, Channel.MEDIA, Mix.STREAM); sonarManager.SetAudienceMonitoringState(false); - sonarManager.SetProcessToDeviceRouting(19152, Channel.MIC); + sonarManager.RoutedProcesses.RouteProcessToChannel(19152, Channel.MIC); } static void OnModeChangeHandler(object? sender, SonarModeEvent eventArgs) diff --git a/SteelSeriesAPI/Sonar/Http/SonarHttpCommand.cs b/SteelSeriesAPI/Sonar/Http/SonarHttpCommand.cs index bd92157..9c07a0a 100644 --- a/SteelSeriesAPI/Sonar/Http/SonarHttpCommand.cs +++ b/SteelSeriesAPI/Sonar/Http/SonarHttpCommand.cs @@ -33,31 +33,4 @@ public void SetAudienceMonitoringState(bool newState) { new HttpFetcher().Put("streamRedirections/isStreamMonitoringEnabled/" + newState); } - - public void SetProcessToDeviceRouting(int pId, Channel channel) - { - if (channel == Channel.MASTER) - { - throw new MasterChannelNotSupportedException(); - } - - JsonDocument audioDeviceRouting = new HttpFetcher().Provide("AudioDeviceRouting"); - - foreach (var element in audioDeviceRouting.RootElement.EnumerateArray()) - { - if (element.GetProperty("role").GetString() == channel.ToDictKey()) - { - if (channel == Channel.MIC) - { - new HttpFetcher().Put("AudioDeviceRouting/capture/" + element.GetProperty("deviceId").GetString() + "/" + pId); - break; - } - else - { - new HttpFetcher().Put("AudioDeviceRouting/render/" + element.GetProperty("deviceId").GetString() + "/" + pId); - break; - } - } - } - } } \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/Http/SonarHttpProvider.cs b/SteelSeriesAPI/Sonar/Http/SonarHttpProvider.cs index c754e7c..431a4da 100644 --- a/SteelSeriesAPI/Sonar/Http/SonarHttpProvider.cs +++ b/SteelSeriesAPI/Sonar/Http/SonarHttpProvider.cs @@ -57,40 +57,4 @@ public bool GetAudienceMonitoringState() return streamMonitoring.RootElement.GetBoolean(); } - - public IEnumerable GetRoutedProcess(Channel channel) - { - if (channel == Channel.MASTER) - { - throw new MasterChannelNotSupportedException(); - } - - JsonDocument audioDeviceRoutings = new HttpFetcher().Provide("AudioDeviceRouting"); - - foreach (var element in audioDeviceRoutings.RootElement.EnumerateArray()) - { - if (element.GetProperty("role").GetString() != channel.ToDictKey()) - { - continue; - } - - var audioSessions = element.GetProperty("audioSessions"); - - foreach (var session in audioSessions.EnumerateArray()) - { - string id = session.GetProperty("id").GetString().Split("|")[0]; - string processName = session.GetProperty("processName").GetString(); - int pId = session.GetProperty("processId").GetInt32(); - RoutedProcessState state = (RoutedProcessState)RoutedProcessStateExtensions.FromDictKey(session.GetProperty("state").GetString()); - string displayName = session.GetProperty("displayName").GetString(); - - if (processName == "Idle" && displayName == "Idle" && state == RoutedProcessState.INACTIVE && pId == 0) - { - continue; - } - - yield return new RoutedProcess(id, processName, pId, state, displayName); - } - } - } } \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/Interfaces/ISonarCommandHandler.cs b/SteelSeriesAPI/Sonar/Interfaces/ISonarCommandHandler.cs index 775efe7..0313b87 100644 --- a/SteelSeriesAPI/Sonar/Interfaces/ISonarCommandHandler.cs +++ b/SteelSeriesAPI/Sonar/Interfaces/ISonarCommandHandler.cs @@ -23,11 +23,4 @@ public interface ISonarCommandHandler ///
/// The new state, un/muted void SetAudienceMonitoringState(bool newState); - - /// - /// Redirect the audio of an app to a Sonar - /// - /// The process ID of the app - /// The Sonar you want to set the app audio - void SetProcessToDeviceRouting(int pId, Channel channel); } \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/Interfaces/ISonarDataProvider.cs b/SteelSeriesAPI/Sonar/Interfaces/ISonarDataProvider.cs index edce5d6..f7297bf 100644 --- a/SteelSeriesAPI/Sonar/Interfaces/ISonarDataProvider.cs +++ b/SteelSeriesAPI/Sonar/Interfaces/ISonarDataProvider.cs @@ -24,11 +24,4 @@ public interface ISonarDataProvider /// /// The current state, un/muted bool GetAudienceMonitoringState(); - - /// - /// Get the apps which their audio is redirected to a Sonar - /// - /// The Sonar you want the associated processes - /// A list of - IEnumerable GetRoutedProcess(Channel channel); } \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/Interfaces/Managers/IRoutedProcessManager.cs b/SteelSeriesAPI/Sonar/Interfaces/Managers/IRoutedProcessManager.cs new file mode 100644 index 0000000..03dd22d --- /dev/null +++ b/SteelSeriesAPI/Sonar/Interfaces/Managers/IRoutedProcessManager.cs @@ -0,0 +1,21 @@ +using SteelSeriesAPI.Sonar.Enums; +using SteelSeriesAPI.Sonar.Models; + +namespace SteelSeriesAPI.Sonar.Interfaces.Managers; + +public interface IRoutedProcessManager +{ + /// + /// Get the apps which their audio is redirected to a Sonar + /// + /// The Sonar you want the associated processes + /// A list of + IEnumerable GetRoutedProcesses(Channel channel); + + /// + /// Redirect the audio of an app to a Sonar + /// + /// The process ID of the app + /// The Sonar you want to set the app audio + void RouteProcessToChannel(int pId, Channel channel); +} \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/Managers/RoutedProcessManager.cs b/SteelSeriesAPI/Sonar/Managers/RoutedProcessManager.cs new file mode 100644 index 0000000..52d253d --- /dev/null +++ b/SteelSeriesAPI/Sonar/Managers/RoutedProcessManager.cs @@ -0,0 +1,75 @@ +using SteelSeriesAPI.Sonar.Exceptions; +using SteelSeriesAPI.Sonar.Enums; +using SteelSeriesAPI.Sonar.Http; +using SteelSeriesAPI.Sonar.Models; +using SteelSeriesAPI.Sonar.Interfaces.Managers; + +using System.Text.Json; + +namespace SteelSeriesAPI.Sonar.Managers; + +public class RoutedProcessManager : IRoutedProcessManager +{ + public IEnumerable GetRoutedProcesses(Channel channel) + { + if (channel == Channel.MASTER) + { + throw new MasterChannelNotSupportedException(); + } + + JsonDocument audioDeviceRoutings = new HttpFetcher().Provide("AudioDeviceRouting"); + + foreach (var element in audioDeviceRoutings.RootElement.EnumerateArray()) + { + if (element.GetProperty("role").GetString() != channel.ToDictKey()) + { + continue; + } + + var audioSessions = element.GetProperty("audioSessions"); + + foreach (var session in audioSessions.EnumerateArray()) + { + string id = session.GetProperty("id").GetString().Split("|")[0]; + string processName = session.GetProperty("processName").GetString(); + int pId = session.GetProperty("processId").GetInt32(); + RoutedProcessState state = (RoutedProcessState)RoutedProcessStateExtensions.FromDictKey(session.GetProperty("state").GetString()); + string displayName = session.GetProperty("displayName").GetString(); + + if (processName == "Idle" && displayName == "Idle" && state == RoutedProcessState.INACTIVE && pId == 0) + { + continue; + } + + yield return new RoutedProcess(id, processName, pId, state, displayName); + } + } + } + + public void RouteProcessToChannel(int pId, Channel channel) + { + if (channel == Channel.MASTER) + { + throw new MasterChannelNotSupportedException(); + } + + JsonDocument audioDeviceRouting = new HttpFetcher().Provide("AudioDeviceRouting"); + + foreach (var element in audioDeviceRouting.RootElement.EnumerateArray()) + { + if (element.GetProperty("role").GetString() == channel.ToDictKey()) + { + if (channel == Channel.MIC) + { + new HttpFetcher().Put("AudioDeviceRouting/capture/" + element.GetProperty("deviceId").GetString() + "/" + pId); + break; + } + else + { + new HttpFetcher().Put("AudioDeviceRouting/render/" + element.GetProperty("deviceId").GetString() + "/" + pId); + break; + } + } + } + } +} \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/SonarBridge.cs b/SteelSeriesAPI/Sonar/SonarBridge.cs index 8e05db0..0b40f13 100644 --- a/SteelSeriesAPI/Sonar/SonarBridge.cs +++ b/SteelSeriesAPI/Sonar/SonarBridge.cs @@ -23,6 +23,7 @@ public class SonarBridge : ISonarBridge public readonly ChatMixManager ChatMix; public readonly ConfigurationManager Configurations; public readonly PlaybackDeviceManager PlaybackDevices; + public readonly RoutedProcessManager RoutedProcesses; public readonly EventManager Events; public SonarBridge() @@ -33,6 +34,7 @@ public SonarBridge() ChatMix = new ChatMixManager(); Configurations = new ConfigurationManager(); PlaybackDevices = new PlaybackDeviceManager(); + RoutedProcesses = new RoutedProcessManager(); Events = new EventManager(); } @@ -115,11 +117,6 @@ public bool GetAudienceMonitoringState() return _sonarProvider.GetAudienceMonitoringState(); } - public IEnumerable GetRoutedProcess(Channel channel) - { - return _sonarProvider.GetRoutedProcess(channel); - } - #endregion #region Commands @@ -139,10 +136,5 @@ public void SetAudienceMonitoringState(bool newState) _sonarCommand.SetAudienceMonitoringState(newState); } - public void SetProcessToDeviceRouting(int pId, Channel channel) - { - _sonarCommand.SetProcessToDeviceRouting(pId, channel); - } - #endregion } \ No newline at end of file From d17c926e3a1a54497ae7d8852f4bcae2140b7e4c Mon Sep 17 00:00:00 2001 From: DataNext Date: Fri, 25 Apr 2025 23:01:31 +0200 Subject: [PATCH 04/12] Made the managers interfaces internal --- SteelSeriesAPI/Sonar/Interfaces/Managers/IChatMixManager.cs | 2 +- .../Sonar/Interfaces/Managers/IConfigurationManager.cs | 2 +- .../Sonar/Interfaces/Managers/IPlaybackDeviceManager.cs | 2 +- .../Sonar/Interfaces/Managers/IRoutedProcessManager.cs | 2 +- SteelSeriesAPI/Sonar/SonarBridge.cs | 2 -- 5 files changed, 4 insertions(+), 6 deletions(-) diff --git a/SteelSeriesAPI/Sonar/Interfaces/Managers/IChatMixManager.cs b/SteelSeriesAPI/Sonar/Interfaces/Managers/IChatMixManager.cs index 6e3dc1f..da719c8 100644 --- a/SteelSeriesAPI/Sonar/Interfaces/Managers/IChatMixManager.cs +++ b/SteelSeriesAPI/Sonar/Interfaces/Managers/IChatMixManager.cs @@ -1,6 +1,6 @@ namespace SteelSeriesAPI.Sonar.Interfaces.Managers; -public interface IChatMixManager +internal interface IChatMixManager { /// /// Get the actual ChatMix balance value diff --git a/SteelSeriesAPI/Sonar/Interfaces/Managers/IConfigurationManager.cs b/SteelSeriesAPI/Sonar/Interfaces/Managers/IConfigurationManager.cs index 1db642a..204698a 100644 --- a/SteelSeriesAPI/Sonar/Interfaces/Managers/IConfigurationManager.cs +++ b/SteelSeriesAPI/Sonar/Interfaces/Managers/IConfigurationManager.cs @@ -3,7 +3,7 @@ namespace SteelSeriesAPI.Sonar.Interfaces.Managers; -public interface IConfigurationManager +internal interface IConfigurationManager { /// diff --git a/SteelSeriesAPI/Sonar/Interfaces/Managers/IPlaybackDeviceManager.cs b/SteelSeriesAPI/Sonar/Interfaces/Managers/IPlaybackDeviceManager.cs index 1fc84e2..af31262 100644 --- a/SteelSeriesAPI/Sonar/Interfaces/Managers/IPlaybackDeviceManager.cs +++ b/SteelSeriesAPI/Sonar/Interfaces/Managers/IPlaybackDeviceManager.cs @@ -3,7 +3,7 @@ namespace SteelSeriesAPI.Sonar.Interfaces.Managers; -public interface IPlaybackDeviceManager +internal interface IPlaybackDeviceManager { /// /// Get all the in/output Redirection Devices (Windows devices) diff --git a/SteelSeriesAPI/Sonar/Interfaces/Managers/IRoutedProcessManager.cs b/SteelSeriesAPI/Sonar/Interfaces/Managers/IRoutedProcessManager.cs index 03dd22d..e744cc7 100644 --- a/SteelSeriesAPI/Sonar/Interfaces/Managers/IRoutedProcessManager.cs +++ b/SteelSeriesAPI/Sonar/Interfaces/Managers/IRoutedProcessManager.cs @@ -3,7 +3,7 @@ namespace SteelSeriesAPI.Sonar.Interfaces.Managers; -public interface IRoutedProcessManager +internal interface IRoutedProcessManager { /// /// Get the apps which their audio is redirected to a Sonar diff --git a/SteelSeriesAPI/Sonar/SonarBridge.cs b/SteelSeriesAPI/Sonar/SonarBridge.cs index 0b40f13..5c9d58b 100644 --- a/SteelSeriesAPI/Sonar/SonarBridge.cs +++ b/SteelSeriesAPI/Sonar/SonarBridge.cs @@ -1,10 +1,8 @@ using System.Security.Principal; -using SteelSeriesAPI.Interfaces; using SteelSeriesAPI.Sonar.Enums; using SteelSeriesAPI.Sonar.Http; using SteelSeriesAPI.Sonar.Interfaces; using SteelSeriesAPI.Sonar.Managers; -using SteelSeriesAPI.Sonar.Models; namespace SteelSeriesAPI.Sonar; From 9a61522fe5e4310c9ac5b1828de2d43a764cb33b Mon Sep 17 00:00:00 2001 From: DataNext Date: Fri, 25 Apr 2025 23:07:04 +0200 Subject: [PATCH 05/12] Added Mode manager --- SteelSeriesAPI/Sonar/Http/SonarHttpCommand.cs | 8 ------- .../Sonar/Http/SonarHttpProvider.cs | 7 ------- .../Sonar/Interfaces/ISonarCommandHandler.cs | 6 ------ .../Sonar/Interfaces/ISonarDataProvider.cs | 6 ------ .../Sonar/Interfaces/Managers/IModeManager.cs | 18 ++++++++++++++++ SteelSeriesAPI/Sonar/Managers/ModeManager.cs | 21 +++++++++++++++++++ SteelSeriesAPI/Sonar/SonarBridge.cs | 12 ++--------- 7 files changed, 41 insertions(+), 37 deletions(-) create mode 100644 SteelSeriesAPI/Sonar/Interfaces/Managers/IModeManager.cs create mode 100644 SteelSeriesAPI/Sonar/Managers/ModeManager.cs diff --git a/SteelSeriesAPI/Sonar/Http/SonarHttpCommand.cs b/SteelSeriesAPI/Sonar/Http/SonarHttpCommand.cs index 9c07a0a..9e199b3 100644 --- a/SteelSeriesAPI/Sonar/Http/SonarHttpCommand.cs +++ b/SteelSeriesAPI/Sonar/Http/SonarHttpCommand.cs @@ -15,14 +15,6 @@ public SonarHttpCommand(SonarBridge sonarBridge) _sonarBridge = sonarBridge; } - public void SetMode(Mode mode) - { - new HttpFetcher().Put("mode/" + mode.ToDictKey(ModeMapChoice.StreamDict)); - Thread.Sleep(100); // Prevent bugs/freezes/crashes - } - - - public void SetRedirectionState(bool newState, Channel channel, Mix mix) { new HttpFetcher().Put("streamRedirections/" + mix.ToDictKey() + "/redirections/" + channel.ToDictKey() + diff --git a/SteelSeriesAPI/Sonar/Http/SonarHttpProvider.cs b/SteelSeriesAPI/Sonar/Http/SonarHttpProvider.cs index 431a4da..f711448 100644 --- a/SteelSeriesAPI/Sonar/Http/SonarHttpProvider.cs +++ b/SteelSeriesAPI/Sonar/Http/SonarHttpProvider.cs @@ -9,13 +9,6 @@ namespace SteelSeriesAPI.Sonar.Http; public class SonarHttpProvider : ISonarDataProvider { - public Mode GetMode() - { - string mode = new HttpFetcher().Provide("mode").RootElement.ToString(); - - return (Mode)ModeExtensions.FromDictKey(mode, ModeMapChoice.StreamDict); - } - public bool GetRedirectionState(Channel channel, Mix mix) { if (channel == Channel.MASTER) diff --git a/SteelSeriesAPI/Sonar/Interfaces/ISonarCommandHandler.cs b/SteelSeriesAPI/Sonar/Interfaces/ISonarCommandHandler.cs index 0313b87..37eed08 100644 --- a/SteelSeriesAPI/Sonar/Interfaces/ISonarCommandHandler.cs +++ b/SteelSeriesAPI/Sonar/Interfaces/ISonarCommandHandler.cs @@ -4,12 +4,6 @@ namespace SteelSeriesAPI.Sonar.Interfaces; public interface ISonarCommandHandler { - /// - /// Set the Sonar will be using - /// - /// The you want to set - void SetMode(Mode mode); - /// /// Enable or disable the Redirection of the chosen Sonar of the chosen Sonar /// diff --git a/SteelSeriesAPI/Sonar/Interfaces/ISonarDataProvider.cs b/SteelSeriesAPI/Sonar/Interfaces/ISonarDataProvider.cs index f7297bf..57108da 100644 --- a/SteelSeriesAPI/Sonar/Interfaces/ISonarDataProvider.cs +++ b/SteelSeriesAPI/Sonar/Interfaces/ISonarDataProvider.cs @@ -5,12 +5,6 @@ namespace SteelSeriesAPI.Sonar.Interfaces; public interface ISonarDataProvider { - /// - /// Get the current mode used by Sonar - /// - /// A , either Classic or Streamer - Mode GetMode(); - /// /// Get the mute state of the Redirection of the chosen Sonar of the chosen Sonar /// diff --git a/SteelSeriesAPI/Sonar/Interfaces/Managers/IModeManager.cs b/SteelSeriesAPI/Sonar/Interfaces/Managers/IModeManager.cs new file mode 100644 index 0000000..f01f412 --- /dev/null +++ b/SteelSeriesAPI/Sonar/Interfaces/Managers/IModeManager.cs @@ -0,0 +1,18 @@ +using SteelSeriesAPI.Sonar.Enums; + +namespace SteelSeriesAPI.Sonar.Interfaces.Managers; + +internal interface IModeManager +{ + /// + /// Get the current mode used by Sonar + /// + /// A , either Classic or Streamer + Mode Get(); + + /// + /// Set the Sonar will be using + /// + /// The you want to set + void Set(Mode mode); +} \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/Managers/ModeManager.cs b/SteelSeriesAPI/Sonar/Managers/ModeManager.cs new file mode 100644 index 0000000..1595164 --- /dev/null +++ b/SteelSeriesAPI/Sonar/Managers/ModeManager.cs @@ -0,0 +1,21 @@ +using SteelSeriesAPI.Sonar.Enums; +using SteelSeriesAPI.Sonar.Http; +using SteelSeriesAPI.Sonar.Interfaces.Managers; + +namespace SteelSeriesAPI.Sonar.Managers; + +public class ModeManager : IModeManager +{ + public Mode Get() + { + string mode = new HttpFetcher().Provide("mode").RootElement.ToString(); + + return (Mode)ModeExtensions.FromDictKey(mode, ModeMapChoice.StreamDict); + } + + public void Set(Mode mode) + { + new HttpFetcher().Put("mode/" + mode.ToDictKey(ModeMapChoice.StreamDict)); + Thread.Sleep(100); // Prevent bugs/freezes/crashes + } +} \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/SonarBridge.cs b/SteelSeriesAPI/Sonar/SonarBridge.cs index 5c9d58b..9920a8a 100644 --- a/SteelSeriesAPI/Sonar/SonarBridge.cs +++ b/SteelSeriesAPI/Sonar/SonarBridge.cs @@ -17,6 +17,7 @@ public class SonarBridge : ISonarBridge private readonly ISonarDataProvider _sonarProvider; private ISonarSocket _sonarSocket; + public readonly ModeManager Mode; public readonly VolumeSettingsManager VolumeSettings; public readonly ChatMixManager ChatMix; public readonly ConfigurationManager Configurations; @@ -28,6 +29,7 @@ public SonarBridge() { _sonarCommand = new SonarHttpCommand(this); _sonarProvider = new SonarHttpProvider(); + Mode = new ModeManager(); VolumeSettings = new VolumeSettingsManager(); ChatMix = new ChatMixManager(); Configurations = new ConfigurationManager(); @@ -100,11 +102,6 @@ public void WaitUntilSonarStarted() #region Providers - public Mode GetMode() - { - return _sonarProvider.GetMode(); - } - public bool GetRedirectionState(Channel channel, Mix mix) { return _sonarProvider.GetRedirectionState(channel, mix); @@ -118,11 +115,6 @@ public bool GetAudienceMonitoringState() #endregion #region Commands - - public void SetMode(Mode mode) - { - _sonarCommand.SetMode(mode); - } public void SetRedirectionState(bool newState, Channel channel, Mix mix) { From e38dc3f20add6cfcdb7e6316b7de986bf65bc6a1 Mon Sep 17 00:00:00 2001 From: DataNext Date: Fri, 25 Apr 2025 23:12:29 +0200 Subject: [PATCH 06/12] Added Redirection State Manager --- SteelSeriesAPI/Sonar/Http/SonarHttpCommand.cs | 13 ----- .../Sonar/Http/SonarHttpProvider.cs | 35 ------------- .../Sonar/Interfaces/ISonarCommandHandler.cs | 8 --- .../Sonar/Interfaces/ISonarDataProvider.cs | 8 --- .../Managers/IRedirectionStateManager.cs | 22 ++++++++ .../Sonar/Managers/RedirectionStateManager.cs | 52 +++++++++++++++++++ SteelSeriesAPI/Sonar/SonarBridge.cs | 14 ++--- 7 files changed, 77 insertions(+), 75 deletions(-) create mode 100644 SteelSeriesAPI/Sonar/Interfaces/Managers/IRedirectionStateManager.cs create mode 100644 SteelSeriesAPI/Sonar/Managers/RedirectionStateManager.cs diff --git a/SteelSeriesAPI/Sonar/Http/SonarHttpCommand.cs b/SteelSeriesAPI/Sonar/Http/SonarHttpCommand.cs index 9e199b3..15f9fca 100644 --- a/SteelSeriesAPI/Sonar/Http/SonarHttpCommand.cs +++ b/SteelSeriesAPI/Sonar/Http/SonarHttpCommand.cs @@ -8,19 +8,6 @@ namespace SteelSeriesAPI.Sonar.Http; public class SonarHttpCommand : ISonarCommandHandler { - private readonly ISonarBridge _sonarBridge; - - public SonarHttpCommand(SonarBridge sonarBridge) - { - _sonarBridge = sonarBridge; - } - - public void SetRedirectionState(bool newState, Channel channel, Mix mix) - { - new HttpFetcher().Put("streamRedirections/" + mix.ToDictKey() + "/redirections/" + channel.ToDictKey() + - "/isEnabled/" + newState); - } - public void SetAudienceMonitoringState(bool newState) { new HttpFetcher().Put("streamRedirections/isStreamMonitoringEnabled/" + newState); diff --git a/SteelSeriesAPI/Sonar/Http/SonarHttpProvider.cs b/SteelSeriesAPI/Sonar/Http/SonarHttpProvider.cs index f711448..fe7dd45 100644 --- a/SteelSeriesAPI/Sonar/Http/SonarHttpProvider.cs +++ b/SteelSeriesAPI/Sonar/Http/SonarHttpProvider.cs @@ -9,41 +9,6 @@ namespace SteelSeriesAPI.Sonar.Http; public class SonarHttpProvider : ISonarDataProvider { - public bool GetRedirectionState(Channel channel, Mix mix) - { - if (channel == Channel.MASTER) - { - throw new MasterChannelNotSupportedException(); - } - - JsonDocument streamRedirections = new HttpFetcher().Provide("streamRedirections"); - JsonElement streamChannel = default; - - foreach (var element in streamRedirections.RootElement.EnumerateArray()) - { - if (element.GetProperty("streamRedirectionId").GetString() == mix.ToDictKey()) - { - streamChannel = element; - break; - } - } - - JsonElement status = default; - - foreach (var element in streamChannel.GetProperty("status").EnumerateArray()) - { - if (element.GetProperty("role").GetString() == channel.ToDictKey()) - { - status = element; - break; - } - } - - bool state = status.GetProperty("isEnabled").GetBoolean(); - - return state; - } - public bool GetAudienceMonitoringState() { JsonDocument streamMonitoring = new HttpFetcher().Provide("streamRedirections/isStreamMonitoringEnabled"); diff --git a/SteelSeriesAPI/Sonar/Interfaces/ISonarCommandHandler.cs b/SteelSeriesAPI/Sonar/Interfaces/ISonarCommandHandler.cs index 37eed08..d89f592 100644 --- a/SteelSeriesAPI/Sonar/Interfaces/ISonarCommandHandler.cs +++ b/SteelSeriesAPI/Sonar/Interfaces/ISonarCommandHandler.cs @@ -4,14 +4,6 @@ namespace SteelSeriesAPI.Sonar.Interfaces; public interface ISonarCommandHandler { - /// - /// Enable or disable the Redirection of the chosen Sonar of the chosen Sonar - /// - /// The new state of the Redirection - /// The Sonar you want to un/mute a Sonar redirection mix - /// The Sonar you want to un/mute - void SetRedirectionState(bool newState, Channel channel, Mix mix); - /// /// Listen to what your audience hear /// diff --git a/SteelSeriesAPI/Sonar/Interfaces/ISonarDataProvider.cs b/SteelSeriesAPI/Sonar/Interfaces/ISonarDataProvider.cs index 57108da..957cc01 100644 --- a/SteelSeriesAPI/Sonar/Interfaces/ISonarDataProvider.cs +++ b/SteelSeriesAPI/Sonar/Interfaces/ISonarDataProvider.cs @@ -5,14 +5,6 @@ namespace SteelSeriesAPI.Sonar.Interfaces; public interface ISonarDataProvider { - /// - /// Get the mute state of the Redirection of the chosen Sonar of the chosen Sonar - /// - /// The Sonar you want the mute state of a Redirection mix - /// The Sonar you want to get the mute state - /// The current state, un/muted - bool GetRedirectionState(Channel channel, Mix mix); - /// /// Get the current state of the Audience Monitoring /// diff --git a/SteelSeriesAPI/Sonar/Interfaces/Managers/IRedirectionStateManager.cs b/SteelSeriesAPI/Sonar/Interfaces/Managers/IRedirectionStateManager.cs new file mode 100644 index 0000000..c64c4d5 --- /dev/null +++ b/SteelSeriesAPI/Sonar/Interfaces/Managers/IRedirectionStateManager.cs @@ -0,0 +1,22 @@ +using SteelSeriesAPI.Sonar.Enums; + +namespace SteelSeriesAPI.Sonar.Interfaces.Managers; + +internal interface IRedirectionStateManager +{ + /// + /// Get the mute state of the Redirection of the chosen Sonar of the chosen Sonar + /// + /// The Sonar you want the mute state of a Redirection mix + /// The Sonar you want to get the mute state + /// The current state, un/muted + bool Get(Channel channel, Mix mix); + + /// + /// Enable or disable the Redirection of the chosen Sonar of the chosen Sonar + /// + /// The new state of the Redirection + /// The Sonar you want to un/mute a Sonar redirection mix + /// The Sonar you want to un/mute + void Set(bool newState, Channel channel, Mix mix); +} \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/Managers/RedirectionStateManager.cs b/SteelSeriesAPI/Sonar/Managers/RedirectionStateManager.cs new file mode 100644 index 0000000..352e6c1 --- /dev/null +++ b/SteelSeriesAPI/Sonar/Managers/RedirectionStateManager.cs @@ -0,0 +1,52 @@ +using SteelSeriesAPI.Sonar.Exceptions; +using SteelSeriesAPI.Sonar.Enums; +using SteelSeriesAPI.Sonar.Http; +using SteelSeriesAPI.Sonar.Interfaces.Managers; + +using System.Text.Json; + +namespace SteelSeriesAPI.Sonar.Managers; + +public class RedirectionStateManager : IRedirectionStateManager +{ + public bool Get(Channel channel, Mix mix) + { + if (channel == Channel.MASTER) + { + throw new MasterChannelNotSupportedException(); + } + + JsonDocument streamRedirections = new HttpFetcher().Provide("streamRedirections"); + JsonElement streamChannel = default; + + foreach (var element in streamRedirections.RootElement.EnumerateArray()) + { + if (element.GetProperty("streamRedirectionId").GetString() == mix.ToDictKey()) + { + streamChannel = element; + break; + } + } + + JsonElement status = default; + + foreach (var element in streamChannel.GetProperty("status").EnumerateArray()) + { + if (element.GetProperty("role").GetString() == channel.ToDictKey()) + { + status = element; + break; + } + } + + bool state = status.GetProperty("isEnabled").GetBoolean(); + + return state; + } + + public void Set(bool newState, Channel channel, Mix mix) + { + new HttpFetcher().Put("streamRedirections/" + mix.ToDictKey() + "/redirections/" + channel.ToDictKey() + + "/isEnabled/" + newState); + } +} \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/SonarBridge.cs b/SteelSeriesAPI/Sonar/SonarBridge.cs index 9920a8a..218e273 100644 --- a/SteelSeriesAPI/Sonar/SonarBridge.cs +++ b/SteelSeriesAPI/Sonar/SonarBridge.cs @@ -22,18 +22,20 @@ public class SonarBridge : ISonarBridge public readonly ChatMixManager ChatMix; public readonly ConfigurationManager Configurations; public readonly PlaybackDeviceManager PlaybackDevices; + public readonly RedirectionStateManager RedirectionStates; public readonly RoutedProcessManager RoutedProcesses; public readonly EventManager Events; public SonarBridge() { - _sonarCommand = new SonarHttpCommand(this); + _sonarCommand = new SonarHttpCommand(); _sonarProvider = new SonarHttpProvider(); Mode = new ModeManager(); VolumeSettings = new VolumeSettingsManager(); ChatMix = new ChatMixManager(); Configurations = new ConfigurationManager(); PlaybackDevices = new PlaybackDeviceManager(); + RedirectionStates = new RedirectionStateManager(); RoutedProcesses = new RoutedProcessManager(); Events = new EventManager(); } @@ -102,11 +104,6 @@ public void WaitUntilSonarStarted() #region Providers - public bool GetRedirectionState(Channel channel, Mix mix) - { - return _sonarProvider.GetRedirectionState(channel, mix); - } - public bool GetAudienceMonitoringState() { return _sonarProvider.GetAudienceMonitoringState(); @@ -115,11 +112,6 @@ public bool GetAudienceMonitoringState() #endregion #region Commands - - public void SetRedirectionState(bool newState, Channel channel, Mix mix) - { - _sonarCommand.SetRedirectionState(newState, channel, mix); - } public void SetAudienceMonitoringState(bool newState) { From c1971e3e6bcd53133a128580b2057defc2e04d76 Mon Sep 17 00:00:00 2001 From: DataNext Date: Fri, 25 Apr 2025 23:18:29 +0200 Subject: [PATCH 07/12] Added Audience Monitoring Manager and removed old Sonar http command and provider as well as their interfaces --- SteelSeriesAPI/Sonar/Http/SonarHttpCommand.cs | 15 ------------ .../Sonar/Http/SonarHttpProvider.cs | 18 -------------- .../Sonar/Interfaces/ISonarBridge.cs | 2 +- .../Sonar/Interfaces/ISonarCommandHandler.cs | 12 ---------- .../Sonar/Interfaces/ISonarDataProvider.cs | 13 ---------- .../Managers/IAudienceMonitoringManager.cs | 16 +++++++++++++ .../Managers/AudienceMonitoringManager.cs | 21 ++++++++++++++++ SteelSeriesAPI/Sonar/SonarBridge.cs | 24 ++----------------- 8 files changed, 40 insertions(+), 81 deletions(-) delete mode 100644 SteelSeriesAPI/Sonar/Http/SonarHttpCommand.cs delete mode 100644 SteelSeriesAPI/Sonar/Http/SonarHttpProvider.cs delete mode 100644 SteelSeriesAPI/Sonar/Interfaces/ISonarCommandHandler.cs delete mode 100644 SteelSeriesAPI/Sonar/Interfaces/ISonarDataProvider.cs create mode 100644 SteelSeriesAPI/Sonar/Interfaces/Managers/IAudienceMonitoringManager.cs create mode 100644 SteelSeriesAPI/Sonar/Managers/AudienceMonitoringManager.cs diff --git a/SteelSeriesAPI/Sonar/Http/SonarHttpCommand.cs b/SteelSeriesAPI/Sonar/Http/SonarHttpCommand.cs deleted file mode 100644 index 15f9fca..0000000 --- a/SteelSeriesAPI/Sonar/Http/SonarHttpCommand.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System.Globalization; -using System.Text.Json; -using SteelSeriesAPI.Sonar.Interfaces; -using SteelSeriesAPI.Sonar.Enums; -using SteelSeriesAPI.Sonar.Exceptions; - -namespace SteelSeriesAPI.Sonar.Http; - -public class SonarHttpCommand : ISonarCommandHandler -{ - public void SetAudienceMonitoringState(bool newState) - { - new HttpFetcher().Put("streamRedirections/isStreamMonitoringEnabled/" + newState); - } -} \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/Http/SonarHttpProvider.cs b/SteelSeriesAPI/Sonar/Http/SonarHttpProvider.cs deleted file mode 100644 index fe7dd45..0000000 --- a/SteelSeriesAPI/Sonar/Http/SonarHttpProvider.cs +++ /dev/null @@ -1,18 +0,0 @@ -using System.Collections; -using System.Text.Json; -using SteelSeriesAPI.Sonar.Interfaces; -using SteelSeriesAPI.Sonar.Enums; -using SteelSeriesAPI.Sonar.Exceptions; -using SteelSeriesAPI.Sonar.Models; - -namespace SteelSeriesAPI.Sonar.Http; - -public class SonarHttpProvider : ISonarDataProvider -{ - public bool GetAudienceMonitoringState() - { - JsonDocument streamMonitoring = new HttpFetcher().Provide("streamRedirections/isStreamMonitoringEnabled"); - - return streamMonitoring.RootElement.GetBoolean(); - } -} \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/Interfaces/ISonarBridge.cs b/SteelSeriesAPI/Sonar/Interfaces/ISonarBridge.cs index a6c80e6..23cc498 100644 --- a/SteelSeriesAPI/Sonar/Interfaces/ISonarBridge.cs +++ b/SteelSeriesAPI/Sonar/Interfaces/ISonarBridge.cs @@ -1,6 +1,6 @@ namespace SteelSeriesAPI.Sonar.Interfaces; -public interface ISonarBridge : ISonarDataProvider, ISonarCommandHandler +public interface ISonarBridge { /// /// The running state of Sonar diff --git a/SteelSeriesAPI/Sonar/Interfaces/ISonarCommandHandler.cs b/SteelSeriesAPI/Sonar/Interfaces/ISonarCommandHandler.cs deleted file mode 100644 index d89f592..0000000 --- a/SteelSeriesAPI/Sonar/Interfaces/ISonarCommandHandler.cs +++ /dev/null @@ -1,12 +0,0 @@ -using SteelSeriesAPI.Sonar.Enums; - -namespace SteelSeriesAPI.Sonar.Interfaces; - -public interface ISonarCommandHandler -{ - /// - /// Listen to what your audience hear - /// - /// The new state, un/muted - void SetAudienceMonitoringState(bool newState); -} \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/Interfaces/ISonarDataProvider.cs b/SteelSeriesAPI/Sonar/Interfaces/ISonarDataProvider.cs deleted file mode 100644 index 957cc01..0000000 --- a/SteelSeriesAPI/Sonar/Interfaces/ISonarDataProvider.cs +++ /dev/null @@ -1,13 +0,0 @@ -using SteelSeriesAPI.Sonar.Enums; -using SteelSeriesAPI.Sonar.Models; - -namespace SteelSeriesAPI.Sonar.Interfaces; - -public interface ISonarDataProvider -{ - /// - /// Get the current state of the Audience Monitoring - /// - /// The current state, un/muted - bool GetAudienceMonitoringState(); -} \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/Interfaces/Managers/IAudienceMonitoringManager.cs b/SteelSeriesAPI/Sonar/Interfaces/Managers/IAudienceMonitoringManager.cs new file mode 100644 index 0000000..87e0dad --- /dev/null +++ b/SteelSeriesAPI/Sonar/Interfaces/Managers/IAudienceMonitoringManager.cs @@ -0,0 +1,16 @@ +namespace SteelSeriesAPI.Sonar.Interfaces.Managers; + +public interface IAudienceMonitoringManager +{ + /// + /// Get the current state of the Audience Monitoring + /// + /// The current state, un/muted + bool GetState(); + + /// + /// Listen to what your audience hear + /// + /// The new state, un/muted + void SetState(bool newState); +} \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/Managers/AudienceMonitoringManager.cs b/SteelSeriesAPI/Sonar/Managers/AudienceMonitoringManager.cs new file mode 100644 index 0000000..635e1cc --- /dev/null +++ b/SteelSeriesAPI/Sonar/Managers/AudienceMonitoringManager.cs @@ -0,0 +1,21 @@ +using SteelSeriesAPI.Sonar.Http; +using SteelSeriesAPI.Sonar.Interfaces.Managers; + +using System.Text.Json; + +namespace SteelSeriesAPI.Sonar.Managers; + +public class AudienceMonitoringManager : IAudienceMonitoringManager +{ + public bool GetState() + { + JsonDocument streamMonitoring = new HttpFetcher().Provide("streamRedirections/isStreamMonitoringEnabled"); + + return streamMonitoring.RootElement.GetBoolean(); + } + + public void SetState(bool newState) + { + new HttpFetcher().Put("streamRedirections/isStreamMonitoringEnabled/" + newState); + } +} \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/SonarBridge.cs b/SteelSeriesAPI/Sonar/SonarBridge.cs index 218e273..4fdb362 100644 --- a/SteelSeriesAPI/Sonar/SonarBridge.cs +++ b/SteelSeriesAPI/Sonar/SonarBridge.cs @@ -13,8 +13,6 @@ public class SonarBridge : ISonarBridge { public bool IsRunning => SonarRetriever.Instance is { IsEnabled: true, IsReady: true, IsRunning: true }; - private readonly ISonarCommandHandler _sonarCommand; - private readonly ISonarDataProvider _sonarProvider; private ISonarSocket _sonarSocket; public readonly ModeManager Mode; @@ -23,19 +21,19 @@ public class SonarBridge : ISonarBridge public readonly ConfigurationManager Configurations; public readonly PlaybackDeviceManager PlaybackDevices; public readonly RedirectionStateManager RedirectionStates; + public readonly AudienceMonitoringManager AudienceMonitoring; public readonly RoutedProcessManager RoutedProcesses; public readonly EventManager Events; public SonarBridge() { - _sonarCommand = new SonarHttpCommand(); - _sonarProvider = new SonarHttpProvider(); Mode = new ModeManager(); VolumeSettings = new VolumeSettingsManager(); ChatMix = new ChatMixManager(); Configurations = new ConfigurationManager(); PlaybackDevices = new PlaybackDeviceManager(); RedirectionStates = new RedirectionStateManager(); + AudienceMonitoring = new AudienceMonitoringManager(); RoutedProcesses = new RoutedProcessManager(); Events = new EventManager(); } @@ -101,22 +99,4 @@ public void WaitUntilSonarStarted() { SonarRetriever.Instance.WaitUntilAppStarted(); } - - #region Providers - - public bool GetAudienceMonitoringState() - { - return _sonarProvider.GetAudienceMonitoringState(); - } - - #endregion - - #region Commands - - public void SetAudienceMonitoringState(bool newState) - { - _sonarCommand.SetAudienceMonitoringState(newState); - } - - #endregion } \ No newline at end of file From ba5b6a8135ce024be3f85873d34f5f90aa3d6c9a Mon Sep 17 00:00:00 2001 From: DataNext Date: Sat, 26 Apr 2025 02:32:12 +0200 Subject: [PATCH 08/12] Renamed HttpFetcher to simply Fetcher --- .../Sonar/Http/{HttpFetcher.cs => Fetcher.cs} | 4 +-- .../Managers/AudienceMonitoringManager.cs | 4 +-- .../Sonar/Managers/ChatMixManager.cs | 6 ++--- .../Sonar/Managers/ConfigurationManager.cs | 6 ++--- SteelSeriesAPI/Sonar/Managers/ModeManager.cs | 4 +-- .../Sonar/Managers/PlaybackDeviceManager.cs | 26 +++++++++---------- .../Sonar/Managers/RedirectionStateManager.cs | 4 +-- .../Sonar/Managers/RoutedProcessManager.cs | 8 +++--- .../Sonar/Managers/VolumeSettingsManager.cs | 16 ++++++------ 9 files changed, 39 insertions(+), 39 deletions(-) rename SteelSeriesAPI/Sonar/Http/{HttpFetcher.cs => Fetcher.cs} (97%) diff --git a/SteelSeriesAPI/Sonar/Http/HttpFetcher.cs b/SteelSeriesAPI/Sonar/Http/Fetcher.cs similarity index 97% rename from SteelSeriesAPI/Sonar/Http/HttpFetcher.cs rename to SteelSeriesAPI/Sonar/Http/Fetcher.cs index b8de29e..d405f4e 100644 --- a/SteelSeriesAPI/Sonar/Http/HttpFetcher.cs +++ b/SteelSeriesAPI/Sonar/Http/Fetcher.cs @@ -5,12 +5,12 @@ namespace SteelSeriesAPI.Sonar.Http; -public class HttpFetcher +public class Fetcher { private readonly HttpClient _httpClient; private readonly IAppRetriever _sonarRetriever; - public HttpFetcher() + public Fetcher() { _sonarRetriever = SonarRetriever.Instance; diff --git a/SteelSeriesAPI/Sonar/Managers/AudienceMonitoringManager.cs b/SteelSeriesAPI/Sonar/Managers/AudienceMonitoringManager.cs index 635e1cc..d0be916 100644 --- a/SteelSeriesAPI/Sonar/Managers/AudienceMonitoringManager.cs +++ b/SteelSeriesAPI/Sonar/Managers/AudienceMonitoringManager.cs @@ -9,13 +9,13 @@ public class AudienceMonitoringManager : IAudienceMonitoringManager { public bool GetState() { - JsonDocument streamMonitoring = new HttpFetcher().Provide("streamRedirections/isStreamMonitoringEnabled"); + JsonDocument streamMonitoring = new Fetcher().Provide("streamRedirections/isStreamMonitoringEnabled"); return streamMonitoring.RootElement.GetBoolean(); } public void SetState(bool newState) { - new HttpFetcher().Put("streamRedirections/isStreamMonitoringEnabled/" + newState); + new Fetcher().Put("streamRedirections/isStreamMonitoringEnabled/" + newState); } } \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/Managers/ChatMixManager.cs b/SteelSeriesAPI/Sonar/Managers/ChatMixManager.cs index f288615..dbbf204 100644 --- a/SteelSeriesAPI/Sonar/Managers/ChatMixManager.cs +++ b/SteelSeriesAPI/Sonar/Managers/ChatMixManager.cs @@ -11,14 +11,14 @@ public class ChatMixManager : IChatMixManager { public double GetBalance() { - JsonDocument chatMix = new HttpFetcher().Provide("chatMix"); + JsonDocument chatMix = new Fetcher().Provide("chatMix"); return chatMix.RootElement.GetProperty("balance").GetDouble(); } public bool GetState() { - JsonDocument chatMix = new HttpFetcher().Provide("chatMix"); + JsonDocument chatMix = new Fetcher().Provide("chatMix"); string cState = chatMix.RootElement.GetProperty("state").ToString(); if (cState == "enabled") @@ -41,6 +41,6 @@ public void SetBalance(double balance) throw new ChatMixBalanceException(); } - new HttpFetcher().Put("chatMix?balance=" + balance.ToString("0.00", CultureInfo.InvariantCulture)); + new Fetcher().Put("chatMix?balance=" + balance.ToString("0.00", CultureInfo.InvariantCulture)); } } \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/Managers/ConfigurationManager.cs b/SteelSeriesAPI/Sonar/Managers/ConfigurationManager.cs index b78df4e..6baecaf 100644 --- a/SteelSeriesAPI/Sonar/Managers/ConfigurationManager.cs +++ b/SteelSeriesAPI/Sonar/Managers/ConfigurationManager.cs @@ -12,7 +12,7 @@ public class ConfigurationManager : IConfigurationManager { public IEnumerable GetAllAudioConfigurations() { - JsonDocument configs = new HttpFetcher().Provide("configs"); + JsonDocument configs = new Fetcher().Provide("configs"); foreach (var element in configs.RootElement.EnumerateArray()) { @@ -69,7 +69,7 @@ public SonarAudioConfiguration GetSelectedAudioConfiguration(Channel channel) throw new MasterChannelNotSupportedException(); } - JsonDocument selectedConfigs = new HttpFetcher().Provide("configs/selected"); + JsonDocument selectedConfigs = new Fetcher().Provide("configs/selected"); JsonElement sConfig = default; foreach (var config in selectedConfigs.RootElement.EnumerateArray()) @@ -92,7 +92,7 @@ public void SetConfig(string configId) { if (string.IsNullOrEmpty(configId)) throw new ConfigNotFoundException($"No audio configuration found with this id: {configId}"); - new HttpFetcher().Put("configs/" + configId + "/select"); + new Fetcher().Put("configs/" + configId + "/select"); } public void SetConfig(SonarAudioConfiguration config) diff --git a/SteelSeriesAPI/Sonar/Managers/ModeManager.cs b/SteelSeriesAPI/Sonar/Managers/ModeManager.cs index 1595164..d393937 100644 --- a/SteelSeriesAPI/Sonar/Managers/ModeManager.cs +++ b/SteelSeriesAPI/Sonar/Managers/ModeManager.cs @@ -8,14 +8,14 @@ public class ModeManager : IModeManager { public Mode Get() { - string mode = new HttpFetcher().Provide("mode").RootElement.ToString(); + string mode = new Fetcher().Provide("mode").RootElement.ToString(); return (Mode)ModeExtensions.FromDictKey(mode, ModeMapChoice.StreamDict); } public void Set(Mode mode) { - new HttpFetcher().Put("mode/" + mode.ToDictKey(ModeMapChoice.StreamDict)); + new Fetcher().Put("mode/" + mode.ToDictKey(ModeMapChoice.StreamDict)); Thread.Sleep(100); // Prevent bugs/freezes/crashes } } \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/Managers/PlaybackDeviceManager.cs b/SteelSeriesAPI/Sonar/Managers/PlaybackDeviceManager.cs index 2607dcd..9aa1a50 100644 --- a/SteelSeriesAPI/Sonar/Managers/PlaybackDeviceManager.cs +++ b/SteelSeriesAPI/Sonar/Managers/PlaybackDeviceManager.cs @@ -13,7 +13,7 @@ public class PlaybackDeviceManager : IPlaybackDeviceManager { public IEnumerable GetPlaybackDevices(DataFlow _dataFlow) { - JsonDocument audioDevices = new HttpFetcher().Provide("audioDevices"); + JsonDocument audioDevices = new Fetcher().Provide("audioDevices"); // JsonDocument classicRedirections = new HttpProvider("classicRedirections").Provide(); // JsonDocument streamRedirections = new HttpProvider("streamRedirections").Provide(); @@ -43,7 +43,7 @@ public PlaybackDevice GetPlaybackDevice(string deviceId) { try { - JsonElement device = new HttpFetcher().Provide("audioDevices/" + deviceId).RootElement; + JsonElement device = new Fetcher().Provide("audioDevices/" + deviceId).RootElement; string id = device.GetProperty("id").GetString(); string name = device.GetProperty("friendlyName").GetString(); @@ -69,7 +69,7 @@ public PlaybackDevice GetClassicPlaybackDevice(Channel channel) throw new MasterChannelNotSupportedException(); } - JsonDocument classicRedirections = new HttpFetcher().Provide("classicRedirections"); + JsonDocument classicRedirections = new Fetcher().Provide("classicRedirections"); JsonElement cRedirections = default; foreach (var element in classicRedirections.RootElement.EnumerateArray()) @@ -87,7 +87,7 @@ public PlaybackDevice GetClassicPlaybackDevice(Channel channel) GetAssociatedChannels(deviceId, associatedClassicChannels, associatedStreamChannels); - JsonDocument audioDevice = new HttpFetcher().Provide("audioDevices/" + deviceId); + JsonDocument audioDevice = new Fetcher().Provide("audioDevices/" + deviceId); string name = audioDevice.RootElement.GetProperty("friendlyName").GetString(); DataFlow dataFlow = (DataFlow)DataFlowExtensions.FromDictKey(audioDevice.RootElement.GetProperty("dataFlow").GetString()); @@ -97,7 +97,7 @@ public PlaybackDevice GetClassicPlaybackDevice(Channel channel) public PlaybackDevice GetStreamerPlaybackDevice(Mix mix) { - JsonDocument streamRedirections = new HttpFetcher().Provide("streamRedirections"); + JsonDocument streamRedirections = new Fetcher().Provide("streamRedirections"); JsonElement sRedirections = default; foreach (var element in streamRedirections.RootElement.EnumerateArray()) @@ -115,7 +115,7 @@ public PlaybackDevice GetStreamerPlaybackDevice(Mix mix) GetAssociatedChannels(deviceId, associatedClassicChannels, associatedStreamChannels); - JsonDocument audioDevice = new HttpFetcher().Provide("audioDevices/" + deviceId); + JsonDocument audioDevice = new Fetcher().Provide("audioDevices/" + deviceId); string name = audioDevice.RootElement.GetProperty("friendlyName").GetString(); DataFlow dataFlow = (DataFlow)DataFlowExtensions.FromDictKey(audioDevice.RootElement.GetProperty("dataFlow").GetString()); @@ -130,7 +130,7 @@ public PlaybackDevice GetStreamerPlaybackDevice(Channel channel = Channel.MIC) throw new MicChannelSupportOnlyException(); } - JsonDocument streamRedirections = new HttpFetcher().Provide("streamRedirections"); + JsonDocument streamRedirections = new Fetcher().Provide("streamRedirections"); JsonElement sRedirections = default; foreach (var element in streamRedirections.RootElement.EnumerateArray()) @@ -148,7 +148,7 @@ public PlaybackDevice GetStreamerPlaybackDevice(Channel channel = Channel.MIC) GetAssociatedChannels(deviceId, associatedClassicChannels, associatedStreamChannels); - JsonDocument audioDevice = new HttpFetcher().Provide("audioDevices/" + deviceId); + JsonDocument audioDevice = new Fetcher().Provide("audioDevices/" + deviceId); string name = audioDevice.RootElement.GetProperty("friendlyName").GetString(); DataFlow dataFlow = (DataFlow)DataFlowExtensions.FromDictKey(audioDevice.RootElement.GetProperty("dataFlow").GetString()); @@ -158,8 +158,8 @@ public PlaybackDevice GetStreamerPlaybackDevice(Channel channel = Channel.MIC) private void GetAssociatedChannels(string deviceId, List associatedClassicDevices, ArrayList associatedStreamDevices) { - JsonDocument classicRedirections = new HttpFetcher().Provide("classicRedirections"); - JsonDocument streamRedirections = new HttpFetcher().Provide("streamRedirections"); + JsonDocument classicRedirections = new Fetcher().Provide("classicRedirections"); + JsonDocument streamRedirections = new Fetcher().Provide("streamRedirections"); foreach (var element in classicRedirections.RootElement.EnumerateArray()) { @@ -187,12 +187,12 @@ private void GetAssociatedChannels(string deviceId, List associatedClas public void SetClassicPlaybackDevice(string deviceId, Channel channel) { - new HttpFetcher().Put("classicRedirections/" + channel.ToDictKey(ChannelMapChoice.ChannelDict) +"/deviceId/" + deviceId); + new Fetcher().Put("classicRedirections/" + channel.ToDictKey(ChannelMapChoice.ChannelDict) +"/deviceId/" + deviceId); } public void SetStreamerPlaybackDevice(string deviceId, Mix mix) { - new HttpFetcher().Put("streamRedirections/" + mix.ToDictKey() +"/deviceId/" + deviceId); + new Fetcher().Put("streamRedirections/" + mix.ToDictKey() +"/deviceId/" + deviceId); } public void SetStreamerPlaybackDevice(string deviceId, Channel channel = Channel.MIC) @@ -202,7 +202,7 @@ public void SetStreamerPlaybackDevice(string deviceId, Channel channel = Channel throw new MicChannelSupportOnlyException(); } - new HttpFetcher().Put("streamRedirections/" + channel.ToDictKey(ChannelMapChoice.ChannelDict) +"/deviceId/" + deviceId); + new Fetcher().Put("streamRedirections/" + channel.ToDictKey(ChannelMapChoice.ChannelDict) +"/deviceId/" + deviceId); } public void SetClassicPlaybackDevice(PlaybackDevice playbackDevice, Channel channel) diff --git a/SteelSeriesAPI/Sonar/Managers/RedirectionStateManager.cs b/SteelSeriesAPI/Sonar/Managers/RedirectionStateManager.cs index 352e6c1..d6e9576 100644 --- a/SteelSeriesAPI/Sonar/Managers/RedirectionStateManager.cs +++ b/SteelSeriesAPI/Sonar/Managers/RedirectionStateManager.cs @@ -16,7 +16,7 @@ public bool Get(Channel channel, Mix mix) throw new MasterChannelNotSupportedException(); } - JsonDocument streamRedirections = new HttpFetcher().Provide("streamRedirections"); + JsonDocument streamRedirections = new Fetcher().Provide("streamRedirections"); JsonElement streamChannel = default; foreach (var element in streamRedirections.RootElement.EnumerateArray()) @@ -46,7 +46,7 @@ public bool Get(Channel channel, Mix mix) public void Set(bool newState, Channel channel, Mix mix) { - new HttpFetcher().Put("streamRedirections/" + mix.ToDictKey() + "/redirections/" + channel.ToDictKey() + + new Fetcher().Put("streamRedirections/" + mix.ToDictKey() + "/redirections/" + channel.ToDictKey() + "/isEnabled/" + newState); } } \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/Managers/RoutedProcessManager.cs b/SteelSeriesAPI/Sonar/Managers/RoutedProcessManager.cs index 52d253d..68c12a9 100644 --- a/SteelSeriesAPI/Sonar/Managers/RoutedProcessManager.cs +++ b/SteelSeriesAPI/Sonar/Managers/RoutedProcessManager.cs @@ -17,7 +17,7 @@ public IEnumerable GetRoutedProcesses(Channel channel) throw new MasterChannelNotSupportedException(); } - JsonDocument audioDeviceRoutings = new HttpFetcher().Provide("AudioDeviceRouting"); + JsonDocument audioDeviceRoutings = new Fetcher().Provide("AudioDeviceRouting"); foreach (var element in audioDeviceRoutings.RootElement.EnumerateArray()) { @@ -53,7 +53,7 @@ public void RouteProcessToChannel(int pId, Channel channel) throw new MasterChannelNotSupportedException(); } - JsonDocument audioDeviceRouting = new HttpFetcher().Provide("AudioDeviceRouting"); + JsonDocument audioDeviceRouting = new Fetcher().Provide("AudioDeviceRouting"); foreach (var element in audioDeviceRouting.RootElement.EnumerateArray()) { @@ -61,12 +61,12 @@ public void RouteProcessToChannel(int pId, Channel channel) { if (channel == Channel.MIC) { - new HttpFetcher().Put("AudioDeviceRouting/capture/" + element.GetProperty("deviceId").GetString() + "/" + pId); + new Fetcher().Put("AudioDeviceRouting/capture/" + element.GetProperty("deviceId").GetString() + "/" + pId); break; } else { - new HttpFetcher().Put("AudioDeviceRouting/render/" + element.GetProperty("deviceId").GetString() + "/" + pId); + new Fetcher().Put("AudioDeviceRouting/render/" + element.GetProperty("deviceId").GetString() + "/" + pId); break; } } diff --git a/SteelSeriesAPI/Sonar/Managers/VolumeSettingsManager.cs b/SteelSeriesAPI/Sonar/Managers/VolumeSettingsManager.cs index 5c97803..01520aa 100644 --- a/SteelSeriesAPI/Sonar/Managers/VolumeSettingsManager.cs +++ b/SteelSeriesAPI/Sonar/Managers/VolumeSettingsManager.cs @@ -12,7 +12,7 @@ public class VolumeSettingsManager : IVolumeSettingsManager // volume = 0,00000000 <-- 8 decimal max public double GetVolume(Channel channel) { - JsonDocument volumeSettings = new HttpFetcher().Provide("volumeSettings/classic/"); + JsonDocument volumeSettings = new Fetcher().Provide("volumeSettings/classic/"); if (channel == Channel.MASTER) return volumeSettings.RootElement.GetProperty("masters").GetProperty("classic").GetProperty("volume").GetDouble(); @@ -21,7 +21,7 @@ public double GetVolume(Channel channel) public double GetVolume(Channel channel, Mix mix) { - JsonDocument volumeSettings = new HttpFetcher().Provide("volumeSettings/streamer/"); + JsonDocument volumeSettings = new Fetcher().Provide("volumeSettings/streamer/"); if (channel == Channel.MASTER) return volumeSettings.RootElement.GetProperty("masters").GetProperty("stream").GetProperty(mix.ToDictKey()).GetProperty("volume").GetDouble(); @@ -30,7 +30,7 @@ public double GetVolume(Channel channel, Mix mix) public bool GetMute(Channel channel) { - JsonDocument volumeSettings = new HttpFetcher().Provide("volumeSettings/classic/"); + JsonDocument volumeSettings = new Fetcher().Provide("volumeSettings/classic/"); if (channel == Channel.MASTER) return volumeSettings.RootElement.GetProperty("masters").GetProperty("classic").GetProperty("muted").GetBoolean(); @@ -39,7 +39,7 @@ public bool GetMute(Channel channel) public bool GetMute(Channel channel, Mix mix) { - JsonDocument volumeSettings = new HttpFetcher().Provide("volumeSettings/streamer/"); + JsonDocument volumeSettings = new Fetcher().Provide("volumeSettings/streamer/"); if (channel == Channel.MASTER) return volumeSettings.RootElement.GetProperty("masters").GetProperty("stream").GetProperty(mix.ToDictKey()).GetProperty("muted").GetBoolean(); @@ -49,22 +49,22 @@ public bool GetMute(Channel channel, Mix mix) public void SetVolume(double vol, Channel channel) { string _vol = vol.ToString("0.00", CultureInfo.InvariantCulture); - new HttpFetcher().Put("volumeSettings/classic/" + channel.ToDictKey(ChannelMapChoice.HttpDict) + "/Volume/" + _vol); + new Fetcher().Put("volumeSettings/classic/" + channel.ToDictKey(ChannelMapChoice.HttpDict) + "/Volume/" + _vol); } public void SetVolume(double vol, Channel channel, Mix mix) { string _vol = vol.ToString("0.00", CultureInfo.InvariantCulture); - new HttpFetcher().Put("volumeSettings/streamer/" + mix.ToDictKey() + "/" + channel.ToDictKey(ChannelMapChoice.HttpDict) + "/volume/" + _vol); + new Fetcher().Put("volumeSettings/streamer/" + mix.ToDictKey() + "/" + channel.ToDictKey(ChannelMapChoice.HttpDict) + "/volume/" + _vol); } public void SetMute(bool mute, Channel channel) { - new HttpFetcher().Put("volumeSettings/classic/" + channel.ToDictKey(ChannelMapChoice.HttpDict) + "/Mute/" + mute); + new Fetcher().Put("volumeSettings/classic/" + channel.ToDictKey(ChannelMapChoice.HttpDict) + "/Mute/" + mute); } public void SetMute(bool mute, Channel channel, Mix mix) { - new HttpFetcher().Put("volumeSettings/streamer/" + mix.ToDictKey() + "/" + channel.ToDictKey(ChannelMapChoice.HttpDict) + "/isMuted/" + mute); + new Fetcher().Put("volumeSettings/streamer/" + mix.ToDictKey() + "/" + channel.ToDictKey(ChannelMapChoice.HttpDict) + "/isMuted/" + mute); } } \ No newline at end of file From 1f73e54e12e426b764c5efd9689caae6eabb5faf Mon Sep 17 00:00:00 2001 From: DataNext Date: Sat, 26 Apr 2025 02:34:11 +0200 Subject: [PATCH 09/12] Made the HandleEvent method internal --- SteelSeriesAPI/Sonar/Managers/EventManager.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SteelSeriesAPI/Sonar/Managers/EventManager.cs b/SteelSeriesAPI/Sonar/Managers/EventManager.cs index b2ca772..0d0628c 100644 --- a/SteelSeriesAPI/Sonar/Managers/EventManager.cs +++ b/SteelSeriesAPI/Sonar/Managers/EventManager.cs @@ -46,7 +46,7 @@ public class EventManager /// public event EventHandler OnSonarAudienceMonitoringChange = delegate{ }; - public void HandleEvent(string path) + internal void HandleEvent(string path) { var eventMessage = PathResolver(path); switch (eventMessage) From bf937c674652a622e555d5d24b9c00a11c788a76 Mon Sep 17 00:00:00 2001 From: DataNext Date: Sat, 26 Apr 2025 05:27:51 +0200 Subject: [PATCH 10/12] Reworked RedirectionStateManager and renamed it to MixManager --- .../Exceptions/ChannelNotFoundException.cs | 8 +++ .../Sonar/Exceptions/MixNotFoundException.cs | 8 +++ .../NoStreamRedirectionSetException.cs | 8 +++ .../Sonar/Interfaces/Managers/IMixManager.cs | 39 ++++++++++++++ .../Managers/IRedirectionStateManager.cs | 22 -------- SteelSeriesAPI/Sonar/Managers/EventManager.cs | 2 +- SteelSeriesAPI/Sonar/Managers/MixManager.cs | 49 +++++++++++++++++ .../Sonar/Managers/RedirectionStateManager.cs | 52 ------------------- SteelSeriesAPI/Sonar/SonarBridge.cs | 16 +++--- 9 files changed, 121 insertions(+), 83 deletions(-) create mode 100644 SteelSeriesAPI/Sonar/Exceptions/ChannelNotFoundException.cs create mode 100644 SteelSeriesAPI/Sonar/Exceptions/MixNotFoundException.cs create mode 100644 SteelSeriesAPI/Sonar/Exceptions/NoStreamRedirectionSetException.cs create mode 100644 SteelSeriesAPI/Sonar/Interfaces/Managers/IMixManager.cs delete mode 100644 SteelSeriesAPI/Sonar/Interfaces/Managers/IRedirectionStateManager.cs create mode 100644 SteelSeriesAPI/Sonar/Managers/MixManager.cs delete mode 100644 SteelSeriesAPI/Sonar/Managers/RedirectionStateManager.cs diff --git a/SteelSeriesAPI/Sonar/Exceptions/ChannelNotFoundException.cs b/SteelSeriesAPI/Sonar/Exceptions/ChannelNotFoundException.cs new file mode 100644 index 0000000..73a5baf --- /dev/null +++ b/SteelSeriesAPI/Sonar/Exceptions/ChannelNotFoundException.cs @@ -0,0 +1,8 @@ +namespace SteelSeriesAPI.Sonar.Exceptions; + +public class ChannelNotFoundException : Exception +{ + public ChannelNotFoundException() : base("Channel could not be found.") { } + public ChannelNotFoundException(string message) : base(message) { } + public ChannelNotFoundException(string message, Exception innerException) : base(message, innerException) { } +} \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/Exceptions/MixNotFoundException.cs b/SteelSeriesAPI/Sonar/Exceptions/MixNotFoundException.cs new file mode 100644 index 0000000..65b339f --- /dev/null +++ b/SteelSeriesAPI/Sonar/Exceptions/MixNotFoundException.cs @@ -0,0 +1,8 @@ +namespace SteelSeriesAPI.Sonar.Exceptions; + +public class MixNotFoundException : Exception +{ + public MixNotFoundException() : base("Mix could not be found.") { } + public MixNotFoundException(string message) : base(message) { } + public MixNotFoundException(string message, Exception innerException) : base(message, innerException) { } +} \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/Exceptions/NoStreamRedirectionSetException.cs b/SteelSeriesAPI/Sonar/Exceptions/NoStreamRedirectionSetException.cs new file mode 100644 index 0000000..467c7de --- /dev/null +++ b/SteelSeriesAPI/Sonar/Exceptions/NoStreamRedirectionSetException.cs @@ -0,0 +1,8 @@ +namespace SteelSeriesAPI.Sonar.Exceptions; + +public class NoStreamRedirectionSetException : Exception +{ + public NoStreamRedirectionSetException() : base("No redirection was set. Check the playback devices of the streamer mode") { } + public NoStreamRedirectionSetException(string message) : base("No redirection was set. Check the playback devices of the streamer mode\n" + message) { } + public NoStreamRedirectionSetException(string message, Exception innerException) : base("No redirection was set. Check the playback devices of the streamer mode\n" + message, innerException) { } +} \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/Interfaces/Managers/IMixManager.cs b/SteelSeriesAPI/Sonar/Interfaces/Managers/IMixManager.cs new file mode 100644 index 0000000..d867d74 --- /dev/null +++ b/SteelSeriesAPI/Sonar/Interfaces/Managers/IMixManager.cs @@ -0,0 +1,39 @@ +using SteelSeriesAPI.Sonar.Enums; + +namespace SteelSeriesAPI.Sonar.Interfaces.Managers; + +/// +/// Manage the personal and stream mix for each channel +/// +public interface IMixManager +{ + /// + /// Get the state of the chosen Sonar of the chosen Sonar + /// + /// The Sonar of the + /// The Sonar you want the state of + /// The current state, activated/deactivated + bool GetState(Channel channel, Mix mix); + + /// + /// Activate or deactivate a Sonar of a Sonar + /// + /// The new state of the Mix + /// The Sonar of the + /// The Sonar you want to activate/deactivate + void SetState(bool newState, Channel channel, Mix mix); + + /// + /// Activate a Sonar of a Sonar + /// + /// The Sonar of the + /// The Sonar you want to activate + void Activate(Channel channel, Mix mix); + + /// + /// Deactivate a Sonar of a Sonar + /// + /// The Sonar of the + /// The Sonar you want to deactivate + void Deactivate(Channel channel, Mix mix); +} \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/Interfaces/Managers/IRedirectionStateManager.cs b/SteelSeriesAPI/Sonar/Interfaces/Managers/IRedirectionStateManager.cs deleted file mode 100644 index c64c4d5..0000000 --- a/SteelSeriesAPI/Sonar/Interfaces/Managers/IRedirectionStateManager.cs +++ /dev/null @@ -1,22 +0,0 @@ -using SteelSeriesAPI.Sonar.Enums; - -namespace SteelSeriesAPI.Sonar.Interfaces.Managers; - -internal interface IRedirectionStateManager -{ - /// - /// Get the mute state of the Redirection of the chosen Sonar of the chosen Sonar - /// - /// The Sonar you want the mute state of a Redirection mix - /// The Sonar you want to get the mute state - /// The current state, un/muted - bool Get(Channel channel, Mix mix); - - /// - /// Enable or disable the Redirection of the chosen Sonar of the chosen Sonar - /// - /// The new state of the Redirection - /// The Sonar you want to un/mute a Sonar redirection mix - /// The Sonar you want to un/mute - void Set(bool newState, Channel channel, Mix mix); -} \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/Managers/EventManager.cs b/SteelSeriesAPI/Sonar/Managers/EventManager.cs index 0d0628c..79f9447 100644 --- a/SteelSeriesAPI/Sonar/Managers/EventManager.cs +++ b/SteelSeriesAPI/Sonar/Managers/EventManager.cs @@ -32,7 +32,7 @@ public class EventManager public event EventHandler OnSonarChatMixChange = delegate{ }; /// - /// Notify when a redirection channel of a channel is changed + /// Notify when a playback device of a channel is changed /// public event EventHandler OnSonarPlaybackDeviceChange = delegate{ }; diff --git a/SteelSeriesAPI/Sonar/Managers/MixManager.cs b/SteelSeriesAPI/Sonar/Managers/MixManager.cs new file mode 100644 index 0000000..8c8c555 --- /dev/null +++ b/SteelSeriesAPI/Sonar/Managers/MixManager.cs @@ -0,0 +1,49 @@ +using SteelSeriesAPI.Sonar.Exceptions; +using SteelSeriesAPI.Sonar.Enums; +using SteelSeriesAPI.Sonar.Http; + +using System.Text.Json; +using SteelSeriesAPI.Sonar.Interfaces.Managers; + +namespace SteelSeriesAPI.Sonar.Managers; + +internal class MixManager : IMixManager +{ + public bool GetState(Channel channel, Mix mix) + { + JsonElement streamRedirections = new Fetcher().Provide("streamRedirections").RootElement; + + foreach (JsonElement element in streamRedirections.EnumerateArray()) + { + if (element.GetProperty("streamRedirectionId").GetString() == mix.ToDictKey()) + { + foreach (JsonElement status in element.GetProperty("status").EnumerateArray()) + { + if (status.GetProperty("role").GetString() == channel.ToDictKey()) + { + return status.GetProperty("isEnabled").GetBoolean(); + } + } + + throw new ChannelNotFoundException(); + } + } + + throw new MixNotFoundException(); + } + + public void SetState(bool newState,Channel channel, Mix mix) + { + new Fetcher().Put("streamRedirections/" + mix.ToDictKey() + "/redirections/" + channel.ToDictKey() + "/isEnabled/" + newState); + } + + public void Activate(Channel channel, Mix mix) + { + new Fetcher().Put("streamRedirections/" + mix.ToDictKey() + "/redirections/" + channel.ToDictKey() + "/isEnabled/true"); + } + + public void Deactivate(Channel channel, Mix mix) + { + new Fetcher().Put("streamRedirections/" + mix.ToDictKey() + "/redirections/" + channel.ToDictKey() + "/isEnabled/false"); + } +} \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/Managers/RedirectionStateManager.cs b/SteelSeriesAPI/Sonar/Managers/RedirectionStateManager.cs deleted file mode 100644 index d6e9576..0000000 --- a/SteelSeriesAPI/Sonar/Managers/RedirectionStateManager.cs +++ /dev/null @@ -1,52 +0,0 @@ -using SteelSeriesAPI.Sonar.Exceptions; -using SteelSeriesAPI.Sonar.Enums; -using SteelSeriesAPI.Sonar.Http; -using SteelSeriesAPI.Sonar.Interfaces.Managers; - -using System.Text.Json; - -namespace SteelSeriesAPI.Sonar.Managers; - -public class RedirectionStateManager : IRedirectionStateManager -{ - public bool Get(Channel channel, Mix mix) - { - if (channel == Channel.MASTER) - { - throw new MasterChannelNotSupportedException(); - } - - JsonDocument streamRedirections = new Fetcher().Provide("streamRedirections"); - JsonElement streamChannel = default; - - foreach (var element in streamRedirections.RootElement.EnumerateArray()) - { - if (element.GetProperty("streamRedirectionId").GetString() == mix.ToDictKey()) - { - streamChannel = element; - break; - } - } - - JsonElement status = default; - - foreach (var element in streamChannel.GetProperty("status").EnumerateArray()) - { - if (element.GetProperty("role").GetString() == channel.ToDictKey()) - { - status = element; - break; - } - } - - bool state = status.GetProperty("isEnabled").GetBoolean(); - - return state; - } - - public void Set(bool newState, Channel channel, Mix mix) - { - new Fetcher().Put("streamRedirections/" + mix.ToDictKey() + "/redirections/" + channel.ToDictKey() + - "/isEnabled/" + newState); - } -} \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/SonarBridge.cs b/SteelSeriesAPI/Sonar/SonarBridge.cs index 4fdb362..9e69fb9 100644 --- a/SteelSeriesAPI/Sonar/SonarBridge.cs +++ b/SteelSeriesAPI/Sonar/SonarBridge.cs @@ -1,9 +1,9 @@ -using System.Security.Principal; -using SteelSeriesAPI.Sonar.Enums; -using SteelSeriesAPI.Sonar.Http; -using SteelSeriesAPI.Sonar.Interfaces; +using SteelSeriesAPI.Sonar.Interfaces; +using SteelSeriesAPI.Sonar.Interfaces.Managers; using SteelSeriesAPI.Sonar.Managers; +using System.Security.Principal; + namespace SteelSeriesAPI.Sonar; /// @@ -20,9 +20,9 @@ public class SonarBridge : ISonarBridge public readonly ChatMixManager ChatMix; public readonly ConfigurationManager Configurations; public readonly PlaybackDeviceManager PlaybackDevices; - public readonly RedirectionStateManager RedirectionStates; - public readonly AudienceMonitoringManager AudienceMonitoring; public readonly RoutedProcessManager RoutedProcesses; + public readonly IMixManager Mix; + public readonly AudienceMonitoringManager AudienceMonitoring; public readonly EventManager Events; public SonarBridge() @@ -32,9 +32,9 @@ public SonarBridge() ChatMix = new ChatMixManager(); Configurations = new ConfigurationManager(); PlaybackDevices = new PlaybackDeviceManager(); - RedirectionStates = new RedirectionStateManager(); - AudienceMonitoring = new AudienceMonitoringManager(); RoutedProcesses = new RoutedProcessManager(); + Mix = new MixManager(); + AudienceMonitoring = new AudienceMonitoringManager(); Events = new EventManager(); } From bf9b8930332bfa26f8013848dbe12945cadf2944 Mon Sep 17 00:00:00 2001 From: DataNext Date: Sun, 27 Apr 2025 04:51:01 +0200 Subject: [PATCH 11/12] Reworked entirely the Routed Processes system and added events for it --- .../Sonar/Events/SonarRoutedProcessEvent.cs | 40 ++++ .../RoutedProcessNotFoundException.cs | 8 + .../Managers/IRoutedProcessManager.cs | 57 ++++- SteelSeriesAPI/Sonar/Managers/EventManager.cs | 14 ++ .../Sonar/Managers/RoutedProcessManager.cs | 197 +++++++++++++++--- SteelSeriesAPI/Sonar/Models/RoutedProcess.cs | 2 +- SteelSeriesAPI/Sonar/SonarBridge.cs | 2 +- 7 files changed, 283 insertions(+), 37 deletions(-) create mode 100644 SteelSeriesAPI/Sonar/Events/SonarRoutedProcessEvent.cs create mode 100644 SteelSeriesAPI/Sonar/Exceptions/RoutedProcessNotFoundException.cs diff --git a/SteelSeriesAPI/Sonar/Events/SonarRoutedProcessEvent.cs b/SteelSeriesAPI/Sonar/Events/SonarRoutedProcessEvent.cs new file mode 100644 index 0000000..86271e7 --- /dev/null +++ b/SteelSeriesAPI/Sonar/Events/SonarRoutedProcessEvent.cs @@ -0,0 +1,40 @@ +using SteelSeriesAPI.Sonar.Enums; +using SteelSeriesAPI.Sonar.Http; +using SteelSeriesAPI.Sonar.Exceptions; + +using System.Text.Json; + +namespace SteelSeriesAPI.Sonar.Events; + +public class SonarRoutedProcessEvent : EventArgs +{ + // /AudioDeviceRouting/render/%7B0.0.0.00000000%7D.%7Beb78557a-9882-4205-8014-ad9384173901%7D/4476 + // /AudioDeviceRouting/capture/%7B0.0.1.00000000%7D.%7B989ad130-4b1f-4828-a85a-7aef7fd362b7%7D/4476 + + public int ProcessId { get; init; } + + public Channel NewChannel { get; init; } + + internal SonarRoutedProcessEvent(string deviceId) + { + NewChannel = DeviceIdToChannel(deviceId); + } + + private Channel DeviceIdToChannel(string deviceId) + { + JsonElement audioDeviceRouting = new Fetcher().Provide("AudioDeviceRouting").RootElement; + + foreach (JsonElement device in audioDeviceRouting.EnumerateArray()) + { + if (device.GetProperty("role").GetString() != "none") + { + if (device.GetProperty("deviceId").GetString() == deviceId) + { + return (Channel)ChannelExtensions.FromDictKey(device.GetProperty("role").GetString()!)!; + } + } + } + + throw new RoutedProcessNotFoundException("Event error: Could not find the channel"); + } +} \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/Exceptions/RoutedProcessNotFoundException.cs b/SteelSeriesAPI/Sonar/Exceptions/RoutedProcessNotFoundException.cs new file mode 100644 index 0000000..604deaa --- /dev/null +++ b/SteelSeriesAPI/Sonar/Exceptions/RoutedProcessNotFoundException.cs @@ -0,0 +1,8 @@ +namespace SteelSeriesAPI.Sonar.Exceptions; + +public class RoutedProcessNotFoundException : Exception +{ + public RoutedProcessNotFoundException() : base("Could not find any routed process") { } + public RoutedProcessNotFoundException(string message) : base(message) { } + public RoutedProcessNotFoundException(string message, Exception innerException) : base(message, innerException) { } +} \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/Interfaces/Managers/IRoutedProcessManager.cs b/SteelSeriesAPI/Sonar/Interfaces/Managers/IRoutedProcessManager.cs index e744cc7..2c6f95c 100644 --- a/SteelSeriesAPI/Sonar/Interfaces/Managers/IRoutedProcessManager.cs +++ b/SteelSeriesAPI/Sonar/Interfaces/Managers/IRoutedProcessManager.cs @@ -3,19 +3,62 @@ namespace SteelSeriesAPI.Sonar.Interfaces.Managers; -internal interface IRoutedProcessManager +/// +/// Manage routed audio processes +/// +public interface IRoutedProcessManager { /// - /// Get the apps which their audio is redirected to a Sonar + /// Get all audio processes that are routed to Sonar /// - /// The Sonar you want the associated processes + /// A list of + IEnumerable GetAllRoutedProcesses(); + + /// + /// Get all audio processes that are routed to Sonar and currently active + /// + /// A list of + IEnumerable GetAllActiveRoutedProcesses(); + + /// + /// Get all audio processes that are routed to a + /// + /// /// A list of IEnumerable GetRoutedProcesses(Channel channel); /// - /// Redirect the audio of an app to a Sonar + /// Get all audio processes that are routed to a and currently active + /// + /// + /// A list of + IEnumerable GetActiveRoutedProcesses(Channel channel); + + /// + /// Get an audio process that is routed to Sonar whatever its state + /// + /// The id of the process + /// A list of + IEnumerable GetRoutedProcessesById(int processId); + + /// + /// Get an audio process that is routed to Sonar and is active + /// + /// The id of the process + /// + RoutedProcess GetActiveRoutedProcessesById(int processId); + + /// + /// Route an audio process to a specific + /// + /// The id of the process + /// + void RouteProcessToChannel(int processId, Channel channel); + + /// + /// Route an audio process to a specific /// - /// The process ID of the app - /// The Sonar you want to set the app audio - void RouteProcessToChannel(int pId, Channel channel); + /// + /// + void RouteProcessToChannel(RoutedProcess process, Channel channel); } \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/Managers/EventManager.cs b/SteelSeriesAPI/Sonar/Managers/EventManager.cs index 79f9447..a1d06ad 100644 --- a/SteelSeriesAPI/Sonar/Managers/EventManager.cs +++ b/SteelSeriesAPI/Sonar/Managers/EventManager.cs @@ -36,6 +36,11 @@ public class EventManager /// public event EventHandler OnSonarPlaybackDeviceChange = delegate{ }; + /// + /// Notify when an audio process is routed to a new + /// + public event EventHandler OnSonarRoutedProcessChange = delegate{ }; + /// /// Notify when a redirection state is changed /// @@ -69,6 +74,9 @@ internal void HandleEvent(string path) case SonarPlaybackDeviceEvent sonarRedirectionDeviceEvent: OnSonarPlaybackDeviceChange(this, sonarRedirectionDeviceEvent); break; + case SonarRoutedProcessEvent sonarRoutedProcessEvent: + OnSonarRoutedProcessChange(this, sonarRoutedProcessEvent); + break; case SonarRedirectionStateEvent sonarRedirectionStateEvent: OnSonarRedirectionStateChange(this, sonarRedirectionStateEvent); break; @@ -190,6 +198,12 @@ private EventArgs PathResolver(string path) break; } break; + case "AudioDeviceRouting": + eventArgs = new SonarRoutedProcessEvent(subs[3].Replace("%7B", "{").Replace("%7D", "}")) + { + ProcessId = Convert.ToInt32(subs[4]) + }; + break; default: if (subs[1].StartsWith("chatMix")) { diff --git a/SteelSeriesAPI/Sonar/Managers/RoutedProcessManager.cs b/SteelSeriesAPI/Sonar/Managers/RoutedProcessManager.cs index 68c12a9..11b157c 100644 --- a/SteelSeriesAPI/Sonar/Managers/RoutedProcessManager.cs +++ b/SteelSeriesAPI/Sonar/Managers/RoutedProcessManager.cs @@ -1,15 +1,72 @@ using SteelSeriesAPI.Sonar.Exceptions; using SteelSeriesAPI.Sonar.Enums; using SteelSeriesAPI.Sonar.Http; -using SteelSeriesAPI.Sonar.Models; using SteelSeriesAPI.Sonar.Interfaces.Managers; +using SteelSeriesAPI.Sonar.Models; using System.Text.Json; namespace SteelSeriesAPI.Sonar.Managers; -public class RoutedProcessManager : IRoutedProcessManager +internal class RoutedProcessManager : IRoutedProcessManager { + public IEnumerable GetAllRoutedProcesses() + { + JsonElement audioDeviceRouting = new Fetcher().Provide("AudioDeviceRouting").RootElement; + + foreach (JsonElement device in audioDeviceRouting.EnumerateArray()) + { + string role = device.GetProperty("role").GetString()!; + if (role != "none") + { + foreach (JsonElement session in device.GetProperty("audioSessions").EnumerateArray()) + { + int processId = session.GetProperty("processId").GetInt32(); + string processName = session.GetProperty("processName").GetString()!; + string displayName = session.GetProperty("displayName").GetString()!; + + if (processId == 0 && processName == "Idle" && displayName == "Idle") continue; + + RoutedProcessState state = (RoutedProcessState)RoutedProcessStateExtensions.FromDictKey(device.GetProperty("state").GetString()!)!; + Channel channel = (Channel)ChannelExtensions.FromDictKey(role)!; + string processPath = session.GetProperty("id").GetString()!.Split("|")[1].Replace('\\', '/'); + + yield return new RoutedProcess(processId, processName, displayName, state, channel, processPath); + } + } + } + } + + public IEnumerable GetAllActiveRoutedProcesses() + { + JsonElement audioDeviceRouting = new Fetcher().Provide("AudioDeviceRouting").RootElement; + + foreach (JsonElement device in audioDeviceRouting.EnumerateArray()) + { + string role = device.GetProperty("role").GetString()!; + if (role != "none") + { + foreach (JsonElement session in device.GetProperty("audioSessions").EnumerateArray()) + { + if (session.GetProperty("state").GetString() == "active") + { + int processId = session.GetProperty("processId").GetInt32(); + string processName = session.GetProperty("processName").GetString()!; + string displayName = session.GetProperty("displayName").GetString()!; + + if (processId == 0 && processName == "Idle" && displayName == "Idle") continue; + + RoutedProcessState state = RoutedProcessState.ACTIVE; + Channel channel = (Channel)ChannelExtensions.FromDictKey(role)!; + string processPath = session.GetProperty("id").GetString()!.Split("|")[1].Replace('\\', '/'); + + yield return new RoutedProcess(processId, processName, displayName, state, channel, processPath); + } + } + } + } + } + public IEnumerable GetRoutedProcesses(Channel channel) { if (channel == Channel.MASTER) @@ -17,59 +74,143 @@ public IEnumerable GetRoutedProcesses(Channel channel) throw new MasterChannelNotSupportedException(); } - JsonDocument audioDeviceRoutings = new Fetcher().Provide("AudioDeviceRouting"); + JsonElement audioDeviceRouting = new Fetcher().Provide("AudioDeviceRouting").RootElement; + + foreach (JsonElement device in audioDeviceRouting.EnumerateArray()) + { + if (device.GetProperty("role").GetString() == channel.ToDictKey()) + { + foreach (JsonElement session in device.GetProperty("audioSessions").EnumerateArray()) + { + int processId = session.GetProperty("processId").GetInt32(); + string processName = session.GetProperty("processName").GetString()!; + string displayName = session.GetProperty("displayName").GetString()!; + + if (processId == 0 && processName == "Idle" && displayName == "Idle") continue; + + RoutedProcessState state = (RoutedProcessState)RoutedProcessStateExtensions.FromDictKey(device.GetProperty("state").GetString()!)!; + string processPath = session.GetProperty("id").GetString()!.Split("|")[1].Replace('\\', '/'); + + yield return new RoutedProcess(processId, processName, displayName, state, channel, processPath); + } + } + } + } + + public IEnumerable GetActiveRoutedProcesses(Channel channel) + { + if (channel == Channel.MASTER) + { + throw new MasterChannelNotSupportedException(); + } + + JsonElement audioDeviceRouting = new Fetcher().Provide("AudioDeviceRouting").RootElement; - foreach (var element in audioDeviceRoutings.RootElement.EnumerateArray()) + foreach (JsonElement device in audioDeviceRouting.EnumerateArray()) { - if (element.GetProperty("role").GetString() != channel.ToDictKey()) + if (device.GetProperty("role").GetString() == channel.ToDictKey()) { - continue; + foreach (JsonElement session in device.GetProperty("audioSessions").EnumerateArray()) + { + if (session.GetProperty("state").GetString() == "active") + { + int processId = session.GetProperty("processId").GetInt32(); + string processName = session.GetProperty("processName").GetString()!; + string displayName = session.GetProperty("displayName").GetString()!; + + if (processId == 0 && processName == "Idle" && displayName == "Idle") continue; + + RoutedProcessState state = RoutedProcessState.ACTIVE; + string processPath = session.GetProperty("id").GetString()!.Split("|")[1].Replace('\\', '/'); + + yield return new RoutedProcess(processId, processName, displayName, state, channel, processPath); + } + } } + } + } - var audioSessions = element.GetProperty("audioSessions"); + public IEnumerable GetRoutedProcessesById(int processId) + { + JsonElement audioDeviceRouting = new Fetcher().Provide("AudioDeviceRouting").RootElement; - foreach (var session in audioSessions.EnumerateArray()) + foreach (JsonElement device in audioDeviceRouting.EnumerateArray()) + { + string role = device.GetProperty("role").GetString()!; + if (role != "none") { - string id = session.GetProperty("id").GetString().Split("|")[0]; - string processName = session.GetProperty("processName").GetString(); - int pId = session.GetProperty("processId").GetInt32(); - RoutedProcessState state = (RoutedProcessState)RoutedProcessStateExtensions.FromDictKey(session.GetProperty("state").GetString()); - string displayName = session.GetProperty("displayName").GetString(); + foreach (JsonElement session in device.GetProperty("audioSessions").EnumerateArray()) + { + if (session.GetProperty("processId").GetInt32() == processId) + { + string processName = session.GetProperty("processName").GetString()!; + string displayName = session.GetProperty("displayName").GetString()!; + RoutedProcessState state = (RoutedProcessState)RoutedProcessStateExtensions.FromDictKey(device.GetProperty("state").GetString()!)!; + Channel channel = (Channel)ChannelExtensions.FromDictKey(role)!; + string processPath = session.GetProperty("id").GetString()!.Split("|")[1].Replace('\\', '/'); + + yield return new RoutedProcess(processId, processName, displayName, state, channel, processPath); + } + } + } + } + } - if (processName == "Idle" && displayName == "Idle" && state == RoutedProcessState.INACTIVE && pId == 0) + public RoutedProcess GetActiveRoutedProcessesById(int processId) + { + JsonElement audioDeviceRouting = new Fetcher().Provide("AudioDeviceRouting").RootElement; + + foreach (JsonElement device in audioDeviceRouting.EnumerateArray()) + { + string role = device.GetProperty("role").GetString()!; + if (role != "none") + { + foreach (JsonElement session in device.GetProperty("audioSessions").EnumerateArray()) { - continue; + if (session.GetProperty("state").GetString() == "active" && session.GetProperty("processId").GetInt32() == processId) + { + string processName = session.GetProperty("processName").GetString()!; + string displayName = session.GetProperty("displayName").GetString()!; + RoutedProcessState state = RoutedProcessState.ACTIVE; + Channel channel = (Channel)ChannelExtensions.FromDictKey(role)!; + string processPath = session.GetProperty("id").GetString()!.Split("|")[1].Replace('\\', '/'); + + return new RoutedProcess(processId, processName, displayName, state, channel, processPath); + } } - - yield return new RoutedProcess(id, processName, pId, state, displayName); } } + + throw new RoutedProcessNotFoundException("No active processes with id " + processId + " found"); } - - public void RouteProcessToChannel(int pId, Channel channel) + + public void RouteProcessToChannel(int processId, Channel channel) { if (channel == Channel.MASTER) { throw new MasterChannelNotSupportedException(); } - JsonDocument audioDeviceRouting = new Fetcher().Provide("AudioDeviceRouting"); + JsonElement audioDeviceRouting = new Fetcher().Provide("AudioDeviceRouting").RootElement; - foreach (var element in audioDeviceRouting.RootElement.EnumerateArray()) + foreach (JsonElement device in audioDeviceRouting.EnumerateArray()) { - if (element.GetProperty("role").GetString() == channel.ToDictKey()) + if (device.GetProperty("role").GetString() == channel.ToDictKey()) { if (channel == Channel.MIC) { - new Fetcher().Put("AudioDeviceRouting/capture/" + element.GetProperty("deviceId").GetString() + "/" + pId); - break; - } - else - { - new Fetcher().Put("AudioDeviceRouting/render/" + element.GetProperty("deviceId").GetString() + "/" + pId); + new Fetcher().Put("AudioDeviceRouting/capture/" + device.GetProperty("deviceId").GetString() + "/" + processId); break; } + + new Fetcher().Put("AudioDeviceRouting/render/" + device.GetProperty("deviceId").GetString() + "/" + processId); + break; } } } + + public void RouteProcessToChannel(RoutedProcess process, Channel channel) + { + RouteProcessToChannel(process.ProcessId, channel); + } } \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/Models/RoutedProcess.cs b/SteelSeriesAPI/Sonar/Models/RoutedProcess.cs index bcb256f..09c8c97 100644 --- a/SteelSeriesAPI/Sonar/Models/RoutedProcess.cs +++ b/SteelSeriesAPI/Sonar/Models/RoutedProcess.cs @@ -2,4 +2,4 @@ namespace SteelSeriesAPI.Sonar.Models; -public record RoutedProcess(string Id, string ProcessName, int PId, RoutedProcessState State, string DisplayName); \ No newline at end of file +public record RoutedProcess(int ProcessId, string ProcessName, string DisplayName, RoutedProcessState State, Channel Channel, string ProcessPath); \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/SonarBridge.cs b/SteelSeriesAPI/Sonar/SonarBridge.cs index 9e69fb9..fed1dce 100644 --- a/SteelSeriesAPI/Sonar/SonarBridge.cs +++ b/SteelSeriesAPI/Sonar/SonarBridge.cs @@ -20,7 +20,7 @@ public class SonarBridge : ISonarBridge public readonly ChatMixManager ChatMix; public readonly ConfigurationManager Configurations; public readonly PlaybackDeviceManager PlaybackDevices; - public readonly RoutedProcessManager RoutedProcesses; + public readonly IRoutedProcessManager RoutedProcesses; public readonly IMixManager Mix; public readonly AudienceMonitoringManager AudienceMonitoring; public readonly EventManager Events; From d48e411538dd6a2b47453067bd6bfb5e78306a8a Mon Sep 17 00:00:00 2001 From: DataNext Date: Sun, 27 Apr 2025 17:27:08 +0200 Subject: [PATCH 12/12] Revamped events --- .../Events/SonarAudienceMonitoringEvent.cs | 4 +- ...irectionStateEvent.cs => SonarMixEvent.cs} | 5 +- SteelSeriesAPI/Sonar/Events/SonarMuteEvent.cs | 1 + .../Sonar/Events/SonarPlaybackDeviceEvent.cs | 3 +- .../Sonar/Events/SonarVolumeEvent.cs | 1 + SteelSeriesAPI/Sonar/Managers/EventManager.cs | 81 ++++++++++--------- 6 files changed, 51 insertions(+), 44 deletions(-) rename SteelSeriesAPI/Sonar/Events/{SonarRedirectionStateEvent.cs => SonarMixEvent.cs} (73%) diff --git a/SteelSeriesAPI/Sonar/Events/SonarAudienceMonitoringEvent.cs b/SteelSeriesAPI/Sonar/Events/SonarAudienceMonitoringEvent.cs index 32aec9b..279839d 100644 --- a/SteelSeriesAPI/Sonar/Events/SonarAudienceMonitoringEvent.cs +++ b/SteelSeriesAPI/Sonar/Events/SonarAudienceMonitoringEvent.cs @@ -2,6 +2,6 @@ namespace SteelSeriesAPI.Sonar.Events; public class SonarAudienceMonitoringEvent : EventArgs { - // /streamRedirections/isStreamMonitoringEnabled/bool - public bool AudienceMonitoringState { get; set; } + // /streamRedirections/isStreamMonitoringEnabled/true + public bool NewState { get; set; } } \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/Events/SonarRedirectionStateEvent.cs b/SteelSeriesAPI/Sonar/Events/SonarMixEvent.cs similarity index 73% rename from SteelSeriesAPI/Sonar/Events/SonarRedirectionStateEvent.cs rename to SteelSeriesAPI/Sonar/Events/SonarMixEvent.cs index bdda476..d4fae6c 100644 --- a/SteelSeriesAPI/Sonar/Events/SonarRedirectionStateEvent.cs +++ b/SteelSeriesAPI/Sonar/Events/SonarMixEvent.cs @@ -2,12 +2,13 @@ namespace SteelSeriesAPI.Sonar.Events; -public class SonarRedirectionStateEvent : EventArgs +public class SonarMixEvent : EventArgs { // /streamRedirections/monitoring/redirections/chatRender/isEnabled/true - public bool State { get; set; } + public bool NewState { get; set; } public Channel Channel { get; set; } + public Mix Mix { get; set; } } \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/Events/SonarMuteEvent.cs b/SteelSeriesAPI/Sonar/Events/SonarMuteEvent.cs index 3f2bf5b..1cce0a9 100644 --- a/SteelSeriesAPI/Sonar/Events/SonarMuteEvent.cs +++ b/SteelSeriesAPI/Sonar/Events/SonarMuteEvent.cs @@ -12,5 +12,6 @@ public class SonarMuteEvent : EventArgs public Mode Mode { get; set; } public Channel Channel { get; set; } + public Mix? Mix { get; set; } } \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/Events/SonarPlaybackDeviceEvent.cs b/SteelSeriesAPI/Sonar/Events/SonarPlaybackDeviceEvent.cs index 8e3e76b..5ef3a9a 100644 --- a/SteelSeriesAPI/Sonar/Events/SonarPlaybackDeviceEvent.cs +++ b/SteelSeriesAPI/Sonar/Events/SonarPlaybackDeviceEvent.cs @@ -7,10 +7,11 @@ public class SonarPlaybackDeviceEvent : EventArgs // /classicRedirections/game/deviceId/%7B0.0.0.00000000%7D.%7B1e1ebefc-2c51-4675-aebe-085a06efd255%7D // /streamRedirections/monitoring/deviceId/%7B0.0.0.00000000%7D.%7B1e1ebefc-2c51-4675-aebe-085a06efd255%7D - public string RedirectionDeviceId { get; set; } + public string PlaybackDeviceId { get; set; } public Mode Mode { get; set; } public Channel? Device { get; set; } + public Mix? Channel { get; set; } } \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/Events/SonarVolumeEvent.cs b/SteelSeriesAPI/Sonar/Events/SonarVolumeEvent.cs index 65d3098..e00607e 100644 --- a/SteelSeriesAPI/Sonar/Events/SonarVolumeEvent.cs +++ b/SteelSeriesAPI/Sonar/Events/SonarVolumeEvent.cs @@ -12,5 +12,6 @@ public class SonarVolumeEvent : EventArgs public Mode Mode { get; set; } public Channel Channel { get; set; } + public Mix? Mix { get; set; } } \ No newline at end of file diff --git a/SteelSeriesAPI/Sonar/Managers/EventManager.cs b/SteelSeriesAPI/Sonar/Managers/EventManager.cs index a1d06ad..e20a657 100644 --- a/SteelSeriesAPI/Sonar/Managers/EventManager.cs +++ b/SteelSeriesAPI/Sonar/Managers/EventManager.cs @@ -4,25 +4,28 @@ namespace SteelSeriesAPI.Sonar.Managers; +/// +/// Manage the different Sonar Events +/// public class EventManager { /// - /// Notify when mode changed + /// Notify when the current changed /// public event EventHandler OnSonarModeChange = delegate{ }; /// - /// Notify when a volume of a channel changed + /// Notify when the volume of a has changed /// public event EventHandler OnSonarVolumeChange = delegate{ }; /// - /// Notify when a channel is un/muted + /// Notify when a gets un/muted /// public event EventHandler OnSonarMuteChange = delegate{ }; /// - /// Notify when the config of a channel is changed + /// Notify when the config of a is changed /// public event EventHandler OnSonarConfigChange = delegate{ }; @@ -32,7 +35,7 @@ public class EventManager public event EventHandler OnSonarChatMixChange = delegate{ }; /// - /// Notify when a playback device of a channel is changed + /// Notify when the playback device of a is changed /// public event EventHandler OnSonarPlaybackDeviceChange = delegate{ }; @@ -42,9 +45,9 @@ public class EventManager public event EventHandler OnSonarRoutedProcessChange = delegate{ }; /// - /// Notify when a redirection state is changed + /// Notify when a gets de/activated /// - public event EventHandler OnSonarRedirectionStateChange = delegate{ }; + public event EventHandler OnSonarMixChange = delegate{ }; /// /// Notify when the audience monitoring state is changed @@ -71,14 +74,14 @@ internal void HandleEvent(string path) case SonarChatMixEvent sonarChatMixEvent: OnSonarChatMixChange(this, sonarChatMixEvent); break; - case SonarPlaybackDeviceEvent sonarRedirectionDeviceEvent: - OnSonarPlaybackDeviceChange(this, sonarRedirectionDeviceEvent); + case SonarPlaybackDeviceEvent sonarPlaybackDeviceEvent: + OnSonarPlaybackDeviceChange(this, sonarPlaybackDeviceEvent); break; case SonarRoutedProcessEvent sonarRoutedProcessEvent: OnSonarRoutedProcessChange(this, sonarRoutedProcessEvent); break; - case SonarRedirectionStateEvent sonarRedirectionStateEvent: - OnSonarRedirectionStateChange(this, sonarRedirectionStateEvent); + case SonarMixEvent sonarMixEvent: + OnSonarMixChange(this, sonarMixEvent); break; case SonarAudienceMonitoringEvent sonarAudienceMonitoringEvent: OnSonarAudienceMonitoringChange(this, sonarAudienceMonitoringEvent); @@ -89,13 +92,13 @@ internal void HandleEvent(string path) private EventArgs PathResolver(string path) { string[] subs = path.Split("/"); - EventArgs eventArgs = null; + EventArgs eventArgs = null!; switch (subs[1]) { case "mode": - eventArgs = new SonarModeEvent() - { NewMode = (Mode)ModeExtensions.FromDictKey(subs[2], ModeMapChoice.StreamDict) }; + eventArgs = new SonarModeEvent + { NewMode = (Mode)ModeExtensions.FromDictKey(subs[2], ModeMapChoice.StreamDict)! }; break; case "volumeSettings": switch (subs[2]) @@ -104,19 +107,19 @@ private EventArgs PathResolver(string path) switch (subs[4]) { case "Volume": - eventArgs = new SonarVolumeEvent() + eventArgs = new SonarVolumeEvent { Volume = double.Parse(subs[5], CultureInfo.InvariantCulture.NumberFormat), Mode = Mode.CLASSIC, - Channel = (Channel)ChannelExtensions.FromDictKey(subs[3], ChannelMapChoice.HttpDict) + Channel = (Channel)ChannelExtensions.FromDictKey(subs[3], ChannelMapChoice.HttpDict)! }; break; case"Mute": - eventArgs = new SonarMuteEvent() + eventArgs = new SonarMuteEvent { Muted = Convert.ToBoolean(subs[5]), Mode = Mode.CLASSIC, - Channel = (Channel)ChannelExtensions.FromDictKey(subs[3], ChannelMapChoice.HttpDict) + Channel = (Channel)ChannelExtensions.FromDictKey(subs[3], ChannelMapChoice.HttpDict)! }; break; } @@ -125,21 +128,21 @@ private EventArgs PathResolver(string path) switch (subs[5]) { case "volume": - eventArgs = new SonarVolumeEvent() + eventArgs = new SonarVolumeEvent { Volume = double.Parse(subs[6], CultureInfo.InvariantCulture.NumberFormat), Mode = Mode.STREAMER, - Channel = (Channel)ChannelExtensions.FromDictKey(subs[4], ChannelMapChoice.HttpDict), - Mix = (Mix)MixExtensions.FromDictKey(subs[3]) + Channel = (Channel)ChannelExtensions.FromDictKey(subs[4], ChannelMapChoice.HttpDict)!, + Mix = (Mix)MixExtensions.FromDictKey(subs[3])! }; break; case "isMuted": - eventArgs = new SonarMuteEvent() + eventArgs = new SonarMuteEvent { Muted = Convert.ToBoolean(subs[6]), Mode = Mode.STREAMER, - Channel = (Channel)ChannelExtensions.FromDictKey(subs[4], ChannelMapChoice.HttpDict), - Mix = (Mix)MixExtensions.FromDictKey(subs[3]) + Channel = (Channel)ChannelExtensions.FromDictKey(subs[4], ChannelMapChoice.HttpDict)!, + Mix = (Mix)MixExtensions.FromDictKey(subs[3])! }; break; } @@ -149,21 +152,21 @@ private EventArgs PathResolver(string path) case "configs": if (!(subs.Length < 3)) { - eventArgs = new SonarConfigEvent() { ConfigId = subs[2] }; + eventArgs = new SonarConfigEvent { ConfigId = subs[2] }; } break; case "classicRedirections": - eventArgs = new SonarPlaybackDeviceEvent() + eventArgs = new SonarPlaybackDeviceEvent { - RedirectionDeviceId = subs[4].Replace("%7B", "{").Replace("%7D", "}"), + PlaybackDeviceId = subs[4].Replace("%7B", "{").Replace("%7D", "}"), Mode = Mode.CLASSIC, - Device = (Channel)ChannelExtensions.FromDictKey(subs[2], ChannelMapChoice.ChannelDict) + Device = (Channel)ChannelExtensions.FromDictKey(subs[2], ChannelMapChoice.ChannelDict)! }; break; case "streamRedirections": if (subs[2] == "isStreamMonitoringEnabled") { - eventArgs = new SonarAudienceMonitoringEvent() { AudienceMonitoringState = Convert.ToBoolean(subs[3]) }; + eventArgs = new SonarAudienceMonitoringEvent { NewState = Convert.ToBoolean(subs[3]) }; break; } @@ -172,28 +175,28 @@ private EventArgs PathResolver(string path) case "deviceId": if (subs[2] == "mic") { - eventArgs = new SonarPlaybackDeviceEvent() + eventArgs = new SonarPlaybackDeviceEvent { - RedirectionDeviceId = subs[4].Replace("%7B", "{").Replace("%7D", "}"), + PlaybackDeviceId = subs[4].Replace("%7B", "{").Replace("%7D", "}"), Mode = Mode.STREAMER, Device = Channel.MIC }; break; } - eventArgs = new SonarPlaybackDeviceEvent() + eventArgs = new SonarPlaybackDeviceEvent { - RedirectionDeviceId = subs[4].Replace("%7B", "{").Replace("%7D", "}"), + PlaybackDeviceId = subs[4].Replace("%7B", "{").Replace("%7D", "}"), Mode = Mode.STREAMER, - Channel = (Mix)MixExtensions.FromDictKey(subs[2]) + Channel = (Mix)MixExtensions.FromDictKey(subs[2])! }; break; case "redirections": - eventArgs = new SonarRedirectionStateEvent() + eventArgs = new SonarMixEvent { - State = Convert.ToBoolean(subs[6]), - Channel = (Channel)ChannelExtensions.FromDictKey(subs[4]), - Mix = (Mix)MixExtensions.FromDictKey(subs[2]) + NewState = Convert.ToBoolean(subs[6]), + Channel = (Channel)ChannelExtensions.FromDictKey(subs[4])!, + Mix = (Mix)MixExtensions.FromDictKey(subs[2])! }; break; } @@ -207,7 +210,7 @@ private EventArgs PathResolver(string path) default: if (subs[1].StartsWith("chatMix")) { - eventArgs = new SonarChatMixEvent() { Balance = Convert.ToDouble(subs[1].Split("=")[1], CultureInfo.InvariantCulture) }; + eventArgs = new SonarChatMixEvent { Balance = Convert.ToDouble(subs[1].Split("=")[1], CultureInfo.InvariantCulture) }; } break; }