Advertisement
Guest User

Untitled

a guest
Apr 26th, 2019
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. AFRAME.registerComponent('photo-mode', {
  2. init: function() {
  3. const container = document.getElementById('photoModeContainer')
  4. const image = document.getElementById('photoModeImage')
  5. const shutterButton = document.getElementById('shutterButton')
  6. const closeButton = document.getElementById('closeButton')
  7.  
  8. // Container starts hidden so it isn't visible when the page is still loading
  9. container.style.display = 'block'
  10.  
  11. closeButton.addEventListener('click', () => {
  12. container.classList.remove('photo')
  13. })
  14.  
  15. shutterButton.addEventListener('click', () => {
  16. // Emit a screenshotrequest to the xrweb component
  17. this.el.sceneEl.emit('screenshotrequest')
  18.  
  19. // Show the flash while the image is being taken
  20. container.classList.add('flash')
  21. })
  22.  
  23. this.el.sceneEl.addEventListener('screenshotready', e => {
  24. // Hide the flash
  25. container.classList.remove('flash')
  26.  
  27. // If an error occurs while trying to take the screenshot, e.detail will be empty.
  28. // We could either retry or return control to the user
  29. if (!e.detail) {
  30. return
  31. }
  32.  
  33. // e.detail is the base64 representation of the JPEG screenshot
  34. image.src = 'data:image/jpeg;base64,' + e.detail
  35.  
  36. // Show the photo
  37. container.classList.add('photo')
  38. })
  39. }
  40. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement