2014-11-09 122 views
2

在尝试使用Objective C API建立WebRTC数据通道时,我无法获得任何实际捕获的RTCDataChannelDelegate回调。一切似乎都很好,关于对等连接,但我只到达对等连接流已成功添加的点。WebRTC数据通道未连接或未调用回调

我的步骤大致有:

创建报价:

_channel = [_connection createDataChannelWithLabel: @"offer-1" 
               config: [[RTCDataChannelInit alloc] init]]; 
    _channel.delegate = _stateMachine; 
    [_connection createOfferWithDelegate: _stateMachine constraints: [[RTCMediaConstraints alloc] init]]; 

客户端1的SDP被发送到客户端2,其中创建了一个答案:

[_connection setRemoteDescriptionWithDelegate: _stateMachine sessionDescription: [[RTCSessionDescription alloc] initWithType: @"offer" sdp: sdp]]; 
    [_connection createAnswerWithDelegate: _stateMachine constraints: [[RTCMediaConstraints alloc] init]]; 

客户端的SDP 2发送回客户端1:

[_connection setRemoteDescriptionWithDelegate: _stateMachine sessionDescription: [[RTCSessionDescription alloc] initWithType: @"answer" sdp: sdp]]; 

之后,我得到媒体流被添加信号稳定。之前,在我的POC期间,我能够获得数据通道回调,但我不确定我在这里错过了什么。

下面是对等连接设置:

RTCPeerConnectionFactory* _cfactory = [[RTCPeerConnectionFactory alloc] init]; 

    NSArray* mandatory = @[ 
          [[RTCPair alloc] initWithKey:@"DtlsSrtpKeyAgreement" value:@"true"], 
          [[RTCPair alloc] initWithKey:@"internalSctpDataChannels" value:@"true"], 
          ]; 

    RTCMediaConstraints* pcConstraints = [[RTCMediaConstraints alloc] initWithMandatoryConstraints: mandatory 
                       optionalConstraints: nil]; 
    RTCICEServer* server = [[RTCICEServer alloc] initWithURI:[NSURL URLWithString:@"stun:stun.l.google.com:19302"] 
                username: @"" 
                password: @""]; 
    NSArray* servers = @[server]; 

    _connection = [_cfactory peerConnectionWithICEServers: servers 
               constraints: pcConstraints 
               delegate: _stateMachine]; 

我的状态机实现与目前所有的方法如下:

@protocol DelegateAggregator 
    <RTCPeerConnectionDelegate, RTCSessionDescriptionDelegate, RTCDataChannelDelegate, RTCStatsDelegate> 
@end 

有我丢失的东西吗?看起来频道正在建立并且媒体流被添加(我只想要数据),但没有任何回调。我能否启用更多日志记录?任何帮助将非常感激!

回答

2

所以事实证明,我是如何构建我的答案的关键错误是在回调启动SDP发送到客户端1.我正在等待会话创建回调代表发送我的答案回到客户端事实证明,这太早了,候选人聚会还没有结束。我有回调建立在委托附加到这个样子:

//WRONG 
_tunnel.stateMachine.peerConnectionSessionCallback = ^(RTCPeerConnection* peerConnection, RTCSessionDescription* sdp, NSError* error) { 
     SessionAnswer* answer = [[SessionAnswer alloc] init]; 
     answer.sdp = [sdp description]; 

     [queueManager sendEvent: answer]; 
    }; 

正确的方法是等待这个事件:

_tunnel.stateMachine.peerConnectionICEGatheringCallback = ^(RTCPeerConnection* peerConnection, RTCICEGatheringState newState) { 
     if (newState == RTCICEGatheringComplete) { 
      SessionAnswer* answer = [[SessionAnswer alloc] init]; 
      answer.sdp = [[peerConnection localDescription] description]; 

      [queueManager sendEvent: answer]; 
     } 
    }; 

一旦我的结构是这样,数据通道回调按预期发射。

1

DtlsSrtpKeyAgreementinternalSctpDataChannels需要放入可选约束而不是强制性。

为了建立一个数据通道,我也把RtpDataChannels设置为可选。

+0

看起来像我得到相同的结果,无论他们在可选或必需的。我已经将我的webrtc版本升级到了7700,并且正在使用https://github.com/pristineio/webrtc-build-scripts进行构建,应该使用HAVE_SCTP宏进行编译。有没有办法让我打开更多的日志记录来达到它的底部? – Zack 2014-11-15 04:52:56

+0

我收到来自我提供的客户端的响应,并且我收到的唯一一行是: 2014-11-14 22:47:49.908远程[52330:4141871] peerConnection状态更改。 ,0 2014-11-14 22:47:49.908远程[52330:4141871]设置了带有错误的会话描述。 ,(null) 2014-11-14 22:47:51。远程遥控[52330:4141871]冰面变化。 ,2 – Zack 2014-11-15 06:49:21

+1

如果您打开调试打开WebRTC您应该得到更多的调试输出 – iain 2014-11-16 19:57:33