peers / peerjs

Simple peer-to-peer with WebRTC.
https://peerjs.com
MIT License
12.35k stars 1.43k forks source link

(OperationError) Failed to set local offer sdp: Called in wrong state: kHaveRemoteOffer #428

Closed iakashpaul closed 6 years ago

iakashpaul commented 6 years ago

(OperationError) Failed to set local offer sdp: Called in wrong state: kHaveRemoteOffer

0.3.14v of PeerJS

Above error occurs with video calls going from,

This was working fine until Chrome 65 IIRC. The callee is able to get the other party's video stream but the called party gets the above error & a black window from the callee. There's not much info in the logs either.

kidandcat commented 6 years ago

Could you clone the repository, execute grunt, and use the build peer.min.js? Use master branch.

Or if you prefer, I'm attaching the already built lib:

peer.min.js.zip

Tell me if it works or not please.

kidandcat commented 6 years ago

Also you can use

const peer = new Peer({ debug: 3 });

to see logs.

iakashpaul commented 6 years ago

Ok I'm checking it out now, thanks.

iakashpaul commented 6 years ago

This is the log,

Callee log [remote video loads]

PeerJS: Socket open peer.min.js:1 PeerJS: Creating RTCPeerConnection. peer.min.js:1 PeerJS: Listening for ICE candidates. peer.min.js:1 PeerJS: Listening for negotiationneeded peer.min.js:1 PeerJS: Listening for data channel peer.min.js:1 PeerJS: Listening for remote stream 2peer.min.js:1 PeerJS: negotiationneeded triggered 2peer.min.js:1 PeerJS: Created offer. 2peer.min.js:1 PeerJS: Set localDescription: offer for: fff 28peer.min.js:1 PeerJS: Received ICE candidates for: fff peer.min.js:1 PeerJS: ERROR Error: Could not connect to peer fff peer.min.js:1 PeerJS: Creating RTCPeerConnection. peer.min.js:1 PeerJS: Listening for ICE candidates. peer.min.js:1 PeerJS: Listening for negotiationneeded peer.min.js:1 PeerJS: Listening for data channel peer.min.js:1 PeerJS: Listening for remote stream 2peer.min.js:1 PeerJS: negotiationneeded triggered 2peer.min.js:1 PeerJS: Created offer. 2peer.min.js:1 PeerJS: Set localDescription: offer for: ddd 22peer.min.js:1 PeerJS: Received ICE candidates for: ddd peer.min.js:1 PeerJS: Setting remote description RTCSessionDescriptionsdp: "v=0 ↵o=- 7737904789115560210 4 IN IP4 127.0.0.1 ↵s=- ↵t=0 0 ↵a=group:BUNDLE audio video ↵a=msid-semantic: WMS ohmXipt0iGnaJGpn9lWb7XZVrAk7D3fXOfuv ↵m=audio 9 UDP/TLS/RTP/SAVPF 111 103 104 9 0 8 106 105 13 110 112 113 126 ↵c=IN IP4 0.0.0.0 ↵a=rtcp:9 IN IP4 0.0.0.0 ↵a=ice-ufrag:ssc1 ↵a=ice-pwd:CJuJdycKa42kam1wI3GcoI9V ↵a=ice-options:trickle ↵a=fingerprint:sha-256 0B:82:E0:D3:D8:3E:D1:01:89:05:3A:2A:07:E0:31:98:20:64:8B:53:83:9F:09:BE:5B:5C:EA:1E:D3:C8:3C:92 ↵a=setup:active ↵a=mid:audio ↵a=extmap:1 urn:ietf:params:rtp-hdrext:ssrc-audio-level ↵a=sendrecv ↵a=rtcp-mux ↵a=rtpmap:111 opus/48000/2 ↵a=rtcp-fb:111 transport-cc ↵a=fmtp:111 minptime=10;useinbandfec=1 ↵a=rtpmap:103 ISAC/16000 ↵a=rtpmap:104 ISAC/32000 ↵a=rtpmap:9 G722/8000 ↵a=rtpmap:0 PCMU/8000 ↵a=rtpmap:8 PCMA/8000 ↵a=rtpmap:106 CN/32000 ↵a=rtpmap:105 CN/16000 ↵a=rtpmap:13 CN/8000 ↵a=rtpmap:110 telephone-event/48000 ↵a=rtpmap:112 telephone-event/32000 ↵a=rtpmap:113 telephone-event/16000 ↵a=rtpmap:126 telephone-event/8000 ↵a=ssrc:4019198901 cname:ZK602U6Nv/HWP+yF ↵a=ssrc:4019198901 msid:ohmXipt0iGnaJGpn9lWb7XZVrAk7D3fXOfuv b36de7c6-f053-41c9-9a19-cec1ffe96502 ↵a=ssrc:4019198901 mslabel:ohmXipt0iGnaJGpn9lWb7XZVrAk7D3fXOfuv ↵a=ssrc:4019198901 label:b36de7c6-f053-41c9-9a19-cec1ffe96502 ↵m=video 9 UDP/TLS/RTP/SAVPF 96 97 98 99 100 101 102 123 127 122 125 107 108 109 124 ↵c=IN IP4 0.0.0.0 ↵a=rtcp:9 IN IP4 0.0.0.0 ↵a=ice-ufrag:ssc1 ↵a=ice-pwd:CJuJdycKa42kam1wI3GcoI9V ↵a=ice-options:trickle ↵a=fingerprint:sha-256 0B:82:E0:D3:D8:3E:D1:01:89:05:3A:2A:07:E0:31:98:20:64:8B:53:83:9F:09:BE:5B:5C:EA:1E:D3:C8:3C:92 ↵a=setup:active ↵a=mid:video ↵a=extmap:2 urn:ietf:params:rtp-hdrext:toffset ↵a=extmap:3 http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time ↵a=extmap:4 urn:3gpp:video-orientation ↵a=extmap:5 http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01 ↵a=extmap:6 http://www.webrtc.org/experiments/rtp-hdrext/playout-delay ↵a=extmap:7 http://www.webrtc.org/experiments/rtp-hdrext/video-content-type ↵a=extmap:8 http://www.webrtc.org/experiments/rtp-hdrext/video-timing ↵a=sendrecv ↵a=rtcp-mux ↵a=rtcp-rsize ↵a=rtpmap:96 VP8/90000 ↵a=rtcp-fb:96 goog-remb ↵a=rtcp-fb:96 transport-cc ↵a=rtcp-fb:96 ccm fir ↵a=rtcp-fb:96 nack ↵a=rtcp-fb:96 nack pli ↵a=rtpmap:97 rtx/90000 ↵a=fmtp:97 apt=96 ↵a=rtpmap:98 VP9/90000 ↵a=rtcp-fb:98 goog-remb ↵a=rtcp-fb:98 transport-cc ↵a=rtcp-fb:98 ccm fir ↵a=rtcp-fb:98 nack ↵a=rtcp-fb:98 nack pli ↵a=rtpmap:99 rtx/90000 ↵a=fmtp:99 apt=98 ↵a=rtpmap:100 H264/90000 ↵a=rtcp-fb:100 goog-remb ↵a=rtcp-fb:100 transport-cc ↵a=rtcp-fb:100 ccm fir ↵a=rtcp-fb:100 nack ↵a=rtcp-fb:100 nack pli ↵a=fmtp:100 level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=42001f ↵a=rtpmap:101 rtx/90000 ↵a=fmtp:101 apt=100 ↵a=rtpmap:102 H264/90000 ↵a=rtcp-fb:102 goog-remb ↵a=rtcp-fb:102 transport-cc ↵a=rtcp-fb:102 ccm fir ↵a=rtcp-fb:102 nack ↵a=rtcp-fb:102 nack pli ↵a=fmtp:102 level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=42e01f ↵a=rtpmap:123 rtx/90000 ↵a=fmtp:123 apt=102 ↵a=rtpmap:127 H264/90000 ↵a=rtcp-fb:127 goog-remb ↵a=rtcp-fb:127 transport-cc ↵a=rtcp-fb:127 ccm fir ↵a=rtcp-fb:127 nack ↵a=rtcp-fb:127 nack pli ↵a=fmtp:127 level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=4d0032 ↵a=rtpmap:122 rtx/90000 ↵a=fmtp:122 apt=127 ↵a=rtpmap:125 H264/90000 ↵a=rtcp-fb:125 goog-remb ↵a=rtcp-fb:125 transport-cc ↵a=rtcp-fb:125 ccm fir ↵a=rtcp-fb:125 nack ↵a=rtcp-fb:125 nack pli ↵a=fmtp:125 level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=640032 ↵a=rtpmap:107 rtx/90000 ↵a=fmtp:107 apt=125 ↵a=rtpmap:108 red/90000 ↵a=rtpmap:109 rtx/90000 ↵a=fmtp:109 apt=108 ↵a=rtpmap:124 ulpfec/90000 ↵a=ssrc-group:FID 1783608533 51096151 ↵a=ssrc:1783608533 cname:ZK602U6Nv/HWP+yF ↵a=ssrc:1783608533 msid:ohmXipt0iGnaJGpn9lWb7XZVrAk7D3fXOfuv 0b029456-7b93-4675-869f-ea5ae5b153fa ↵a=ssrc:1783608533 mslabel:ohmXipt0iGnaJGpn9lWb7XZVrAk7D3fXOfuv ↵a=ssrc:1783608533 label:0b029456-7b93-4675-869f-ea5ae5b153fa ↵a=ssrc:51096151 cname:ZK602U6Nv/HWP+yF ↵a=ssrc:51096151 msid:ohmXipt0iGnaJGpn9lWb7XZVrAk7D3fXOfuv 0b029456-7b93-4675-869f-ea5ae5b153fa ↵a=ssrc:51096151 mslabel:ohmXipt0iGnaJGpn9lWb7XZVrAk7D3fXOfuv ↵a=ssrc:51096151 label:0b029456-7b93-4675-869f-ea5ae5b153fa ↵"type: "answer"proto: RTCSessionDescription peer.min.js:1 PeerJS: Received remote stream peer.min.js:1 PeerJS: Receiving stream MediaStreamactive: trueid: "ohmXipt0iGnaJGpn9lWb7XZVrAk7D3fXOfuv"onactive: nullonaddtrack: nulloninactive: nullonremovetrack: nullproto: MediaStream peer.min.js:1 PeerJS: Set remoteDescription: ANSWER for: ddd 5peer.min.js:1 PeerJS: Added ICE candidate for: ddd


