Skip to content

Commit a30cfc2

Browse files
authored
Update publish.py
1 parent 1172590 commit a30cfc2

File tree

1 file changed

+21
-20
lines changed

1 file changed

+21
-20
lines changed

publish.py

+21-20
Original file line numberDiff line numberDiff line change
@@ -254,22 +254,6 @@ def decrypt_message(encrypted_data, iv, phrase):
254254
print(f"Error decoding message: {e}")
255255
return None
256256

257-
def setup_ice_servers(webrtc, params):
258-
try:
259-
if args.stun_server:
260-
webrtc.set_property('stun-server', args.stun_server)
261-
elif not params.no_stun: # Fall back to defaults if not disabled
262-
for server in ["stun://stun.cloudflare.com:3478", "stun://stun.l.google.com:19302"]:
263-
webrtc.set_property('stun-server', server)
264-
265-
if args.turn_server:
266-
webrtc.set_property('turn-server', args.turn_server)
267-
268-
if args.ice_transport_policy:
269-
webrtc.set_property('ice-transport-policy', args.ice_transport_policy)
270-
271-
except Exception as E:
272-
printwarn(get_exception_info(E))
273257

274258
class WebRTCClient:
275259
def __init__(self, params):
@@ -336,9 +320,26 @@ def __init__(self, params):
336320

337321
if self.save_file:
338322
self.pipe = Gst.parse_launch(self.pipeline)
339-
setup_ice_servers(self.pipe.get_by_name('sendrecv'))
323+
self.setup_ice_servers(self.pipe.get_by_name('sendrecv'))
340324
self.pipe.set_state(Gst.State.PLAYING)
341325
print("RECORDING TO DISK STARTED")
326+
327+
def setup_ice_servers(self, webrtc):
328+
try:
329+
if hasattr(self, 'stun_server') and self.stun_server:
330+
webrtc.set_property('stun-server', self.stun_server)
331+
elif not hasattr(self, 'no_stun') or not self.no_stun:
332+
for server in ["stun://stun.cloudflare.com:3478", "stun://stun.l.google.com:19302"]:
333+
webrtc.set_property('stun-server', server)
334+
335+
if hasattr(self, 'turn_server') and self.turn_server:
336+
webrtc.set_property('turn-server', self.turn_server)
337+
338+
if hasattr(self, 'ice_transport_policy') and self.ice_transport_policy:
339+
webrtc.set_property('ice-transport-policy', self.ice_transport_policy)
340+
341+
except Exception as E:
342+
printwarn(get_exception_info(E))
342343

343344
async def connect(self):
344345
print("Connecting to handshake server")
@@ -1373,7 +1374,7 @@ def on_stats(promise, abin, data):
13731374
if self.streamin:
13741375
client['webrtc'] = Gst.ElementFactory.make("webrtcbin", client['UUID'])
13751376
client['webrtc'].set_property('bundle-policy', "max-bundle")
1376-
setup_ice_servers(client['webrtc'])
1377+
ssetup_ice_servers(client['webrtc'], self)
13771378

13781379
try:
13791380
client['webrtc'].set_property('latency', self.buffer)
@@ -1393,12 +1394,12 @@ def on_stats(promise, abin, data):
13931394

13941395
elif not self.multiviewer:
13951396
client['webrtc'] = self.pipe.get_by_name('sendrecv')
1396-
setup_ice_servers(client['webrtc'])
1397+
self.setup_ice_servers(client['webrtc'])
13971398
pass
13981399
else:
13991400
client['webrtc'] = Gst.ElementFactory.make("webrtcbin", client['UUID'])
14001401
client['webrtc'].set_property('bundle-policy', 'max-bundle')
1401-
setup_ice_servers(client['webrtc'])
1402+
self.setup_ice_servers(client['webrtc'])
14021403

14031404
try:
14041405
client['webrtc'].set_property('latency', self.buffer)

0 commit comments

Comments
 (0)