@@ -4,7 +4,7 @@ use serde_derive::{Deserialize, Serialize};
44use webrtc_sdp:: {
55 address:: Address ,
66 attribute_type:: {
7- SdpAttributeCandidate , SdpAttributeCandidateTransport , SdpAttributeCandidateType ,
7+ SdpAttributeCandidate , SdpAttributeCandidateTransport , SdpAttributeCandidateType , SdpAttributeCandidateTcpType
88 } ,
99 error:: SdpParserInternalError ,
1010} ;
@@ -147,6 +147,8 @@ pub struct JingleTransportCandidate {
147147 rport : Option < u32 > ,
148148 #[ serde( rename = "@type" ) ]
149149 c_type : JingleTransportCandidateType ,
150+ #[ serde( rename = "@tcp-type" , skip_serializing_if = "Option::is_none" ) ]
151+ tcp_type : Option < JingleTransportCandidateTcpType > ,
150152}
151153
152154impl JingleTransportCandidate {
@@ -178,6 +180,7 @@ impl JingleTransportCandidate {
178180 raddr : candidate. raddr . as_ref ( ) . map ( |addr| format ! ( "{}" , addr) ) ,
179181 rport : candidate. rport ,
180182 c_type : JingleTransportCandidateType :: new_from_sdp ( & candidate. c_type ) ,
183+ tcp_type : candidate. tcp_type . as_ref ( ) . map ( |v| JingleTransportCandidateTcpType :: new_from_sdp ( & v) ) ,
181184 } )
182185 }
183186
@@ -211,7 +214,7 @@ impl JingleTransportCandidate {
211214 } ,
212215 } ,
213216 rport : self . rport ,
214- tcp_type : None , //tcp transport is not specced in any xep
217+ tcp_type : self . tcp_type . as_ref ( ) . map ( |v| v . to_sdp ( ) ) , //tcp transport is not specced in any xep
215218 generation : Some ( self . generation ) ,
216219 ufrag,
217220 networkcost : None , //not specced in xep-0176
@@ -249,3 +252,31 @@ impl JingleTransportCandidateType {
249252 }
250253 }
251254}
255+
256+ // *** xep-0176
257+ #[ derive( Serialize , Deserialize , Clone ) ]
258+ #[ serde( rename_all = "lowercase" ) ]
259+ pub enum JingleTransportCandidateTcpType {
260+ Active ,
261+ Passive ,
262+ #[ serde( rename = "so" ) ]
263+ Simultaneous ,
264+ }
265+
266+ impl JingleTransportCandidateTcpType {
267+ pub fn new_from_sdp ( tcp_type : & SdpAttributeCandidateTcpType ) -> Self {
268+ match tcp_type {
269+ SdpAttributeCandidateTcpType :: Active => Self :: Active ,
270+ SdpAttributeCandidateTcpType :: Passive => Self :: Passive ,
271+ SdpAttributeCandidateTcpType :: Simultaneous => Self :: Simultaneous ,
272+ }
273+ }
274+
275+ pub fn to_sdp ( & self ) -> SdpAttributeCandidateTcpType {
276+ match self {
277+ Self :: Active => SdpAttributeCandidateTcpType :: Active ,
278+ Self :: Passive => SdpAttributeCandidateTcpType :: Passive ,
279+ Self :: Simultaneous => SdpAttributeCandidateTcpType :: Simultaneous ,
280+ }
281+ }
282+ }
0 commit comments