refactored RTCEngine

This commit is contained in:
Théo Monnom
2022-12-20 23:05:31 +01:00
parent 2e3c87f232
commit 1ed925dd38
8 changed files with 339 additions and 501 deletions
@@ -24,10 +24,10 @@ class DataChannel {
void register_observer(NativeDataChannelObserver& observer);
void unregister_observer();
bool send(const DataBuffer& buffer);
bool send(const DataBuffer& buffer) const;
rust::String label() const;
DataState state() const;
void close();
void close() const;
private:
std::shared_ptr<RTCRuntime> rtc_runtime_;
@@ -24,7 +24,7 @@ void DataChannel::unregister_observer() {
data_channel_->UnregisterObserver();
}
bool DataChannel::send(const DataBuffer& buffer) {
bool DataChannel::send(const DataBuffer& buffer) const {
return data_channel_->Send(webrtc::DataBuffer{
rtc::CopyOnWriteBuffer(buffer.ptr, buffer.len), buffer.binary});
}
@@ -37,7 +37,7 @@ DataState DataChannel::state() const {
return static_cast<DataState>(data_channel_->state());
}
void DataChannel::close() {
void DataChannel::close() const {
return data_channel_->Close();
}
@@ -68,10 +68,10 @@ pub mod ffi {
);
fn unregister_observer(self: Pin<&mut DataChannel>);
fn send(self: Pin<&mut DataChannel>, data: &DataBuffer) -> bool;
fn send(self: &DataChannel, data: &DataBuffer) -> bool;
fn label(self: &DataChannel) -> String;
fn state(self: &DataChannel) -> DataState;
fn close(self: Pin<&mut DataChannel>);
fn close(self: &DataChannel);
fn create_data_channel_init(init: DataChannelInit) -> UniquePtr<NativeDataChannelInit>;
fn create_native_data_channel_observer(
+3 -4
View File
@@ -58,7 +58,7 @@ impl DataChannel {
dc
}
pub fn send(&mut self, data: &[u8], binary: bool) -> Result<(), DataSendError> {
pub fn send(&self, data: &[u8], binary: bool) -> Result<(), DataSendError> {
let buffer = sys_dc::ffi::DataBuffer {
ptr: data.as_ptr(),
len: data.len(),
@@ -66,7 +66,6 @@ impl DataChannel {
};
self.cxx_handle
.pin_mut()
.send(&buffer)
.then_some(())
.ok_or(DataSendError {})
@@ -80,8 +79,8 @@ impl DataChannel {
self.cxx_handle.state()
}
pub fn close(&mut self) {
self.cxx_handle.pin_mut().close();
pub fn close(&self) {
self.cxx_handle.close();
}
pub fn on_state_change(&mut self, handler: OnStateChangeHandler) {