Keep ownership of observers on the Rust side

This commit is contained in:
Théo Monnom
2022-09-18 15:22:57 +02:00
parent 81b45d9c48
commit dca8cf7796
11 changed files with 88 additions and 70 deletions
@@ -18,7 +18,7 @@ namespace livekit {
public:
explicit DataChannel(rtc::scoped_refptr<webrtc::DataChannelInterface> data_channel);
void register_observer(std::unique_ptr<NativeDataChannelObserver> observer);
void register_observer(NativeDataChannelObserver &observer);
void unregister_observer();
void close();
private:
@@ -42,7 +42,7 @@ namespace livekit {
rust::Box<DataChannelObserverWrapper> observer_;
};
std::unique_ptr<NativeDataChannelObserver> create_native_peer_connection_observer(rust::Box<DataChannelObserverWrapper> observer);
std::unique_ptr<NativeDataChannelObserver> create_native_data_channel_observer(rust::Box<DataChannelObserverWrapper> observer);
} // livekit
#endif //CLIENT_SDK_NATIVE_DATA_CHANNEL_H
@@ -17,18 +17,17 @@ namespace livekit {
class PeerConnection {
public:
explicit PeerConnection(rtc::scoped_refptr<webrtc::PeerConnectionInterface> peer_connection, std::unique_ptr<NativePeerConnectionObserver> observer);
explicit PeerConnection(rtc::scoped_refptr<webrtc::PeerConnectionInterface> peer_connection);
void create_offer(std::unique_ptr<NativeCreateSdpObserverHandle> observer, RTCOfferAnswerOptions options);
void create_answer(std::unique_ptr<NativeCreateSdpObserverHandle> observer, RTCOfferAnswerOptions options);
void set_local_description(std::unique_ptr<SessionDescription> desc, std::unique_ptr<NativeSetLocalSdpObserverHandle> observer);
void set_remote_description(std::unique_ptr<SessionDescription> desc, std::unique_ptr<NativeSetRemoteSdpObserverHandle> observer);
void create_offer(NativeCreateSdpObserverHandle &observer, RTCOfferAnswerOptions options);
void create_answer(NativeCreateSdpObserverHandle &observer, RTCOfferAnswerOptions options);
void set_local_description(std::unique_ptr<SessionDescription> desc, NativeSetLocalSdpObserverHandle &observer);
void set_remote_description(std::unique_ptr<SessionDescription> desc, NativeSetRemoteSdpObserverHandle &observer);
std::unique_ptr<DataChannel> create_data_channel(rust::String label, std::unique_ptr<NativeDataChannelInit> init);
void close();
private:
rtc::scoped_refptr<webrtc::PeerConnectionInterface> peer_connection_;
std::unique_ptr<NativePeerConnectionObserver> observer_;
};
static std::unique_ptr<PeerConnection> _unique_peer_connection() {
@@ -17,7 +17,7 @@ namespace livekit {
public:
PeerConnectionFactory();
std::unique_ptr<PeerConnection> create_peer_connection(std::unique_ptr<NativeRTCConfiguration> config, std::unique_ptr<NativePeerConnectionObserver> observer) const;
std::unique_ptr<PeerConnection> create_peer_connection(std::unique_ptr<NativeRTCConfiguration> config, NativePeerConnectionObserver &observer) const;
private:
std::unique_ptr<rtc::Thread> network_thread_;