iOS中的WebRTC:PeerConnection对象无法使用自己的STUN / TURN服务器创建

时间:2019-01-09 14:44:06

标签: ios objective-c webrtc stun turn

我已使用以下参考在iOS应用中实现了WebRTC: AppRTC reference code by Google for iOS

我已经成功实现了语音/视频聊天,并使用以下网址进行了检查:https://appr.tc/

上面的URL仅用于演示目的,因为连接将持续长达一分钟。

因此,我的后端团队决定创建自己的STUN和TURN服务器。

我们根据以下链接生成了自己的STUN&TURN服务器,并将其安装在我们的服务器上: STUN & TURN server reference

在这里,我们在生成对等连接对象时发现了一个新问题,当在配置中添加到我们的STUN和TURN服务器时,它会生成一个nil对象。

请从以下位置找到我的代码段:

// Create peer connection.
NSString *value = _isLoopback ? @"false" : @"true";
NSDictionary *optionalConstraints = @{ @"DtlsSrtpKeyAgreement" : value };
RTCMediaConstraints *constraints =
  [[RTCMediaConstraints alloc]
      initWithMandatoryConstraints:nil
               optionalConstraints:optionalConstraints];

RTCConfiguration *config = [[RTCConfiguration alloc] init];
RTCCertificate *pcert = [RTCCertificate generateCertificateWithParams:@{
@"expires" : @100000,
@"name" : @"RSASSA-PKCS1-v1_5"
}];

config.iceServers = _iceServers;  // OWN STUN & STUN servers
config.sdpSemantics = RTCSdpSemanticsUnifiedPlan;
config.certificate = pcert;
config.bundlePolicy = RTCBundlePolicyMaxBundle; // For checking purpose
config.iceTransportPolicy = RTCIceTransportPolicyAll; // Default value

_peerConnection = [_factory peerConnectionWithConfiguration:config
                                                constraints:constraints
                                                   delegate:self]; 

观察:

  • 此处“ _peerConnection”对象为我的IceServers生成了nil,因此不会执行其他代码。
  • 如果在配置时删除了iceServers(即没有iceServers),则我可以成功连接到其他对等方,并且可以进行语音/视频聊天。

注意:

0 个答案:

没有答案
相关问题