This problem only happens when connecting through the internet. When caller and callee are in the same LAN my code works. Everything seems to work fine at first but no remote video stream gets displayed.
Here are the logs of the callee (identical when both on LAN):
PeerJS: Socket open peer.js:1
PeerJS: Creating RTCPeerConnection. peer.js:1
PeerJS: Listening for ICE candidates. peer.js:1
PeerJS: Listening for `negotiationneeded` peer.js:1
PeerJS: Listening for data channel peer.js:1
PeerJS: Listening for remote stream peer.js:1
PeerJS: Setting remote description
RTCSessionDescription {sdp: "v=0
↵o=- 7187042667088147170 2 IN IP4 127.0.0.1
↵s…70 label:ATMg5EjcUtmet7QBmgrXmmVn1OUNKw8om5xVv0
↵", type: "offer"}
peer.js:1
12
PeerJS: Added ICE candidate for: vnxqllnq85g3c8fr peer.js:1
PeerJS: `negotiationneeded` triggered peer.js:1
PeerJS: onnegotiationneeded triggered when not stable. Is another connection being established? peer.js:1
PeerJS: Received remote stream peer.js:1
PeerJS: Receiving stream
MediaStream {onremovetrack: null, onaddtrack: null, onended: null, ended: false, id: "ATMg5EjcUtmet7QBmgrXmmVn1OUNKw8om5xV"…}
peer.js:1
PeerJS: Set remoteDescription: OFFER for: vnxqllnq85g3c8fr peer.js:1
PeerJS: Created answer. peer.js:1
PeerJS: Set localDescription: answer for: vnxqllnq85g3c8fr peer.js:1
6
PeerJS: Received ICE candidates for: vnxqllnq85g3c8fr
This is the code for the answering peer:
var answer = function(peer, onCall){
peer.on('call', function(call) {
navigator.getUserMedia(
{video: true, audio: true},
function(stream) {
call.answer(stream);
myVideoObject.src = window.URL.createObjectURL(
stream
);
myVideoObject.play();
},
function(err) {
console.log(
'Failed to get local stream',
err
);
call.answer();
});
call.on('stream', function(remoteStream) {
console.log(
'Received remoteStream',
remoteStream
);
inVideoObject.src = window.URL.createObjectURL(
remoteStream
);
inVideoObject.play();
});
// ... more error handlers and hangup code here
};
The calling peer uses similar code, this is how the peers get initiated on both ends:
peer = new Peer('{{appointment.uid}}',
{
host: '
control.vistacan.com',
port: 9000,
key: 'peerjs',
debug: 3,
config: { 'iceServers': [
{ 'url': 'stun:
stun.l.google.com:19302' }
] }
});
Both caller and callee use latest versions of chrome, as I said it all works when both are in the same LAN. I am running my own peerjs service as such:
/usr/local/node-v0.10.6-linux-x64/lib/node_modules/peer/bin/peerjs -p 9000 --sslcert /path/to/my/cert --sslkey /path/to/my/key
Feel free to try it out (ssl only) at
control.vistacan.com:9000 key: peerjs
What am I doing wrong?
Cheers,
Ivan