Enable the use of CreateDataChannel with a DataChannelInit config.

Change-Id: Ie9b783464c7b4f6c2d5624a96221f266531acbe9
Bug: b/267359410
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/292861
Reviewed-by: Artem Titov <titovartem@webrtc.org>
Reviewed-by: Henrik Boström <hbos@webrtc.org>
Commit-Queue: Jeremy Leconte <jleconte@google.com>
Cr-Commit-Position: refs/heads/main@{#39293}
diff --git a/pc/BUILD.gn b/pc/BUILD.gn
index 4411fce..41b2e7e 100644
--- a/pc/BUILD.gn
+++ b/pc/BUILD.gn
@@ -2269,6 +2269,7 @@
       "../rtc_base:logging",
       "../test:test_support",
     ]
+    absl_deps = [ "//third_party/abseil-cpp/absl/types:optional" ]
   }
 
   rtc_test("slow_peer_connection_unittests") {
diff --git a/pc/peer_connection_wrapper.cc b/pc/peer_connection_wrapper.cc
index 653d8b7..2fbca1d 100644
--- a/pc/peer_connection_wrapper.cc
+++ b/pc/peer_connection_wrapper.cc
@@ -15,6 +15,7 @@
 #include <utility>
 #include <vector>
 
+#include "absl/types/optional.h"
 #include "api/function_view.h"
 #include "api/set_remote_description_observer_interface.h"
 #include "pc/sdp_utils.h"
@@ -312,8 +313,11 @@
 }
 
 rtc::scoped_refptr<DataChannelInterface>
-PeerConnectionWrapper::CreateDataChannel(const std::string& label) {
-  auto result = pc()->CreateDataChannelOrError(label, nullptr);
+PeerConnectionWrapper::CreateDataChannel(
+    const std::string& label,
+    const absl::optional<DataChannelInit>& config) {
+  const DataChannelInit* config_ptr = config.has_value() ? &(*config) : nullptr;
+  auto result = pc()->CreateDataChannelOrError(label, config_ptr);
   if (!result.ok()) {
     RTC_LOG(LS_ERROR) << "CreateDataChannel failed: "
                       << ToString(result.error().type()) << " "
diff --git a/pc/peer_connection_wrapper.h b/pc/peer_connection_wrapper.h
index c503a48..bf40bbc 100644
--- a/pc/peer_connection_wrapper.h
+++ b/pc/peer_connection_wrapper.h
@@ -15,6 +15,7 @@
 #include <string>
 #include <vector>
 
+#include "absl/types/optional.h"
 #include "api/data_channel_interface.h"
 #include "api/function_view.h"
 #include "api/jsep.h"
@@ -169,7 +170,8 @@
   // Calls the underlying PeerConnection's CreateDataChannel method with default
   // initialization parameters.
   rtc::scoped_refptr<DataChannelInterface> CreateDataChannel(
-      const std::string& label);
+      const std::string& label,
+      const absl::optional<DataChannelInit>& config = absl::nullopt);
 
   // Returns the signaling state of the underlying PeerConnection.
   PeerConnectionInterface::SignalingState signaling_state();
diff --git a/test/pc/e2e/BUILD.gn b/test/pc/e2e/BUILD.gn
index 7354aa8..11616d0 100644
--- a/test/pc/e2e/BUILD.gn
+++ b/test/pc/e2e/BUILD.gn
@@ -80,6 +80,7 @@
       absl_deps = [
         "//third_party/abseil-cpp/absl/memory",
         "//third_party/abseil-cpp/absl/strings",
+        "//third_party/abseil-cpp/absl/types:optional",
         "//third_party/abseil-cpp/absl/types:variant",
       ]
     }
diff --git a/test/pc/e2e/test_peer.h b/test/pc/e2e/test_peer.h
index 1088871..1ce2acb 100644
--- a/test/pc/e2e/test_peer.h
+++ b/test/pc/e2e/test_peer.h
@@ -16,6 +16,7 @@
 
 #include "absl/memory/memory.h"
 #include "absl/strings/string_view.h"
+#include "absl/types/optional.h"
 #include "api/function_view.h"
 #include "api/scoped_refptr.h"
 #include "api/sequence_checker.h"
@@ -109,9 +110,10 @@
   }
 
   rtc::scoped_refptr<DataChannelInterface> CreateDataChannel(
-      const std::string& label) {
+      const std::string& label,
+      const absl::optional<DataChannelInit>& config = absl::nullopt) {
     RTC_CHECK(wrapper_) << "TestPeer is already closed";
-    return wrapper_->CreateDataChannel(label);
+    return wrapper_->CreateDataChannel(label, config);
   }
 
   PeerConnectionInterface::SignalingState signaling_state() {