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?