重新连接后WebRTC断开连接(Android)

时间:2020-09-19 14:14:32

标签: android webrtc openvidu

一切正常,但是当我关闭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);
        }

    });
}

P.S。我正在使用OpenVidu android系统信息库中的代码。

0 个答案:

没有答案