Spaces:
Running
on
T4
Running
on
T4
Mark Duppenthaler
commited on
Commit
•
7571f4c
1
Parent(s):
343dd34
Update correct file
Browse files
seamless_server/app_pubsub.py
CHANGED
@@ -123,9 +123,12 @@ class ServerLock(TypedDict):
|
|
123 |
client_id: str
|
124 |
member_object: Member
|
125 |
|
|
|
126 |
|
127 |
if os.environ.get("LOCK_SERVER_COMPLETELY"):
|
128 |
logger.info("LOCK_SERVER_COMPLETELY is set. Server will be locked on startup.")
|
|
|
|
|
129 |
dummy_server_lock_member_object = Member(
|
130 |
client_id="seamless_user", session_id="dummy", name="Seamless User"
|
131 |
)
|
@@ -556,6 +559,12 @@ async def join_room(sid, client_id, room_id_from_client, config_dict):
|
|
556 |
|
557 |
return {"roomsJoined": sio.rooms(sid), "roomID": room_id}
|
558 |
|
|
|
|
|
|
|
|
|
|
|
|
|
559 |
|
560 |
# TODO: Add code to prevent more than one speaker from connecting/streaming at a time
|
561 |
@sio.event
|
@@ -576,6 +585,12 @@ async def configure_stream(sid, config):
|
|
576 |
)
|
577 |
return {"status": "error", "message": "member_or_room_is_none"}
|
578 |
|
|
|
|
|
|
|
|
|
|
|
|
|
579 |
# If there is a server lock WITH an active transcoder session, prevent other users from configuring and starting a stream
|
580 |
# If the server lock client does NOT have an active transcoder session allow this to proceed, knowing that
|
581 |
# this stream will be interrupted if the server lock client starts streaming
|
|
|
123 |
client_id: str
|
124 |
member_object: Member
|
125 |
|
126 |
+
MAX_SPEAKERS = os.environ.get("MAX_SPEAKERS")
|
127 |
|
128 |
if os.environ.get("LOCK_SERVER_COMPLETELY"):
|
129 |
logger.info("LOCK_SERVER_COMPLETELY is set. Server will be locked on startup.")
|
130 |
+
if MAX_SPEAKERS is not None:
|
131 |
+
logger.info(f"MAX_SPEAKERS is set to: {MAX_SPEAKERS}")
|
132 |
dummy_server_lock_member_object = Member(
|
133 |
client_id="seamless_user", session_id="dummy", name="Seamless User"
|
134 |
)
|
|
|
559 |
|
560 |
return {"roomsJoined": sio.rooms(sid), "roomID": room_id}
|
561 |
|
562 |
+
def allow_speaker(room, client_id):
|
563 |
+
if MAX_SPEAKERS is not None and client_id in room.speakers:
|
564 |
+
room_statuses = {room_id: room.get_room_status_dict() for room_id, room in rooms.items()}
|
565 |
+
speakers = sum(room_status["activeTranscoders"] for room_status in room_statuses.values())
|
566 |
+
return speakers < int(MAX_SPEAKERS)
|
567 |
+
return True
|
568 |
|
569 |
# TODO: Add code to prevent more than one speaker from connecting/streaming at a time
|
570 |
@sio.event
|
|
|
585 |
)
|
586 |
return {"status": "error", "message": "member_or_room_is_none"}
|
587 |
|
588 |
+
if not allow_speaker(room, client_id):
|
589 |
+
logger.error(
|
590 |
+
f"In MAX_SPEAKERS mode we only allow one speaker at a time. Ignoring request to configure stream from client {client_id}."
|
591 |
+
)
|
592 |
+
return {"status": "error", "message": "max_speakers"}
|
593 |
+
|
594 |
# If there is a server lock WITH an active transcoder session, prevent other users from configuring and starting a stream
|
595 |
# If the server lock client does NOT have an active transcoder session allow this to proceed, knowing that
|
596 |
# this stream will be interrupted if the server lock client starts streaming
|