0

I am trying to implement WebRTC call in js but I am not sure why this weird thing happens.

My question is exactly like this question. But the answers don't fix it in my case and I am using the latest FF and Chrome browsers.

This is what happens:

Peer A sends OFFER to Peer B.

Peer B sends back ANSWER to Peer A.

Peer B sends OFFER to Peer A.

Peer A sends back ANSWER to Peer B.

What my debugging suggests is that when Peer B executes this below code a negotiationneeded event is fired which in my understanding shouldn't happen.

const answer = await myPeerConnection.createAnswer();
await myPeerConnection.setLocalDescription(answer);

When Peer A has answered to the Peer B's offer call works.

In nutshell, the caller has to become callee for the call to work.

If you need more code please let me know.

Community
  • 1
  • 1
Newbie
  • 343
  • 2
  • 13

1 Answers1

0

I got the issue.

I will post the answer here incase anyone in future is facing the same issue.

The place where I was adding my cam stream to RTCPeerConnection I was using:

webcamStream.getTracks().forEach(
        transceiver = track => myPeerConnection.addTransceiver(track, {streams: [webcamStream]})
      );

I replaced above with below:

webcamStream.getTracks().forEach(track => myPeerConnection.addTrack(track, webcamStream));

I am not sure which is the best way to go. But I will read about both these ways so that I don't introduce new bugs while fixes this issue.

Newbie
  • 343
  • 2
  • 13