javascript – Why ‘mute’ event is generated in webRtc for connection FF->Edge or Chrome and isn’t generated in FF->FF connection

I have implemented webRtc connection between peer1 (starts connection) and peer2.
Peer1 – is Firefox v.112.
If peer2 = Firefox too, there is no problem.
If peer2 = Ms Edge v.118 or Chrome v.117, then I observe 2 cases:

  1. If I don’t set a breakpoint in line (*) – see code below, then peer2 gets events:
    unmute (audio),
    unmute (video) — it’s OK,
    mute (video) !!! and video and audio do not play (player is displayed).

    I can’t understand what is the reason of the mute event !
    So, the problem is – browser doesn’t play video/audio normally without breakpoint.

  2. If I set a breakpoint in line (*) , then peer2 gets events mentioned above except mute (!) and the browser plays audio and video normally.

    It seems to me my breakpoint makes a delay that eliminates the problem. Why it helps – I don’t know.

The question: what is the reason of mute event of the case 1 ?
What could you advice to check, trace etc. to eliminate the problem ?

The code is:

       navigator.mediaDevices.getUserMedia(constraints).then(
        function Resolve_GetUserMedia(stream) {
            // add track to peerConnection to send it to peer

            let streamToAdd = mediaControl.stream;

            let tracksArray = streamToAdd.getTracks();

            let msgText = "(1) Adding tracks of the stream _" + streamToAdd.id + "_  " +
            "Activity = " + streamToAdd.active + "  Total = " + tracksArray.length;
            appendMessageText(msgText, "msg_log");

            for (let i = 0; i < tracksArray.length; i++) {
                let track = tracksArray[i];

                // try to add track
                let ok_add_1track = false;
                try {
                    //  "par_webRtc.peerConnection" is a peerConnection
                    par_webRtc.peerConnection.addTrack(track, streamToAdd);
                    ok_add_1track = true;
                }
                catch(err) {
                    if (err.code === DOMException.INVALID_ACCESS_ERR) {
                        // track already sent - no error
                        ok_add_1track = true;                   // (*) BREAKPOINT HERE SOLVES THE PROBLEM
                    }
                    else {
                        // other code are "true" errors
                        errorsCount++;
                    }
                }

                if (ok_add_1track) {
                    // track added successfully
                    console.log("OK_Status of adding <" + track.kind + "> = " + "OK");
                }
                else {
                    console.warn("ERR_Status of adding <" + track.kind + "> = " + "ERROR");
                }

                if (track.kind === "audio") {
                    // remember status of track adding
                    connection.noAudio = !ok_add_1track;
                }
                else if (track.kind === "video") {
                    // remember status of track adding
                    connection.noVideo = !ok_add_1track;
                }

                let sig_state = (par_webRtc.peerConnection === undefined) ?
                                    "NO PEER CONN!!!" :
                                    par_webRtc.peerConnection.signalingState;

                let msgText = "Resolve_RemoteDescriptionSet !!!>> " +
                "We sent track to remote.peerConnection : kind=" + track.kind +
                "  label=" + track.label +
                "  muted=" + track.muted.toString() +
                "  id=" + track.id +
                "  State = " + sig_state;

                console.log("WebRTC - " + msgText);

                appendMessageText(msgText, "msg_log");
            }


        } // function Resolve_GetUserMedia(stream)

Read more here: Source link