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);
}
}
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.
Comments