Skip to main content

Are timing requirements in webRtc between calling setRemoteDescription and addIceCandidate?

I have implemented webrtc in 2 browsers that physically work on one local machine (one browser I will call as "local", another - "remote"). The browser - Firefox 112.0.1, TURN, STUN servers are not used.

All strings (offer, answer, ice candidates) are transferred from one to another browser manually (slow transfer - via copy and paste). "Remote" gets an offer from the "local" and processes it by rtc2_RegisterRemoteOffer (see code below). This function creates answer of the "remote". Then: (1) the negotiationneeded event fired on the "remote", (2) because of (1) "remote" creates offer and generates it's own ice candidates (up to here neither "local" nor "remote" ice candidates I didn't transfer to each other). (3) Then after few seconds on the "remote" iceconnectionstate fired with the status failed.

The questions are:

  1. What may be a reason of iceconnectionstate gets failed - see (3) ?
  2. Could this happen because I didn't have enough time to send any ice candidate from the "local" to the "remote" after sending offer ?
  3. Is the case (2) - is correct behavior ? Should the "remote" create your own answer when it processes the answer of the "local" ?
  4. If it shouldn't (question 3), then how the "remote" should correctly process it's own negotiationneeded event ?

The code of the "rtc2_RegisterRemoteOffer"

   function rtc2_RegisterRemoteOffer(remoteOfferText) {
        // Register an offer of a remote machine..
        // Input:
        //      - remoteOfferText - string - offer text.

        let stateStr = webRtc.peerConnection.signalingState;

        let logMsg = "rtc2_RegisterRemoteOffer is called. State = " + stateStr;
        DisplayLogMessage(logMsg);
        console.log(logMsg);

        console.log("==remoteOfferText==" + remoteOfferText);
        console.log(remoteOfferText);
        remoteOfferObj = {type: "offer", sdp: remoteOfferText};
        let remoteDescr = null;
        try {
            remoteDescr = new RTCSessionDescription(remoteOfferObj);
        }
        catch (e) {
            remoteDescr = null;
            DisplayErrMessage("Can't create SDP. Errmsg = " + e.message);
        }

        if (remoteDescr === null) {
            // error - do nothing
            DisplayErrMessage("remoteDescr === null !!!");
        }
        else {
            // set remote description
            let remotedescrPromise = webRtc.peerConnection.setRemoteDescription(remoteDescr)
            .then(function Resolve_rdp() {
                let msg = "rtc2_RegisterRemoteOffer.setRemoteDescription -- fulfilled";
                DisplayLogMessage(msg);
                console.log("===> ", msg);
            },

            function Reject_rdp(e) {
                let msg ="rt2c_RegisterRemoteOffer.setRemoteDescription REJECTED. Msg = " + e.message;
                DisplayErrMessage(msg);
                console.log("===> ", msg);

            }
            );  // let remotedescrPromise =

            stateStr = webRtc.peerConnection.signalingState;
            DisplayLogMessage("rtc2_RegisterRemoteOffer - Creating answer for the remote. State = " + stateStr);

            // create an answer to the remote offer

            let answerTextPromise = webRtc.peerConnection.createAnswer().then(
                // resolve
                function resolve_createAnswer(answer) {
                    // answer is generated

                    stateStr = webRtc.peerConnection.signalingState;
                    let msg = "rtc2_RegisterRemoteOffer.createAnswer - resolved. State = " + stateStr;
                    DisplayLogMessage(msg);
                    console.log(msg);
                    // (***) HERE I get:
                    // rtc2_RegisterRemoteOffer.createAnswer - resolved. State = have-remote-offer
                    // set the answer as the local description
                    webRtc.peerConnection.setLocalDescription(answer,

                        function resolve_setLocalDescription_answer() {
                            // resolve -- local description is set
                            console.log("===> ", "rtc2_RegisterRemoteOffer.SetLocalDescription fulfilled.");
                            // ----------------------------------------------------
                            // (***) HERE I get: the message above
                        },
                        function reject_setLocalDescription_answer() {
                            // resolve -- local description is set
                            console.log("ERROR = (setLocalDescription in rtc_RegisterRemoteOffer) is REJECTED");
                        }
                    );
                    // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

                    // Display local answer for the remote
                    PutLocalAnswerText(answer.sdp);
                    DisplayStatus("Send answer to a remote");

                    // --- try to add local audio/video tracks to the remote ---
                    let tracksAdded = rtc2_addTracks();
                    if (tracksAdded) {
                        // our tracks sent to the remote
                        let msg = "rtc2_RegisterRemoteOffer_Our tracks sent on remote answer.";
                        DisplayLogMessage(msg);
                        console.log(msg);
                    }
                    else {

                        // can't access <mediaDevices>
                        let msg = "ERR1 - rtc_RegisterRemoteOffer_Our tracks WERE NOT sent on remote answer.";
                        DisplayErrMessage(msg);
                        console.log(msg);
                    }

                },
                function reject_createAnswer(e) {
                    let msg = "rt2c_RegisterRemoteOffer.createAnswer - REJECTED. Msg = " + e.message +
                                " State = " + stateStr;
                    DisplayErrMessage(msg);
                    console.log(msg);

                }

            );
        } // if (remoteDescr === null) else

    }   // function rtc2_RegisterRemoteOffer

