diff --git a/src/Streamlabs.SocketClient/Events/Abstractions/IStreamlabsEvent.cs b/src/Streamlabs.SocketClient/Events/Abstractions/IStreamlabsEvent.cs index 192f348..cce7ea5 100644 --- a/src/Streamlabs.SocketClient/Events/Abstractions/IStreamlabsEvent.cs +++ b/src/Streamlabs.SocketClient/Events/Abstractions/IStreamlabsEvent.cs @@ -8,6 +8,7 @@ namespace Streamlabs.SocketClient.Events.Abstractions; [JsonDerivedType(typeof(AlertPlayingEvent), typeDiscriminator: "alertPlaying")] [JsonDerivedType(typeof(BitsEvent), typeDiscriminator: "bits")] [JsonDerivedType(typeof(FollowEvent), typeDiscriminator: "follow")] +[JsonDerivedType(typeof(MuteVolumeEvent), typeDiscriminator: "muteVolume")] [JsonDerivedType(typeof(RaidEvent), typeDiscriminator: "raid")] [JsonDerivedType(typeof(RollEndCreditsEvent), typeDiscriminator: "rollEndCredits")] [JsonDerivedType(typeof(StreamlabelsEvent), typeDiscriminator: "streamlabels")] diff --git a/src/Streamlabs.SocketClient/Events/MuteVolumeEvent.cs b/src/Streamlabs.SocketClient/Events/MuteVolumeEvent.cs new file mode 100644 index 0000000..ed1ef3a --- /dev/null +++ b/src/Streamlabs.SocketClient/Events/MuteVolumeEvent.cs @@ -0,0 +1,14 @@ +using System.Text.Json.Serialization; +using Streamlabs.SocketClient.Events.Abstractions; +using Streamlabs.SocketClient.Messages; + +namespace Streamlabs.SocketClient.Events; + +public sealed record MuteVolumeEvent : IStreamlabsEvent, IHasStreamlabsMessageCollection, IHasEventId +{ + [JsonPropertyName("message")] + public required IReadOnlyCollection Messages { get; init; } + + [JsonPropertyName("event_id")] + public required string EventId { get; init; } +} diff --git a/src/Streamlabs.SocketClient/IStreamlabsClient.cs b/src/Streamlabs.SocketClient/IStreamlabsClient.cs index a4604c6..5f7882c 100644 --- a/src/Streamlabs.SocketClient/IStreamlabsClient.cs +++ b/src/Streamlabs.SocketClient/IStreamlabsClient.cs @@ -1,3 +1,4 @@ +using Streamlabs.SocketClient.Events; using Streamlabs.SocketClient.Events.Abstractions; using Streamlabs.SocketClient.Messages; @@ -49,4 +50,6 @@ public interface IStreamlabsClient : IDisposable [Obsolete("Use the specific AlertPlaying events instead.")] event EventHandler? OnSubscriptionPlaying; + + event EventHandler OnMuteVolume; } diff --git a/src/Streamlabs.SocketClient/Messages/MuteVolumeMessage.cs b/src/Streamlabs.SocketClient/Messages/MuteVolumeMessage.cs new file mode 100644 index 0000000..b12183d --- /dev/null +++ b/src/Streamlabs.SocketClient/Messages/MuteVolumeMessage.cs @@ -0,0 +1,13 @@ +using Streamlabs.SocketClient.Events; +using Streamlabs.SocketClient.Messages.Abstractions; + +namespace Streamlabs.SocketClient.Messages; + +/// +/// The message array for seems to be always empty, +/// so this message type is just a placeholder. +/// +public sealed record MuteVolumeMessage : IStreamlabsMessage +{ + // Empty +} diff --git a/src/Streamlabs.SocketClient/StreamlabsClient.cs b/src/Streamlabs.SocketClient/StreamlabsClient.cs index 069468b..589f320 100644 --- a/src/Streamlabs.SocketClient/StreamlabsClient.cs +++ b/src/Streamlabs.SocketClient/StreamlabsClient.cs @@ -115,6 +115,7 @@ public StreamlabsClient(ILogger logger, IOptions? OnSubMysteryGift; public event EventHandler? OnSubscription; public event EventHandler? OnSubscriptionPlaying; + public event EventHandler? OnMuteVolume; private void OnEventInternal(SocketIOResponse response) => Dispatch(response.ToString()); @@ -210,6 +211,9 @@ private void Dispatch(IStreamlabsEvent streamlabsEvent) case StreamlabelsUnderlyingEvent streamlabelsUnderlyingEvent: OnStreamlabelsUnderlying?.Invoke(this, streamlabelsUnderlyingEvent.Message); break; + case MuteVolumeEvent muteVolumeEvent: + OnMuteVolume?.Invoke(this, muteVolumeEvent); + break; case SubMysteryGiftEvent subMysteryGiftEvent: foreach (SubMysteryGiftMessage message in subMysteryGiftEvent.Messages) { @@ -252,8 +256,8 @@ private void Dispatch(IStreamlabsEvent streamlabsEvent) ); break; } - break; + default: _logger.LogError("Streamlabs: Unsupported event type - {Type}", streamlabsEvent.GetType().Name); break; diff --git a/test/Streamlabs.SocketClient.Tests/MessageJson/muteVolume.json b/test/Streamlabs.SocketClient.Tests/MessageJson/muteVolume.json new file mode 100644 index 0000000..b09cf2e --- /dev/null +++ b/test/Streamlabs.SocketClient.Tests/MessageJson/muteVolume.json @@ -0,0 +1,7 @@ +[ + { + "type": "muteVolume", + "message": [], + "event_id": "evt_4e70a68a1297ba2834d425d784873e6f" + } +] diff --git a/test/Streamlabs.SocketClient.Tests/MessageTypeTests.cs b/test/Streamlabs.SocketClient.Tests/MessageTypeTests.cs index 5ca117b..aca9f80 100644 --- a/test/Streamlabs.SocketClient.Tests/MessageTypeTests.cs +++ b/test/Streamlabs.SocketClient.Tests/MessageTypeTests.cs @@ -30,17 +30,18 @@ public sealed record JsonFile(string FileName, Type ExpectedType, string? EventN public static IReadOnlyCollection All { get; } = new List { - new("donation.json", typeof(DonationEvent)), - new("bits.json", typeof(BitsEvent)), - new("bits2.json", typeof(BitsEvent)), - new("donationDelete.json", typeof(DonationDeleteEvent)), new("alertPlaying.json", typeof(AlertPlayingEvent), "FollowAlertPlaying"), new("alertPlaying_subscription.json", typeof(AlertPlayingEvent), "SubscriptionAlertPlaying"), new("alertPlaying_bits.json", typeof(AlertPlayingEvent), "BitsAlertPlaying"), new("alertPlaying_subMysteryGift.json", typeof(AlertPlayingEvent), "SubMysteryGiftAlertPlaying"), new("alertPlaying_raid.json", typeof(AlertPlayingEvent), "RaidAlertPlaying"), new("alertPlaying_follow.json", typeof(AlertPlayingEvent), "FollowAlertPlaying"), + new("bits.json", typeof(BitsEvent)), + new("bits2.json", typeof(BitsEvent)), + new("donation.json", typeof(DonationEvent)), + new("donationDelete.json", typeof(DonationDeleteEvent)), new("follow.json", typeof(FollowEvent)), + new("muteVolume.json", typeof(MuteVolumeEvent)), new("raid.json", typeof(RaidEvent)), new("rollEndCredits.json", typeof(RollEndCreditsEvent)), new("streamlabels.json", typeof(StreamlabelsEvent)),