Configuring the receiver when calling webRTC

I use webRTC to open a data channel between two users, a simplified version of the website: 1 to create a call using onclick = "myLive.initiateConnection ()"
1 input with id = "caller" to describe the SDP that will be copied from the first user tabs to second user
1 to answer the call using onclick = "myLive.join ()"
1 with id = "callle" to describe the SDP to be copied from second user to first
1 with onclick = "setCallee ($ ( '# callee'). Val ()) "to set the remote description for the first user

I put the join method before the initiateConnection method because, as indicated below, I think the error is in getCallerInfo called by join:

join = function(){
connection = new peerConnection(servers);
    connection.onicecandidate = function(evt){
        if(evt.candidate){
            connection.addIceCandidate(new RTCIceCandidate(event.candidate));
        }
    };

    connection.ondatachannel = function(ev){
        dataChannel = ev.channel;
        dataChannel.onmessage = receiveMessage;
            ev.channel.onopen = function(){
                alert('connection established, callee');
            };
        };
        gotCallerInfo($("#caller").val())
    };

gotCallerInfo = function(data){
    var newDesc = JSON.parse(data);
    connection.setRemoteDescription(new RTCSessionDescription(newDesc), function(){
        connection.createAnswer(function(desc){          
            connection.setLocalDescription(desc);

2 webRTC. , , webRTC, ... createAnswer 1s(), webRTC , firefox "createAnswer ". createAnswer (, , firefox)? , - , setRemoteDescription, createAnswer setLocalDescription . Desc2, createAnswer, , desc, , , setLocalDescription ICE, , , desc, createAnswer?

            //setTimeout(function(){
                //connection.createAnswer(function(desc){           
                    $("#callee").val(JSON.stringify(desc));
                //}, errorCallback);
            //}, 1000);
        }, errorCallback);
    }, errorCallback);
};

, , , . initiateConnection, "". "join", "set callee description"

initiateConnection = function(){
    connection = new peerConnection(servers);
    connection.onicecandidate = function(evt){
        if(evt.candidate){
        connection.addIceCandidate(new RTCIceCandidate(event.candidate));
        }
    };

    dataChannel = connection.createDataChannel("channel");
    dataChannel.onopen = function(){
        alert('connection established, caller');
    };
    dataChannel.onmessage = receiveMessage;
    connection.createOffer(function(description){
        connection.setLocalDescription(description);
        $("#caller").val(JSON.stringify(description));
    }, errorCallback);
};

setCallee = function(data){
    connection.setRemoteDescription(new RTCSessionDescription(JSON.parse(data)));
};

receiveMessage = function(){};

errorCallback = function(){};  
+4
1

:

connection.onicecandidate = function(evt){
    if(evt.candidate){
    connection.addIceCandidate(new RTCIceCandidate(event.candidate));

peerConnection, . .

, cut'n'paste , , . null . / . null , 1 ~ 20 ( VPN, , ..).

, , .

cut'n'paste . WebRTC,

+1

Source: https://habr.com/ru/post/1666166/


All Articles