Impelementation of RTCDataChannel of WebRTC in iOS

前端 未结 1 1408
耶瑟儿~
耶瑟儿~ 2021-01-04 19:10

I am using ISBX/apprtc-ios code for video chat implementation. This work perfect in iPhone and simulator. I want to send text/string data between two peers and I am using

相关标签:
1条回答
  • 2021-01-04 19:45

    I am able to send data through RTCDataChannel. What I did is before sending the offer. I created the RTCDataChannelInit with the below configuration.

    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;
    

    Once both the devices get connected, I checked the state in the delegate function. The state of the channel is open.

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

    Then I send the data as per the below code:

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

    The configuration I used was given here: https://groups.google.com/forum/#!searchin/discuss-webrtc/RTCDataChannel/discuss-webrtc/9NObqxnItCg/mRvXBIwkA7wJ

    0 讨论(0)
提交回复
热议问题