DataChannel ID is -1 and no callbacks on iOS

I am upgrading to v75 and trying to create a datachannel, however the datachannel ID in native iOS is set to -1 and no events are fired so I do not get the onopen event. Video streaming is working. I had datachannels working in v67 and v69, and I can see the datachannel in the offer. I tried changing the bundle policy and moving the datachannel creation from before the offer to after, but nothing seems to work. Is there an extra step required to get datachannels working in v75? Is possible that our older Kurento server version is causing the problem?

The channel ID (-1) created here: https://github.com/react-native-webrtc/react-native-webrtc/blob/master/ios/RCTWebRTC/WebRTCModule%2BRTCDataChannel.m#L31

Xcode: 10.1
React: .55
React Native WebRTC: 1.75.1

2 Likes

have you solve it? i got the same problem to you!

in WebRTCModule+RTCDataChannel.m
i changed function createDataChannel with:

 //if (-1 != dataChannel.channelId) =>rem this line
  {
    dataChannel.peerConnectionId = peerConnectionId;
    if (-1 != dataChannel.channelId){
      NSNumber *dataChannelId = [NSNumber numberWithInteger:dataChannel.channelId];
      peerConnection.dataChannels[dataChannelId] = dataChannel;
    }else{
        peerConnection.dataChannels[[NSNumber numberWithInteger:0]] = dataChannel;
    }
    dataChannel.delegate = self;
  }
  • in dataChannelSend i changed:

    > RTCDataChannel *dataChannel = peerConnection.dataChannels[dataChannelId];
    >   if(dataChannel == nil){
    >       dataChannel = peerConnection.dataChannels[[NSNumber numberWithInteger:0]];
    >   }
    

and last one:
in RTCPeerConnection.js on createDataChannel.js

if(Platform.OS==='ios'){
        for (id = 1; id < 65535 && dataChannelIds.has(id); ++id);
      }else{
        for (id = 0; id < 65535 && dataChannelIds.has(id); ++id);
      }

it’s worked!

Good job getting it to work. I still wonder why the ID is being set to -1, also if you create another DataChannel this code won’t work.

i dont know why. but, did my code solve your problem?

According to Bugzilla, if negotiate == false, the data channel ID seems to be finalized when the data channel status is opened.
https://bugs.chromium.org/p/webrtc/issues/detail?id=10588&can=1&q=datachannel%20channelId&colspec=ID%20Pri%20Stars%20M%20Component%20Status%20Owner%20Summary%20Modified

This is a specification
https://www.w3.org/TR/webrtc/#rtcpeerconnection-interface-extensions-0

In other words, id cannot be specified if negotiate == false

RTCPeerConnection.js createDataChannel

for (id = 0; id <65535 && dataChannelIds.has (id); ++ id);

And, RTCDataChannel.js _registerEvents

if (ev.peerConnectionId! == this._peerConnectionId
|| ev.id! == this.id) {
return;
}

This guard clause is not functioning correctly. because javascript doesn’t have the correct id
Is this idea correct?
and,I don’t know the solution