Skip to content

Instantly share code, notes, and snippets.

@MagnusThor
Created January 12, 2016 14:47
Show Gist options
  • Save MagnusThor/6dcdfea3f840699e53d2 to your computer and use it in GitHub Desktop.
Save MagnusThor/6dcdfea3f840699e53d2 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset="utf-8" />
</head>
<body>
<script src="js/XSockets.latest.js"></script>
<script src="js/XSockets.WebRTC.latest.js"></script>
<script>
var Camera = (function () {
var ctor = function (srm, w, h) {
this.canvas = document.createElement("canvas");
this.canvas.with = w || 320;
this.canvas.h = h || 180;
this.video = document.createElement("video");
this.video.autoplay = true;
this.video.with = w || 320;
this.video.h = h || 180;
attachMediaStream(this.video, srm);
this.context = this.canvas.getContext('2d');
this.interval = -1;
};
ctor.prototype.takePicture = function (fn,ms) {
if (!ms) {
this.context.drawImage(this.video, 0, 0, this.canvas.width, this.canvas.height);
fn(this.canvas.toDataURL('image/png'));
fn(data);
} else {
var that = this;
this.interval = window.setInterval(function() {
that.context.drawImage(that.video, 0, 0, that.canvas.width, that.canvas.height);
fn(that.canvas.toDataURL('image/png'));
},ms);
}
};
return ctor;
})();
var camera;
document.addEventListener("DOMContentLoaded", function () {
getUserMedia(
{
video: {
mandatory: {
maxWidth: 320,
maxHeight: 180
}
},
audio: false
},
function (stream) {
camera = new Camera(stream, 329, 180);
camera.takePicture(function(base64, peerId) {
console.log("base64", base64);
}, 3000);
},
function (err) {
console.log("An error occured! " + err);
}
);
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment