Skip to content

Commit 117f39e

Browse files
committed
Refactor ICECandidate.from_json/1
1 parent 7b96028 commit 117f39e

File tree

1 file changed

+5
-20
lines changed

1 file changed

+5
-20
lines changed

lib/ex_webrtc/ice_candidate.ex

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -23,27 +23,12 @@ defmodule ExWebRTC.ICECandidate do
2323
end
2424

2525
@spec from_json(%{String.t() => String.t() | non_neg_integer() | nil}) :: t()
26-
def from_json(
27-
%{
28-
"candidate" => c,
29-
"sdpMid" => mid,
30-
"sdpMLineIndex" => mline_idx
31-
} = json
32-
) do
33-
from_json(Map.put(json, "usernameFragment", nil))
34-
end
35-
36-
def from_json(%{
37-
"candidate" => c,
38-
"sdpMid" => mid,
39-
"sdpMLineIndex" => mline_idx,
40-
"usernameFragment" => ufrag
41-
}) do
26+
def from_json(json) when is_map(json) do
4227
%__MODULE__{
43-
candidate: c,
44-
sdp_mid: mid,
45-
sdp_m_line_index: mline_idx,
46-
username_fragment: ufrag
28+
candidate: Map.fetch!(json, "candidate"),
29+
sdp_mid: Map.fetch!(json, "sdpMid"),
30+
sdp_m_line_index: Map.fetch!(json, "sdpMLineIndex"),
31+
username_fragment: Map.get(json, "usernameFragment")
4732
}
4833
end
4934
end

0 commit comments

Comments
 (0)