blob: cb75f061d848416b5d87a91c94ecfb8e3d16427d [file] [log] [blame]
hjonf396f602016-02-11 16:19:06 -08001/*
2 * Copyright 2015 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
tkchin9eeb6242016-04-27 01:54:20 -070011#import "RTCPeerConnection+Private.h"
hjonf396f602016-02-11 16:19:06 -080012
tkchin9eeb6242016-04-27 01:54:20 -070013#import "RTCDataChannel+Private.h"
14#import "RTCDataChannelConfiguration+Private.h"
Anders Carlsson7bca8ca2018-08-30 09:30:29 +020015#import "helpers/NSString+StdString.h"
hjonf396f602016-02-11 16:19:06 -080016
Mirko Bonadeia81e9c82020-05-04 16:14:32 +020017@implementation RTC_OBJC_TYPE (RTCPeerConnection)
18(DataChannel)
hjonf396f602016-02-11 16:19:06 -080019
Mirko Bonadeia81e9c82020-05-04 16:14:32 +020020 - (nullable RTC_OBJC_TYPE(RTCDataChannel) *)dataChannelForLabel
21 : (NSString *)label configuration
22 : (RTC_OBJC_TYPE(RTCDataChannelConfiguration) *)configuration {
hjonf396f602016-02-11 16:19:06 -080023 std::string labelString = [NSString stdStringForString:label];
24 const webrtc::DataChannelInit nativeInit =
25 configuration.nativeDataChannelInit;
Harald Alvestranda9af50f2021-05-21 13:33:51 +000026 auto result = self.nativePeerConnection->CreateDataChannelOrError(labelString, &nativeInit);
27 if (!result.ok()) {
deadbeef299c8e02017-05-05 10:00:18 -070028 return nil;
29 }
Mirko Bonadeia81e9c82020-05-04 16:14:32 +020030 return [[RTC_OBJC_TYPE(RTCDataChannel) alloc] initWithFactory:self.factory
Harald Alvestranda9af50f2021-05-21 13:33:51 +000031 nativeDataChannel:result.MoveValue()];
hjonf396f602016-02-11 16:19:06 -080032}
33
34@end