@@ -27,16 +27,10 @@ use super::{
2727 ParticipantTrackPermission ,
2828} ;
2929use crate :: {
30- data_stream:: {
30+ ChatMessage , DataPacket , RoomSession , RpcAck , RpcRequest , RpcResponse , SipDTMF , Transcription , data_stream:: {
3131 ByteStreamInfo , ByteStreamWriter , StreamByteOptions , StreamResult , StreamTextOptions ,
3232 TextStreamInfo , TextStreamWriter ,
33- } ,
34- e2ee:: EncryptionType ,
35- options:: { self , compute_video_encodings, video_layers_from_encodings, TrackPublishOptions } ,
36- prelude:: * ,
37- room:: participant:: rpc:: { RpcError , RpcErrorCode , RpcInvocationData , MAX_PAYLOAD_BYTES } ,
38- rtc_engine:: { EngineError , RtcEngine } ,
39- ChatMessage , DataPacket , RoomSession , RpcAck , RpcRequest , RpcResponse , SipDTMF , Transcription ,
33+ } , e2ee:: EncryptionType , options:: { self , TrackPublishOptions , compute_video_encodings, video_layers_from_encodings} , participant:: RpcHandlerRegistry , prelude:: * , room:: participant:: rpc:: { MAX_PAYLOAD_BYTES , RpcError , RpcErrorCode , RpcInvocationData } , rtc_engine:: { EngineError , RtcEngine }
4034} ;
4135use chrono:: Utc ;
4236use libwebrtc:: { native:: create_random_uuid, rtp_parameters:: RtpEncodingParameters } ;
@@ -68,15 +62,15 @@ struct LocalEvents {
6862struct RpcState {
6963 pending_acks : HashMap < String , oneshot:: Sender < ( ) > > ,
7064 pending_responses : HashMap < String , oneshot:: Sender < Result < String , RpcError > > > ,
71- handlers : HashMap < String , RpcHandler > ,
65+ handlers : RpcHandlerRegistry
7266}
7367
7468impl RpcState {
7569 fn new ( ) -> Self {
7670 Self {
7771 pending_acks : HashMap :: new ( ) ,
7872 pending_responses : HashMap :: new ( ) ,
79- handlers : HashMap :: new ( ) ,
73+ handlers : Default :: default ( )
8074 }
8175 }
8276}
@@ -867,11 +861,11 @@ impl LocalParticipant {
867861 + Sync
868862 + ' static ,
869863 ) {
870- self . local . rpc_state . lock ( ) . handlers . insert ( method, Arc :: new ( handler) ) ;
864+ self . local . rpc_state . lock ( ) . handlers . register ( method, handler) ;
871865 }
872866
873867 pub fn unregister_rpc_method ( & self , method : String ) {
874- self . local . rpc_state . lock ( ) . handlers . remove ( & method) ;
868+ self . local . rpc_state . lock ( ) . handlers . unregister ( & method) ;
875869 }
876870
877871 pub ( crate ) fn handle_incoming_rpc_ack ( & self , request_id : String ) {
@@ -925,7 +919,7 @@ impl LocalParticipant {
925919 let response = if version != 1 {
926920 Err ( RpcError :: built_in ( RpcErrorCode :: UnsupportedVersion , None ) )
927921 } else {
928- let handler = self . local . rpc_state . lock ( ) . handlers . get ( & method) . cloned ( ) ;
922+ let handler = self . local . rpc_state . lock ( ) . handlers . get ( & method) ;
929923
930924 match handler {
931925 Some ( handler) => {
0 commit comments