Skip to content

Instantly share code, notes, and snippets.

@mganeko
Created March 10, 2015 23:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mganeko/ee1f644b08fdca6970ca to your computer and use it in GitHub Desktop.
Save mganeko/ee1f644b08fdca6970ca to your computer and use it in GitHub Desktop.
WebRTC getUserMedia demo with "Simple Web Server
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>WebRTC getUserMedia</title>
<!-- this is demo for http://www.slideshare.net/mganeko/chromebook-webrtc -->
<!-- please install from : https://chrome.google.com/webstore/detail/simple-web-server/gajihfoegjplbobbcnikileolkbgjaaf -->
</head>
<body>
<button type="button" onclick="startVideo();">Start video</button>
<button type="button" onclick="stopVideo();">Stop video</button>
&nbsp;&nbsp;&nbsp;&nbsp;
<br />
<div style="position: relative;">
<video id="local-video" autoplay style="position: absolute; top: 0px; width: 320px; height: 240px; border: 1px solid black;"></video>
</div>
<script>
// ---------------------- video handling -----------------------
var localVideo = document.getElementById('local-video');
var localStream = null;
// get the local video up
function startVideo() {
navigator.webkitGetUserMedia({video: true, audio: true}, successCallback, errorCallback);
function successCallback(stream) {
localStream = stream;
localVideo.src = window.webkitURL.createObjectURL(stream);
localVideo.play();
}
function errorCallback(error) {
console.error('An error occurred: [CODE ' + error.code + ']');
return;
}
}
// stop local video
function stopVideo() {
localVideo.src = "";
localStream.stop();
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment