@@ -33,22 +33,22 @@ use crate::{
3333#[ cfg( all( not( target_arch = "wasm32" ) , feature = "p2p-webrtc-rs" ) ) ]
3434mod imports {
3535 pub use super :: webrtc_rs:: {
36- build_api, webrtc_signal_send, Api , RTCChannel , RTCConnection , RTCConnectionState ,
37- RTCSignalingError ,
36+ build_api, certificate_from_pem_key , webrtc_signal_send, Api , RTCCertificate , RTCChannel ,
37+ RTCConnection , RTCConnectionState , RTCSignalingError ,
3838 } ;
3939}
4040#[ cfg( all( not( target_arch = "wasm32" ) , feature = "p2p-webrtc-cpp" ) ) ]
4141mod imports {
4242 pub use super :: webrtc_cpp:: {
43- build_api, webrtc_signal_send, Api , RTCChannel , RTCConnection , RTCConnectionState ,
44- RTCSignalingError ,
43+ build_api, certificate_from_pem_key , webrtc_signal_send, Api , RTCCertificate , RTCChannel ,
44+ RTCConnection , RTCConnectionState , RTCSignalingError ,
4545 } ;
4646}
4747#[ cfg( target_arch = "wasm32" ) ]
4848mod imports {
4949 pub use super :: web:: {
50- build_api, webrtc_signal_send, Api , RTCChannel , RTCConnection , RTCConnectionState ,
51- RTCSignalingError ,
50+ build_api, certificate_from_pem_key , webrtc_signal_send, Api , RTCCertificate , RTCChannel ,
51+ RTCConnection , RTCConnectionState , RTCSignalingError ,
5252 } ;
5353}
5454
@@ -140,7 +140,7 @@ pub type OnConnectionStateChangeHdlrFn = Box<
140140
141141pub struct RTCConfig {
142142 pub ice_servers : RTCConfigIceServers ,
143- // TODO(binier): certificate
143+ pub certificate : RTCCertificate ,
144144}
145145
146146#[ derive( Serialize ) ]
@@ -223,7 +223,13 @@ async fn wait_for_ice_gathering_complete(pc: &mut RTCConnection) {
223223 }
224224}
225225
226- async fn peer_start ( api : Api , args : PeerAddArgs , abort : Aborted , closed : mpsc:: Sender < ( ) > ) {
226+ async fn peer_start (
227+ api : Api ,
228+ args : PeerAddArgs ,
229+ abort : Aborted ,
230+ closed : mpsc:: Sender < ( ) > ,
231+ certificate : RTCCertificate ,
232+ ) {
227233 let PeerAddArgs {
228234 peer_id,
229235 kind,
@@ -234,6 +240,7 @@ async fn peer_start(api: Api, args: PeerAddArgs, abort: Aborted, closed: mpsc::S
234240
235241 let config = RTCConfig {
236242 ice_servers : Default :: default ( ) ,
243+ certificate,
237244 } ;
238245 let fut = async {
239246 let mut pc = RTCConnection :: create ( & api, config) . await ?;
@@ -727,7 +734,7 @@ pub trait P2pServiceWebrtc: redux::Service {
727734 const MAX_PEERS : usize = 500 ;
728735 let ( cmd_sender, mut cmd_receiver) = mpsc:: unbounded_channel ( ) ;
729736
730- let _ = secret_key;
737+ let certificate = certificate_from_pem_key ( secret_key. to_pem ( ) . as_str ( ) ) ;
731738
732739 spawner. spawn_main ( "webrtc" , async move {
733740 #[ allow( clippy:: all) ]
@@ -741,6 +748,7 @@ pub trait P2pServiceWebrtc: redux::Service {
741748 let conn_permits = conn_permits. clone ( ) ;
742749 let peer_id = args. peer_id ;
743750 let event_sender = args. event_sender . clone ( ) ;
751+ let certificate = certificate. clone ( ) ;
744752 spawn_local ( async move {
745753 let Ok ( _permit) = conn_permits. try_acquire ( ) else {
746754 // state machine shouldn't allow this to happen.
@@ -755,8 +763,9 @@ pub trait P2pServiceWebrtc: redux::Service {
755763 event_sender_clone ( P2pConnectionEvent :: Closed ( peer_id) . into ( ) ) ;
756764 } ) ;
757765 tokio:: select! {
758- _ = peer_start( api, args, aborted. clone( ) , closed_tx. clone( ) ) => { }
759- _ = aborted. wait( ) => { }
766+ _ = peer_start( api, args, aborted. clone( ) , closed_tx. clone( ) , certificate) => { }
767+ _ = aborted. wait( ) => {
768+ }
760769 }
761770
762771 // delay dropping permit to give some time for cleanup.
0 commit comments