PeerJS webRTC app not working on android 11

Published

I’m working on an audio/video call app for android. It uses PeerJS on a webView.
Here is my code for PeerJs client,

let localVideo = document.getElementById("local-video")
let remoteVideo = document.getElementById("remote-video")

let peer
var enableVideo
function init(userId, isVideoCall) {
    if (isVideoCall == "true") enableVideo = true
    else enableVideo = false

    peer = new Peer(userId, {
        host: '<My GCP server IP>',
        port: 9000,
        key: "myKey",
        path: '/calls',
        config: {
            'iceServers': [
                { url: 'stun:stun.ekiga.net' },
                { url: 'stun:stun.schlund.de' },
                { url: 'stun:stun.voipbuster.com' },
                { url: 'stun:stun.voipstunt.com' },
                { url: 'stun:stun.xten.com' },
                { url: 'stun:stun.l.google.com:19302' },
                { url: 'stun:stun1.l.google.com:19302' },
                { url: 'stun:stun2.l.google.com:19302' },
                { url: 'stun:stun3.l.google.com:19302' },
                { url: 'stun:stun4.l.google.com:19302' },
                {
                    url: 'turn:numb.viagenie.ca',
                    username: "<myUsername>",
                    credential: '<myPassword>'
                }

            ]
        }
    })
    peer.on('open', () => {
        Android.onPeerConnected()
    })

    peer.on('error', () => {
        Android.onError()
    })
    listen()
}
let localStream;
function listen() {
    peer.on('call', (call) => {
        navigator.getUserMedia({
            audio: true,
            video: enableVideo
        }, (stream) => {
            localVideo.srcObject = stream
            localStream = stream

            call.answer(stream)
            call.on('stream', (remoteStream) => {
                Android.onCallConnected()
                remoteVideo.srcObject = remoteStream
                remoteVideo.className = "primary-video"
                localVideo.className = "secondary-video"
            })
        })
    })
}

function startCall(otherUserId) {
    navigator.getUserMedia({
        audio: true,
        video: enableVideo
    }, (stream) => {
        localVideo.srcObject = stream
        localStream = stream

        const call = peer.call(otherUserId, stream)
        call.on('stream', (remoteStream) => {
            Android.onCallConnected()
            remoteVideo.srcObject = remoteStream
            remoteVideo.className = "primary-video"
            localVideo.className = "secondary-video"
        })
    })
}


Everything was working fine until I updated my phone to android 11 recently. Now the connection gets established but there is no audio or video.

It works well If we compile the app against SDK version 29. But I am targeting this app for newer versions of android.

So, if I compile for SDK version 31, then it refuses to work on the emulator(android 11) and some Samsung phones(android 11). That said, it works perfectly on some other Samsung and Realme devices running android 11.

I don’t think it’s a NAT traversal issue, because it was working fine on my Samsung phone before the android 11 update. I doubt it has something to do with android 11 webView and the chromium engine. Checkout this link.

Can someone please help me to find a workaround for this issue?

Source: Android Questions

Published
Categorized as android, chromium, nat, peerjs, webrtc

Answers

did you find any solution, i am facing same problem


yogesh sirsat

Leave a Reply

Still Have Questions?


Our dedicated development team is here for you!

We can help you find answers to your question for as low as 5$.

Contact Us
faq