WebRTC - peer2peer connection stopped working

Andrius

I started testing WebRTC and started with examples in https://github.com/samdutton/simpl/

I was testing this example: https://github.com/samdutton/simpl/blob/master/rtcpeerconnection/

I ran python's simple webserver: python -m SimpleHTTPServer

Then tried out if that example works on my end. And it did. Then I modified one part of the code (- means removed line and + added line):

function start() {
  trace("Requesting local stream");
  startButton.disabled = true;
  navigator.getUserMedia = navigator.getUserMedia ||
      navigator.webkitGetUserMedia || navigator.mozGetUserMedia;
  - navigator.getUserMedia({video:true}, gotStream,
  + navigator.getUserMedia({video:true, audio:true}, gotStream,
    function(error) {
      trace("navigator.getUserMedia error: ", error);
    });
}

When I ran it, video stopped working but I could hear my voice. Then I changed back how it was, but for some reason it stopped working all together.

Later I noticed that my camera was blocked for some reason, then I unblocked it, but it still does not work. I even replaced whole code with original one from github (even though it was the same).

And I get error without any error indication so I don't know whats wrong:

463.069: Requesting local stream main.js:31
465.550: navigator.getUserMedia error:

I also thought maybe somehow getUserMedia was disabled in Chromium (I use - Version 34.0.1847.116 Ubuntu 14.04 aura (260972))

So I enabled getUserMedia in Chromium settings. But still nothing.

You can check how it is working on this link: http://www.simpl.info/rtcpeerconnection/

The line that points out error (31 line):

console.log((performance.now() / 1000).toFixed(3) + ": " + text);

Function that got this line:

var total = '';
function trace(text) {
  total += text;
  console.log((performance.now() / 1000).toFixed(3) + ": " + text);
}

Also whole javascript code:

var localStream, localPeerConnection, remotePeerConnection;

var localVideo = document.getElementById("localVideo");
var remoteVideo = document.getElementById("remoteVideo");

localVideo.addEventListener("loadedmetadata", function(){
trace("Local video currentSrc: " + this.currentSrc +
        ", videoWidth: " + this.videoWidth +
        "px,  videoHeight: " + this.videoHeight + "px");
});

remoteVideo.addEventListener("loadedmetadata", function(){
trace("Remote video currentSrc: " + this.currentSrc +
        ", videoWidth: " + this.videoWidth +
        "px,  videoHeight: " + this.videoHeight + "px");
});

var startButton = document.getElementById("startButton");
var callButton = document.getElementById("callButton");
var hangupButton = document.getElementById("hangupButton");
startButton.disabled = false;
callButton.disabled = true;
hangupButton.disabled = true;
startButton.onclick = start;
callButton.onclick = call;
hangupButton.onclick = hangup;

var total = '';
function trace(text) {
  total += text;
  console.log((performance.now() / 1000).toFixed(3) + ": " + text);
}

function gotStream(stream){
  trace("Received local stream");
  localVideo.src = URL.createObjectURL(stream);
  localStream = stream;
  callButton.disabled = false;
}

function start() {
  trace("Requesting local stream");
  startButton.disabled = true;
  navigator.getUserMedia = navigator.getUserMedia ||
    navigator.webkitGetUserMedia || navigator.mozGetUserMedia;
  navigator.getUserMedia({video:true}, gotStream,
    function(error) {
      trace("navigator.getUserMedia error: ", error);
    });
}

function call() {
  callButton.disabled = true;
  hangupButton.disabled = false;
  trace("Starting call");

  if (localStream.getVideoTracks().length > 0) {
    trace('Using video device: ' + localStream.getVideoTracks()[0].label);
  }
  if (localStream.getAudioTracks().length > 0) {
    trace('Using audio device: ' + localStream.getAudioTracks()[0].label);
  }

  var servers = null;

  localPeerConnection = new webkitRTCPeerConnection(servers);
  trace("Created local peer connection object localPeerConnection");
  localPeerConnection.onicecandidate = gotLocalIceCandidate;

  remotePeerConnection = new webkitRTCPeerConnection(servers);
  trace("Created remote peer connection object remotePeerConnection");
  remotePeerConnection.onicecandidate = gotRemoteIceCandidate;
  remotePeerConnection.onaddstream = gotRemoteStream;

  localPeerConnection.addStream(localStream);
  trace("Added localStream to localPeerConnection");
  localPeerConnection.createOffer(gotLocalDescription);
}

function gotLocalDescription(description){
  localPeerConnection.setLocalDescription(description);
  trace("Offer from localPeerConnection: \n" + description.sdp);
  remotePeerConnection.setRemoteDescription(description);
  remotePeerConnection.createAnswer(gotRemoteDescription);
}

function gotRemoteDescription(description){
  remotePeerConnection.setLocalDescription(description);
  trace("Answer from remotePeerConnection: \n" + description.sdp);
  localPeerConnection.setRemoteDescription(description);
}

function hangup() {
  trace("Ending call");
  localPeerConnection.close();
  remotePeerConnection.close();
  localPeerConnection = null;
  remotePeerConnection = null;
  hangupButton.disabled = true;
  callButton.disabled = false;
}

function gotRemoteStream(event){
  remoteVideo.src = URL.createObjectURL(event.stream);
  trace("Received remote stream");
}

function gotLocalIceCandidate(event){
  if (event.candidate) {
    remotePeerConnection.addIceCandidate(new RTCIceCandidate(event.candidate));
    trace("Local ICE candidate: \n" + event.candidate.candidate);
  }
}

function gotRemoteIceCandidate(event){
  if (event.candidate) {
    localPeerConnection.addIceCandidate(new RTCIceCandidate(event.candidate));
    trace("Remote ICE candidate: \n " + event.candidate.candidate);
  }
}
Andrius

So much trouble for such thing. I didn't notice that I was running same page on firefox when I was testing on chromium. So I'm guessing it got into a conflict. First unexpected thing happened when chromium blocked my camera and I didn't notice that.

Then I tried to run same program with firefox (version 30), but I guess its not turned on on firefox, because it didn't recognize some parameters from javascript file and threw some errors. Then I left that page hanging on firefox while my camera was running and even when I unblocked my camera on chromium I couldnt run it because of firefox.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

WebRTC Peer to Peer Connection

From Dev

Multi peer connection in webrtc

From Dev

Detect offline peer in WebRTC connection

From Dev

WebRTC android example, XMPP or Http Peer Connection?

From Dev

WebRTC android example, XMPP or Http Peer Connection?

From Dev

WebRTC issue on closing peer connection in have-local-offer state

From Dev

WebRTC: Cannot do Peer to Peer connection. Browser Does not ask to Grant permission for Microphone/ Webcam

From Dev

Building a video Streaming App using WebRtc And Along With Peer to peer connection Locally?

From Dev

internet connection stopped working, but wifi connection looks fine (ubuntu 18.04.2)

From Dev

WCF service stop working 10054 WSAECONNRESET Connection reset by peer

From Dev

Does PeerJS or WebRTC peer connection require a server or it's only between clients?

From Dev

Does PeerJS or WebRTC peer connection require a server or it's only between clients?

From Dev

Cordova peer-to-peer app using webRTC

From Dev

Is WebRTC really peer-to-peer protocol?

From Dev

Forwarding WebRTC Video for Peer to Peer Broadcasting

From Dev

Microsoft Visual Studio 2013 Stopped Working when adding connection

From Dev

Windows 10 “Remote Desktop Connection has stopped working.”

From Dev

Internet Connection Sharing stopped working after Windows 10 Anniversary Update

From Dev

Evolution ews connection to exchange suddenly stopped working (unauthorized)

From Dev

MongoDB connection reset by peer

From Dev

Connection reset by peer - winsock

From Dev

openSSH connection reset by peer

From Dev

write: Connection reset by peer

From Dev

sublime text 2 autocomplete stopped working

From Dev

Symfony2 login stopped working

From Dev

Peer-to-Peer connection over the internet

From Dev

Peer-to-Peer connection over the internet

From Dev

Peer-2-peer or client/server connection over cell network to connect 2 android device

From Dev

Does WebRTC allow actual peer-to-peer communication?

Related Related

  1. 1

    WebRTC Peer to Peer Connection

  2. 2

    Multi peer connection in webrtc

  3. 3

    Detect offline peer in WebRTC connection

  4. 4

    WebRTC android example, XMPP or Http Peer Connection?

  5. 5

    WebRTC android example, XMPP or Http Peer Connection?

  6. 6

    WebRTC issue on closing peer connection in have-local-offer state

  7. 7

    WebRTC: Cannot do Peer to Peer connection. Browser Does not ask to Grant permission for Microphone/ Webcam

  8. 8

    Building a video Streaming App using WebRtc And Along With Peer to peer connection Locally?

  9. 9

    internet connection stopped working, but wifi connection looks fine (ubuntu 18.04.2)

  10. 10

    WCF service stop working 10054 WSAECONNRESET Connection reset by peer

  11. 11

    Does PeerJS or WebRTC peer connection require a server or it's only between clients?

  12. 12

    Does PeerJS or WebRTC peer connection require a server or it's only between clients?

  13. 13

    Cordova peer-to-peer app using webRTC

  14. 14

    Is WebRTC really peer-to-peer protocol?

  15. 15

    Forwarding WebRTC Video for Peer to Peer Broadcasting

  16. 16

    Microsoft Visual Studio 2013 Stopped Working when adding connection

  17. 17

    Windows 10 “Remote Desktop Connection has stopped working.”

  18. 18

    Internet Connection Sharing stopped working after Windows 10 Anniversary Update

  19. 19

    Evolution ews connection to exchange suddenly stopped working (unauthorized)

  20. 20

    MongoDB connection reset by peer

  21. 21

    Connection reset by peer - winsock

  22. 22

    openSSH connection reset by peer

  23. 23

    write: Connection reset by peer

  24. 24

    sublime text 2 autocomplete stopped working

  25. 25

    Symfony2 login stopped working

  26. 26

    Peer-to-Peer connection over the internet

  27. 27

    Peer-to-Peer connection over the internet

  28. 28

    Peer-2-peer or client/server connection over cell network to connect 2 android device

  29. 29

    Does WebRTC allow actual peer-to-peer communication?

HotTag

Archive