无法在iOS

时间:2017-05-04 05:28:35

标签: ios webrtc

我设法在A和B之间共享视频和音频,我发现RTCDataChannelState已更改为kRTCDataChannelStateOpen。​​

- (void)channelDidChangeState:(RTCDataChannel*)channel

sendData也可以返回YES,但是我无法收到消息并且

- (void)peerConnection:(RTCPeerConnection*)peerConnection
    didOpenDataChannel:(RTCDataChannel*)dataChannel

从未打过电话。我认为应该在冰状态变为RTCICEConnectionConnected之后调用它,但它不会! 创建数据通道:

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.datachannel = dataChannel;

我的提议和anwser:

- (RTCMediaConstraints *)defaultOfferConstraints {
  NSArray *mandatoryConstraints = @[
      [[RTCPair alloc] initWithKey:@"OfferToReceiveAudio" value:@"true"],
      [[RTCPair alloc] initWithKey:@"OfferToReceiveVideo" value:@"true"]
  ];

    NSArray *optionalConstraints = @[
                                      [[RTCPair alloc] initWithKey:@"internalSctpDataChannels" value:@"true"],
                                      [[RTCPair alloc] initWithKey:@"DtlsSrtpKeyAgreement" value:@"true"]
                                      ];
  RTCMediaConstraints *constraints =
      [[RTCMediaConstraints alloc]
          initWithMandatoryConstraints:mandatoryConstraints
                   optionalConstraints:optionalConstraints];
  return constraints;
}

1 个答案:

答案 0 :(得分:0)

如果您附加提供/回答SDP和WebRTC框架版本,将更容易识别问题。

如果正确添加数据通道,则在设置RemoteDescription后,以下代理应在接收方呼叫

-(void)peerConnection:(RTCPeerConnection *)peerConnection
   didOpenDataChannel:(RTCDataChannel *)dataChannel {
     NSLog(@"Received remote data channel %ld ", (long)dataChannel.readyState);
     dc = dataChannel;
     dc.delegate = self;
}
  

您应该在创建数据通道后创建要约,以便该要约带有数据通道详细信息

     

无需在接收器侧创建数据通道,因为数据通道是全双工的。