PeerJS: ICE candidates found but no call established

Viewed 316

I'd like to use PeerJS to let users share an audio stream. However, when calling peer.call(remoteId, stream) on the caller's side, the call event on the receiver's side is not emitted.

Here's the code on the caller side:

const peer = new Peer(learnerId, { debug: 3 });
peer.on('call', call => console.log('PeerJS call', call));
peer.on('open', event => console.log('PeerJS open', event));
peer.on('error', err => console.log('PeerJS error', err));
peer.on('connection', conn => console.log('PeerJS connection', conn));
peer.on('close', () => console.log('PeerJS close'));
peer.on('disconnected', () => console.log('PeerJS disconnected'));

console.log('Calling tutor', tutorId);
const call = peer.call(tutorId, stream);
call.on('close', () => console.log('PeerJS call close'));
call.on('error', (error) => console.log('PeerJS call error', error));
call.on('stream', (stream) => console.log('PeerJS call stream', stream));
console.log('Call:', call);

And on the receiver side:

const peer = new Peer(user.id, { debug: 3 });
console.log('Listening for calls as', user.id);
peer.on('open', event => console.log('PeerJS open', event));
peer.on('error', err => console.log('PeerJS error', err));
peer.on('connection', conn => console.log('PeerJS connection', conn));
peer.on('close', () => console.log('PeerJS close'));
peer.on('disconnected', () => console.log('PeerJS disconnected'));
peer.on('call', (call) => {
   console.log('Learner is calling', call);
   call.answer();
   call.on('stream', (remoteStream) => {
      console.log('Learner stream is ready', remoteStream);
   });
});

And here is the log from the caller side:

Calling tutor mN5yM0bjK7
peerjs.min.js:48 PeerJS:  Creating RTCPeerConnection.
peerjs.min.js:48 PeerJS:  Listening for ICE candidates.
peerjs.min.js:48 PeerJS:  Listening for data channel
peerjs.min.js:48 PeerJS:  Listening for remote stream
peerjs.min.js:48 PeerJS:  add tracks from stream RN32mP1gvF17wN33TTMGpJeOQpkTGmbHQfSf to peer connection
peerjs.min.js:48 PeerJS:  add connection media:mc_40t8d7p60r4 to peerId:mN5yM0bjK7
learn.service.ts:49 Call: l {_events: n, _eventsCount: 3, peer: "mN5yM0bjK7", provider: i, options: {…}, …}
peerjs.min.js:48 PeerJS:  Created offer.
peerjs.min.js:48 PeerJS:  Set localDescription: RTCSessionDescription {type: "offer", sdp: "v=0
↵o=- 488477196842332188 2 IN IP4 127.0.0.1
↵s=…1764 label:2b92f434-9de1-4845-a4ab-16e785cf10db
↵"} for:mN5yM0bjK7
peerjs.min.js:48 PeerJS:  Received ICE candidates for mN5yM0bjK7: RTCIceCandidate {candidate: "candidate:2940153462 1 udp 2122260223 192.168.178.…eration 0 ufrag NRFG network-id 1 network-cost 10", sdpMid: "0", sdpMLineIndex: 0, foundation: "2940153462", component: "rtp", …}
peerjs.min.js:48 PeerJS:  Received ICE candidates for mN5yM0bjK7: RTCIceCandidate {candidate: "candidate:3787248262 1 tcp 1518280447 192.168.178.…eration 0 ufrag NRFG network-id 1 network-cost 10", sdpMid: "0", sdpMLineIndex: 0, foundation: "3787248262", component: "rtp", …}
peerjs.min.js:48 PeerJS:  Received ICE candidates for mN5yM0bjK7: RTCIceCandidate {candidate: "candidate:1672614373 1 udp 1686052607 84.24.9.188 …eration 0 ufrag NRFG network-id 1 network-cost 10", sdpMid: "0", sdpMLineIndex: 0, foundation: "1672614373", component: "rtp", …}
peerjs.min.js:48 PeerJS:  Socket open
peerjs.min.js:48 PeerJS:  Server message received: {type: "OPEN"}
PeerJS open kBCpQQFAtW

and the receiver side:

Listening for calls as mN5yM0bjK7
peerjs.min.js:48 PeerJS:  Socket open
peerjs.min.js:48 PeerJS:  Server message received: {type: "OPEN"}
PeerJS open mN5yM0bjK7
peerjs.min.js:48 PeerJS:  Server message received: {type: "CANDIDATE", src: "kBCpQQFAtW", dst: "mN5yM0bjK7", payload: {…}}

It looks like the caller side is receiving ICE candidates for the receiver, but no connection seems to be established. Any idea what could be wrong here?

0 Answers
Related