fix: windows crashes & builds (#55)
- Doing jobs in parallels in GHA (Divide build time by 3).
- Now use custom webrtc builds for this repo
- Windows crashes when receiving video is now fixed (thanks @cloudwebrtc)
- Now reading defines from webrtc.ninja
- Added a small create_pc test to be sure libwebrtc is working/linked correctly
- Fix MacOS builds
- Fixed Linux duplicated main build error (due to nasm)
This commit is contained in:
@@ -110,6 +110,7 @@ impl From<sys_pc::ffi::SignalingState> for SignalingState {
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct PeerConnection {
|
||||
#[allow(dead_code)]
|
||||
native_observer: SharedPtr<sys_pc::ffi::NativePeerConnectionObserver>,
|
||||
observer: Arc<PeerObserver>,
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
use crate::rtp_parameters::*;
|
||||
use crate::MediaType;
|
||||
use webrtc_sys::rtp_parameters as sys_rp;
|
||||
use webrtc_sys::webrtc as sys_webrtc;
|
||||
|
||||
|
||||
@@ -5,7 +5,6 @@ use crate::rtp_receiver;
|
||||
use crate::rtp_sender;
|
||||
use crate::rtp_transceiver::RtpTransceiverDirection;
|
||||
use crate::rtp_transceiver::RtpTransceiverInit;
|
||||
use crate::MediaType;
|
||||
use crate::RtcError;
|
||||
use cxx::SharedPtr;
|
||||
use webrtc_sys::rtc_error as sys_err;
|
||||
@@ -33,7 +32,6 @@ impl From<RtpTransceiverDirection> for sys_webrtc::ffi::RtpTransceiverDirection
|
||||
RtpTransceiverDirection::RecvOnly => Self::RecvOnly,
|
||||
RtpTransceiverDirection::Inactive => Self::Inactive,
|
||||
RtpTransceiverDirection::Stopped => Self::Stopped,
|
||||
_ => panic!("unknown RtpTransceiverDirection"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -238,3 +238,84 @@ impl Debug for PeerConnection {
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::peer_connection::*;
|
||||
use crate::peer_connection_factory::*;
|
||||
use log::trace;
|
||||
use tokio::sync::mpsc;
|
||||
|
||||
fn init_log() {
|
||||
let _ = env_logger::builder().is_test(true).try_init();
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn create_pc() {
|
||||
init_log();
|
||||
|
||||
let factory = PeerConnectionFactory::default();
|
||||
let config = RtcConfiguration {
|
||||
ice_servers: vec![IceServer {
|
||||
urls: vec!["stun:stun1.l.google.com:19302".to_string()],
|
||||
username: "".into(),
|
||||
password: "".into(),
|
||||
}],
|
||||
continual_gathering_policy: ContinualGatheringPolicy::GatherOnce,
|
||||
ice_transport_type: IceTransportsType::All,
|
||||
};
|
||||
|
||||
let bob = factory.create_peer_connection(config.clone()).unwrap();
|
||||
let alice = factory.create_peer_connection(config.clone()).unwrap();
|
||||
|
||||
let (bob_ice_tx, mut bob_ice_rx) = mpsc::channel::<IceCandidate>(16);
|
||||
let (alice_ice_tx, mut alice_ice_rx) = mpsc::channel::<IceCandidate>(16);
|
||||
let (alice_dc_tx, mut alice_dc_rx) = mpsc::channel::<DataChannel>(16);
|
||||
|
||||
bob.on_ice_candidate(Some(Box::new(move |candidate| {
|
||||
bob_ice_tx.blocking_send(candidate).unwrap();
|
||||
})));
|
||||
|
||||
alice.on_ice_candidate(Some(Box::new(move |candidate| {
|
||||
alice_ice_tx.blocking_send(candidate).unwrap();
|
||||
})));
|
||||
|
||||
alice.on_data_channel(Some(Box::new(move |dc| {
|
||||
alice_dc_tx.blocking_send(dc).unwrap();
|
||||
})));
|
||||
|
||||
let bob_dc = bob
|
||||
.create_data_channel("test_dc", DataChannelInit::default())
|
||||
.unwrap();
|
||||
|
||||
let offer = bob.create_offer(OfferOptions::default()).await.unwrap();
|
||||
trace!("Bob offer: {:?}", offer);
|
||||
bob.set_local_description(offer.clone()).await.unwrap();
|
||||
alice.set_remote_description(offer).await.unwrap();
|
||||
|
||||
let answer = alice.create_answer(AnswerOptions::default()).await.unwrap();
|
||||
trace!("Alice answer: {:?}", answer);
|
||||
alice.set_local_description(answer.clone()).await.unwrap();
|
||||
bob.set_remote_description(answer).await.unwrap();
|
||||
|
||||
let bob_ice = bob_ice_rx.recv().await.unwrap();
|
||||
let alice_ice = alice_ice_rx.recv().await.unwrap();
|
||||
|
||||
bob.add_ice_candidate(alice_ice).await.unwrap();
|
||||
alice.add_ice_candidate(bob_ice).await.unwrap();
|
||||
|
||||
let (data_tx, mut data_rx) = mpsc::channel::<String>(1);
|
||||
let alice_dc = alice_dc_rx.recv().await.unwrap();
|
||||
alice_dc.on_message(Some(Box::new(move |buffer| {
|
||||
data_tx
|
||||
.blocking_send(String::from_utf8_lossy(buffer.data).to_string())
|
||||
.unwrap();
|
||||
})));
|
||||
|
||||
bob_dc.send(b"This is a test", true).unwrap();
|
||||
assert_eq!(data_rx.recv().await.unwrap(), "This is a test");
|
||||
|
||||
alice.close();
|
||||
bob.close();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user