File tree Expand file tree Collapse file tree 7 files changed +20
-27
lines changed Expand file tree Collapse file tree 7 files changed +20
-27
lines changed Original file line number Diff line number Diff line change @@ -201,7 +201,7 @@ async fn main() -> Result<()> {
201
201
202
202
let dc_params = DataChannelParameters {
203
203
label : "Foo" . to_owned ( ) ,
204
- id ,
204
+ negotiated : Some ( id ) ,
205
205
..Default :: default ( )
206
206
} ;
207
207
Original file line number Diff line number Diff line change @@ -20,13 +20,10 @@ pub struct RTCDataChannelInit {
20
20
pub protocol : Option < String > ,
21
21
22
22
/// 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
24
24
/// 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
26
26
/// to negotiate the channel and create an DataChannel with the same id
27
27
/// 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 > ,
32
29
}
Original file line number Diff line number Diff line change @@ -5,9 +5,8 @@ use serde::{Deserialize, Serialize};
5
5
pub struct DataChannelParameters {
6
6
pub label : String ,
7
7
pub protocol : String ,
8
- pub id : u16 ,
9
8
pub ordered : bool ,
10
9
pub max_packet_life_time : u16 ,
11
10
pub max_retransmits : u16 ,
12
- pub negotiated : bool ,
11
+ pub negotiated : Option < u16 > ,
13
12
}
Original file line number Diff line number Diff line change @@ -536,11 +536,9 @@ async fn test_data_channel_parameters_negotiated_exchange() -> Result<()> {
536
536
537
537
const EXPECTED_MESSAGE : & str = "Hello World" ;
538
538
539
- let negotiated = true ;
540
539
let id = 500u16 ;
541
540
let options = RTCDataChannelInit {
542
- negotiated : Some ( negotiated) ,
543
- id : Some ( id) ,
541
+ negotiated : Some ( id) ,
544
542
..Default :: default ( )
545
543
} ;
546
544
@@ -1523,10 +1521,9 @@ async fn test_data_channel_ortc_e2e() -> Result<()> {
1523
1521
1524
1522
signal_ortc_pair ( Arc :: clone ( & stack_a) , Arc :: clone ( & stack_b) ) . await ?;
1525
1523
1526
- let id = 1u16 ;
1527
1524
let dc_params = DataChannelParameters {
1528
1525
label : "Foo" . to_owned ( ) ,
1529
- id ,
1526
+ negotiated : None ,
1530
1527
..Default :: default ( )
1531
1528
} ;
1532
1529
Original file line number Diff line number Diff line change @@ -86,6 +86,9 @@ pub struct RTCDataChannel {
86
86
impl RTCDataChannel {
87
87
// create the DataChannel object before the networking is set up.
88
88
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 ) ;
89
92
RTCDataChannel {
90
93
stats_id : format ! (
91
94
"DataChannel-{}" ,
@@ -95,8 +98,8 @@ impl RTCDataChannel {
95
98
) ,
96
99
label : params. label ,
97
100
protocol : params. protocol ,
98
- negotiated : params. negotiated ,
99
- id : AtomicU16 :: new ( params . id ) ,
101
+ negotiated : params. negotiated . is_some ( ) ,
102
+ id : AtomicU16 :: new ( id) ,
100
103
ordered : params. ordered ,
101
104
max_packet_lifetime : params. max_packet_life_time ,
102
105
max_retransmits : params. max_retransmits ,
@@ -157,7 +160,7 @@ impl RTCDataChannel {
157
160
negotiated : self . negotiated ,
158
161
} ;
159
162
160
- if self . id . load ( Ordering :: SeqCst ) == 0 {
163
+ if ! self . negotiated {
161
164
self . id . store (
162
165
sctp_transport
163
166
. generate_and_set_data_channel_id (
Original file line number Diff line number Diff line change @@ -1857,10 +1857,6 @@ impl RTCPeerConnection {
1857
1857
1858
1858
// https://w3c.github.io/webrtc-pc/#peer-to-peer-data-api (Step #19)
1859
1859
if let Some ( options) = options {
1860
- if let Some ( id) = options. id {
1861
- params. id = id;
1862
- }
1863
-
1864
1860
// Ordered indicates if data is allowed to be delivered out of order. The
1865
1861
// default value of true, guarantees that data will be delivered in order.
1866
1862
// https://w3c.github.io/webrtc-pc/#peer-to-peer-data-api (Step #9)
@@ -1889,9 +1885,7 @@ impl RTCPeerConnection {
1889
1885
}
1890
1886
1891
1887
// 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 ;
1895
1889
}
1896
1890
1897
1891
let d = Arc :: new ( RTCDataChannel :: new (
Original file line number Diff line number Diff line change @@ -275,13 +275,16 @@ impl RTCSctpTransport {
275
275
}
276
276
} ;
277
277
278
- let id = dc. stream_identifier ( ) ;
278
+ let negotiated = if dc. config . negotiated {
279
+ Some ( dc. stream_identifier ( ) )
280
+ } else {
281
+ None
282
+ } ;
279
283
let rtc_dc = Arc :: new ( RTCDataChannel :: new (
280
284
DataChannelParameters {
281
- id,
282
285
label : dc. config . label . clone ( ) ,
283
286
protocol : dc. config . protocol . clone ( ) ,
284
- negotiated : dc . config . negotiated ,
287
+ negotiated,
285
288
ordered,
286
289
max_packet_life_time : max_packet_lifetime,
287
290
max_retransmits,
You can’t perform that action at this time.
0 commit comments