-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
96 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
defmodule ExWebRTC.SDPUtils do | ||
@moduledoc false | ||
|
||
@spec get_media_direction(ExSDP.Media.t()) :: | ||
:sendrecv | :sendonly | :recvonly | :inactive | nil | ||
def get_media_direction(media) do | ||
Enum.find(media.attributes, fn attr -> | ||
attr in [:sendrecv, :sendonly, :recvonly, :inactive] | ||
end) | ||
end | ||
|
||
@spec ensure_mid(ExSDP.t()) :: :ok | {:error, :missing_mid | :duplicated_mid} | ||
def ensure_mid(sdp) do | ||
sdp.media | ||
|> Enum.reduce_while({:ok, []}, fn media, {:ok, acc} -> | ||
case ExSDP.Media.get_attributes(media, :mid) do | ||
[{:mid, mid}] -> {:cont, {:ok, [mid | acc]}} | ||
[] -> {:halt, {:error, :missing_mid}} | ||
other when is_list(other) -> {:halt, {:error, :duplicated_mid}} | ||
end | ||
end) | ||
|> case do | ||
{:ok, mids} -> if Enum.uniq(mids) == mids, do: :ok, else: {:error, :duplicated_mid} | ||
error -> error | ||
end | ||
end | ||
|
||
@spec ensure_bundle(ExSDP.t()) :: | ||
:ok | ||
| {:error, | ||
:non_exhaustive_bundle_group | :missing_budnle_group | :multiple_bundle_groups} | ||
def ensure_bundle(sdp) do | ||
groups = ExSDP.get_attributes(sdp, ExSDP.Attribute.Group) | ||
|
||
mline_mids = | ||
Enum.map(sdp.media, fn media -> | ||
{:mid, mid} = ExSDP.Media.get_attribute(media, :mid) | ||
mid | ||
end) | ||
|
||
case groups do | ||
[%ExSDP.Attribute.Group{semantics: "BUNDLE", mids: group_mids}] -> | ||
if group_mids -- mline_mids == [], do: :ok, else: {:error, :non_exhaustive_bundle_group} | ||
|
||
[] -> | ||
{:error, :missing_bundle_group} | ||
|
||
other when is_list(other) -> | ||
{:error, :multiple_bundle_groups} | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters