没有STUN服务器,是否可以通过LAN使用webRTC拨打电话?

时间:2019-04-11 12:23:10

标签: android webrtc

我正在尝试使一个应用程序仅在LAN环境中工作。我非常有信心可以做到,因为webRTC仅在我们不支持NAT时才需要STUN。我正在使用NSD发出信号(TCP套接字)。我能够发送和接收offericecandidates。我还可以捕获onAddSteam事件,但不知道为什么两个同伴都不能共享流。这是我与空ice服务器进行对等连接的代码。

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);
}

0 个答案:

没有答案