Skip to content

Commit ff7f1f7

Browse files
committed
fix: fixing p2p webrtc
1 parent e291b89 commit ff7f1f7

2 files changed

Lines changed: 19 additions & 7 deletions

File tree

intercomclient/config.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ class Config:
4141
http_api_base_url: str = os.getenv("HTTP_API_BASE_URL", "wrong")
4242
websocket_api_base_url: str = os.getenv("WEBSOCKET_API_BASE_URL", "wrong")
4343
max_polling_time_mins: int = int(os.getenv("MAX_POLLING_TIME_MINS", 5))
44+
turn_url: str | None = os.getenv("TURN_URL")
45+
turn_username: str | None = os.getenv("TURN_USERNAME")
46+
turn_credential: str | None = os.getenv("TURN_CREDENTIAL")
4447

4548

4649
logging.basicConfig(level=logging.DEBUG if Config.debug_mode else logging.INFO)

main.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -136,14 +136,23 @@ async def setup_peer_connection(self):
136136
if old_pc:
137137
await old_pc.close()
138138

139-
pc = RTCPeerConnection(
140-
configuration=RTCConfiguration(
141-
iceServers=[
142-
RTCIceServer(urls="stun:stun.l.google.com:19302"),
143-
RTCIceServer(urls="stun:stun1.l.google.com:19302"),
144-
]
139+
ice_servers = [
140+
RTCIceServer(urls="stun:stun.l.google.com:19302"),
141+
RTCIceServer(urls="stun:stun1.l.google.com:19302"),
142+
]
143+
if (
144+
self.config.turn_url
145+
and self.config.turn_username
146+
and self.config.turn_credential
147+
):
148+
ice_servers.append(
149+
RTCIceServer(
150+
urls=self.config.turn_url,
151+
username=self.config.turn_username,
152+
credential=self.config.turn_credential,
153+
)
145154
)
146-
)
155+
pc = RTCPeerConnection(configuration=RTCConfiguration(iceServers=ice_servers))
147156
self.pc = pc
148157

149158
@pc.on("connectionstatechange")

0 commit comments

Comments
 (0)