Started Room, publisher negotiation, add RTCRuntime dependencies across webrtc instances
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
use std::fmt::{Debug, Formatter};
|
||||
use std::error::Error;
|
||||
use std::fmt::{Debug, Display, Formatter};
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
use cxx::UniquePtr;
|
||||
use log::trace;
|
||||
|
||||
use libwebrtc_sys::data_channel as sys_dc;
|
||||
pub use sys_dc::ffi::Priority;
|
||||
|
||||
pub use sys_dc::ffi::{Priority, DataState};
|
||||
|
||||
pub struct DataChannel {
|
||||
cxx_handle: UniquePtr<sys_dc::ffi::DataChannel>,
|
||||
@@ -21,6 +22,17 @@ impl Debug for DataChannel {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct DataSendError;
|
||||
|
||||
impl Display for DataSendError {
|
||||
fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
|
||||
write!(f, "failed to send data to the DataChannel")
|
||||
}
|
||||
}
|
||||
|
||||
impl Error for DataSendError { }
|
||||
|
||||
impl DataChannel {
|
||||
pub(crate) fn new(cxx_handle: UniquePtr<sys_dc::ffi::DataChannel>) -> Self {
|
||||
let mut observer = Box::new(InternalDataChannelObserver::default());
|
||||
@@ -44,19 +56,28 @@ impl DataChannel {
|
||||
dc
|
||||
}
|
||||
|
||||
pub fn send(&mut self, data: &[u8], binary: bool) -> bool {
|
||||
pub fn send(&mut self, data: &[u8], binary: bool) -> Result<(), DataSendError> {
|
||||
let buffer = sys_dc::ffi::DataBuffer {
|
||||
ptr: data.as_ptr(),
|
||||
len: data.len(),
|
||||
binary,
|
||||
};
|
||||
self.cxx_handle.pin_mut().send(&buffer)
|
||||
|
||||
self.cxx_handle
|
||||
.pin_mut()
|
||||
.send(&buffer)
|
||||
.then_some(())
|
||||
.ok_or(DataSendError {})
|
||||
}
|
||||
|
||||
pub fn label(&self) -> String {
|
||||
self.cxx_handle.label()
|
||||
}
|
||||
|
||||
pub fn state(&self) -> DataState {
|
||||
self.cxx_handle.state()
|
||||
}
|
||||
|
||||
pub fn close(&mut self) {
|
||||
self.cxx_handle.pin_mut().close();
|
||||
}
|
||||
@@ -69,7 +90,7 @@ impl DataChannel {
|
||||
*self.observer.on_message_handler.lock().unwrap() = Some(handler);
|
||||
}
|
||||
|
||||
pub fn on_buffer(&mut self, handler: OnBufferedAmountChangeHandler) {
|
||||
pub fn on_buffered_amount_change(&mut self, handler: OnBufferedAmountChangeHandler) {
|
||||
*self
|
||||
.observer
|
||||
.on_buffered_amount_change_handler
|
||||
|
||||
@@ -26,6 +26,18 @@ impl IceCandidate {
|
||||
pub(crate) fn release(self) -> UniquePtr<sys_jsep::ffi::IceCandidate> {
|
||||
self.cxx_handle
|
||||
}
|
||||
|
||||
pub fn sdp_mid(&self) -> String {
|
||||
self.cxx_handle.sdp_mid()
|
||||
}
|
||||
|
||||
pub fn sdp_mline_index(&self) -> i32 {
|
||||
self.cxx_handle.sdp_mline_index()
|
||||
}
|
||||
|
||||
pub fn candidate(&self) -> String {
|
||||
self.cxx_handle.candidate()
|
||||
}
|
||||
}
|
||||
|
||||
impl ToString for IceCandidate {
|
||||
|
||||
@@ -25,6 +25,7 @@ pub struct PeerConnection {
|
||||
observer: Box<InternalObserver>,
|
||||
|
||||
// Keep alive for C++
|
||||
#[allow(unused)]
|
||||
native_observer: UniquePtr<sys_pc::ffi::NativePeerConnectionObserver>,
|
||||
}
|
||||
|
||||
@@ -174,6 +175,10 @@ impl PeerConnection {
|
||||
self.cxx_handle.ice_gathering_state()
|
||||
}
|
||||
|
||||
pub fn ice_connection_state(&self) -> IceConnectionState {
|
||||
self.cxx_handle.ice_connection_state()
|
||||
}
|
||||
|
||||
pub fn close(&mut self) {
|
||||
self.cxx_handle.pin_mut().close();
|
||||
}
|
||||
|
||||
@@ -8,15 +8,18 @@ pub use sys_factory::ffi::{
|
||||
|
||||
use crate::peer_connection::{InternalObserver, PeerConnection};
|
||||
use crate::rtc_error::RTCError;
|
||||
use crate::webrtc::RTCRuntime;
|
||||
|
||||
pub struct PeerConnectionFactory {
|
||||
cxx_handle: UniquePtr<sys_factory::ffi::PeerConnectionFactory>,
|
||||
rtc_runtime: RTCRuntime,
|
||||
}
|
||||
|
||||
impl PeerConnectionFactory {
|
||||
pub fn new() -> Self {
|
||||
pub fn new(rtc_runtime: RTCRuntime) -> Self {
|
||||
Self {
|
||||
cxx_handle: sys_factory::ffi::create_peer_connection_factory(),
|
||||
cxx_handle: sys_factory::ffi::create_peer_connection_factory(rtc_runtime.clone().release()),
|
||||
rtc_runtime,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,8 +31,8 @@ impl PeerConnectionFactory {
|
||||
|
||||
unsafe {
|
||||
let mut observer = Box::new(InternalObserver::default());
|
||||
let mut native_observer = sys_pc::ffi::create_native_peer_connection_observer(
|
||||
Box::new(sys_pc::PeerConnectionObserverWrapper::new(&mut *observer)),
|
||||
let mut native_observer = sys_pc::ffi::create_native_peer_connection_observer(self.rtc_runtime.clone().release(),
|
||||
Box::new(sys_pc::PeerConnectionObserverWrapper::new(&mut *observer)),
|
||||
);
|
||||
|
||||
let res = self
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
use cxx::UniquePtr;
|
||||
use cxx::{SharedPtr};
|
||||
|
||||
use libwebrtc_sys::webrtc as sys_rtc;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct RTCRuntime {
|
||||
cxx_handle: UniquePtr<sys_rtc::ffi::RTCRuntime>,
|
||||
cxx_handle: SharedPtr<sys_rtc::ffi::RTCRuntime>,
|
||||
}
|
||||
|
||||
impl RTCRuntime {
|
||||
@@ -12,4 +13,8 @@ impl RTCRuntime {
|
||||
cxx_handle: sys_rtc::ffi::create_rtc_runtime(),
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn release(self) -> SharedPtr<sys_rtc::ffi::RTCRuntime> {
|
||||
self.cxx_handle
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user