// // Created by Théo Monnom on 30/08/2022. // #ifndef CLIENT_SDK_NATIVE_PEER_CONNECTION_H #define CLIENT_SDK_NATIVE_PEER_CONNECTION_H #include #include "api/peer_connection_interface.h" #include "data_channel.h" #include "jsep.h" #include "rust/cxx.h" #include "rust_types.h" #include "webrtc.h" namespace livekit { class NativeAddIceCandidateObserver; class PeerConnection { public: explicit PeerConnection( std::shared_ptr rtc_runtime, rtc::scoped_refptr peer_connection); void create_offer(NativeCreateSdpObserverHandle& observer, RTCOfferAnswerOptions options); void create_answer(NativeCreateSdpObserverHandle& observer, RTCOfferAnswerOptions options); void set_local_description(std::unique_ptr desc, NativeSetLocalSdpObserverHandle& observer); void set_remote_description(std::unique_ptr desc, NativeSetRemoteSdpObserverHandle& observer); std::unique_ptr create_data_channel( rust::String label, std::unique_ptr init); void add_ice_candidate(std::unique_ptr candidate, NativeAddIceCandidateObserver& observer); std::unique_ptr local_description() const; std::unique_ptr remote_description() const; SignalingState signaling_state() const; IceGatheringState ice_gathering_state() const; IceConnectionState ice_connection_state() const; void close(); private: std::shared_ptr rtc_runtime_; rtc::scoped_refptr peer_connection_; }; static std::unique_ptr _unique_peer_connection() { return nullptr; // Ignore } class NativeAddIceCandidateObserver { public: explicit NativeAddIceCandidateObserver( rust::Box observer); void OnComplete(const RTCError& error); private: rust::Box observer_; }; std::unique_ptr create_native_add_ice_candidate_observer( rust::Box observer); class NativePeerConnectionObserver : public webrtc::PeerConnectionObserver { public: explicit NativePeerConnectionObserver( std::shared_ptr rtc_runtime, rust::Box observer); void OnSignalingChange( webrtc::PeerConnectionInterface::SignalingState new_state) override; void OnAddStream( rtc::scoped_refptr stream) override; void OnRemoveStream( rtc::scoped_refptr stream) override; void OnDataChannel( rtc::scoped_refptr data_channel) override; void OnRenegotiationNeeded() override; void OnNegotiationNeededEvent(uint32_t event_id) override; void OnIceConnectionChange( webrtc::PeerConnectionInterface::IceConnectionState new_state) override; void OnStandardizedIceConnectionChange( webrtc::PeerConnectionInterface::IceConnectionState new_state) override; void OnConnectionChange( webrtc::PeerConnectionInterface::PeerConnectionState new_state) override; void OnIceGatheringChange( webrtc::PeerConnectionInterface::IceGatheringState new_state) override; void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) override; void OnIceCandidateError(const std::string& address, int port, const std::string& url, int error_code, const std::string& error_text) override; void OnIceCandidatesRemoved( const std::vector& candidates) override; void OnIceConnectionReceivingChange(bool receiving) override; void OnIceSelectedCandidatePairChanged( const cricket::CandidatePairChangeEvent& event) override; void OnAddTrack( rtc::scoped_refptr receiver, const std::vector>& streams) override; void OnTrack( rtc::scoped_refptr transceiver) override; void OnRemoveTrack( rtc::scoped_refptr receiver) override; void OnInterestingUsage(int usage_pattern) override; private: std::shared_ptr rtc_runtime_; rust::Box observer_; }; std::unique_ptr create_native_peer_connection_observer( std::shared_ptr rtc_runtime, rust::Box observer); } // namespace livekit #endif // CLIENT_SDK_NATIVE_PEER_CONNECTION_H