diff options
| author | JP Dillingham <jp@dillingham.me> | 2026-02-01 14:11:40 -0600 |
|---|---|---|
| committer | JP Dillingham <jp@dillingham.me> | 2026-02-01 14:11:40 -0600 |
| commit | a3e880e813d97e917ba2f41b756e2430efd7d60e (patch) | |
| tree | f4a6c62986cb4d1a5a6be7943f22791ada7d2940 | |
| parent | 2b3e6f30420128940c6c626b78028386e6c5a54b (diff) | |
| download | slskd-a3e880e813d97e917ba2f41b756e2430efd7d60e.tar.gz | |
add events for client connect and disconnect
| -rw-r--r-- | src/slskd/Application.cs | 15 | ||||
| -rw-r--r-- | src/slskd/Events/Types/Events.cs | 18 |
2 files changed, 32 insertions, 1 deletions
diff --git a/src/slskd/Application.cs b/src/slskd/Application.cs index bed8aab2..93db9073 100644 --- a/src/slskd/Application.cs +++ b/src/slskd/Application.cs @@ -40,6 +40,7 @@ namespace slskd using Serilog.Events; using slskd.Configuration; using slskd.Core.API; + using slskd.Events; using slskd.Files; using slskd.Integrations.Pushbullet; using slskd.Messaging; @@ -105,7 +106,8 @@ namespace slskd IPushbulletService pushbulletService, IRelayService relayService, IHubContext<ApplicationHub> applicationHub, - IHubContext<LogsHub> logHub) + IHubContext<LogsHub> logHub, + EventBus eventBus) { Console.CancelKeyPress += (_, args) => { @@ -130,6 +132,8 @@ namespace slskd OptionsMonitor = optionsMonitor; OptionsMonitor.OnChange(async options => await OptionsMonitor_OnChange(options)); + EventBus = eventBus; + IncomingSearchRequestSemaphore = new SemaphoreSlim( initialCount: OptionsAtStartup.Throttling.Search.Incoming.Concurrency, maxCount: OptionsAtStartup.Throttling.Search.Incoming.Concurrency); @@ -240,6 +244,7 @@ namespace slskd private ITransferService Transfers { get; init; } private IHubContext<ApplicationHub> ApplicationHub { get; set; } private IHubContext<LogsHub> LogHub { get; set; } + private EventBus EventBus { get; } private IUserService Users { get; set; } private IShareService Shares { get; set; } private ISearchService Search { get; set; } @@ -900,6 +905,8 @@ namespace slskd { ConnectionWatchdog.Stop(); Log.Information("Connected to the Soulseek server"); + + EventBus.Raise(new SoulseekClientConnectedEvent()); } private void Client_DiagnosticGenerated(object sender, DiagnosticEventArgs args) @@ -960,6 +967,12 @@ namespace slskd Log.Error("Disconnected from the Soulseek server: {Message}", args.Exception?.Message ?? args.Message); ConnectionWatchdog.Start(); } + + EventBus.Raise(new SoulseekClientDisconnectedEvent() + { + Message = args.Message, + Exception = args.Exception, + }); } private async Task RefreshUserStatistics(bool force = false) diff --git a/src/slskd/Events/Types/Events.cs b/src/slskd/Events/Types/Events.cs index 577e41e3..d67396dc 100644 --- a/src/slskd/Events/Types/Events.cs +++ b/src/slskd/Events/Types/Events.cs @@ -32,6 +32,10 @@ public enum EventType // UploadDirectoryComplete = 5, PrivateMessageReceived = 6, RoomMessageReceived = 7, + + SoulseekClientConnected = 50, + SoulseekClientDisconnected = 51, + Noop = int.MaxValue, } @@ -43,6 +47,20 @@ public abstract record Event public abstract int Version { get; } } +public sealed record SoulseekClientConnectedEvent : Event +{ + public override EventType Type => EventType.SoulseekClientConnected; + public override int Version { get; } = 0; +} + +public sealed record SoulseekClientDisconnectedEvent : Event +{ + public override EventType Type => EventType.SoulseekClientDisconnected; + public override int Version { get; } = 0; + public required string Message { get; init; } + public required Exception Exception { get; init; } +} + public sealed record DownloadFileCompleteEvent : Event { public override EventType Type => EventType.DownloadFileComplete; |
