2

I'm using RTCDataChannel. But messages which i'm sending through the channel are not receiving at the other peer.

Here is the code:

        let audioConstraint : RTCPair = RTCPair(key: "OfferToReceiveAudio", value: "true")
        let videoConstraint : RTCPair = RTCPair(key: "OfferToReceiveVideo", value: "true")
        let dtlsConstraint : RTCPair = RTCPair(key: "DtlsSrtpKeyAgreement", value: "true")
        let mediaContraints : RTCMediaConstraints = RTCMediaConstraints(mandatoryConstraints: [audioConstraint, videoConstraint], optionalConstraints: [ dtlsConstraint])

        RTCPeerConnectionFactory.initializeSSL()
        peerConnection = peerConnectionFactory.peerConnectionWithICEServers(servers, constraints: mediaContraints, delegate: self)

        dataChannels = peerConnection?.createDataChannelWithLabel(channelName,config: nil)
        dataChannels?.delegate = self


        var message : NSData = NSData(base64EncodedString: "helloo")
        var buffer : RTCDataBuffer = RTCDataBuffer(data: message, isBinary: true)
        dataChannels?.sendData(buffer)
Dev
  • 3,885
  • 10
  • 39
  • 65
  • Did you actually create a connection? Take a look at the diagrams on [this page](http://www.webrtc.org/native-code/native-apis) – Kevin May 08 '15 at 06:59
  • Yes, I created a peerconnection. I can able to exchange video and audio. But text msg is not able to send. – Dev May 08 '15 at 09:45
  • Ah I see, as far as I can tell your code looks alright, but I haven't implemented the data channel myself. Try the [webrtc mailing list](https://www.ietf.org/mailman/listinfo/rtcweb) and [google discussion groups](https://groups.google.com/forum/#!forum/discuss-webrtc), there are a lot more people there who can help with webrtc implementations. You could link them to this question. From my experience, the webrtc tag isn't very active here on SO (just check my question history with the webrtc tag, hardly any views in weeks). – Kevin May 08 '15 at 20:07
  • @Dev DId you ever figure this out? – Andy Hin Jan 24 '16 at 00:08

3 Answers3

3

Have you resolved it? One of the two peers should create data channel and other should attach the received data channel object to its data channel object. The initiator should create datachannel before sending offer. Hope this might be helpful

Sumaira
  • 71
  • 7
  • But how do you receive the data channel object on the receiving side? I have some difficulties with this. See my post: http://stackoverflow.com/questions/42788020/datachannel-webrtc-swift – da1lbi3 Mar 14 '17 at 14:06
0

I had the same problem until I set the option not to nil. If I skipped the steamId, it would not send. Even though the channel is open.

RTCDataChannelInit *dataInit = [[RTCDataChannelInit alloc] init];
dataInit.isNegotiated = YES;
dataInit.isOrdered = YES;
dataInit.maxRetransmits = 30;
dataInit.maxRetransmitTimeMs = 30000;
dataInit.streamId = 12;  //important setting
self.dataChannel = [_peerConnection createDataChannelWithLabel:kRTCDataChannelLabel config:dataInit];
self.dataChannel.delegate = self;
user523234
  • 14,323
  • 10
  • 62
  • 102
0

To make it works I call this send routine:

 let buffer = RTCDataBuffer(data: data, isBinary: true)
 remoteDataChannel?.sendData(buffer)

from the main thread.

Hihikomori
  • 950
  • 6
  • 12