Hello, I have a problem with my ReactNative WEB-RTC connection.
I have a very basic file (answer.html) that i want to communicate with from my react-native app.
Enclosed you will the sample the app-code. I really tried to keep it short there.
My main Problem is, that the connection jumps first to connecting and then to failed after I set the remoteDescription.
I did basically the same thing in browser with anser.htm and offer.html and i do not have any problems there
_handleBarCodeScanned = async ({type, data}) => {
this.setState({shouldScan: false});
this._createAnswerConnection(data);
};
_handleBarCodeAnswerScanned = async ({data}) => {
this.setState({shouldScanAnswer: false});
this._setRemoteDescription(data);
};
_setupConnectionParams = async () => {
const iceConfiguration = {
iceServers: [
{
urls: [
'stun:stun.services.mozilla.org',
'stun:stun.nextcloud.com:443',
'stun:stun4.l.google.com:19302',
],
},
{
urls: "turn:TURN_IP?transport=tcp",
username: "TURN_USER",
credential: "TURN_PASSWORD"
}],
};
this.setState({
peerConnection: new RTCPeerConnection(iceConfiguration),
});
this.state.peerConnection.onicecandidate = e => console.log(JSON.stringify(this.state.peerConnection.localDescription));
this.state.peerConnection.onconnectionstatechange = event => console.log(event);
};
_setupRemoteChannel = async () => {
this.state.peerConnection.ondatachannel = e => {
console.log("data channel triggered");
const receiveChannel = e.channel;
this._registerChannelListeners(receiveChannel);
this.state.peerConnection.channel = receiveChannel;
this.setState({dataChannel: receiveChannel});
};
};
_registerChannelListeners = (channel) => {
channel.onmessage = e => console.log("messsage received!!!" + e.data);
channel.onopen = () => console.log("open!!!!");
channel.onclose = () => console.log("closed!!!!!!");
channel.onerror = e => console.log("Error", e);
};
_setupLocalChannel = async () => {
const sendChannel = this.state.peerConnection.createDataChannel('sendChannel');
this._registerChannelListeners(sendChannel);
let offer = await this.state.peerConnection.createOffer();
await this.state.peerConnection.setLocalDescription(offer);
this.setState({shouldScanAnswer: true});
};
_setRemoteDescription = async (remoteDescription) => {
await this.state.peerConnection.setRemoteDescription(JSON.parse(remoteDescription));
};
_createAnswerConnection = async (offer) => {
this._setupRemoteChannel();
this._setRemoteDescription(offer);
let localDescription = await this.state.peerConnection.createAnswer();
await this.state.peerConnection.setLocalDescription(localDescription);
console.log(JSON.stringify(this.state.peerConnection.localDescription));
};
componentDidMount = async () => {
await Helper.getOrCreateKeyPair();
this._setupConnectionParams();
};
[Sat May 08 2021 11:25:00.953] LOG {"bubbles": false, "cancelable": false, "currentTarget": {"_dataChannelIds": Set {1}, "_localStreams": [], "_peerConnectionId": 0, "_remoteStreams": [], "_subscriptions": [[EmitterSubscription], [EmitterSubscription], [EmitterSubscription], [EmitterSubscription], [EmitterSubscription], [EmitterSubscription], [EmitterSubscription], [EmitterSubscription], [EmitterSubscription], [EmitterSubscription]], "connectionState": "connecting", "iceConnectionState": "checking", "iceGatheringState": "complete", "localDescription": [Object], "signalingState": "stable"}, "eventPhase": 2, "isTrusted": false, "target": {"_dataChannelIds": Set {1}, "_localStreams": [], "_peerConnectionId": 0, "_remoteStreams": [], "_subscriptions": [[EmitterSubscription], [EmitterSubscription], [EmitterSubscription], [EmitterSubscription], [EmitterSubscription], [EmitterSubscription], [EmitterSubscription], [EmitterSubscription], [EmitterSubscription], [EmitterSubscription]], "connectionState": "connecting", "iceConnectionState": "checking", "iceGatheringState": "complete", "localDescription": [Object], "signalingState": "stable"}, "timeStamp": 1620465902668, "type": "connectionstatechange"}
{"bubbles": false, "cancelable": false, "currentTarget": {"_dataChannelIds": Set {1}, "_localStreams": [], "_peerConnectionId": 0, "_remoteStreams": [], "_subscriptions": [[EmitterSubscription], [EmitterSubscription], [EmitterSubscription], [EmitterSubscription], [EmitterSubscription], [EmitterSubscription], [EmitterSubscription], [EmitterSubscription], [EmitterSubscription], [EmitterSubscription]], "connectionState": "failed", "iceConnectionState": "failed", "iceGatheringState": "complete", "localDescription": [Object], "remoteDescription": {"sdp": "v=0
o=- 1251264347655153318 2 IN IP4 127.0.0.1
s=-
t=0 0
a=group:BUNDLE data
a=msid-semantic: WMS
m=application 56447 UDP/DTLS/SCTP webrtc-datachannel
c=IN IP4 85.214.171.120
a=candidate:1170127721 1 udp 16785151 85.214.171.120 56447 typ relay raddr 0.0.0.0 rport 0 generation 0 network-cost 999
a=ice-ufrag:b0lv
a=ice-pwd:9qH2KQn2EymkbYoIKP8xAzLT
a=ice-options:trickle