Skip to content

Commit

Permalink
Revert "Convert PeerConnection internal state into map (#24)"
Browse files Browse the repository at this point in the history
This reverts commit 66e9c67.
  • Loading branch information
mickel8 authored Nov 28, 2023
1 parent 66e9c67 commit aa4c927
Showing 1 changed file with 25 additions and 16 deletions.
41 changes: 25 additions & 16 deletions lib/ex_webrtc/peer_connection.ex
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,26 @@ defmodule ExWebRTC.PeerConnection do
"""
@type connection_state() :: :closed | :failed | :disconnected | :new | :connecting | :connected

@enforce_keys [:config, :owner]
defstruct @enforce_keys ++
[
:current_local_desc,
:pending_local_desc,
:current_remote_desc,
:pending_remote_desc,
:ice_agent,
:dtls_transport,
demuxer: %Demuxer{},
transceivers: [],
ice_state: nil,
dtls_state: nil,
signaling_state: :stable,
conn_state: :new,
last_offer: nil,
last_answer: nil,
peer_fingerprint: nil
]

#### API ####
@spec start_link(Configuration.options()) :: GenServer.on_start()
def start_link(options \\ []) do
Expand Down Expand Up @@ -112,24 +132,13 @@ defmodule ExWebRTC.PeerConnection do
{:ok, dtls_transport} = DTLSTransport.start_link(ice_config)
ice_agent = DTLSTransport.get_ice_agent(dtls_transport)

state = %{
state = %__MODULE__{
owner: owner,
config: config,
current_local_desc: nil,
pending_local_desc: nil,
current_remote_desc: nil,
pending_remote_desc: nil,
ice_agent: ice_agent,
dtls_transport: dtls_transport,
demuxer: %Demuxer{},
transceivers: [],
ice_state: :new,
dtls_state: :new,
signaling_state: :stable,
conn_state: :new,
last_offer: nil,
last_answer: nil,
peer_fingerprint: nil
dtls_state: :new
}

notify(state.owner, {:connection_state_change, :new})
Expand Down Expand Up @@ -340,7 +349,7 @@ defmodule ExWebRTC.PeerConnection do

@impl true
def handle_info({:ex_ice, _from, {:connection_state_change, new_ice_state}}, state) do
state = %{state | ice_state: new_ice_state}
state = %__MODULE__{state | ice_state: new_ice_state}
next_conn_state = next_conn_state(new_ice_state, state.dtls_state)
state = update_conn_state(state, next_conn_state)

Expand Down Expand Up @@ -368,7 +377,7 @@ defmodule ExWebRTC.PeerConnection do

@impl true
def handle_info({:dtls_transport, _pid, {:state_change, new_dtls_state}}, state) do
state = %{state | dtls_state: new_dtls_state}
state = %__MODULE__{state | dtls_state: new_dtls_state}
next_conn_state = next_conn_state(state.ice_state, new_dtls_state)
state = update_conn_state(state, next_conn_state)
{:noreply, state}
Expand All @@ -379,7 +388,7 @@ defmodule ExWebRTC.PeerConnection do
case Demuxer.demux(state.demuxer, data) do
{:ok, demuxer, mid, packet} ->
notify(state.owner, {:data, {mid, packet}})
{:noreply, %{state | demuxer: demuxer}}
{:noreply, %__MODULE__{state | demuxer: demuxer}}

{:error, reason} ->
Logger.error("Unable to demux RTP, reason: #{inspect(reason)}")
Expand Down

0 comments on commit aa4c927

Please sign in to comment.