Datachannel: Use absl::optional for maxRetransmits and maxRetransmitTime.

These parameters are nullable in the JS API.
This allows cleaner handling of "unset" vs "set" in Chrome.

Backwards compatibility note: Behavior should not change, even for users
who set the values explicitly to -1 in the DataChannelInit struct.
Those who try to read back the value will get a compile-time error.

Bug: chromium:854385
Change-Id: Ib488ca5f70bc24ba8b4a3f71b506434c4d2c60b2
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/131381
Reviewed-by: Henrik Boström <hbos@webrtc.org>
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Commit-Queue: Harald Alvestrand <hta@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#27507}
This commit is contained in:
Harald Alvestrand
2019-04-08 13:09:30 +02:00
committed by Commit Bot
parent 8581877121
commit f3736ed3d8
9 changed files with 112 additions and 52 deletions

View File

@ -2082,7 +2082,6 @@ TEST_P(PeerConnectionInterfaceTest, CreateSctpDataChannel) {
CreatePeerConnection(rtc_config);
webrtc::DataChannelInit config;
rtc::scoped_refptr<DataChannelInterface> channel =
pc_->CreateDataChannel("1", &config);
EXPECT_TRUE(channel != NULL);
@ -2103,7 +2102,7 @@ TEST_P(PeerConnectionInterfaceTest, CreateSctpDataChannel) {
EXPECT_FALSE(channel->reliable());
EXPECT_FALSE(observer_.renegotiation_needed_);
config.maxRetransmits = -1;
config.maxRetransmits = absl::nullopt;
config.maxRetransmitTime = 0;
channel = pc_->CreateDataChannel("4", &config);
EXPECT_TRUE(channel != NULL);
@ -2111,6 +2110,21 @@ TEST_P(PeerConnectionInterfaceTest, CreateSctpDataChannel) {
EXPECT_FALSE(observer_.renegotiation_needed_);
}
// For backwards compatibility, we want people who "unset" maxRetransmits
// and maxRetransmitTime by setting them to -1 to get what they want.
TEST_P(PeerConnectionInterfaceTest, CreateSctpDataChannelWithMinusOne) {
RTCConfiguration rtc_config;
rtc_config.enable_dtls_srtp = true;
CreatePeerConnection(rtc_config);
webrtc::DataChannelInit config;
config.maxRetransmitTime = -1;
config.maxRetransmits = -1;
rtc::scoped_refptr<DataChannelInterface> channel =
pc_->CreateDataChannel("1", &config);
EXPECT_TRUE(channel != NULL);
}
// This tests that no data channel is returned if both maxRetransmits and
// maxRetransmitTime are set for SCTP data channels.
TEST_P(PeerConnectionInterfaceTest,