Flutter - WebRTC: not working on WIFI / works on Mobile Data

Viewed 1002

I am using Flutter WebRTC for creating P2P video calling.

I have encountered a problem which is related to networking: I have completeled the application but it only works with Mobile Data.

When changing the network to WiFi, it is not working and connection state hangs on Checking

I used Google Community STUN/TURN Servers and Node JS socket.io for signalling purposes. It also works when the mobile is not on same network but only with Mobile Data.

1 Answers
_createPeer() async {
    try {
      if (_peerConnection != null) return;

      navigator.getUserMedia(mediaConstraints).then((stream) {
        _localStream = stream;
        _localRenderer.srcObject = stream;
      });

      _peerConnection = await createPeerConnection(configuration, constraints);

      _peerConnection.onSignalingState = _onSignalingState;
      _peerConnection.onIceGatheringState = _onIceGatheringState;
      _peerConnection.onIceConnectionState = _onIceConnectionState;
      _peerConnection.onAddStream = _onAddStream;
      _peerConnection.onRemoveStream = _onRemoveStream;
      _peerConnection.onIceCandidate = _onCandidate;
      _peerConnection.onRenegotiationNeeded = _onRenegotiationNeeded;

      _peerConnection.addStream(_localStream);

      RTCSessionDescription offer =
          await _peerConnection.createOffer(_offer_constraints);
      _peerConnection.setLocalDescription(offer);

      socket.emit('add-student', [
        {'room': room, 'offer': offer.sdp}
      ]);
    } catch (e) {
      _snackBar(e.toString());
    }
  }

  _onSignalingState(RTCSignalingState state) {
    // _snackBar(state.toString());
  }

  _onIceGatheringState(RTCIceGatheringState state) {
    // _snackBar(state.toString());
  }

  _onIceConnectionState(RTCIceConnectionState state) {
    _snackBar(state.toString());
  }

  _onAddStream(MediaStream stream) {
    if (stream == null) {
      _snackBar('null');
      return;
    }
    _progressVisible = false;
    _buttonsVisible = true;
    _remoteRenderer.srcObject = stream;
    setState(() {});
  }

  _onRemoveStream(MediaStream stream) {
    _snackBar('remove');
  }

  _onCandidate(RTCIceCandidate candidate) {
    socket.emit('studentCandidate', [
      {
        'room': room,
        'candidate': {
          'candidate': candidate.candidate,
          'sdpMid': candidate.sdpMid,
          'sdpMLineIndex': candidate.sdpMlineIndex
        }
      }
    ]);
  }

  _onRenegotiationNeeded() {
    _snackBar('reneg');
  }
Related