Skip to content

Commit

Permalink
Move PeerConnection initialization to handle_continue
Browse files Browse the repository at this point in the history
  • Loading branch information
mickel8 committed Oct 21, 2024
1 parent 6838505 commit 576b06e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .credo.exs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
# set this value to 0 (zero).
#
{Credo.Check.Design.TagTODO, [exit_status: 0]},
{Credo.Check.Design.TagFIXME, []},
{Credo.Check.Design.TagFIXME, [exit_status: 0]},

#
## Readability Checks
Expand Down
17 changes: 16 additions & 1 deletion lib/ex_webrtc/peer_connection.ex
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,15 @@ defmodule ExWebRTC.PeerConnection do

@impl true
def init(config) do
# FIXME: Spawning a lot of peer connections simultaneously, often takes a lot of time.
# This does not happen when spawning a single peer connection.
# Moving actual initialization to handle_continue at least does not block
# supervisor/dynamic supervisor under which those peer connections are spawned.
{:ok, nil, {:continue, config}}
end

@impl true
def handle_continue(config, _state) do
{:ok, _} = Registry.register(ExWebRTC.Registry, self(), self())

ice_config = [
Expand Down Expand Up @@ -533,7 +542,7 @@ defmodule ExWebRTC.PeerConnection do
notify(state.owner, {:connection_state_change, :new})
notify(state.owner, {:signaling_state_change, :stable})

{:ok, state}
{:noreply, state}
end

@impl true
Expand Down Expand Up @@ -1376,6 +1385,12 @@ defmodule ExWebRTC.PeerConnection do
{:noreply, state}
end

@impl true
def terminate(reason, nil) do
# we exit before finishing handle_continue
Logger.debug("Closing peer connection with reason: #{inspect(reason)}")
end

@impl true
def terminate(reason, state) do
Logger.debug("Closing peer connection with reason: #{inspect(reason)}")
Expand Down

0 comments on commit 576b06e

Please sign in to comment.