-
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
7 changed files
with
135 additions
and
48 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,7 @@ | ||
defmodule ExWebRTC.MediaStreamTrack do | ||
Check warning on line 1 in lib/ex_webrtc/media_stream_track.ex GitHub Actions / Lint (OTP 26 / Elixir 1.15)
|
||
defstruct [] | ||
|
||
def from_transceiver(_tr) do | ||
%__MODULE__{} | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,47 @@ | ||
defmodule ExWebRTC.RTPTransceiver do | ||
@moduledoc """ | ||
RTPTransceiver | ||
""" | ||
|
||
@type t() :: %__MODULE__{ | ||
mid: String.t(), | ||
direction: :sendonly | :recvonly | :sendrecv | :inactive | :stopped | ||
} | ||
|
||
@enforce_keys [:mid, :direction] | ||
defstruct @enforce_keys | ||
|
||
@doc false | ||
def find_by_mid(transceivers, mid) do | ||
transceivers | ||
|> Enum.with_index(fn tr, idx -> {idx, tr} end) | ||
|> Enum.find(fn {_idx, tr} -> tr.mid == mid end) | ||
end | ||
|
||
# searches for transceiver for a given mline | ||
# if it exists, updates its configuration | ||
# if it doesn't exist, creats a new one | ||
# returns list of updated transceivers | ||
@doc false | ||
def update_or_create(transceivers, mid, mline) do | ||
case find_by_mid(transceivers, mid) do | ||
{idx, %__MODULE__{} = tr} -> | ||
case update(tr, mline) do | ||
{:ok, tr} -> List.replace_at(transceivers, idx, tr) | ||
{:error, :remove} -> List.delete_at(transceivers, idx) | ||
end | ||
|
||
nil -> | ||
transceivers ++ [%RTPTransceiver{mid: mid, direction: :recvonly}] | ||
end | ||
end | ||
|
||
defp update(transceiver, mline) do | ||
# if there is no direction, the default is sendrecv | ||
# see RFC 3264, sec. 6.1 | ||
case ExWebRTC.Utils.get_media_direction(mline) || :sendrecv do | ||
:inactive -> {:error, :remove} | ||
other_direction -> {:ok, %__MODULE__{transceiver | direction: other_direction}} | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
defmodule ExWebRTC.PeerConnectionTest do | ||
use ExUnit.Case, async: true | ||
|
||
alias ExWebRTC.{MediaStreamTrack, PeerConnection, SessionDescription} | ||
|
||
@offer """ | ||
v=0 | ||
o=- 6788894006044524728 2 IN IP4 127.0.0.1 | ||
s=- | ||
t=0 0 | ||
a=group:BUNDLE 0 | ||
a=extmap-allow-mixed | ||
a=msid-semantic: WMS | ||
m=audio 9 UDP/TLS/RTP/SAVPF 111 | ||
c=IN IP4 0.0.0.0 | ||
a=rtcp:9 IN IP4 0.0.0.0 | ||
a=ice-ufrag:cDua | ||
a=ice-pwd:v9SCmZHxJWtgpyzn8Ts1puT6 | ||
a=ice-options:trickle | ||
a=fingerprint:sha-256 11:35:68:66:A4:C3:C0:AA:37:4E:0F:97:D7:9F:76:11:08:DB:56:DA:4B:83:77:50:9A:D2:71:8D:2A:A8:E3:07 | ||
a=setup:actpass | ||
a=mid:0 | ||
a=sendrecv | ||
a=msid:- 54f0751b-086f-433c-af40-79c179182423 | ||
a=rtcp-mux | ||
a=rtpmap:111 opus/48000/2 | ||
a=rtcp-fb:111 transport-cc | ||
a=fmtp:111 minptime=10;useinbandfec=1 | ||
a=ssrc:1463342914 cname:poWwjNZ4I2ZZgzY7 | ||
a=ssrc:1463342914 msid:- 54f0751b-086f-433c-af40-79c179182423 | ||
""" | ||
|
||
test "transceivers" do | ||
{:ok, pc} = PeerConnection.start_link() | ||
|
||
offer = %SessionDescription{type: :offer, sdp: @offer} | ||
:ok = PeerConnection.set_remote_description(pc, offer) | ||
|
||
assert_receive {:ex_webrtc, ^pc, {:track, %MediaStreamTrack{}}} | ||
end | ||
end |