Skip to content

Commit

Permalink
feat: support muteVolume event
Browse files Browse the repository at this point in the history
  • Loading branch information
meenzen committed Apr 20, 2024
1 parent e00cd5d commit b2d8433
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down
14 changes: 14 additions & 0 deletions src/Streamlabs.SocketClient/Events/MuteVolumeEvent.cs
Original file line number Diff line number Diff line change
@@ -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<MuteVolumeMessage>, IHasEventId
{
[JsonPropertyName("message")]
public required IReadOnlyCollection<MuteVolumeMessage> Messages { get; init; }

[JsonPropertyName("event_id")]
public required string EventId { get; init; }
}
3 changes: 3 additions & 0 deletions src/Streamlabs.SocketClient/IStreamlabsClient.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Streamlabs.SocketClient.Events;
using Streamlabs.SocketClient.Events.Abstractions;
using Streamlabs.SocketClient.Messages;

Expand Down Expand Up @@ -49,4 +50,6 @@ public interface IStreamlabsClient : IDisposable

[Obsolete("Use the specific AlertPlaying events instead.")]
event EventHandler<AlertPlayingMessage>? OnSubscriptionPlaying;

event EventHandler<MuteVolumeEvent> OnMuteVolume;
}
13 changes: 13 additions & 0 deletions src/Streamlabs.SocketClient/Messages/MuteVolumeMessage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Streamlabs.SocketClient.Events;
using Streamlabs.SocketClient.Messages.Abstractions;

namespace Streamlabs.SocketClient.Messages;

/// <summary>
/// The message array for <see cref="MuteVolumeEvent"/> seems to be always empty,
/// so this message type is just a placeholder.
/// </summary>
public sealed record MuteVolumeMessage : IStreamlabsMessage
{
// Empty
}
6 changes: 5 additions & 1 deletion src/Streamlabs.SocketClient/StreamlabsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ public StreamlabsClient(ILogger<StreamlabsClient> logger, IOptions<StreamlabsOpt
public event EventHandler<SubMysteryGiftMessage>? OnSubMysteryGift;
public event EventHandler<SubscriptionMessage>? OnSubscription;
public event EventHandler<AlertPlayingMessage>? OnSubscriptionPlaying;
public event EventHandler<MuteVolumeEvent>? OnMuteVolume;

private void OnEventInternal(SocketIOResponse response) => Dispatch(response.ToString());

Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -252,8 +256,8 @@ private void Dispatch(IStreamlabsEvent streamlabsEvent)
);
break;
}

break;

default:
_logger.LogError("Streamlabs: Unsupported event type - {Type}", streamlabsEvent.GetType().Name);
break;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[
{
"type": "muteVolume",
"message": [],
"event_id": "evt_4e70a68a1297ba2834d425d784873e6f"
}
]
9 changes: 5 additions & 4 deletions test/Streamlabs.SocketClient.Tests/MessageTypeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,18 @@ public sealed record JsonFile(string FileName, Type ExpectedType, string? EventN
public static IReadOnlyCollection<JsonFile> All { get; } =
new List<JsonFile>
{
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)),
Expand Down

0 comments on commit b2d8433

Please sign in to comment.