Created
February 25, 2013 01:32
-
-
Save HTMLToronto/5026752 to your computer and use it in GitHub Desktop.
WebRTC minimal example for you to start playing with. Post your results back to @HTML5_Toronto and show off your skills. Remember, if you’re using Firefox, the current version requires you to activate the media.peerconnection.enabled within the about:config setting.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE HTML> | |
<html lang="en"> | |
<head> | |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> | |
</head> | |
<body> | |
<video></video> | |
<script> | |
window.addEventListener('DOMContentLoaded', function() { | |
'use strict'; | |
var video = document.querySelector('video'); | |
function successCallback(stream) { | |
if (video.mozSrcObject !== undefined) { | |
video.mozSrcObject = stream; | |
} else { | |
video.src = (window.URL && window.URL.createObjectURL(stream)) || stream; | |
} | |
video.play(); | |
} | |
function errorCallback(error) { | |
console.error('An error occurred: [CODE ' + error.code + ']'); | |
} | |
navigator.getUserMedia = | |
navigator.getUserMedia || // W3C | |
navigator.webkitGetUserMedia || // Webkit | |
navigator.mozGetUserMedia || // Mozilla | |
navigator.msGetUserMedia; // Microsoft | |
window.URL = window.URL || window.webkitURL || window.mozURL || window.msURL; | |
if (navigator.getUserMedia) { | |
navigator.getUserMedia({video: true}, successCallback, errorCallback); | |
} else { | |
console.log('Native web camera streaming (getUserMedia) not supported in this browser.'); | |
} | |
}, false); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment