Webrtc how to set the video remote after receiver back an asnwer Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!WebRTC onicecandidate: Am getting ICE candidates with sdpMid=audio only but not for videoHow to manage a redirect request after a jQuery Ajax callHow to Check if element is visible after scrolling?How do I set/unset a cookie with jQuery?Remote VideoStream not working with WebRTCWhere can I find a simple webrtc video chat 1to1 sample?WebRTC Remote video not showing up on non-localhostWebRTC onicecandidate: Am getting ICE candidates with sdpMid=audio only but not for videoWebRTC using promises - Remote Video not seen at either endUnderstanding how to generate correct sdp for offer/answer (webrtc) between android/IphoneRemote video stream not displaying

What does the "x" in "x86" represent?

First console to have temporary backward compatibility

Has negative voting ever been officially implemented in elections, or seriously proposed, or even studied?

Extracting terms with certain heads in a function

Can a party unilaterally change candidates in preparation for a General election?

How to react to hostile behavior from a senior developer?

Is there such thing as an Availability Group failover trigger?

Delete nth line from bottom

Generate an RGB colour grid

Does classifying an integer as a discrete log require it be part of a multiplicative group?

Denied boarding although I have proper visa and documentation. To whom should I make a complaint?

How to tell that you are a giant?

Should I use a zero-interest credit card for a large one-time purchase?

Can anything be seen from the center of the Boötes void? How dark would it be?

What font is "z" in "z-score"?

また usage in a dictionary

Wu formula for manifolds with boundary

What is homebrew?

Crossing US/Canada Border for less than 24 hours

How can I use the Python library networkx from Mathematica?

Significance of Cersei's obsession with elephants?

Why wasn't DOSKEY integrated with COMMAND.COM?

What would be the ideal power source for a cybernetic eye?

How do I find out the mythology and history of my Fortress?



Webrtc how to set the video remote after receiver back an asnwer



Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)
Data science time! April 2019 and salary with experience
The Ask Question Wizard is Live!WebRTC onicecandidate: Am getting ICE candidates with sdpMid=audio only but not for videoHow to manage a redirect request after a jQuery Ajax callHow to Check if element is visible after scrolling?How do I set/unset a cookie with jQuery?Remote VideoStream not working with WebRTCWhere can I find a simple webrtc video chat 1to1 sample?WebRTC Remote video not showing up on non-localhostWebRTC onicecandidate: Am getting ICE candidates with sdpMid=audio only but not for videoWebRTC using promises - Remote Video not seen at either endUnderstanding how to generate correct sdp for offer/answer (webrtc) between android/IphoneRemote video stream not displaying



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








1















hello to all I am new in this I have all almost done,but just on my initiator for say something I don't know the way for receiver the remote video stream after receiver the answer, can some one help me please ?



this is my client



$(document).ready(() => 

const configuration =
iceServers: [ url: 'stun:stun2.1.google.com:19302' ]


var peerConection = null;
// var btnCall = $('body #call');
var list = $('#mylist');
var TitlePrint = $('#titleUser');
var localVideo = document.getElementById('local');
var remoteVideo = document.getElementById('remote');
var userid = null;

var socket = io();


socket.on('connect', () =>
userid = socket.id
TitlePrint.text(userid);
);



socket.on('users', data =>
var users = [];
list.empty();
for (let index = 0; index < data.user.length; index++)
if (data.user[index] != userid)
users.push(`<button id="call" class="list-group-item list-group-item-action" data-ids="$data.user[index]">$data.user[index]</button>`);


if (users.length != 0)

list.html(users);
else
list.html(`<div class="list-group-item"> Any users connected! </div>`);

);


$('body').on('click', '#call', function ()
let toId = $(this).attr('data-ids');
socket.emit('initiator', initiatorid: userid, receiverid: toId );
);


socket.on('initiator', data =>

peerConection = createRTC(socket);

if (data.initiatorid === userid)
console.log('this is the initiator');
initiateSignaling(socket, peerConection, data.receiverid, data.initiatorid);
else
console.log('this is the receiver');
prepareToReceiveOffer(socket, peerConection, data.initiatorid, data.receiverid);

);


// =============== HELPERS =====================//

function createRTC(socket)
console.log('createRTC')
var peerConection = new RTCPeerConnection(configuration);
peerConection.onicecandidate = (e) =>
if (e.candidate)
console.log('emit candidate')
socket.emit('send-candidate', e.candidate);



socket.on('receiver-candidate', (candidate) =>
peerConection.addIceCandidate(candidate);
);

return peerConection;


function initiateSignaling(socket, peerConection, targetID, from)
navigator.mediaDevices.getUserMedia( video: true, audio: false ).then((stream) =>
stream.getTracks().forEach(function (track)
peerConection.addTrack(track, stream);
);
localVideo.srcObject = stream;
peerConection.createOffer().then(function (offer)
return peerConection.setLocalDescription(offer);
)
.then(function ()
socket.emit('send-offer',
from: from,
target: targetID,
type: "send-offer",
sdp: peerConection.localDescription
);
)
.catch(function (reason)
console.log('error on create offer', reason);
);

)

socket.on('receiver-answer', (answer) =>
console.log(answer);
peerConection.setRemoteDescription(answer.sdp);
peerConection.ontrack = function (event)
remoteVideo.srcObject = event.streams[0];
;
);






function prepareToReceiveOffer(socket, peerConection, targetID, from)
socket.on('receiver-offer', (offer) =>
console.log(offer);
peerConection.setRemoteDescription(offer.sdp);
peerConection.createAnswer().then(function (answer)
return peerConection.setLocalDescription(answer);
)
.then(function ()
socket.emit('send-answer',
from: from,
target: targetID,
type: "send-answer",
sdp: peerConection.localDescription
);
);

peerConection.ontrack = function (event)
remoteVideo.srcObject = event.streams[0];
;
navigator.mediaDevices.getUserMedia( video: true, audio: false ).then((stream) =>
localVideo.srcObject = stream;
)
);


);


I just using socket.io I am handle the offer and answer then on my socket server I just set like this



socket.on('initiator', (init) => 
console.log(init);
io.to('video').emit('initiator', init);
);

socket.on('send-offer', offer =>
console.log('sending offer', offer);
socket.broadcast.emit('receiver-offer', offer);
);

socket.on('send-answer', answer =>
console.log('sending answer', answer);
socket.broadcast.emit('receiver-answer', answer);
);

socket.on('send-candidate', candidate =>
console.log(candidate);
socket.broadcast.emit('receiver-candidate',candidate);
);


I am get video remote on my receiver from the initiator but not in the initiator, I don't know what I miss for getting the remote video thanks so mush guys










share|improve this question




























    1















    hello to all I am new in this I have all almost done,but just on my initiator for say something I don't know the way for receiver the remote video stream after receiver the answer, can some one help me please ?



    this is my client



    $(document).ready(() => 

    const configuration =
    iceServers: [ url: 'stun:stun2.1.google.com:19302' ]


    var peerConection = null;
    // var btnCall = $('body #call');
    var list = $('#mylist');
    var TitlePrint = $('#titleUser');
    var localVideo = document.getElementById('local');
    var remoteVideo = document.getElementById('remote');
    var userid = null;

    var socket = io();


    socket.on('connect', () =>
    userid = socket.id
    TitlePrint.text(userid);
    );



    socket.on('users', data =>
    var users = [];
    list.empty();
    for (let index = 0; index < data.user.length; index++)
    if (data.user[index] != userid)
    users.push(`<button id="call" class="list-group-item list-group-item-action" data-ids="$data.user[index]">$data.user[index]</button>`);


    if (users.length != 0)

    list.html(users);
    else
    list.html(`<div class="list-group-item"> Any users connected! </div>`);

    );


    $('body').on('click', '#call', function ()
    let toId = $(this).attr('data-ids');
    socket.emit('initiator', initiatorid: userid, receiverid: toId );
    );


    socket.on('initiator', data =>

    peerConection = createRTC(socket);

    if (data.initiatorid === userid)
    console.log('this is the initiator');
    initiateSignaling(socket, peerConection, data.receiverid, data.initiatorid);
    else
    console.log('this is the receiver');
    prepareToReceiveOffer(socket, peerConection, data.initiatorid, data.receiverid);

    );


    // =============== HELPERS =====================//

    function createRTC(socket)
    console.log('createRTC')
    var peerConection = new RTCPeerConnection(configuration);
    peerConection.onicecandidate = (e) =>
    if (e.candidate)
    console.log('emit candidate')
    socket.emit('send-candidate', e.candidate);



    socket.on('receiver-candidate', (candidate) =>
    peerConection.addIceCandidate(candidate);
    );

    return peerConection;


    function initiateSignaling(socket, peerConection, targetID, from)
    navigator.mediaDevices.getUserMedia( video: true, audio: false ).then((stream) =>
    stream.getTracks().forEach(function (track)
    peerConection.addTrack(track, stream);
    );
    localVideo.srcObject = stream;
    peerConection.createOffer().then(function (offer)
    return peerConection.setLocalDescription(offer);
    )
    .then(function ()
    socket.emit('send-offer',
    from: from,
    target: targetID,
    type: "send-offer",
    sdp: peerConection.localDescription
    );
    )
    .catch(function (reason)
    console.log('error on create offer', reason);
    );

    )

    socket.on('receiver-answer', (answer) =>
    console.log(answer);
    peerConection.setRemoteDescription(answer.sdp);
    peerConection.ontrack = function (event)
    remoteVideo.srcObject = event.streams[0];
    ;
    );






    function prepareToReceiveOffer(socket, peerConection, targetID, from)
    socket.on('receiver-offer', (offer) =>
    console.log(offer);
    peerConection.setRemoteDescription(offer.sdp);
    peerConection.createAnswer().then(function (answer)
    return peerConection.setLocalDescription(answer);
    )
    .then(function ()
    socket.emit('send-answer',
    from: from,
    target: targetID,
    type: "send-answer",
    sdp: peerConection.localDescription
    );
    );

    peerConection.ontrack = function (event)
    remoteVideo.srcObject = event.streams[0];
    ;
    navigator.mediaDevices.getUserMedia( video: true, audio: false ).then((stream) =>
    localVideo.srcObject = stream;
    )
    );


    );


    I just using socket.io I am handle the offer and answer then on my socket server I just set like this



    socket.on('initiator', (init) => 
    console.log(init);
    io.to('video').emit('initiator', init);
    );

    socket.on('send-offer', offer =>
    console.log('sending offer', offer);
    socket.broadcast.emit('receiver-offer', offer);
    );

    socket.on('send-answer', answer =>
    console.log('sending answer', answer);
    socket.broadcast.emit('receiver-answer', answer);
    );

    socket.on('send-candidate', candidate =>
    console.log(candidate);
    socket.broadcast.emit('receiver-candidate',candidate);
    );


    I am get video remote on my receiver from the initiator but not in the initiator, I don't know what I miss for getting the remote video thanks so mush guys










    share|improve this question
























      1












      1








      1








      hello to all I am new in this I have all almost done,but just on my initiator for say something I don't know the way for receiver the remote video stream after receiver the answer, can some one help me please ?



      this is my client



      $(document).ready(() => 

      const configuration =
      iceServers: [ url: 'stun:stun2.1.google.com:19302' ]


      var peerConection = null;
      // var btnCall = $('body #call');
      var list = $('#mylist');
      var TitlePrint = $('#titleUser');
      var localVideo = document.getElementById('local');
      var remoteVideo = document.getElementById('remote');
      var userid = null;

      var socket = io();


      socket.on('connect', () =>
      userid = socket.id
      TitlePrint.text(userid);
      );



      socket.on('users', data =>
      var users = [];
      list.empty();
      for (let index = 0; index < data.user.length; index++)
      if (data.user[index] != userid)
      users.push(`<button id="call" class="list-group-item list-group-item-action" data-ids="$data.user[index]">$data.user[index]</button>`);


      if (users.length != 0)

      list.html(users);
      else
      list.html(`<div class="list-group-item"> Any users connected! </div>`);

      );


      $('body').on('click', '#call', function ()
      let toId = $(this).attr('data-ids');
      socket.emit('initiator', initiatorid: userid, receiverid: toId );
      );


      socket.on('initiator', data =>

      peerConection = createRTC(socket);

      if (data.initiatorid === userid)
      console.log('this is the initiator');
      initiateSignaling(socket, peerConection, data.receiverid, data.initiatorid);
      else
      console.log('this is the receiver');
      prepareToReceiveOffer(socket, peerConection, data.initiatorid, data.receiverid);

      );


      // =============== HELPERS =====================//

      function createRTC(socket)
      console.log('createRTC')
      var peerConection = new RTCPeerConnection(configuration);
      peerConection.onicecandidate = (e) =>
      if (e.candidate)
      console.log('emit candidate')
      socket.emit('send-candidate', e.candidate);



      socket.on('receiver-candidate', (candidate) =>
      peerConection.addIceCandidate(candidate);
      );

      return peerConection;


      function initiateSignaling(socket, peerConection, targetID, from)
      navigator.mediaDevices.getUserMedia( video: true, audio: false ).then((stream) =>
      stream.getTracks().forEach(function (track)
      peerConection.addTrack(track, stream);
      );
      localVideo.srcObject = stream;
      peerConection.createOffer().then(function (offer)
      return peerConection.setLocalDescription(offer);
      )
      .then(function ()
      socket.emit('send-offer',
      from: from,
      target: targetID,
      type: "send-offer",
      sdp: peerConection.localDescription
      );
      )
      .catch(function (reason)
      console.log('error on create offer', reason);
      );

      )

      socket.on('receiver-answer', (answer) =>
      console.log(answer);
      peerConection.setRemoteDescription(answer.sdp);
      peerConection.ontrack = function (event)
      remoteVideo.srcObject = event.streams[0];
      ;
      );






      function prepareToReceiveOffer(socket, peerConection, targetID, from)
      socket.on('receiver-offer', (offer) =>
      console.log(offer);
      peerConection.setRemoteDescription(offer.sdp);
      peerConection.createAnswer().then(function (answer)
      return peerConection.setLocalDescription(answer);
      )
      .then(function ()
      socket.emit('send-answer',
      from: from,
      target: targetID,
      type: "send-answer",
      sdp: peerConection.localDescription
      );
      );

      peerConection.ontrack = function (event)
      remoteVideo.srcObject = event.streams[0];
      ;
      navigator.mediaDevices.getUserMedia( video: true, audio: false ).then((stream) =>
      localVideo.srcObject = stream;
      )
      );


      );


      I just using socket.io I am handle the offer and answer then on my socket server I just set like this



      socket.on('initiator', (init) => 
      console.log(init);
      io.to('video').emit('initiator', init);
      );

      socket.on('send-offer', offer =>
      console.log('sending offer', offer);
      socket.broadcast.emit('receiver-offer', offer);
      );

      socket.on('send-answer', answer =>
      console.log('sending answer', answer);
      socket.broadcast.emit('receiver-answer', answer);
      );

      socket.on('send-candidate', candidate =>
      console.log(candidate);
      socket.broadcast.emit('receiver-candidate',candidate);
      );


      I am get video remote on my receiver from the initiator but not in the initiator, I don't know what I miss for getting the remote video thanks so mush guys










      share|improve this question














      hello to all I am new in this I have all almost done,but just on my initiator for say something I don't know the way for receiver the remote video stream after receiver the answer, can some one help me please ?



      this is my client



      $(document).ready(() => 

      const configuration =
      iceServers: [ url: 'stun:stun2.1.google.com:19302' ]


      var peerConection = null;
      // var btnCall = $('body #call');
      var list = $('#mylist');
      var TitlePrint = $('#titleUser');
      var localVideo = document.getElementById('local');
      var remoteVideo = document.getElementById('remote');
      var userid = null;

      var socket = io();


      socket.on('connect', () =>
      userid = socket.id
      TitlePrint.text(userid);
      );



      socket.on('users', data =>
      var users = [];
      list.empty();
      for (let index = 0; index < data.user.length; index++)
      if (data.user[index] != userid)
      users.push(`<button id="call" class="list-group-item list-group-item-action" data-ids="$data.user[index]">$data.user[index]</button>`);


      if (users.length != 0)

      list.html(users);
      else
      list.html(`<div class="list-group-item"> Any users connected! </div>`);

      );


      $('body').on('click', '#call', function ()
      let toId = $(this).attr('data-ids');
      socket.emit('initiator', initiatorid: userid, receiverid: toId );
      );


      socket.on('initiator', data =>

      peerConection = createRTC(socket);

      if (data.initiatorid === userid)
      console.log('this is the initiator');
      initiateSignaling(socket, peerConection, data.receiverid, data.initiatorid);
      else
      console.log('this is the receiver');
      prepareToReceiveOffer(socket, peerConection, data.initiatorid, data.receiverid);

      );


      // =============== HELPERS =====================//

      function createRTC(socket)
      console.log('createRTC')
      var peerConection = new RTCPeerConnection(configuration);
      peerConection.onicecandidate = (e) =>
      if (e.candidate)
      console.log('emit candidate')
      socket.emit('send-candidate', e.candidate);



      socket.on('receiver-candidate', (candidate) =>
      peerConection.addIceCandidate(candidate);
      );

      return peerConection;


      function initiateSignaling(socket, peerConection, targetID, from)
      navigator.mediaDevices.getUserMedia( video: true, audio: false ).then((stream) =>
      stream.getTracks().forEach(function (track)
      peerConection.addTrack(track, stream);
      );
      localVideo.srcObject = stream;
      peerConection.createOffer().then(function (offer)
      return peerConection.setLocalDescription(offer);
      )
      .then(function ()
      socket.emit('send-offer',
      from: from,
      target: targetID,
      type: "send-offer",
      sdp: peerConection.localDescription
      );
      )
      .catch(function (reason)
      console.log('error on create offer', reason);
      );

      )

      socket.on('receiver-answer', (answer) =>
      console.log(answer);
      peerConection.setRemoteDescription(answer.sdp);
      peerConection.ontrack = function (event)
      remoteVideo.srcObject = event.streams[0];
      ;
      );






      function prepareToReceiveOffer(socket, peerConection, targetID, from)
      socket.on('receiver-offer', (offer) =>
      console.log(offer);
      peerConection.setRemoteDescription(offer.sdp);
      peerConection.createAnswer().then(function (answer)
      return peerConection.setLocalDescription(answer);
      )
      .then(function ()
      socket.emit('send-answer',
      from: from,
      target: targetID,
      type: "send-answer",
      sdp: peerConection.localDescription
      );
      );

      peerConection.ontrack = function (event)
      remoteVideo.srcObject = event.streams[0];
      ;
      navigator.mediaDevices.getUserMedia( video: true, audio: false ).then((stream) =>
      localVideo.srcObject = stream;
      )
      );


      );


      I just using socket.io I am handle the offer and answer then on my socket server I just set like this



      socket.on('initiator', (init) => 
      console.log(init);
      io.to('video').emit('initiator', init);
      );

      socket.on('send-offer', offer =>
      console.log('sending offer', offer);
      socket.broadcast.emit('receiver-offer', offer);
      );

      socket.on('send-answer', answer =>
      console.log('sending answer', answer);
      socket.broadcast.emit('receiver-answer', answer);
      );

      socket.on('send-candidate', candidate =>
      console.log(candidate);
      socket.broadcast.emit('receiver-candidate',candidate);
      );


      I am get video remote on my receiver from the initiator but not in the initiator, I don't know what I miss for getting the remote video thanks so mush guys







      javascript jquery socket.io video-streaming webrtc






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 8 at 18:54









      Alfredo IzquierdoAlfredo Izquierdo

      566




      566






















          2 Answers
          2






          active

          oldest

          votes


















          2














          The initiator calls addTrack(), but not the receiver doesn't, so this is only sending media one way.



          In prepareToReceiveOffer you call getUserMedia() but never add resulting tracks to the peer connection. If you want a two-way call, it needs to call addTrack() as part of the offer/answer negotiation.



          Just be sure to call getUserMedia() after setRemoteDescription to not miss ICE candidates:



          function prepareToReceiveOffer(socket, peerConection, targetID, from) 
          socket.on('receiver-offer', (offer) =>
          console.log(offer);
          peerConection.setRemoteDescription(offer.sdp)
          .then(() => navigator.mediaDevices.getUserMedia(video: true, audio: false))
          .then(stream =>
          localVideo.srcObject = stream;
          for (const track of stream.getTracks())
          peerConection.addTrack(track, stream);

          return peerConection.createAnswer();
          )
          .then(function (answer)
          return peerConection.setLocalDescription(answer);
          )
          .then(function ()
          socket.emit('send-answer',
          from: from,
          target: targetID,
          type: "send-answer",
          sdp: peerConection.localDescription
          );
          )
          .catch(err => console.log(err.message));

          peerConection.ontrack = function (event)
          remoteVideo.srcObject = event.streams[0];
          ;
          );






          share|improve this answer























          • thanks I try it but same result

            – Alfredo Izquierdo
            Mar 8 at 21:55











          • Sorry to hear that. I'd personally move the two peerConection.ontrack = to one in createRTC(), but I don't see anything immediately wrong here. Here's a working fiddle if it helps.

            – jib
            Mar 8 at 22:47



















          0














          I get resolve it, in this particular case I my initiateSignaling function when I receiver the offer I has to include this



          socket.on('receiver-answer', (answer) => 
          console.log(answer);
          peerConection.setRemoteDescription(answer.sdp)
          .then(function ()
          return navigator.mediaDevices.getUserMedia(video:true, audio: false);
          )
          .then(function (stream)
          return peerConection.addStream(stream);
          )

          peerConection.ontrack = function (event)
          remoteVideo.srcObject = event.streams[0];
          ;
          );


          now is working for me






          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55069345%2fwebrtc-how-to-set-the-video-remote-after-receiver-back-an-asnwer%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            2














            The initiator calls addTrack(), but not the receiver doesn't, so this is only sending media one way.



            In prepareToReceiveOffer you call getUserMedia() but never add resulting tracks to the peer connection. If you want a two-way call, it needs to call addTrack() as part of the offer/answer negotiation.



            Just be sure to call getUserMedia() after setRemoteDescription to not miss ICE candidates:



            function prepareToReceiveOffer(socket, peerConection, targetID, from) 
            socket.on('receiver-offer', (offer) =>
            console.log(offer);
            peerConection.setRemoteDescription(offer.sdp)
            .then(() => navigator.mediaDevices.getUserMedia(video: true, audio: false))
            .then(stream =>
            localVideo.srcObject = stream;
            for (const track of stream.getTracks())
            peerConection.addTrack(track, stream);

            return peerConection.createAnswer();
            )
            .then(function (answer)
            return peerConection.setLocalDescription(answer);
            )
            .then(function ()
            socket.emit('send-answer',
            from: from,
            target: targetID,
            type: "send-answer",
            sdp: peerConection.localDescription
            );
            )
            .catch(err => console.log(err.message));

            peerConection.ontrack = function (event)
            remoteVideo.srcObject = event.streams[0];
            ;
            );






            share|improve this answer























            • thanks I try it but same result

              – Alfredo Izquierdo
              Mar 8 at 21:55











            • Sorry to hear that. I'd personally move the two peerConection.ontrack = to one in createRTC(), but I don't see anything immediately wrong here. Here's a working fiddle if it helps.

              – jib
              Mar 8 at 22:47
















            2














            The initiator calls addTrack(), but not the receiver doesn't, so this is only sending media one way.



            In prepareToReceiveOffer you call getUserMedia() but never add resulting tracks to the peer connection. If you want a two-way call, it needs to call addTrack() as part of the offer/answer negotiation.



            Just be sure to call getUserMedia() after setRemoteDescription to not miss ICE candidates:



            function prepareToReceiveOffer(socket, peerConection, targetID, from) 
            socket.on('receiver-offer', (offer) =>
            console.log(offer);
            peerConection.setRemoteDescription(offer.sdp)
            .then(() => navigator.mediaDevices.getUserMedia(video: true, audio: false))
            .then(stream =>
            localVideo.srcObject = stream;
            for (const track of stream.getTracks())
            peerConection.addTrack(track, stream);

            return peerConection.createAnswer();
            )
            .then(function (answer)
            return peerConection.setLocalDescription(answer);
            )
            .then(function ()
            socket.emit('send-answer',
            from: from,
            target: targetID,
            type: "send-answer",
            sdp: peerConection.localDescription
            );
            )
            .catch(err => console.log(err.message));

            peerConection.ontrack = function (event)
            remoteVideo.srcObject = event.streams[0];
            ;
            );






            share|improve this answer























            • thanks I try it but same result

              – Alfredo Izquierdo
              Mar 8 at 21:55











            • Sorry to hear that. I'd personally move the two peerConection.ontrack = to one in createRTC(), but I don't see anything immediately wrong here. Here's a working fiddle if it helps.

              – jib
              Mar 8 at 22:47














            2












            2








            2







            The initiator calls addTrack(), but not the receiver doesn't, so this is only sending media one way.



            In prepareToReceiveOffer you call getUserMedia() but never add resulting tracks to the peer connection. If you want a two-way call, it needs to call addTrack() as part of the offer/answer negotiation.



            Just be sure to call getUserMedia() after setRemoteDescription to not miss ICE candidates:



            function prepareToReceiveOffer(socket, peerConection, targetID, from) 
            socket.on('receiver-offer', (offer) =>
            console.log(offer);
            peerConection.setRemoteDescription(offer.sdp)
            .then(() => navigator.mediaDevices.getUserMedia(video: true, audio: false))
            .then(stream =>
            localVideo.srcObject = stream;
            for (const track of stream.getTracks())
            peerConection.addTrack(track, stream);

            return peerConection.createAnswer();
            )
            .then(function (answer)
            return peerConection.setLocalDescription(answer);
            )
            .then(function ()
            socket.emit('send-answer',
            from: from,
            target: targetID,
            type: "send-answer",
            sdp: peerConection.localDescription
            );
            )
            .catch(err => console.log(err.message));

            peerConection.ontrack = function (event)
            remoteVideo.srcObject = event.streams[0];
            ;
            );






            share|improve this answer













            The initiator calls addTrack(), but not the receiver doesn't, so this is only sending media one way.



            In prepareToReceiveOffer you call getUserMedia() but never add resulting tracks to the peer connection. If you want a two-way call, it needs to call addTrack() as part of the offer/answer negotiation.



            Just be sure to call getUserMedia() after setRemoteDescription to not miss ICE candidates:



            function prepareToReceiveOffer(socket, peerConection, targetID, from) 
            socket.on('receiver-offer', (offer) =>
            console.log(offer);
            peerConection.setRemoteDescription(offer.sdp)
            .then(() => navigator.mediaDevices.getUserMedia(video: true, audio: false))
            .then(stream =>
            localVideo.srcObject = stream;
            for (const track of stream.getTracks())
            peerConection.addTrack(track, stream);

            return peerConection.createAnswer();
            )
            .then(function (answer)
            return peerConection.setLocalDescription(answer);
            )
            .then(function ()
            socket.emit('send-answer',
            from: from,
            target: targetID,
            type: "send-answer",
            sdp: peerConection.localDescription
            );
            )
            .catch(err => console.log(err.message));

            peerConection.ontrack = function (event)
            remoteVideo.srcObject = event.streams[0];
            ;
            );







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Mar 8 at 21:18









            jibjib

            22.2k64695




            22.2k64695












            • thanks I try it but same result

              – Alfredo Izquierdo
              Mar 8 at 21:55











            • Sorry to hear that. I'd personally move the two peerConection.ontrack = to one in createRTC(), but I don't see anything immediately wrong here. Here's a working fiddle if it helps.

              – jib
              Mar 8 at 22:47


















            • thanks I try it but same result

              – Alfredo Izquierdo
              Mar 8 at 21:55











            • Sorry to hear that. I'd personally move the two peerConection.ontrack = to one in createRTC(), but I don't see anything immediately wrong here. Here's a working fiddle if it helps.

              – jib
              Mar 8 at 22:47

















            thanks I try it but same result

            – Alfredo Izquierdo
            Mar 8 at 21:55





            thanks I try it but same result

            – Alfredo Izquierdo
            Mar 8 at 21:55













            Sorry to hear that. I'd personally move the two peerConection.ontrack = to one in createRTC(), but I don't see anything immediately wrong here. Here's a working fiddle if it helps.

            – jib
            Mar 8 at 22:47






            Sorry to hear that. I'd personally move the two peerConection.ontrack = to one in createRTC(), but I don't see anything immediately wrong here. Here's a working fiddle if it helps.

            – jib
            Mar 8 at 22:47














            0














            I get resolve it, in this particular case I my initiateSignaling function when I receiver the offer I has to include this



            socket.on('receiver-answer', (answer) => 
            console.log(answer);
            peerConection.setRemoteDescription(answer.sdp)
            .then(function ()
            return navigator.mediaDevices.getUserMedia(video:true, audio: false);
            )
            .then(function (stream)
            return peerConection.addStream(stream);
            )

            peerConection.ontrack = function (event)
            remoteVideo.srcObject = event.streams[0];
            ;
            );


            now is working for me






            share|improve this answer



























              0














              I get resolve it, in this particular case I my initiateSignaling function when I receiver the offer I has to include this



              socket.on('receiver-answer', (answer) => 
              console.log(answer);
              peerConection.setRemoteDescription(answer.sdp)
              .then(function ()
              return navigator.mediaDevices.getUserMedia(video:true, audio: false);
              )
              .then(function (stream)
              return peerConection.addStream(stream);
              )

              peerConection.ontrack = function (event)
              remoteVideo.srcObject = event.streams[0];
              ;
              );


              now is working for me






              share|improve this answer

























                0












                0








                0







                I get resolve it, in this particular case I my initiateSignaling function when I receiver the offer I has to include this



                socket.on('receiver-answer', (answer) => 
                console.log(answer);
                peerConection.setRemoteDescription(answer.sdp)
                .then(function ()
                return navigator.mediaDevices.getUserMedia(video:true, audio: false);
                )
                .then(function (stream)
                return peerConection.addStream(stream);
                )

                peerConection.ontrack = function (event)
                remoteVideo.srcObject = event.streams[0];
                ;
                );


                now is working for me






                share|improve this answer













                I get resolve it, in this particular case I my initiateSignaling function when I receiver the offer I has to include this



                socket.on('receiver-answer', (answer) => 
                console.log(answer);
                peerConection.setRemoteDescription(answer.sdp)
                .then(function ()
                return navigator.mediaDevices.getUserMedia(video:true, audio: false);
                )
                .then(function (stream)
                return peerConection.addStream(stream);
                )

                peerConection.ontrack = function (event)
                remoteVideo.srcObject = event.streams[0];
                ;
                );


                now is working for me







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Mar 11 at 13:29









                Alfredo IzquierdoAlfredo Izquierdo

                566




                566



























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55069345%2fwebrtc-how-to-set-the-video-remote-after-receiver-back-an-asnwer%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    1928 у кіно

                    Захаров Федір Захарович

                    Ель Греко