commit 5606a604f6c6a7a3eb4a67127ce521818170274b
parent 40df073650c293305e5a32d6c5e5b1959b10c374
Author: n0tr1v <n0tr1v@protonmail.com>
Date: Thu, 14 Dec 2023 05:29:23 -0500
fix stream limit
Diffstat:
1 file changed, 14 insertions(+), 0 deletions(-)
diff --git a/pkg/web/handlers/poker/poker.go b/pkg/web/handlers/poker/poker.go
@@ -4,6 +4,7 @@ import (
"dkforest/pkg/database"
"dkforest/pkg/pubsub"
"dkforest/pkg/utils"
+ "dkforest/pkg/web/handlers/usersStreamsManager"
hutils "dkforest/pkg/web/handlers/utils"
"errors"
"fmt"
@@ -1909,6 +1910,7 @@ body {
func PokerLogsHandler(c echo.Context) error {
roomID := c.Param("roomID")
+ authUser := c.Get("authUser").(*database.User)
send := func(s string) { _, _ = c.Response().Write([]byte(s)) }
g := PokerInstance.GetGame(roomID)
if g == nil {
@@ -1920,6 +1922,12 @@ func PokerLogsHandler(c echo.Context) error {
quit := hutils.CloseSignalChan(c)
hutils.SetStreamingHeaders(c)
+ // Keep track of users streams, so we can limit how many are open at one time per user
+ if err := usersStreamsManager.Inst.Add(authUser.ID, roomLogsTopic); err != nil {
+ return nil
+ }
+ defer usersStreamsManager.Inst.Remove(authUser.ID, roomLogsTopic)
+
send(hutils.HtmlCssReset)
send(`<style>body { background-color: #ccc; }</style><div style="display:flex;flex-direction:column-reverse;">`)
if g.Ongoing != nil {
@@ -1975,6 +1983,12 @@ func PokerHandler(c echo.Context) error {
quit := hutils.CloseSignalChan(c)
hutils.SetStreamingHeaders(c)
+ // Keep track of users streams, so we can limit how many are open at one time per user
+ if err := usersStreamsManager.Inst.Add(authUser.ID, roomTopic); err != nil {
+ return nil
+ }
+ defer usersStreamsManager.Inst.Remove(authUser.ID, roomTopic)
+
sub := PokerPubSub.Subscribe([]string{roomTopic, roomUserTopic})
defer sub.Close()