Yura Yaroshevich | 5297bd2 | 2018-06-19 12:51:51 +0300 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018 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 | |
Anders Carlsson | 7bca8ca | 2018-08-30 09:30:29 +0200 | [diff] [blame] | 11 | #import "api/peerconnection/RTCAudioSource.h" |
| 12 | #import "api/peerconnection/RTCConfiguration.h" |
| 13 | #import "api/peerconnection/RTCDataChannel.h" |
| 14 | #import "api/peerconnection/RTCDataChannelConfiguration.h" |
| 15 | #import "api/peerconnection/RTCMediaConstraints.h" |
| 16 | #import "api/peerconnection/RTCMediaStreamTrack.h" |
| 17 | #import "api/peerconnection/RTCPeerConnection.h" |
| 18 | #import "api/peerconnection/RTCPeerConnectionFactory.h" |
| 19 | #import "api/peerconnection/RTCRtpReceiver.h" |
| 20 | #import "api/peerconnection/RTCRtpSender.h" |
| 21 | #import "api/peerconnection/RTCRtpTransceiver.h" |
Philipp Hancke | daec488 | 2020-09-15 10:40:07 +0200 | [diff] [blame] | 22 | #import "api/peerconnection/RTCSessionDescription.h" |
Anders Carlsson | 7bca8ca | 2018-08-30 09:30:29 +0200 | [diff] [blame] | 23 | #import "api/peerconnection/RTCVideoSource.h" |
Yura Yaroshevich | 5297bd2 | 2018-06-19 12:51:51 +0300 | [diff] [blame] | 24 | |
| 25 | #import <XCTest/XCTest.h> |
| 26 | |
| 27 | @interface RTCPeerConnectionFactoryTests : XCTestCase |
Yura Yaroshevich | 5297bd2 | 2018-06-19 12:51:51 +0300 | [diff] [blame] | 28 | @end |
| 29 | |
| 30 | @implementation RTCPeerConnectionFactoryTests |
| 31 | |
| 32 | - (void)testPeerConnectionLifetime { |
| 33 | @autoreleasepool { |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 34 | RTC_OBJC_TYPE(RTCConfiguration) *config = [[RTC_OBJC_TYPE(RTCConfiguration) alloc] init]; |
Yura Yaroshevich | 5297bd2 | 2018-06-19 12:51:51 +0300 | [diff] [blame] | 35 | |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 36 | RTC_OBJC_TYPE(RTCMediaConstraints) *constraints = |
| 37 | [[RTC_OBJC_TYPE(RTCMediaConstraints) alloc] initWithMandatoryConstraints:@{} |
| 38 | optionalConstraints:nil]; |
Yura Yaroshevich | 5297bd2 | 2018-06-19 12:51:51 +0300 | [diff] [blame] | 39 | |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 40 | RTC_OBJC_TYPE(RTCPeerConnectionFactory) * factory; |
| 41 | RTC_OBJC_TYPE(RTCPeerConnection) * peerConnection; |
Yura Yaroshevich | 5297bd2 | 2018-06-19 12:51:51 +0300 | [diff] [blame] | 42 | |
Yura Yaroshevich | c806c1d | 2018-06-21 12:51:11 +0300 | [diff] [blame] | 43 | @autoreleasepool { |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 44 | factory = [[RTC_OBJC_TYPE(RTCPeerConnectionFactory) alloc] init]; |
Yura Yaroshevich | c806c1d | 2018-06-21 12:51:11 +0300 | [diff] [blame] | 45 | peerConnection = |
Yura Yaroshevich | 7a16c54 | 2018-07-11 12:55:04 +0300 | [diff] [blame] | 46 | [factory peerConnectionWithConfiguration:config constraints:constraints delegate:nil]; |
Yura Yaroshevich | c806c1d | 2018-06-21 12:51:11 +0300 | [diff] [blame] | 47 | [peerConnection close]; |
| 48 | factory = nil; |
| 49 | } |
Yura Yaroshevich | 5297bd2 | 2018-06-19 12:51:51 +0300 | [diff] [blame] | 50 | peerConnection = nil; |
| 51 | } |
| 52 | |
| 53 | XCTAssertTrue(true, @"Expect test does not crash"); |
| 54 | } |
| 55 | |
Yura Yaroshevich | c806c1d | 2018-06-21 12:51:11 +0300 | [diff] [blame] | 56 | - (void)testMediaStreamLifetime { |
| 57 | @autoreleasepool { |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 58 | RTC_OBJC_TYPE(RTCPeerConnectionFactory) * factory; |
| 59 | RTC_OBJC_TYPE(RTCMediaStream) * mediaStream; |
Yura Yaroshevich | c806c1d | 2018-06-21 12:51:11 +0300 | [diff] [blame] | 60 | |
| 61 | @autoreleasepool { |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 62 | factory = [[RTC_OBJC_TYPE(RTCPeerConnectionFactory) alloc] init]; |
Yura Yaroshevich | c806c1d | 2018-06-21 12:51:11 +0300 | [diff] [blame] | 63 | mediaStream = [factory mediaStreamWithStreamId:@"mediaStream"]; |
| 64 | factory = nil; |
| 65 | } |
| 66 | mediaStream = nil; |
| 67 | } |
| 68 | |
| 69 | XCTAssertTrue(true, "Expect test does not crash"); |
| 70 | } |
| 71 | |
Yura Yaroshevich | c75b35a | 2018-06-27 17:09:14 +0300 | [diff] [blame] | 72 | - (void)testDataChannelLifetime { |
| 73 | @autoreleasepool { |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 74 | RTC_OBJC_TYPE(RTCConfiguration) *config = [[RTC_OBJC_TYPE(RTCConfiguration) alloc] init]; |
| 75 | RTC_OBJC_TYPE(RTCMediaConstraints) *constraints = |
| 76 | [[RTC_OBJC_TYPE(RTCMediaConstraints) alloc] initWithMandatoryConstraints:@{} |
| 77 | optionalConstraints:nil]; |
| 78 | RTC_OBJC_TYPE(RTCDataChannelConfiguration) *dataChannelConfig = |
| 79 | [[RTC_OBJC_TYPE(RTCDataChannelConfiguration) alloc] init]; |
Yura Yaroshevich | c75b35a | 2018-06-27 17:09:14 +0300 | [diff] [blame] | 80 | |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 81 | RTC_OBJC_TYPE(RTCPeerConnectionFactory) * factory; |
| 82 | RTC_OBJC_TYPE(RTCPeerConnection) * peerConnection; |
| 83 | RTC_OBJC_TYPE(RTCDataChannel) * dataChannel; |
Yura Yaroshevich | c75b35a | 2018-06-27 17:09:14 +0300 | [diff] [blame] | 84 | |
| 85 | @autoreleasepool { |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 86 | factory = [[RTC_OBJC_TYPE(RTCPeerConnectionFactory) alloc] init]; |
Yura Yaroshevich | c75b35a | 2018-06-27 17:09:14 +0300 | [diff] [blame] | 87 | peerConnection = |
Yura Yaroshevich | 7a16c54 | 2018-07-11 12:55:04 +0300 | [diff] [blame] | 88 | [factory peerConnectionWithConfiguration:config constraints:constraints delegate:nil]; |
Yura Yaroshevich | c75b35a | 2018-06-27 17:09:14 +0300 | [diff] [blame] | 89 | dataChannel = |
| 90 | [peerConnection dataChannelForLabel:@"test_channel" configuration:dataChannelConfig]; |
Yura Yaroshevich | 7a16c54 | 2018-07-11 12:55:04 +0300 | [diff] [blame] | 91 | XCTAssertNotNil(dataChannel); |
Yura Yaroshevich | c75b35a | 2018-06-27 17:09:14 +0300 | [diff] [blame] | 92 | [peerConnection close]; |
| 93 | peerConnection = nil; |
| 94 | factory = nil; |
| 95 | } |
| 96 | dataChannel = nil; |
| 97 | } |
| 98 | |
| 99 | XCTAssertTrue(true, "Expect test does not crash"); |
| 100 | } |
| 101 | |
Yura Yaroshevich | 08f14dd | 2018-07-09 11:56:06 +0300 | [diff] [blame] | 102 | - (void)testRTCRtpTransceiverLifetime { |
| 103 | @autoreleasepool { |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 104 | RTC_OBJC_TYPE(RTCConfiguration) *config = [[RTC_OBJC_TYPE(RTCConfiguration) alloc] init]; |
Yura Yaroshevich | 08f14dd | 2018-07-09 11:56:06 +0300 | [diff] [blame] | 105 | config.sdpSemantics = RTCSdpSemanticsUnifiedPlan; |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 106 | RTC_OBJC_TYPE(RTCMediaConstraints) *contraints = |
| 107 | [[RTC_OBJC_TYPE(RTCMediaConstraints) alloc] initWithMandatoryConstraints:@{} |
| 108 | optionalConstraints:nil]; |
| 109 | RTC_OBJC_TYPE(RTCRtpTransceiverInit) *init = |
| 110 | [[RTC_OBJC_TYPE(RTCRtpTransceiverInit) alloc] init]; |
Yura Yaroshevich | 08f14dd | 2018-07-09 11:56:06 +0300 | [diff] [blame] | 111 | |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 112 | RTC_OBJC_TYPE(RTCPeerConnectionFactory) * factory; |
| 113 | RTC_OBJC_TYPE(RTCPeerConnection) * peerConnection; |
| 114 | RTC_OBJC_TYPE(RTCRtpTransceiver) * tranceiver; |
Yura Yaroshevich | 08f14dd | 2018-07-09 11:56:06 +0300 | [diff] [blame] | 115 | |
| 116 | @autoreleasepool { |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 117 | factory = [[RTC_OBJC_TYPE(RTCPeerConnectionFactory) alloc] init]; |
Yura Yaroshevich | 08f14dd | 2018-07-09 11:56:06 +0300 | [diff] [blame] | 118 | peerConnection = |
| 119 | [factory peerConnectionWithConfiguration:config constraints:contraints delegate:nil]; |
| 120 | tranceiver = [peerConnection addTransceiverOfType:RTCRtpMediaTypeAudio init:init]; |
Yura Yaroshevich | 7a16c54 | 2018-07-11 12:55:04 +0300 | [diff] [blame] | 121 | XCTAssertNotNil(tranceiver); |
Yura Yaroshevich | 08f14dd | 2018-07-09 11:56:06 +0300 | [diff] [blame] | 122 | [peerConnection close]; |
| 123 | peerConnection = nil; |
| 124 | factory = nil; |
| 125 | } |
| 126 | tranceiver = nil; |
| 127 | } |
| 128 | |
| 129 | XCTAssertTrue(true, "Expect test does not crash"); |
| 130 | } |
| 131 | |
Yura Yaroshevich | ef43aaf | 2018-07-09 19:16:32 +0300 | [diff] [blame] | 132 | - (void)testRTCRtpSenderLifetime { |
| 133 | @autoreleasepool { |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 134 | RTC_OBJC_TYPE(RTCConfiguration) *config = [[RTC_OBJC_TYPE(RTCConfiguration) alloc] init]; |
| 135 | RTC_OBJC_TYPE(RTCMediaConstraints) *constraints = |
| 136 | [[RTC_OBJC_TYPE(RTCMediaConstraints) alloc] initWithMandatoryConstraints:@{} |
| 137 | optionalConstraints:nil]; |
Yura Yaroshevich | ef43aaf | 2018-07-09 19:16:32 +0300 | [diff] [blame] | 138 | |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 139 | RTC_OBJC_TYPE(RTCPeerConnectionFactory) * factory; |
| 140 | RTC_OBJC_TYPE(RTCPeerConnection) * peerConnection; |
| 141 | RTC_OBJC_TYPE(RTCRtpSender) * sender; |
Yura Yaroshevich | ef43aaf | 2018-07-09 19:16:32 +0300 | [diff] [blame] | 142 | |
| 143 | @autoreleasepool { |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 144 | factory = [[RTC_OBJC_TYPE(RTCPeerConnectionFactory) alloc] init]; |
Yura Yaroshevich | ef43aaf | 2018-07-09 19:16:32 +0300 | [diff] [blame] | 145 | peerConnection = |
Yura Yaroshevich | 7a16c54 | 2018-07-11 12:55:04 +0300 | [diff] [blame] | 146 | [factory peerConnectionWithConfiguration:config constraints:constraints delegate:nil]; |
Yura Yaroshevich | ef43aaf | 2018-07-09 19:16:32 +0300 | [diff] [blame] | 147 | sender = [peerConnection senderWithKind:kRTCMediaStreamTrackKindVideo streamId:@"stream"]; |
Yura Yaroshevich | 7a16c54 | 2018-07-11 12:55:04 +0300 | [diff] [blame] | 148 | XCTAssertNotNil(sender); |
Yura Yaroshevich | ef43aaf | 2018-07-09 19:16:32 +0300 | [diff] [blame] | 149 | [peerConnection close]; |
| 150 | peerConnection = nil; |
| 151 | factory = nil; |
| 152 | } |
| 153 | sender = nil; |
| 154 | } |
| 155 | |
| 156 | XCTAssertTrue(true, "Expect test does not crash"); |
| 157 | } |
| 158 | |
Yura Yaroshevich | 7a16c54 | 2018-07-11 12:55:04 +0300 | [diff] [blame] | 159 | - (void)testRTCRtpReceiverLifetime { |
| 160 | @autoreleasepool { |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 161 | RTC_OBJC_TYPE(RTCConfiguration) *config = [[RTC_OBJC_TYPE(RTCConfiguration) alloc] init]; |
| 162 | RTC_OBJC_TYPE(RTCMediaConstraints) *constraints = |
| 163 | [[RTC_OBJC_TYPE(RTCMediaConstraints) alloc] initWithMandatoryConstraints:@{} |
| 164 | optionalConstraints:nil]; |
Yura Yaroshevich | 7a16c54 | 2018-07-11 12:55:04 +0300 | [diff] [blame] | 165 | |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 166 | RTC_OBJC_TYPE(RTCPeerConnectionFactory) * factory; |
| 167 | RTC_OBJC_TYPE(RTCPeerConnection) * pc1; |
| 168 | RTC_OBJC_TYPE(RTCPeerConnection) * pc2; |
Yura Yaroshevich | 7a16c54 | 2018-07-11 12:55:04 +0300 | [diff] [blame] | 169 | |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 170 | NSArray<RTC_OBJC_TYPE(RTCRtpReceiver) *> *receivers1; |
| 171 | NSArray<RTC_OBJC_TYPE(RTCRtpReceiver) *> *receivers2; |
Yura Yaroshevich | 7a16c54 | 2018-07-11 12:55:04 +0300 | [diff] [blame] | 172 | |
| 173 | @autoreleasepool { |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 174 | factory = [[RTC_OBJC_TYPE(RTCPeerConnectionFactory) alloc] init]; |
Yura Yaroshevich | 7a16c54 | 2018-07-11 12:55:04 +0300 | [diff] [blame] | 175 | pc1 = [factory peerConnectionWithConfiguration:config constraints:constraints delegate:nil]; |
| 176 | [pc1 senderWithKind:kRTCMediaStreamTrackKindAudio streamId:@"stream"]; |
| 177 | |
| 178 | pc2 = [factory peerConnectionWithConfiguration:config constraints:constraints delegate:nil]; |
| 179 | [pc2 senderWithKind:kRTCMediaStreamTrackKindAudio streamId:@"stream"]; |
| 180 | |
| 181 | NSTimeInterval negotiationTimeout = 15; |
| 182 | XCTAssertTrue([self negotiatePeerConnection:pc1 |
| 183 | withPeerConnection:pc2 |
| 184 | negotiationTimeout:negotiationTimeout]); |
| 185 | |
| 186 | XCTAssertEqual(pc1.signalingState, RTCSignalingStateStable); |
| 187 | XCTAssertEqual(pc2.signalingState, RTCSignalingStateStable); |
| 188 | |
| 189 | receivers1 = pc1.receivers; |
| 190 | receivers2 = pc2.receivers; |
| 191 | XCTAssertTrue(receivers1.count > 0); |
| 192 | XCTAssertTrue(receivers2.count > 0); |
| 193 | [pc1 close]; |
| 194 | [pc2 close]; |
| 195 | pc1 = nil; |
| 196 | pc2 = nil; |
| 197 | factory = nil; |
| 198 | } |
| 199 | receivers1 = nil; |
| 200 | receivers2 = nil; |
| 201 | } |
| 202 | |
| 203 | XCTAssertTrue(true, "Expect test does not crash"); |
| 204 | } |
| 205 | |
Yura Yaroshevich | 01cee07 | 2018-07-11 15:35:40 +0300 | [diff] [blame] | 206 | - (void)testAudioSourceLifetime { |
| 207 | @autoreleasepool { |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 208 | RTC_OBJC_TYPE(RTCPeerConnectionFactory) * factory; |
| 209 | RTC_OBJC_TYPE(RTCAudioSource) * audioSource; |
Yura Yaroshevich | 01cee07 | 2018-07-11 15:35:40 +0300 | [diff] [blame] | 210 | |
| 211 | @autoreleasepool { |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 212 | factory = [[RTC_OBJC_TYPE(RTCPeerConnectionFactory) alloc] init]; |
Yura Yaroshevich | 01cee07 | 2018-07-11 15:35:40 +0300 | [diff] [blame] | 213 | audioSource = [factory audioSourceWithConstraints:nil]; |
| 214 | XCTAssertNotNil(audioSource); |
| 215 | factory = nil; |
| 216 | } |
| 217 | audioSource = nil; |
| 218 | } |
| 219 | |
| 220 | XCTAssertTrue(true, "Expect test does not crash"); |
| 221 | } |
| 222 | |
| 223 | - (void)testVideoSourceLifetime { |
| 224 | @autoreleasepool { |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 225 | RTC_OBJC_TYPE(RTCPeerConnectionFactory) * factory; |
| 226 | RTC_OBJC_TYPE(RTCVideoSource) * videoSource; |
Yura Yaroshevich | 01cee07 | 2018-07-11 15:35:40 +0300 | [diff] [blame] | 227 | |
| 228 | @autoreleasepool { |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 229 | factory = [[RTC_OBJC_TYPE(RTCPeerConnectionFactory) alloc] init]; |
Yura Yaroshevich | 01cee07 | 2018-07-11 15:35:40 +0300 | [diff] [blame] | 230 | videoSource = [factory videoSource]; |
| 231 | XCTAssertNotNil(videoSource); |
| 232 | factory = nil; |
| 233 | } |
| 234 | videoSource = nil; |
| 235 | } |
| 236 | |
| 237 | XCTAssertTrue(true, "Expect test does not crash"); |
| 238 | } |
| 239 | |
| 240 | - (void)testAudioTrackLifetime { |
| 241 | @autoreleasepool { |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 242 | RTC_OBJC_TYPE(RTCPeerConnectionFactory) * factory; |
| 243 | RTC_OBJC_TYPE(RTCAudioTrack) * audioTrack; |
Yura Yaroshevich | 01cee07 | 2018-07-11 15:35:40 +0300 | [diff] [blame] | 244 | |
| 245 | @autoreleasepool { |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 246 | factory = [[RTC_OBJC_TYPE(RTCPeerConnectionFactory) alloc] init]; |
Yura Yaroshevich | 01cee07 | 2018-07-11 15:35:40 +0300 | [diff] [blame] | 247 | audioTrack = [factory audioTrackWithTrackId:@"audioTrack"]; |
| 248 | XCTAssertNotNil(audioTrack); |
| 249 | factory = nil; |
| 250 | } |
| 251 | audioTrack = nil; |
| 252 | } |
| 253 | |
| 254 | XCTAssertTrue(true, "Expect test does not crash"); |
| 255 | } |
| 256 | |
| 257 | - (void)testVideoTrackLifetime { |
| 258 | @autoreleasepool { |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 259 | RTC_OBJC_TYPE(RTCPeerConnectionFactory) * factory; |
| 260 | RTC_OBJC_TYPE(RTCVideoTrack) * videoTrack; |
Yura Yaroshevich | 01cee07 | 2018-07-11 15:35:40 +0300 | [diff] [blame] | 261 | |
| 262 | @autoreleasepool { |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 263 | factory = [[RTC_OBJC_TYPE(RTCPeerConnectionFactory) alloc] init]; |
Yura Yaroshevich | 01cee07 | 2018-07-11 15:35:40 +0300 | [diff] [blame] | 264 | videoTrack = [factory videoTrackWithSource:[factory videoSource] trackId:@"videoTrack"]; |
| 265 | XCTAssertNotNil(videoTrack); |
| 266 | factory = nil; |
| 267 | } |
| 268 | videoTrack = nil; |
| 269 | } |
| 270 | |
| 271 | XCTAssertTrue(true, "Expect test does not crash"); |
| 272 | } |
| 273 | |
Philipp Hancke | daec488 | 2020-09-15 10:40:07 +0200 | [diff] [blame] | 274 | - (void)testRollback { |
| 275 | @autoreleasepool { |
| 276 | RTC_OBJC_TYPE(RTCConfiguration) *config = [[RTC_OBJC_TYPE(RTCConfiguration) alloc] init]; |
| 277 | config.sdpSemantics = RTCSdpSemanticsUnifiedPlan; |
| 278 | RTC_OBJC_TYPE(RTCMediaConstraints) *constraints = |
| 279 | [[RTC_OBJC_TYPE(RTCMediaConstraints) alloc] initWithMandatoryConstraints:@{ |
| 280 | kRTCMediaConstraintsOfferToReceiveAudio : kRTCMediaConstraintsValueTrue |
| 281 | } |
| 282 | optionalConstraints:nil]; |
| 283 | |
| 284 | __block RTC_OBJC_TYPE(RTCPeerConnectionFactory) * factory; |
| 285 | __block RTC_OBJC_TYPE(RTCPeerConnection) * pc1; |
| 286 | RTCSessionDescription *rollback = [[RTCSessionDescription alloc] initWithType:RTCSdpTypeRollback |
| 287 | sdp:@""]; |
| 288 | |
| 289 | @autoreleasepool { |
| 290 | factory = [[RTC_OBJC_TYPE(RTCPeerConnectionFactory) alloc] init]; |
| 291 | pc1 = [factory peerConnectionWithConfiguration:config constraints:constraints delegate:nil]; |
| 292 | dispatch_semaphore_t negotiatedSem = dispatch_semaphore_create(0); |
| 293 | [pc1 offerForConstraints:constraints |
| 294 | completionHandler:^(RTC_OBJC_TYPE(RTCSessionDescription) * offer, NSError * error) { |
| 295 | XCTAssertNil(error); |
| 296 | XCTAssertNotNil(offer); |
| 297 | |
| 298 | __weak RTC_OBJC_TYPE(RTCPeerConnection) *weakPC1 = pc1; |
| 299 | [pc1 setLocalDescription:offer |
| 300 | completionHandler:^(NSError *error) { |
| 301 | XCTAssertNil(error); |
| 302 | [weakPC1 setLocalDescription:rollback |
| 303 | completionHandler:^(NSError *error) { |
| 304 | XCTAssertNil(error); |
| 305 | }]; |
| 306 | }]; |
| 307 | NSTimeInterval negotiationTimeout = 15; |
| 308 | dispatch_semaphore_wait( |
| 309 | negotiatedSem, |
| 310 | dispatch_time(DISPATCH_TIME_NOW, (int64_t)(negotiationTimeout * NSEC_PER_SEC))); |
| 311 | |
| 312 | XCTAssertEqual(pc1.signalingState, RTCSignalingStateStable); |
| 313 | |
| 314 | [pc1 close]; |
| 315 | pc1 = nil; |
| 316 | factory = nil; |
| 317 | }]; |
| 318 | } |
| 319 | |
| 320 | XCTAssertTrue(true, "Expect test does not crash"); |
| 321 | } |
| 322 | } |
| 323 | |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 324 | - (bool)negotiatePeerConnection:(RTC_OBJC_TYPE(RTCPeerConnection) *)pc1 |
| 325 | withPeerConnection:(RTC_OBJC_TYPE(RTCPeerConnection) *)pc2 |
Yura Yaroshevich | 7a16c54 | 2018-07-11 12:55:04 +0300 | [diff] [blame] | 326 | negotiationTimeout:(NSTimeInterval)timeout { |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 327 | __weak RTC_OBJC_TYPE(RTCPeerConnection) *weakPC1 = pc1; |
| 328 | __weak RTC_OBJC_TYPE(RTCPeerConnection) *weakPC2 = pc2; |
| 329 | RTC_OBJC_TYPE(RTCMediaConstraints) *sdpConstraints = |
| 330 | [[RTC_OBJC_TYPE(RTCMediaConstraints) alloc] initWithMandatoryConstraints:@{ |
Yura Yaroshevich | 7a16c54 | 2018-07-11 12:55:04 +0300 | [diff] [blame] | 331 | kRTCMediaConstraintsOfferToReceiveAudio : kRTCMediaConstraintsValueTrue |
| 332 | } |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 333 | optionalConstraints:nil]; |
Yura Yaroshevich | 7a16c54 | 2018-07-11 12:55:04 +0300 | [diff] [blame] | 334 | |
| 335 | dispatch_semaphore_t negotiatedSem = dispatch_semaphore_create(0); |
| 336 | [weakPC1 offerForConstraints:sdpConstraints |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 337 | completionHandler:^(RTC_OBJC_TYPE(RTCSessionDescription) * offer, NSError * error) { |
Yura Yaroshevich | 7a16c54 | 2018-07-11 12:55:04 +0300 | [diff] [blame] | 338 | XCTAssertNil(error); |
| 339 | XCTAssertNotNil(offer); |
| 340 | [weakPC1 |
| 341 | setLocalDescription:offer |
| 342 | completionHandler:^(NSError *error) { |
| 343 | XCTAssertNil(error); |
| 344 | [weakPC2 |
| 345 | setRemoteDescription:offer |
| 346 | completionHandler:^(NSError *error) { |
| 347 | XCTAssertNil(error); |
| 348 | [weakPC2 |
| 349 | answerForConstraints:sdpConstraints |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 350 | completionHandler:^( |
| 351 | RTC_OBJC_TYPE(RTCSessionDescription) * answer, |
| 352 | NSError * error) { |
Yura Yaroshevich | 7a16c54 | 2018-07-11 12:55:04 +0300 | [diff] [blame] | 353 | XCTAssertNil(error); |
| 354 | XCTAssertNotNil(answer); |
| 355 | [weakPC2 |
| 356 | setLocalDescription:answer |
| 357 | completionHandler:^(NSError *error) { |
| 358 | XCTAssertNil(error); |
| 359 | [weakPC1 |
| 360 | setRemoteDescription:answer |
| 361 | completionHandler:^(NSError *error) { |
| 362 | XCTAssertNil(error); |
| 363 | dispatch_semaphore_signal(negotiatedSem); |
| 364 | }]; |
| 365 | }]; |
| 366 | }]; |
| 367 | }]; |
| 368 | }]; |
| 369 | }]; |
| 370 | |
| 371 | return 0 == |
| 372 | dispatch_semaphore_wait(negotiatedSem, |
| 373 | dispatch_time(DISPATCH_TIME_NOW, (int64_t)(timeout * NSEC_PER_SEC))); |
| 374 | } |
| 375 | |
Yura Yaroshevich | 5297bd2 | 2018-06-19 12:51:51 +0300 | [diff] [blame] | 376 | @end |