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

1

6

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.

Pb answered 9/8, 2020 at 15:29 Comment(7)
I know there are few public STUN severs, but public TURN servers? In either case, your problem seems to be NAT related, and lack of using proper TURN server. On WIFI, your computer is behind the router, so others won't be able to directly connect to it.Haggai
@Haggai Both the computer and mobile is on same wifi. But the computer in wifi and mobile with mobile data works. But Computer in wifi and mobile also in wifi is not working.Pb
@Haggai the usage of the application is based on kurento. broadcaster and viewer part. Mobile receives video when using mobile data and not when using wifi. If wifi and mobile data both is ON at same time then it automatically selects mobile data route. I need it to force WIFI route.Pb
Your question is missing those details that you added in the comments. You might want to elaborate your question about your setup, such as what is working, what is not working, and what you have tried, and some code samples.Haggai
Application was created in Flutter Webrtc which is working fine on mobile data but while using it on wifi connection, webrtc ice candidates stuck in checking state. The wifi connectivity is allowed in flutter and able to reach the signalling server over wifi. But the problem is that webrtc automatically uses mobile network as transmission medium for mediastream and generating ice candidates according to mobile network.Pb
But for the STUN servers, their no need for it. Basically I installed media server for the data transmission. Rather than it, without media server, webrtc works fine in all the network. But the problems stays in flutter webrtc sdk.Pb
I just posted few code line in answer section. Please check it. @HaggaiPb
P
0
_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');
  }
Pb answered 11/8, 2020 at 7:46 Comment(1)
Yes, observed the same problem, works with Mobile Data/4G but not with wifiSnips

© 2022 - 2024 — McMap. All rights reserved.