-
Notifications
You must be signed in to change notification settings - Fork 16
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
4 changed files
with
176 additions
and
22 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
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,85 @@ | ||
defmodule ExWebRTC.RTPTransceiverTest do | ||
use ExUnit.Case, async: true | ||
|
||
alias ExWebRTC.{MediaStreamTrack, PeerConnection, RTPTransceiver, Utils} | ||
|
||
{:ok, pc} = PeerConnection.start_link() | ||
@config PeerConnection.get_configuration(pc) | ||
:ok = PeerConnection.close(pc) | ||
|
||
@ssrc 1234 | ||
@rtx_ssrc 2345 | ||
|
||
@track MediaStreamTrack.new(:video, [MediaStreamTrack.generate_stream_id()]) | ||
|
||
{_key, cert} = ExDTLS.generate_key_cert() | ||
|
||
@opts [ | ||
ice_ufrag: "ice_ufrag", | ||
ice_pwd: "ice_pwd", | ||
ice_options: "trickle", | ||
fingerprint: {:sha256, Utils.hex_dump(cert)}, | ||
setup: :actpass | ||
] | ||
|
||
describe "to_offer_mline/1" do | ||
test "with sendrecv direction" do | ||
tr = RTPTransceiver.new(:video, @track, @config, ssrc: @ssrc, rtx_ssrc: @rtx_ssrc) | ||
test_sender_attrs(tr) | ||
end | ||
|
||
test "with sendonly direction" do | ||
tr = | ||
RTPTransceiver.new(:video, @track, @config, | ||
ssrc: @ssrc, | ||
rtx_ssrc: @rtx_ssrc, | ||
direction: :sendonly | ||
) | ||
|
||
test_sender_attrs(tr) | ||
end | ||
|
||
test "with recvonly direction" do | ||
tr = | ||
RTPTransceiver.new(:video, @track, @config, | ||
ssrc: @ssrc, | ||
rtx_ssrc: @rtx_ssrc, | ||
direction: :recvonly | ||
) | ||
|
||
test_no_sender_attrs(tr) | ||
end | ||
|
||
test "with inactive direction" do | ||
tr = | ||
RTPTransceiver.new(:video, @track, @config, | ||
ssrc: @ssrc, | ||
rtx_ssrc: @rtx_ssrc, | ||
direction: :inactive | ||
) | ||
|
||
test_no_sender_attrs(tr) | ||
end | ||
end | ||
|
||
defp test_sender_attrs(tr) do | ||
mline = RTPTransceiver.to_offer_mline(tr, @opts) | ||
|
||
# Assert rtp sender attributes are present. | ||
# Their exact values are checked in rtp_sender_test.exs. | ||
assert [%ExSDP.Attribute.MSID{}] = ExSDP.get_attributes(mline, ExSDP.Attribute.MSID) | ||
assert [%ExSDP.Attribute.SSRCGroup{}] = ExSDP.get_attributes(mline, ExSDP.Attribute.SSRCGroup) | ||
|
||
assert [%ExSDP.Attribute.SSRC{}, %ExSDP.Attribute.SSRC{}] = | ||
ExSDP.get_attributes(mline, ExSDP.Attribute.SSRC) | ||
end | ||
|
||
defp test_no_sender_attrs(tr) do | ||
mline = RTPTransceiver.to_offer_mline(tr, @opts) | ||
|
||
# assert there are no sender attributes | ||
assert [] == ExSDP.get_attributes(mline, ExSDP.Attribute.MSID) | ||
assert [] == ExSDP.get_attributes(mline, ExSDP.Attribute.SSRCGroup) | ||
assert [] == ExSDP.get_attributes(mline, ExSDP.Attribute.SSRC) | ||
end | ||
end |