1

一切正常,但是当我关闭 wifi 并再次打开时,WebRTC 会话重新连接,但 6-7 秒后它进入断开状态,然后进入失败状态。

日志

2020-09-19 19:34:27.112 5941-6059/com.thirdeyegen.mr_workspacee D/NEW_WEBRTC_STATE==>: CHECKING
2020-09-19 19:34:28.338 5941-6059/com.thirdeyegen.mr_workspacee D/NEW_WEBRTC_STATE==>: CONNECTED
2020-09-19 19:35:06.133 5941-6059/com.thirdeyegen.mr_workspacee D/NEW_WEBRTC_STATE==>: DISCONNECTED
2020-09-19 19:35:06.473 5941-6059/com.thirdeyegen.mr_workspacee D/NEW_WEBRTC_STATE==>: CONNECTED
2020-09-19 19:35:21.363 5941-6059/com.thirdeyegen.mr_workspacee D/NEW_WEBRTC_STATE==>: DISCONNECTED
2020-09-19 19:35:31.379 5941-6059/com.thirdeyegen.mr_workspacee D/NEW_WEBRTC_STATE==>: FAILED

事件 1、2 初始会话(工作正常) 事件 3、4、5、6 当我关闭 wifi 并再次连接时的一系列事件。在事件 4 上,一切正常,但 5、6 发生在 6-7 秒后。

我的代码

public PeerConnection createLocalPeerConnection() {
    final List<PeerConnection.IceServer> iceServers = new ArrayList<>();
    PeerConnection.IceServer iceServer = PeerConnection.IceServer
            .builder("turn:" + turnUrl)
            .setUsername(turnUsername)
            .setPassword(turnPassword)
            .createIceServer();
    iceServers.add(iceServer);

    PeerConnection.RTCConfiguration rtcConfig = new PeerConnection.RTCConfiguration(iceServers);
    rtcConfig.tcpCandidatePolicy = PeerConnection.TcpCandidatePolicy.ENABLED;
    rtcConfig.bundlePolicy = PeerConnection.BundlePolicy.MAXBUNDLE;
    rtcConfig.rtcpMuxPolicy = PeerConnection.RtcpMuxPolicy.REQUIRE;
    rtcConfig.continualGatheringPolicy = PeerConnection.ContinualGatheringPolicy.GATHER_CONTINUALLY;
    rtcConfig.keyType = PeerConnection.KeyType.ECDSA;
    rtcConfig.enableDtlsSrtp = true;
    rtcConfig.enableRtpDataChannel = true;
    rtcConfig.sdpSemantics = PeerConnection.SdpSemantics.UNIFIED_PLAN;

    return peerConnectionFactory.createPeerConnection(rtcConfig, new CustomPeerConnectionObserver("local") {
        @Override
        public void onIceCandidate(IceCandidate iceCandidate) {
            super.onIceCandidate(iceCandidate);
            websocket.onIceCandidate(iceCandidate, localParticipant.getConnectionId());
        }

        @Override
        public void onSignalingChange(PeerConnection.SignalingState signalingState) {
            super.onSignalingChange(signalingState);
        }

        @Override
        public void onIceConnectionChange(PeerConnection.IceConnectionState iceConnectionState) {
            if (iceConnectionState.name().toLowerCase().equals("connected")) {
                isLocalConnected = true;
            }
            Log.d("NEW_WEBRTC_STATE==>", iceConnectionState.name());

            if (iceConnectionState.equals(PeerConnection.IceConnectionState.FAILED)) {
               checkForInternetAndReconnect();
            } else if (iceConnectionState.equals(PeerConnection.IceConnectionState.DISCONNECTED)) {
                activity.showConnectingAnimation(View.VISIBLE);
            } else {
                activity.showConnectingAnimation(View.GONE);
            }
            super.onIceConnectionChange(iceConnectionState);
        }

    });
}

PS 我正在使用来自 OpenVidu android 存储库的代码。

4

0 回答 0