fork/rust-sdks
git clone https://git.julia.blue/fork/rust-sdks
f162413
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#include <mutex> 21 22#include "api/data_channel_interface.h" 23#include "livekit/webrtc.h" 24#include "rtc_base/synchronization/mutex.h" 25#include "rust/cxx.h" 26 27namespace livekit { 28class DataChannel ; 29}// namespace livekit 30#include "webrtc-sys/src/data_channel.rs.h" 31 32namespace livekit { 33 34class NativeDataChannelObserver ; 35 36webrtc ::DataChannelInit to_native_data_channel_init (DataChannelInit init ); 37 38class DataChannel { 39public : 40explicit DataChannel ( 41std ::shared_ptr < RtcRuntime > rtc_runtime , 42rtc ::scoped_refptr < webrtc ::DataChannelInterface > data_channel ); 43 ~DataChannel (); 44 45void register_observer (rust ::Box < DataChannelObserverWrapper > observer )const ; 46void unregister_observer ()const ; 47bool send (const DataBuffer & buffer )const ; 48int id ()const ; 49rust ::String label ()const ; 50DataState state ()const ; 51void close ()const ; 52uint64_t buffered_amount ()const ; 53 54private : 55mutable webrtc ::Mutex mutex_ ; 56std ::shared_ptr < RtcRuntime > rtc_runtime_ ; 57rtc ::scoped_refptr < webrtc ::DataChannelInterface > data_channel_ ; 58mutable std ::unique_ptr < NativeDataChannelObserver > observer_ ; 59}; 60 61static std ::shared_ptr < DataChannel > _shared_data_channel () { 62return nullptr ;// Ignore 63} 64 65class NativeDataChannelObserver :public webrtc ::DataChannelObserver { 66public : 67NativeDataChannelObserver (rust ::Box < DataChannelObserverWrapper > observer , 68const DataChannel * dc ); 69 70void OnStateChange ()override ; 71void OnMessage ( const webrtc ::DataBuffer & buffer) override; 72void OnBufferedAmountChange ( uint64_t sent_data_size) override; 73 74private: 75rust::Box < DataChannelObserverWrapper > observer_; 76const DataChannel * dc_; 77}; 78 79} // namespace livekit