Called party [remote video doesn't load]

PeerJS: Socket open peer.min.js:1 PeerJS: Creating RTCPeerConnection. peer.min.js:1 PeerJS: Listening for ICE candidates. peer.min.js:1 PeerJS: Listening for negotiationneeded peer.min.js:1 PeerJS: Listening for data channel peer.min.js:1 PeerJS: Listening for remote stream peer.min.js:1 PeerJS: Setting remote description RTCSessionDescription peer.min.js:1 PeerJS: negotiationneeded triggered peer.min.js:1 PeerJS: Created offer. peer.min.js:1 PeerJS: Received remote stream peer.min.js:1 PeerJS: Receiving stream MediaStream peer.min.js:1 PeerJS: Set remoteDescription: OFFER for: spoe309hcnrhehfr peer.min.js:1 PeerJS: ERROR Error: (OperationError) Failed to set local offer sdp: Called in wrong state: kHaveRemoteOffer _print @ peer.min.js:1 peer.min.js:1 PeerJS: Failed to setLocalDescription, (OperationError) Failed to set local offer sdp: Called in wrong state: kHaveRemoteOffer _print @ peer.min.js:1 peer.min.js:1 PeerJS: ERROR Error: (OperationError) Failed to set local offer sdp: Called in wrong state: kHaveRemoteOffer _print @ peer.min.js:1 peer.min.js:1 PeerJS: Failed to setLocalDescription, (OperationError) Failed to set local offer sdp: Called in wrong state: kHaveRemoteOffer _print @ peer.min.js:1 peer.min.js:1 PeerJS: Created answer. peer.min.js:1 PeerJS: Set localDescription: answer for: spoe309hcnrhehfr 5peer.min.js:1 PeerJS: Received ICE candidates for: spoe309hcnrhehfr peer.min.js:1 PeerJS: WARNING Offer received for existing Connection ID: mc_ygg6w68l2b peer.min.js:1 PeerJS: Added ICE candidate for: spoe309hcnrhehfr

PeerJS-log.txt

From the logs I can see that the ID, which both peers are trying to connect with are not each other but some other random ID despite providing the other party's ID.

kidandcat commented 6 years ago

Could you post your code?

iakashpaul commented 6 years ago

https://github.com/iakashpaul/peerjsipx, this is the main page https://github.com/iakashpaul/peerjsipx/blob/master/views/pages/index.ejs It's running on heroku at https://peerjsipx.herokuapp.com/

kidandcat commented 6 years ago

Use peer.min.js from dist folder from master branch. https://raw.githubusercontent.com/peers/peerjs/master/dist/peer.min.js

When I publish the new version, you can install it like always from NPM. It will be at the end of the month.

Feel free to reopen if it doesn't work. (I tested it with your code, so that shouldn't happen)

