Kick client directly by on_hls->client_id
This commit is contained in:
@ -43,9 +43,9 @@ public class SrsController : Controller
|
|||||||
await _streamManager.StreamStopped(req.Stream);
|
await _streamManager.StreamStopped(req.Stream);
|
||||||
return new();
|
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();
|
return new();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -56,7 +56,7 @@ public class StreamManager
|
|||||||
await PublishEvent(user, ev);
|
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);
|
var user = await GetUserFromStreamKey(streamKey);
|
||||||
if (user == default) throw new Exception("No stream key found");
|
if (user == default) throw new Exception("No stream key found");
|
||||||
@ -77,14 +77,7 @@ public class StreamManager
|
|||||||
if (user.Balance <= 0)
|
if (user.Balance <= 0)
|
||||||
{
|
{
|
||||||
_logger.LogInformation("Kicking stream due to low balance");
|
_logger.LogInformation("Kicking stream due to low balance");
|
||||||
var streams = await _srsApi.ListStreams();
|
await _srsApi.KickClient(clientId);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user