Skip to content
File

Blob: firmware/vendor/str0m/tests/no-local-media-added.rs

rust94 lines
1use std::net::Ipv4Addr;
2 
3use str0m::media::{Direction, MediaKind};
4use str0m::rtp::Ssrc;
5use str0m::{Event, RtcError};
6 
7mod common;
8use common::{Peer, TestRtc, connect_l_r, init_crypto_default, init_log, progress};
9 
10#[test]
11pub fn direct_declare_media_no_media_added_event() -> Result<(), RtcError> {
12 init_log();
13 init_crypto_default();
14 
15 let (mut l, mut r) = connect_l_r();
16 
17 let mid = "aud".into();
18 
19 // In this example we are using MID only (no RID) to identify the incoming media.
20 let ssrc_tx: Ssrc = 42.into();
21 
22 l.direct_api().declare_media(mid, MediaKind::Audio);
23 l.direct_api().declare_stream_tx(ssrc_tx, None, mid, None);
24 
25 r.direct_api().declare_media(mid, MediaKind::Audio);
26 
27 let max = l.last.max(r.last);
28 l.last = max;
29 r.last = max;
30 
31 loop {
32 if l.is_connected() || r.is_connected() {
33 break;
34 }
35 progress(&mut l, &mut r)?;
36 }
37 
38 let found_local = l
39 .events
40 .iter()
41 .any(|(_, e)| matches!(e, Event::MediaAdded(_)));
42 
43 let found_remote = r
44 .events
45 .iter()
46 .any(|(_, e)| matches!(e, Event::MediaAdded(_)));
47 
48 assert!(!found_local, "declare_media with local MediaAdded");
49 assert!(!found_remote, "declare_media found remote MediaAdded");
50 
51 Ok(())
52}
53 
54#[test]
55pub fn sdp_no_media_added_event() -> Result<(), RtcError> {
56 init_log();
57 init_crypto_default();
58 
59 let mut l = TestRtc::new(Peer::Left);
60 let mut r = TestRtc::new(Peer::Right);
61 
62 l.add_host_candidate((Ipv4Addr::new(1, 1, 1, 1), 1000).into());
63 r.add_host_candidate((Ipv4Addr::new(2, 2, 2, 2), 2000).into());
64 
65 let mut change = l.sdp_api();
66 let _ = change.add_media(MediaKind::Audio, Direction::SendRecv, None, None, None);
67 let (offer, pending) = change.apply().unwrap();
68 
69 let answer = r.rtc.sdp_api().accept_offer(offer)?;
70 l.rtc.sdp_api().accept_answer(pending, answer)?;
71 
72 loop {
73 if l.is_connected() || r.is_connected() {
74 break;
75 }
76 progress(&mut l, &mut r)?;
77 }
78 
79 let found_local = l
80 .events
81 .iter()
82 .any(|(_, e)| matches!(e, Event::MediaAdded(_)));
83 
84 let found_remote = r
85 .events
86 .iter()
87 .any(|(_, e)| matches!(e, Event::MediaAdded(_)));
88 
89 assert!(!found_local, "declare_media with local MediaAdded");
90 assert!(found_remote, "declare_media found remote MediaAdded");
91 
92 Ok(())
93}