UPDATE: added live viewer display on home and category pages (need to remove dummy values)

This commit is contained in:
white
2025-02-17 12:23:32 +00:00
parent 3528b6517a
commit ca4bb76996

View File

@@ -23,10 +23,10 @@ def handle_join(data) -> None:
Allow a user to join the chat of the stream they are watching.
"""
stream_id = data.get("stream_id")
print(f"Stream ID GLORP: {stream_id}", flush=True)
if stream_id:
join_room(stream_id)
num_viewers = len(list(socketio.server.manager.get_participants("/", stream_id)))
update_viewers(stream_id, num_viewers)
emit("status",
{
"message": f"Welcome to the chat, stream_id: {stream_id}",
@@ -44,6 +44,7 @@ def handle_leave(data) -> None:
if stream_id:
leave_room(stream_id)
num_viewers = len(list(socketio.server.manager.get_participants("/", stream_id)))
update_viewers(stream_id, num_viewers)
emit("status",
{
"message": f"Welcome to the chat, stream_id: {stream_id}",
@@ -120,7 +121,7 @@ def save_chat(chatter_id, stream_id, message):
VALUES (?, ?, ?);""", (chatter_id, stream_id, message))
db.close_connection()
def update_viewers(stream_id, num_viewers):
def update_viewers(user_id, num_viewers):
"""
Live Update the number of viewers in the stream to be
displayed in the homepage or discovery pages
@@ -130,4 +131,5 @@ def update_viewers(stream_id, num_viewers):
UPDATE streams
SET num_viewers = ?
WHERE user_id = ?;
""")
""", (num_viewers, user_id))
db.close_connection