-
Notifications
You must be signed in to change notification settings - Fork 8
/
ice_candidate.ex
39 lines (35 loc) · 1.03 KB
/
ice_candidate.ex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
defmodule ExWebRTC.ICECandidate do
@moduledoc """
Implementation of the [RTCIceCandidate](https://www.w3.org/TR/webrtc/#rtcicecandidate-interface).
"""
@type t() :: %__MODULE__{
candidate: binary(),
sdp_mid: non_neg_integer() | nil,
sdp_m_line_index: non_neg_integer() | nil,
username_fragment: binary() | nil
}
defstruct [:candidate, :username_fragment, :sdp_mid, :sdp_m_line_index]
@spec to_json(t()) :: %{String.t() => String.t()}
def to_json(%__MODULE__{} = c) do
%{
"candidate" => c.candidate,
"sdpMid" => c.sdp_mid,
"sdpMLineIndex" => c.sdp_m_line_index,
"usernameFragment" => c.username_fragment
}
end
@spec from_json(%{String.t() => String.t()}) :: t()
def from_json(%{
"candidate" => c,
"sdpMid" => mid,
"sdpMLineIndex" => mline_idx,
"usernameFragment" => ufrag
}) do
%__MODULE__{
candidate: c,
sdp_mid: mid,
sdp_m_line_index: mline_idx,
username_fragment: ufrag
}
end
end