Skip to content

Commit cc8ee55

Browse files
Swap tcptype hack with proper rust implementation
The mozilla sdp lib supports tcptype now.
1 parent 6a30e6f commit cc8ee55

File tree

2 files changed

+35
-24
lines changed

2 files changed

+35
-24
lines changed

Monal/Classes/MLCall.m

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1217,19 +1217,7 @@ -(void) webRTCClient:(WebRTCClient*) webRTCClient didDiscoverLocalCandidate:(RTC
12171217
DDLogError(@"Failed to convert raw sdp candidate to jingle, ignoring this candidate: %@", candidate);
12181218
return;
12191219
}
1220-
#ifdef IS_ALPHA
1221-
if([contentNode check:@"{urn:xmpp:jingle:transports:ice-udp:1}transport/candidate<protocol=tcp>"])
1222-
{
1223-
//add tcptype because that attribute is apparently not supported by our mozilla sdp lib
1224-
MLXMLNode* candidateNode = [contentNode findFirst:@"{urn:xmpp:jingle:transports:ice-udp:1}transport/candidate"];
1225-
if([candidate.sdp containsString:@"typ host tcptype active"])
1226-
candidateNode.attributes[@"tcptype"] = @"active";
1227-
else if([candidate.sdp containsString:@"typ host tcptype passive"])
1228-
candidateNode.attributes[@"tcptype"] = @"passive";
1229-
else
1230-
DDLogWarn(@"Unknown type-tcptype combination!");
1231-
}
1232-
#else
1220+
#ifndef IS_ALPHA
12331221
if([contentNode check:@"{urn:xmpp:jingle:transports:ice-udp:1}transport/candidate<protocol=tcp>"])
12341222
{
12351223
DDLogError(@"Ignoring raw sdp candidate, because it's using tcp instead of udp: %@", candidate);
@@ -1395,15 +1383,7 @@ -(void) processRemoteICECandidate:(XMPPIQ*) iqNode
13951383
{
13961384
RTCIceCandidate* incomingCandidate = nil;
13971385
NSString* rawSdp = [HelperTools xml2candidate:[iqNode findFirst:@"{urn:xmpp:jingle:1}jingle"] withInitiator:self.direction==MLCallDirectionIncoming];
1398-
#ifdef IS_ALPHA
1399-
if([iqNode check:@"{urn:xmpp:jingle:1}jingle/content/{urn:xmpp:jingle:transports:ice-udp:1}transport/candidate<protocol=tcp>"])
1400-
{
1401-
NSString* type = [iqNode findFirst:@"{urn:xmpp:jingle:1}jingle/content/{urn:xmpp:jingle:transports:ice-udp:1}transport/candidate@type"];
1402-
NSString* tcptype = [iqNode findFirst:@"{urn:xmpp:jingle:1}jingle/content/{urn:xmpp:jingle:transports:ice-udp:1}transport/candidate@tcptype"];
1403-
DDLogDebug(@"Patching raw sdp type=%@ to contain tcptype: %@", type, tcptype);
1404-
rawSdp = [rawSdp stringByReplacingOccurrencesOfString:[NSString stringWithFormat:@"typ %@", type] withString:[NSString stringWithFormat:@"typ %@ tcptype %@", type, tcptype]];
1405-
}
1406-
#else
1386+
#ifndef IS_ALPHA
14071387
if([iqNode check:@"{urn:xmpp:jingle:1}jingle/content/{urn:xmpp:jingle:transports:ice-udp:1}transport/candidate<protocol=tcp>"])
14081388
{
14091389
DDLogWarn(@"Got tcp candidate, ignoring: %@", [iqNode findFirst:@"{urn:xmpp:jingle:1}jingle/content/{urn:xmpp:jingle:transports:ice-udp:1}transport/candidate"]);

rust/sdp-to-jingle/src/xep_0176.rs

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use serde_derive::{Deserialize, Serialize};
44
use 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

152154
impl 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

Comments
 (0)