在iOS中加载WebRTC的RTCDataChannel

我正在使用ISBX / apprtc-ios代码进行video聊天实施。 这项工作完美的iPhone和模拟器。 我想发送两个对端之间的文本/string数据,我正在使用RTCDataChannel类。

以下是我的实施,我无法build立连接。 它总是给出状态kRTCDataChannelStateConnecting我怎样才能连接到RTCDataChannel? WebRTC RTCDataChannel for iOS是否有任何工作实现?

 - (void)createNewDataChannel { if (self.clientDataChannel) { switch(self.clientDataChannel.state) { case kRTCDataChannelStateConnecting: NSLog(@"kRTCDataChannelStateConnecting"); break; case kRTCDataChannelStateOpen: NSLog(@"kRTCDataChannelStateOpen"); break; case kRTCDataChannelStateClosing: NSLog(@"kRTCDataChannelStateClosing"); break; case kRTCDataChannelStateClosed: NSLog(@"kRTCDataChannelStateClosed"); break; default: NSLog(@"Unknown"); } return; } if (self.peerConnection == nil) { NSLog(@"Peerconnection is nil"); } RTCDataChannelInit *DataChannelInit = [[RTCDataChannelInit alloc] init]; DataChannelInit.maxRetransmits = 0; DataChannelInit.isOrdered=false; DataChannelInit.maxRetransmitTimeMs = -1; DataChannelInit.isNegotiated = false; DataChannelInit.streamId = 25; RTCDataChannel *dataChannel =[_peerConnection createDataChannelWithLabel:@"commands" config:DataChannelInit]; dataChannel.delegate=self; self.clientDataChannel = dataChannel; if (self.clientDataChannel == nil) { NSLog(@"Datachannel is nil"); } else { NSLog(@"Datachannel is working"); } } 

我能够通过RTCDataChannel发送数据。 我所做的是在发送报价之前。 我使用下面的configuration创build了RTCDataChannelInit。

 RTCDataChannelInit *datainit = [[RTCDataChannelInit alloc] init]; datainit.isNegotiated = YES; datainit.isOrdered = YES; datainit.maxRetransmits = 30; datainit.maxRetransmitTimeMs = 30000; datainit.streamId = 1; self.dataChannel = [_peerConnection createDataChannelWithLabel:@"commands" config:datainit]; self.dataChannel.delegate=self; 

一旦两个设备连接,我在代理function中检查了状态。 频道的状态是开放的。

 - (void)channelDidChangeState:(RTCDataChannel*)channel { NSLog(@"channel.state %u",channel.state); } 

然后我按照下面的代码发送数据:

 RTCDataBuffer *buffer = [[RTCDataBuffer alloc] initWithData:[str dataUsingEncoding:NSUTF8StringEncoding] isBinary:NO]; BOOL x = [self.dataChannel sendData:buffer]; 

我使用的configuration在这里给出: https : //groups.google.com/forum/#!searchin/discuss-webrtc/RTCDataChannel/discuss-webrtc/9NObqxnItCg/mRvXBIwkA7wJ