Fixed negotiation

This commit is contained in:
James Ketr 2025-09-08 16:14:53 -07:00
parent afdf856f2b
commit ce012e253c

View File

@ -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}, "