@@ -479,6 +479,15 @@ defmodule ExWebRTC.PeerConnection do
479
479
480
480
@ impl true
481
481
def init ( config ) do
482
+ # FIXME: Spawning a lot of peer connections simultaneously, often takes a lot of time.
483
+ # This does not happen when spawning a single peer connection.
484
+ # Moving actual initialization to handle_continue at least does not block
485
+ # supervisor/dynamic supervisor under which those peer connections are spawned.
486
+ { :ok , nil , { :continue , config } }
487
+ end
488
+
489
+ @ impl true
490
+ def handle_continue ( config , _state ) do
482
491
{ :ok , _ } = Registry . register ( ExWebRTC.Registry , self ( ) , self ( ) )
483
492
484
493
ice_config = [
@@ -533,7 +542,7 @@ defmodule ExWebRTC.PeerConnection do
533
542
notify ( state . owner , { :connection_state_change , :new } )
534
543
notify ( state . owner , { :signaling_state_change , :stable } )
535
544
536
- { :ok , state }
545
+ { :noreply , state }
537
546
end
538
547
539
548
@ impl true
@@ -1376,6 +1385,12 @@ defmodule ExWebRTC.PeerConnection do
1376
1385
{ :noreply , state }
1377
1386
end
1378
1387
1388
+ @ impl true
1389
+ def terminate ( reason , nil ) do
1390
+ # we exit before finishing handle_continue
1391
+ Logger . debug ( "Closing peer connection with reason: #{ inspect ( reason ) } " )
1392
+ end
1393
+
1379
1394
@ impl true
1380
1395
def terminate ( reason , state ) do
1381
1396
Logger . debug ( "Closing peer connection with reason: #{ inspect ( reason ) } " )
0 commit comments