2

I'm using webrtc for video calling in react native app.
If I call to someone else and receivers receives call then I get stream of receiver but there is a problem at receiver side.
Receiver gets remotestream but it shows blank view.

import AsyncStorage from '@react-native-async-storage/async-storage';
    import {
      RTCIceCandidate,
      RTCPeerConnection,
      RTCSessionDescription,
    } from 'react-native-webrtc';
    import io from '../scripts/socket.io';
    const PC_CONFIG = {
      iceServers: [
        { url: 'stun:motac85002'},
      ],
    };
    export const pc = new RTCPeerConnection(PC_CONFIG);
    // Signaling methods
    export const onData = data => {
      handleSignalingData(data.data);
    };
    const ENDPOINT = 'http://52.52.75.250:3000/';
    const socket = io(ENDPOINT);
    //  const PeerConnection = () => {
    const sendData = async data => {
      const roomId = await AsyncStorage.getItem('roomId');
      const userId = parseInt(await AsyncStorage.getItem('user_id'));
      socket.emit('data', roomId, userId, data);
    };
    export const createPeerConnection = async(stream, setUsers) => {
      try {
        pc.onicecandidate = onIceCandidate;
        const userId = parseInt(await AsyncStorage.getItem('user_id'));
        pc.onaddstream = e => {
          setUsers(e.stream);
        };
        pc.addStream(stream)
       pc.oniceconnectionstatechange = function () {
      // console.log('ICE state: ', pc);
      console.log('iceConnectionState', pc.iceConnectionState);
      if (pc.iceConnectionState === "failed" ||
      pc.iceConnectionState === "disconnected" ||
      pc.iceConnectionState === "closed") {
        console.log('iceConnectionState  restart', userId);
          //  console.log('ICE state: ', pc);
    // Handle the failure
    pc.restartIce();
  }
    };
        console.log('PeerConnection created',      userId);
        // sendOffer();
      } catch (error) {
        console.error('PeerConnection failed: ', error);
      }
    };
    export const callSomeone = () => {
      pc.createOffer({}).then(setAndSendLocalDescription, error => {
        console.error('Send offer failed: ', error);
      });
    };
    const setAndSendLocalDescription = sessionDescription => {
      pc.setLocalDescription(sessionDescription);
      sendData(sessionDescription);
    };
    const onIceCandidate = event => {
      if (event.candidate) {
        sendData({
          type: 'candidate',
          candidate: event.candidate,
        });
      }
    };
    export const disconnectPeer = () =>{
      pc.close();
    }
    const sendAnswer = () => {
      pc.createAnswer().then(setAndSendLocalDescription, error => {
        console.error('Send answer failed: ', error);
      });
    };
    export const handleSignalingData = data => {
      switch (data.type) {
        case 'offer':
          pc.setRemoteDescription(new RTCSessionDescription(data));
          sendAnswer();
          break;
        case 'answer':
          pc.setRemoteDescription(new RTCSessionDescription(data));
          break;
        case 'candidate':
          pc.addIceCandidate(new RTCIceCandidate(data.candidate));
          break;
      }
    };
    // }
    // export default PeerConnection

Can anyone please tell me why at receiver side video stream is not displaying?
Also there is a remoteStream issue in motorola device. Why is this happening?

amM
  • 509
  • 2
  • 14
  • 33
  • `motac85002` as your stun server looks suspicious. It implies it's on your local network and unlikely to return back a real internet address to a client. Add a logging statement to `onIceCandidate` and see what is getting used. – selbie Mar 06 '22 at 05:47
  • @selbie Getting following data in onIceCandidate - {"candidate": {"candidate": "candidate:1908129852 1 tcp 1518151935 2402:3a80:20b8:6b8d:d37c:df37:8a8:fe06 9 typ host tcptype active generation 0 ufrag aEox network-id 3 network-cost 900", "sdpMLineIndex": 1, "sdpMid": "video"}, "isTrusted": false} – amM Mar 07 '22 at 05:18

1 Answers1

1

This statement:

const PC_CONFIG = {
  iceServers: [
    { url: 'stun:motac85002'},
  ],
};

Has two potential issues:

First, the parameter for the iceServers object should be urls, not url. (Although it wouldn't surprise me if the browsers accepted either).

Second, as I mentioned in comments to your question, the STUN address itself looks to be a local address instead of an Internet address. That might explain why you aren't seeing any srflx or UDP candidates in the SDP. And as such, that might explain connectivity issues.

So instead of the above, could you try this:

const PC_CONFIG= {iceServers: [{urls: "stun:stun.stunprotocol.org"}]};
selbie
  • 100,020
  • 15
  • 103
  • 173
  • Thanks for your answer. By using const PC_CONFIG= {iceServers: [{urls: "stun:stun.stunprotocol.org"}]}; it's working. I have created own stun and turn server now. If I'm using own stun turn server then I'm getting state response as Checking, failed for console.log('iceConnectionState', pc.iceConnectionState) – amM Mar 09 '22 at 04:50
  • Can you share the DNS or IP address of your STUN/TURN server. I can ping it to see if it's up. – selbie Mar 09 '22 at 05:53
  • Invoking `stunclient.exe stun.yoforce.com 5349` is not getting a response. I tried port 3478 as well. Can you check your connectivity to UDP ports 3478 and 5349. – selbie Mar 09 '22 at 07:01
  • perhaps you need to open **UDP** ports 3478,3439,5349, and 5350 to your AWS security group for your server. – selbie Mar 09 '22 at 08:01
  • Thank you so much for helping. Issue is fixed now. – amM Mar 09 '22 at 08:02