fork/rust-sdks
git clone https://git.julia.blue/fork/rust-sdks
e33c5a9
main
1/* 2* Copyright 2023 LiveKit 3* 4* Licensed under the Apache License, Version 2.0 (the “License”); 5* you may not use this file except in compliance with the License. 6* You may obtain a copy of the License at 7* 8* http://www.apache.org/licenses/LICENSE-2.0 9* 10* Unless required by applicable law or agreed to in writing, software 11* distributed under the License is distributed on an “AS IS” BASIS, 12* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13* See the License for the specific language governing permissions and 14* limitations under the License. 15*/ 16 17#pragma once 18 19#include <memory> 20 21#include "api/peer_connection_interface.h" 22#include "api/scoped_refptr.h" 23#include "livekit/data_channel.h" 24#include "livekit/helper.h" 25#include "livekit/jsep.h" 26#include "livekit/media_stream.h" 27#include "livekit/rtc_error.h" 28#include "livekit/rtp_receiver.h" 29#include "livekit/rtp_sender.h" 30#include "livekit/rtp_transceiver.h" 31#include "livekit/webrtc.h" 32#include "rust/cxx.h" 33#include "webrtc-sys/src/data_channel.rs.h" 34 35namespace livekit { 36class PeerConnection ; 37}// namespace livekit 38#include "webrtc-sys/src/peer_connection.rs.h" 39 40namespace livekit { 41 42webrtc ::PeerConnectionInterface ::RTCConfiguration to_native_rtc_configuration ( 43RtcConfiguration config ); 44 45class PeerConnectionObserverWrapper ; 46 47class PeerConnection :webrtc ::PeerConnectionObserver { 48public : 49PeerConnection ( 50std ::shared_ptr < RtcRuntime > rtc_runtime , 51rtc ::scoped_refptr < webrtc ::PeerConnectionFactoryInterface > pc_factory , 52rust ::Box < PeerConnectionObserverWrapper > observer ); 53 54 ~PeerConnection (); 55 56bool Initialize (webrtc ::PeerConnectionInterface ::RTCConfiguration config ); 57 58void set_configuration (RtcConfiguration config )const ; 59 60void create_offer ( 61RtcOfferAnswerOptions options , 62rust ::Box < PeerContext > ctx , 63rust ::Fn < void (rust ::Box < PeerContext > , 64std ::unique_ptr < SessionDescription > )> on_success , 65rust ::Fn < void (rust ::Box < PeerContext > ,RtcError )> on_error )const ; 66 67void create_answer ( 68RtcOfferAnswerOptions options , 69rust ::Box < PeerContext > ctx , 70rust ::Fn < void (rust ::Box < PeerContext > , 71std ::unique_ptr < SessionDescription > )> on_success , 72rust ::Fn < void (rust ::Box < PeerContext > ,RtcError )> on_error )const ; 73 74void set_local_description ( 75std ::unique_ptr < SessionDescription > desc , 76rust ::Box < PeerContext > ctx , 77rust ::Fn < void (rust ::Box < PeerContext > ,RtcError )> on_complete )const ; 78 79void set_remote_description ( 80std ::unique_ptr < SessionDescription > desc , 81rust ::Box < PeerContext > ctx , 82rust ::Fn < void (rust ::Box < PeerContext > ,RtcError )> on_complete )const ; 83 84std ::shared_ptr < DataChannel > create_data_channel (rust ::String label , 85DataChannelInit init )const ; 86 87void add_ice_candidate ( 88std ::shared_ptr < IceCandidate > candidate , 89rust ::Box < PeerContext > ctx , 90rust ::Fn < void (rust ::Box < PeerContext > ,RtcError )> on_complete )const ; 91 92std ::shared_ptr < RtpSender > add_track ( 93std ::shared_ptr < MediaStreamTrack > track , 94const rust ::Vec < rust ::String >& stream_ids )const ; 95 96void remove_track (std ::shared_ptr < RtpSender > sender )const ; 97 98void get_stats ( 99rust ::Box < PeerContext > ctx , 100rust ::Fn < void (rust ::Box < PeerContext > ,rust ::String )> on_stats )const ; 101 102void restart_ice ()const ; 103 104std ::shared_ptr < RtpTransceiver > add_transceiver ( 105std ::shared_ptr < MediaStreamTrack > track , 106RtpTransceiverInit init )const ; 107 108std ::shared_ptr < RtpTransceiver > add_transceiver_for_media ( 109MediaType media_type , 110RtpTransceiverInit init )const ; 111 112rust ::Vec < RtpSenderPtr > get_senders ()const ; 113 114rust ::Vec < RtpReceiverPtr > get_receivers ()const ; 115 116rust ::Vec < RtpTransceiverPtr > get_transceivers ()const ; 117 118std ::unique_ptr < SessionDescription > current_local_description ()const ; 119 120std ::unique_ptr < SessionDescription > current_remote_description ()const ; 121 122std ::unique_ptr < SessionDescription > pending_local_description ()const ; 123 124std ::unique_ptr < SessionDescription > pending_remote_description ()const ; 125 126std ::unique_ptr < SessionDescription > local_description ()const ; 127 128std ::unique_ptr < SessionDescription > remote_description ()const ; 129 130PeerConnectionState connection_state ()const ; 131 132SignalingState signaling_state ()const ; 133 134IceGatheringState ice_gathering_state ()const ; 135 136IceConnectionState ice_connection_state ()const ; 137 138void close ()const ; 139 140void OnSignalingChange ( 141webrtc ::PeerConnectionInterface ::SignalingState new_state )override ; 142 143void OnAddStream ( 144rtc ::scoped_refptr < webrtc ::MediaStreamInterface > stream )override ; 145 146void OnRemoveStream ( 147rtc ::scoped_refptr < webrtc ::MediaStreamInterface > stream )override ; 148 149void OnDataChannel ( 150rtc ::scoped_refptr < webrtc ::DataChannelInterface > data_channel )override ; 151 152void OnRenegotiationNeeded ()override ; 153 154void OnNegotiationNeededEvent (uint32_t event_id )override ; 155 156void OnIceConnectionChange ( 157webrtc ::PeerConnectionInterface ::IceConnectionState new_state )override ; 158 159void OnStandardizedIceConnectionChange ( 160webrtc ::PeerConnectionInterface ::IceConnectionState new_state )override ; 161 162void OnConnectionChange ( 163webrtc ::PeerConnectionInterface ::PeerConnectionState new_state )override ; 164 165void OnIceGatheringChange ( 166webrtc ::PeerConnectionInterface ::IceGatheringState new_state )override ; 167 168void OnIceCandidate (const webrtc ::IceCandidateInterface * candidate )override ; 169 170void OnIceCandidateError (const std ::string & address , 171int port , 172const std ::string & url , 173int error_code , 174const std ::string & error_text )override ; 175 176void OnIceCandidatesRemoved ( 177const std ::vector < cricket ::Candidate >& candidates )override ; 178 179void OnIceConnectionReceivingChange (bool receiving )override ; 180 181void OnIceSelectedCandidatePairChanged ( 182const cricket ::CandidatePairChangeEvent & event )override ; 183 184void OnAddTrack ( 185rtc ::scoped_refptr < webrtc ::RtpReceiverInterface > receiver , 186const std ::vector < rtc ::scoped_refptr < webrtc ::MediaStreamInterface >>& 187streams )override ; 188 189void OnTrack ( 190rtc ::scoped_refptr < webrtc ::RtpTransceiverInterface > transceiver )override ; 191 192void OnRemoveTrack ( 193rtc ::scoped_refptr < webrtc ::RtpReceiverInterface > receiver )override ; 194 195void OnInterestingUsage (int usage_pattern )override ; 196 197private : 198std ::shared_ptr < RtcRuntime > rtc_runtime_ ; 199rtc ::scoped_refptr < webrtc ::PeerConnectionFactoryInterface > pc_factory_ ; 200rust ::Box < PeerConnectionObserverWrapper > observer_ ; 201rtc ::scoped_refptr < webrtc ::PeerConnectionInterface > peer_connection_ ; 202}; 203 204static std ::shared_ptr < PeerConnection > _shared_peer_connection () { 205return nullptr ;// Ignore 206} 207 208}// namespace livekit