diff --git a/server/websocket/webrtc_signaling.py b/server/websocket/webrtc_signaling.py index 5874d36..d419fd2 100644 --- a/server/websocket/webrtc_signaling.py +++ b/server/websocket/webrtc_signaling.py @@ -233,10 +233,20 @@ class WebRTCSignalingHandlers: # Determine deterministic offerer to avoid glare/collision: # the peer with the lexicographically smaller session ID will create the offer. try: - session_is_offer = session.id < peer_session.id + # Prefer bots to be the offerer when pairing a bot with a human. + # If one side is a bot and the other isn't, the bot will create the offer. + if getattr(session, "bot_instance_id", None) and not getattr(peer_session, "bot_instance_id", None): + session_is_offer = True + elif getattr(peer_session, "bot_instance_id", None) and not getattr(session, "bot_instance_id", None): + session_is_offer = False + else: + # Deterministic fallback: lexicographic session id + session_is_offer = session.id < peer_session.id # Notify existing peer about new peer - peer_should_create_offer = peer_session.id < session.id + peer_should_create_offer = peer_session.id < session.id if not ( + getattr(session, "bot_instance_id", None) or getattr(peer_session, "bot_instance_id", None) + ) else (True if getattr(peer_session, "bot_instance_id", None) and not getattr(session, "bot_instance_id", None) else False) logger.info( f"{session.getName()} -> {peer_session.getName()}:addPeer(" f"{session.getName()}, {lobby.getName()}, should_create_offer={peer_should_create_offer}, "