The offer of the "local"

v=0
o=mozilla...THIS_IS_SDPARTA-99.0 672388715268626096 0 IN IP4 0.0.0.0
s=-
t=0 0
a=sendrecv
a=fingerprint:sha-256 65:F6:31:2A:FF:DD:7C:E1:89:83:C6:F1:8C:61:25:8F:E4:AD:0A:B6:8A:A7:D0:A3:0E:E0:DF:C8:99:5F:85:73
a=group:BUNDLE 0
a=ice-options:trickle
a=msid-semantic:WMS *
m=application 9 UDP/DTLS/SCTP webrtc-datachannel
c=IN IP4 0.0.0.0
a=sendrecv
a=ice-pwd:e0e9063fdcde2bd9f4c3068accca0907
a=ice-ufrag:4386e8e0
a=mid:0
a=setup:actpass
a=sctp-port:5000
a=max-message-size:1073741823
Via Active questions tagged javascript - Stack Overflow https://ift.tt/JdeyXA2

Comments

Popular posts from this blog

ValueError: X has 10 features, but LinearRegression is expecting 1 features as input

So, I am trying to predict the model but its throwing error like it has 10 features but it expacts only 1. So I am confused can anyone help me with it? more importantly its not working for me when my friend runs it. It works perfectly fine dose anyone know the reason about it? cv = KFold(n_splits = 10) all_loss = [] for i in range(9): # 1st for loop over polynomial orders poly_order = i X_train = make_polynomial(x, poly_order) loss_at_order = [] # initiate a set to collect loss for CV for train_index, test_index in cv.split(X_train): print('TRAIN:', train_index, 'TEST:', test_index) X_train_cv, X_test_cv = X_train[train_index], X_test[test_index] t_train_cv, t_test_cv = t[train_index], t[test_index] reg.fit(X_train_cv, t_train_cv) loss_at_order.append(np.mean((t_test_cv - reg.predict(X_test_cv))**2)) # collect loss at fold all_loss.append(np.mean(loss_at_order)) # collect loss at order plt.plot(np.log(al...

Sorting large arrays of big numeric stings

I was solving bigSorting() problem from hackerrank: Consider an array of numeric strings where each string is a positive number with anywhere from to digits. Sort the array's elements in non-decreasing, or ascending order of their integer values and return the sorted array. I know it works as follows: def bigSorting(unsorted): return sorted(unsorted, key=int) But I didnt guess this approach earlier. Initially I tried below: def bigSorting(unsorted): int_unsorted = [int(i) for i in unsorted] int_sorted = sorted(int_unsorted) return [str(i) for i in int_sorted] However, for some of the test cases, it was showing time limit exceeded. Why is it so? PS: I dont know exactly what those test cases were as hacker rank does not reveal all test cases. source https://stackoverflow.com/questions/73007397/sorting-large-arrays-of-big-numeric-stings

How to load Javascript with imported modules?

I am trying to import modules from tensorflowjs, and below is my code. test.html <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title </head> <body> <script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@2.0.0/dist/tf.min.js"></script> <script type="module" src="./test.js"></script> </body> </html> test.js import * as tf from "./node_modules/@tensorflow/tfjs"; import {loadGraphModel} from "./node_modules/@tensorflow/tfjs-converter"; const MODEL_URL = './model.json'; const model = await loadGraphModel(MODEL_URL); const cat = document.getElementById('cat'); model.execute(tf.browser.fromPixels(cat)); Besides, I run the server using python -m http.server in my command prompt(Windows 10), and this is the error prompt in the console log of my browser: Failed to loa...