UPDATE: added live viewer display on home and category pages (need to remove dummy values)
This commit is contained in:
@@ -23,10 +23,10 @@ def handle_join(data) -> None:
|
|||||||
Allow a user to join the chat of the stream they are watching.
|
Allow a user to join the chat of the stream they are watching.
|
||||||
"""
|
"""
|
||||||
stream_id = data.get("stream_id")
|
stream_id = data.get("stream_id")
|
||||||
print(f"Stream ID GLORP: {stream_id}", flush=True)
|
|
||||||
if stream_id:
|
if stream_id:
|
||||||
join_room(stream_id)
|
join_room(stream_id)
|
||||||
num_viewers = len(list(socketio.server.manager.get_participants("/", stream_id)))
|
num_viewers = len(list(socketio.server.manager.get_participants("/", stream_id)))
|
||||||
|
update_viewers(stream_id, num_viewers)
|
||||||
emit("status",
|
emit("status",
|
||||||
{
|
{
|
||||||
"message": f"Welcome to the chat, stream_id: {stream_id}",
|
"message": f"Welcome to the chat, stream_id: {stream_id}",
|
||||||
@@ -44,6 +44,7 @@ def handle_leave(data) -> None:
|
|||||||
if stream_id:
|
if stream_id:
|
||||||
leave_room(stream_id)
|
leave_room(stream_id)
|
||||||
num_viewers = len(list(socketio.server.manager.get_participants("/", stream_id)))
|
num_viewers = len(list(socketio.server.manager.get_participants("/", stream_id)))
|
||||||
|
update_viewers(stream_id, num_viewers)
|
||||||
emit("status",
|
emit("status",
|
||||||
{
|
{
|
||||||
"message": f"Welcome to the chat, stream_id: {stream_id}",
|
"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))
|
VALUES (?, ?, ?);""", (chatter_id, stream_id, message))
|
||||||
db.close_connection()
|
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
|
Live Update the number of viewers in the stream to be
|
||||||
displayed in the homepage or discovery pages
|
displayed in the homepage or discovery pages
|
||||||
@@ -130,4 +131,5 @@ def update_viewers(stream_id, num_viewers):
|
|||||||
UPDATE streams
|
UPDATE streams
|
||||||
SET num_viewers = ?
|
SET num_viewers = ?
|
||||||
WHERE user_id = ?;
|
WHERE user_id = ?;
|
||||||
""")
|
""", (num_viewers, user_id))
|
||||||
|
db.close_connection
|
||||||
Reference in New Issue
Block a user