Kick client directly by on_hls->client_id

This commit is contained in:
2023-07-05 21:08:09 +01:00
parent 531c5614cb
commit 7dcc1cca83
2 changed files with 4 additions and 11 deletions

View File

@ -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();
}
}

View File

@ -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);
}
}