在尝试使用 Objective C API 建立 WebRTC 数据通道时,我无法实际捕获任何 RTCDataChannelDelegate 回调。关于对等连接,一切似乎都很好,但我只到了成功添加对等连接流的地步。
我的步骤大致是:
创建报价:
_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]];
客户端 2 的 SDP 被发送回客户端 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
我在这里缺少什么吗?似乎正在建立频道并添加了媒体流(我只想要数据),但没有任何回调。我可以启用更多日志记录吗?任何帮助将非常感激!