From 60130329f0fc6deb7ba69497eaaca83bcb7f3658 Mon Sep 17 00:00:00 2001 From: Kieran Date: Mon, 10 Jul 2023 16:06:37 +0100 Subject: [PATCH] Adjust rates --- NostrStreamer/Config.cs | 5 +++++ NostrStreamer/Controllers/NostrController.cs | 2 +- NostrStreamer/Services/StreamManager.cs | 12 +++++++----- docker-compose.yaml | 1 + docker/srs.conf | 14 ++++++++++++++ 5 files changed, 28 insertions(+), 6 deletions(-) diff --git a/NostrStreamer/Config.cs b/NostrStreamer/Config.cs index 51bbdc2..45e596f 100644 --- a/NostrStreamer/Config.cs +++ b/NostrStreamer/Config.cs @@ -36,6 +36,11 @@ public class Config public string[] Relays { get; init; } = Array.Empty(); public LndConfig Lnd { get; init; } = null!; + + /// + /// Cost/min + /// + public int Cost { get; init; } = 10; } public class LndConfig diff --git a/NostrStreamer/Controllers/NostrController.cs b/NostrStreamer/Controllers/NostrController.cs index 0485dd6..c74efb8 100644 --- a/NostrStreamer/Controllers/NostrController.cs +++ b/NostrStreamer/Controllers/NostrController.cs @@ -57,7 +57,7 @@ public class NostrController : Controller Quota = new() { Unit = "min", - Rate = 21, + Rate = _config.Cost, Remaining = user.Balance } }; diff --git a/NostrStreamer/Services/StreamManager.cs b/NostrStreamer/Services/StreamManager.cs index ef2c534..d2ea7c1 100644 --- a/NostrStreamer/Services/StreamManager.cs +++ b/NostrStreamer/Services/StreamManager.cs @@ -62,11 +62,13 @@ public class StreamManager if (user == default) throw new Exception("No stream key found"); const long balanceAlertThreshold = 500; - const double rate = 21.0d; // 21 sats/min - var cost = Math.Round(rate * (duration / 60d)); - await _db.Users - .Where(a => a.PubKey == user.PubKey) - .ExecuteUpdateAsync(o => o.SetProperty(v => v.Balance, v => v.Balance - cost)); + var cost = (int)Math.Ceiling(_config.Cost * (duration / 60d)); + if (cost > 0) + { + await _db.Users + .Where(a => a.PubKey == user.PubKey) + .ExecuteUpdateAsync(o => o.SetProperty(v => v.Balance, v => v.Balance - cost)); + } _logger.LogInformation("Stream consumed {n} seconds for {pubkey} costing {cost} sats", duration, user.PubKey, cost); if (user.Balance >= balanceAlertThreshold && user.Balance - cost < balanceAlertThreshold) diff --git a/docker-compose.yaml b/docker-compose.yaml index a114b31..f91fc95 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -7,6 +7,7 @@ services: - "1935:1935" - "1985:1985" - "8082:8080" + - "8003:8000" nostr: image: scsibug/nostr-rs-relay ports: diff --git a/docker/srs.conf b/docker/srs.conf index 713748e..bb69e2c 100644 --- a/docker/srs.conf +++ b/docker/srs.conf @@ -10,6 +10,11 @@ http_server { enabled on; listen 8080; } +rtc_server { + enabled on; + listen 8000; + candidate *; +} vhost __defaultVhost__ { hls { enabled on; @@ -23,4 +28,13 @@ vhost __defaultVhost__ { on_unpublish http://10.100.2.226:5295/api/srs; on_hls http://10.100.2.226:5295/api/srs; } + rtc { + enabled on; + rtmp_to_rtc on; + rtc_to_rtmp on; + } + http_remux { + enabled on; + mount [vhost]/[app]/[stream].ts; + } }