Можно ли совершать вызовы с помощью webRTC через LAN без сервера STUN? - PullRequest
0 голосов
/ 11 апреля 2019

Я пытаюсь заставить приложение работать только в локальной сети. Я вполне уверен, что это можно сделать, поскольку webRTC требует STUN, только если мы находимся за NAT. Я использую NSD для сигнализации (сокет TCP). Я могу отправить и получить offer и icecandidates. Я также могу захватить событие onAddSteam, но не знаю, почему оба пира не могут делиться потоком. Это мой код для peerconnection с пустым сервером льда.

private PeerConnection createPeerConnection(PeerConnectionFactory factory) {
    ArrayList<PeerConnection.IceServer> iceServers = new ArrayList<>();

    PeerConnection.RTCConfiguration rtcConfig = new PeerConnection.RTCConfiguration(iceServers);
    MediaConstraints pcConstraints = new MediaConstraints();

    PeerConnection.Observer pcObserver = new PeerConnection.Observer() {

       ...

        @Override
        public void onIceCandidate(IceCandidate iceCandidate) {
            Log.d(TAG, "onIceCandidate: ");
            JSONObject message = new JSONObject();

            try {
                message.put("type", "candidate");
                message.put("label", iceCandidate.sdpMLineIndex);
                message.put("id", iceCandidate.sdpMid);
                message.put("candidate", iceCandidate.sdp);

                Log.d(TAG, "onIceCandidate: sending candidate " + message);
                if (isInitiator) {
                    sendMessage(message, IS_CANDIATE);
                } else {

                    mService.sendMessageTOService(message.toString());
                }
                //sendMessage(sendMessage);
            } catch (JSONException e) {
                Log.d(TAG, "onIceCandidate: " + e.getMessage());
            }
        }

        @Override
        public void onIceCandidatesRemoved(IceCandidate[] iceCandidates) {
            Log.d(TAG, "onIceCandidatesRemoved: ");
        }

        @Override
        public void onAddStream(MediaStream mediaStream) {
            Log.d(TAG, "onAddStream: " + mediaStream.videoTracks.size());
            VideoTrack remoteVideoTrack = mediaStream.videoTracks.get(0);
            remoteVideoTrack.setEnabled(true);
            remoteVideoTrack.addRenderer(new VideoRenderer(surfaceView2));

        }

        ...
    };

    return factory.createPeerConnection(rtcConfig, pcConstraints, pcObserver);
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...