diff --git a/NostrStreamer/Controllers/SRSController.cs b/NostrStreamer/Controllers/SRSController.cs index f15213e..339de58 100644 --- a/NostrStreamer/Controllers/SRSController.cs +++ b/NostrStreamer/Controllers/SRSController.cs @@ -43,9 +43,9 @@ public class SrsController : Controller await _streamManager.StreamStopped(req.Stream); return new(); } - if (req.Action == "on_hls" && req.Duration.HasValue) + if (req.Action == "on_hls" && req.Duration.HasValue && !string.IsNullOrEmpty(req.ClientId)) { - await _streamManager.ConsumeQuota(req.Stream, req.Duration.Value); + await _streamManager.ConsumeQuota(req.Stream, req.Duration.Value, req.ClientId); return new(); } } diff --git a/NostrStreamer/Services/StreamManager.cs b/NostrStreamer/Services/StreamManager.cs index 756c511..58cbfbe 100644 --- a/NostrStreamer/Services/StreamManager.cs +++ b/NostrStreamer/Services/StreamManager.cs @@ -56,7 +56,7 @@ public class StreamManager await PublishEvent(user, ev); } - public async Task ConsumeQuota(string streamKey, double duration) + public async Task ConsumeQuota(string streamKey, double duration, string clientId) { var user = await GetUserFromStreamKey(streamKey); if (user == default) throw new Exception("No stream key found"); @@ -77,14 +77,7 @@ public class StreamManager if (user.Balance <= 0) { _logger.LogInformation("Kicking stream due to low balance"); - var streams = await _srsApi.ListStreams(); - var stream = streams.FirstOrDefault(a => a.Name == streamKey); - if (stream == default) - { - throw new Exception("Stream not found, cannot kick"); - } - - await _srsApi.KickClient(stream.Publish.Cid); + await _srsApi.KickClient(clientId); } }