elixir-webrtc / ex_webrtc

An Elixir implementation of the W3C WebRTC API
Apache License 2.0
269 stars 8 forks source link

/lib/ex_webrtc/peer_connection.handle_cast(:send_rtp) refactor circa line 982 #113

Closed ndrean closed 3 weeks ago

ndrean commented 4 weeks ago

https://github.com/elixir-webrtc/ex_webrtc/blob/cbfdc56b5d3b8f2e62cfbc832786fdd653827a16/lib/ex_webrtc/peer_connection.ex#L982

This callback is said to be refactored. However, as it is, you don't get what you want if the find is nil.

If you change to this, you get your message.

def handle_cast({:send_rtp, track_id, packet, opts}, state) do
    rtx? = Keyword.get(opts, :rtx?, false)

      state.transceivers
      |> Stream.with_index()
      |> Enum.find(fn
        {%{sender: %{track: %{id: id}}}, _idx} -> id == track_id
        _ -> false
      end)
      |> case do

      nil ->
        Logger.warning(
          "Attempted to send packet to track with unrecognized id: #{inspect(track_id)}"
        )

     {transceiver, idx} ->
      {packet, state} =
        case Map.fetch(...)
LVala commented 4 weeks ago

Yeah, you're right. Do you want to open a PR?

ndrean commented 4 weeks ago

114