Search code examples
iosswiftwebrtc

WebRTC Audio call voice not hearing in iOS not working with Mobile data but works with WIFI connection


This scenario fails every time Audio call If the sender uses the wifi network and the receiver uses mobile data 3G/4G network then the receiver hearing sender's voice but the receiver's voice can’t hear from the sender side.

peer connection is connected successfully with sender and receiver on both sides.

"peerConnection new connection state: checking" "peerConnection new connection state: connected"

also, we are using STUN and TURN servers like "stun:stun.l.google.com:19302" and config.iceServers = [RTCIceServer(urlStrings: ["turn:numb.viagenie.ca:3478"], username: "username@xyz.com", credential: "@password")]

please find below the Audio remote stream code:

private func configureAudioSession() {
    self.rtcAudioSession.lockForConfiguration()
    do {
        try self.rtcAudioSession.setCategory(AVAudioSessionCategoryPlayAndRecord)
        try self.rtcAudioSession.setMode(AVAudioSessionModeVoiceChat)
    } catch {
        print("Error setting configuration: \(error.localizedDescription)")
    }
    self.rtcAudioSession.unlockForConfiguration()
}

private func createMediaSenders() {
    let streamId = "XYZ"
    let audioTrack = self.createAudioTrack()
    self.peerConnection.add(audioTrack, streamIds: [streamId])
}

Solution

  • I'm trying to follow three steps of integration properly and working fine in my Application.

    1. Configure WebRTC audio session to use manual audio and disable audio:

      RTCAudioSession.sharedInstance().useManualAudio = true RTCAudioSession.sharedInstance().isAudioEnabled = false

    2. On your CXProvider delegate's provider(CXProvider, didActivate: AVAudioSession) method:

    • Call RTCAudioSession.sharedInstance().audioSessionDidActivate with the
    • AVAudioSession from the CXProvider Enable audio: RTCAudioSession.sharedInstance().isAudioEnabled = true
    1. On your CXProvider delegate's provider(CXProvider, didDeactivate: AVAudioSession) call RTCAudioSession.sharedInstance().audioSessionDidDeactivate with the AVAudioSession from the CXProvider