Skip to content

Commit b43e05b

Browse files
authored
Fix datachannel id setting for 0.5.0 release (#237)
1 parent 86255e8 commit b43e05b

File tree

7 files changed

+20
-27
lines changed

7 files changed

+20
-27
lines changed

examples/examples/ortc/ortc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ async fn main() -> Result<()> {
201201

202202
let dc_params = DataChannelParameters {
203203
label: "Foo".to_owned(),
204-
id,
204+
negotiated: Some(id),
205205
..Default::default()
206206
};
207207

webrtc/src/data_channel/data_channel_init.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,10 @@ pub struct RTCDataChannelInit {
2020
pub protocol: Option<String>,
2121

2222
/// negotiated describes if the data channel is created by the local peer or
23-
/// the remote peer. The default value of false tells the user agent to
23+
/// the remote peer. The default value of None tells the user agent to
2424
/// announce the channel in-band and instruct the other peer to dispatch a
25-
/// corresponding DataChannel. If set to true, it is up to the application
25+
/// corresponding DataChannel. If set to Some(id), it is up to the application
2626
/// to negotiate the channel and create an DataChannel with the same id
2727
/// at the other peer.
28-
pub negotiated: Option<bool>,
29-
30-
/// id overrides the default selection of ID for this channel.
31-
pub id: Option<u16>,
28+
pub negotiated: Option<u16>,
3229
}

webrtc/src/data_channel/data_channel_parameters.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@ use serde::{Deserialize, Serialize};
55
pub struct DataChannelParameters {
66
pub label: String,
77
pub protocol: String,
8-
pub id: u16,
98
pub ordered: bool,
109
pub max_packet_life_time: u16,
1110
pub max_retransmits: u16,
12-
pub negotiated: bool,
11+
pub negotiated: Option<u16>,
1312
}

webrtc/src/data_channel/data_channel_test.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -536,11 +536,9 @@ async fn test_data_channel_parameters_negotiated_exchange() -> Result<()> {
536536

537537
const EXPECTED_MESSAGE: &str = "Hello World";
538538

539-
let negotiated = true;
540539
let id = 500u16;
541540
let options = RTCDataChannelInit {
542-
negotiated: Some(negotiated),
543-
id: Some(id),
541+
negotiated: Some(id),
544542
..Default::default()
545543
};
546544

@@ -1523,10 +1521,9 @@ async fn test_data_channel_ortc_e2e() -> Result<()> {
15231521

15241522
signal_ortc_pair(Arc::clone(&stack_a), Arc::clone(&stack_b)).await?;
15251523

1526-
let id = 1u16;
15271524
let dc_params = DataChannelParameters {
15281525
label: "Foo".to_owned(),
1529-
id,
1526+
negotiated: None,
15301527
..Default::default()
15311528
};
15321529

webrtc/src/data_channel/mod.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ pub struct RTCDataChannel {
8686
impl RTCDataChannel {
8787
// create the DataChannel object before the networking is set up.
8888
pub(crate) fn new(params: DataChannelParameters, setting_engine: Arc<SettingEngine>) -> Self {
89+
// the id value if non-negotiated doesn't matter, since it will be overwritten
90+
// on opening
91+
let id = params.negotiated.unwrap_or(0);
8992
RTCDataChannel {
9093
stats_id: format!(
9194
"DataChannel-{}",
@@ -95,8 +98,8 @@ impl RTCDataChannel {
9598
),
9699
label: params.label,
97100
protocol: params.protocol,
98-
negotiated: params.negotiated,
99-
id: AtomicU16::new(params.id),
101+
negotiated: params.negotiated.is_some(),
102+
id: AtomicU16::new(id),
100103
ordered: params.ordered,
101104
max_packet_lifetime: params.max_packet_life_time,
102105
max_retransmits: params.max_retransmits,
@@ -157,7 +160,7 @@ impl RTCDataChannel {
157160
negotiated: self.negotiated,
158161
};
159162

160-
if self.id.load(Ordering::SeqCst) == 0 {
163+
if !self.negotiated {
161164
self.id.store(
162165
sctp_transport
163166
.generate_and_set_data_channel_id(

webrtc/src/peer_connection/mod.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1857,10 +1857,6 @@ impl RTCPeerConnection {
18571857

18581858
// https://w3c.github.io/webrtc-pc/#peer-to-peer-data-api (Step #19)
18591859
if let Some(options) = options {
1860-
if let Some(id) = options.id {
1861-
params.id = id;
1862-
}
1863-
18641860
// Ordered indicates if data is allowed to be delivered out of order. The
18651861
// default value of true, guarantees that data will be delivered in order.
18661862
// https://w3c.github.io/webrtc-pc/#peer-to-peer-data-api (Step #9)
@@ -1889,9 +1885,7 @@ impl RTCPeerConnection {
18891885
}
18901886

18911887
// https://w3c.github.io/webrtc-pc/#peer-to-peer-data-api (Step #12)
1892-
if let Some(negotiated) = options.negotiated {
1893-
params.negotiated = negotiated;
1894-
}
1888+
params.negotiated = options.negotiated;
18951889
}
18961890

18971891
let d = Arc::new(RTCDataChannel::new(

webrtc/src/sctp_transport/mod.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -275,13 +275,16 @@ impl RTCSctpTransport {
275275
}
276276
};
277277

278-
let id = dc.stream_identifier();
278+
let negotiated = if dc.config.negotiated {
279+
Some(dc.stream_identifier())
280+
} else {
281+
None
282+
};
279283
let rtc_dc = Arc::new(RTCDataChannel::new(
280284
DataChannelParameters {
281-
id,
282285
label: dc.config.label.clone(),
283286
protocol: dc.config.protocol.clone(),
284-
negotiated: dc.config.negotiated,
287+
negotiated,
285288
ordered,
286289
max_packet_life_time: max_packet_lifetime,
287290
max_retransmits,

0 commit comments

Comments
 (0)