BuffMcBigHuge commented 6 years ago

I am also experiencing this problem.

pooljpv84 commented 6 years ago

Gracias...!! 👍 @kidandcat tenia el mismo problema y lo resolví utilizando el archivo:

https://raw.githubusercontent.com/peers/peerjs/master/dist/peer.min.js

kidandcat commented 6 years ago

I updated the NPM version, so you can just update it on your package.json

iakashpaul commented 6 years ago

Thanks a lot, I'll check it out!

jersobh commented 5 years ago

I'm getting this error also:

PeerJS:  Created offer.
peerjs.min.js:9 PeerJS:  Set localDescription: offer for: smartcaller-67c80b6f-9554-44fe-8153-61c7a763e58e

8peerjs.min.js:9 PeerJS:  Received ICE candidates for: smartcaller-67c80b6f-9554-44fe-8153-61c7a763e58e

peerjs.min.js:9 PeerJS:  ERROR Error: Could not connect to peer smartcaller-67c80b6f-9554-44fe-8153-61c7a763e58e
iakashpaul commented 5 years ago

Is this for the latest build? If you are starting off something new, then simple-peer is a good alternative if you need something quickly.

jersobh commented 5 years ago

@iakashpaul I'm using this one:

I guess it's the latest build. The strange part is that it only happens on my vuejs code.

jersobh commented 5 years ago

This is my call function:

  call: function () {
      let self = this
      self.current_call = self.peer.call(self.remoteID, self.localStream)
          self.current_call.on('stream', function(remotestream) {
             console.log('receiving stream')
              self.setRemoteMedia(remotestream)
            });
    },

self.peer is an open peer connection, and it never gets the "receiving stream" part

jersobh commented 5 years ago

The only difference seems to be that I'm storing the stream from getUserMedia on a data variable on vuejs

iakashpaul commented 5 years ago

Have you seen this article? https://www.eli5.io/blog/recording-audio-with-laravel-and-vuejs-using-webrtc-part-1 see if the variable is properly storing that stream.

jersobh commented 5 years ago

Yep, it is. I've even set another

ShindeSwapnali commented 4 years ago

Hello All, I am also facing the same issue when i am connecting to SDP using RTC data channel

operationerror: failed to set local offer sdp: called in wrong state: khaveremoteoffer

Not able to view the video of the peer connected.

ShindeSwapnali commented 4 years ago

Please update the peer.min.js file from below path and check https://gitlab.com/zkry.akgul/peerjs