viewer.html 1.94 KB
Newer Older
Neil Gershenfeld's avatar
Neil Gershenfeld committed
1 2
<html>
<body>
Neil Gershenfeld's avatar
Neil Gershenfeld committed
3
<div id="page">
Neil Gershenfeld's avatar
Neil Gershenfeld committed
4 5 6
<img id="img" alt="waiting for screen transmission to start"><br>
<a href="screen.js">screen.js</a>
<a href="viewer.html">viewer.html</a>
Neil Gershenfeld's avatar
Neil Gershenfeld committed
7
</div>
Neil Gershenfeld's avatar
Neil Gershenfeld committed
8 9 10 11 12
<script type="text/javascript">
//
// viewer.html
//    screen.js content viewer
//    Neil Gershenfeld
Neil Gershenfeld's avatar
Neil Gershenfeld committed
13
//    2/26/19
Neil Gershenfeld's avatar
Neil Gershenfeld committed
14 15
//
var client_delay
Neil Gershenfeld's avatar
Neil Gershenfeld committed
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
var code = CODE
insecure_auth()
function insecure_auth() {
   if (code == '') {
      initialize()
      update()
      }
   else {
      var resp = prompt('screencast code?')
      if (resp == code) {
         initialize()
         update()
         }
      else {
         document.body.removeChild(document.getElementById('page'))
         document.write('incorrect code')
         }
      }
   }
Neil Gershenfeld's avatar
Neil Gershenfeld committed
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
function initialize() {
   var req = new XMLHttpRequest()
   req.open('GET','/initvars',true);
   req.send()
   req.addEventListener('loadend',function(evt) {
      if (evt.loaded == 0) {
         req.abort()
         }
      else {
         var vars = JSON.parse(req.responseText)
         client_delay = vars.client_delay
         }
      })
   var req = new XMLHttpRequest()
   req.open('GET','/initimg',true);
   req.responseType = 'blob'
   req.send()
   req.addEventListener('loadend',function(evt) {
      if (evt.loaded == 0) {
         req.abort()
         }
      else {
         var url = window.URL.createObjectURL(req.response)
         document.getElementById("img").src = url
         }
      })
   }
function update() {
   var req = new XMLHttpRequest()
   req.open('GET','/img',true);
   req.responseType = 'blob'
   req.send()
   req.addEventListener('loadend',function(evt) {
      if (evt.loaded == 0) {
         req.abort()
Neil Gershenfeld's avatar
Neil Gershenfeld committed
70 71
         document.body.removeChild(document.getElementById('page'))
         document.write('screen transmission ended')
Neil Gershenfeld's avatar
Neil Gershenfeld committed
72 73 74 75 76 77 78 79 80
         }
      else {
         var url = window.URL.createObjectURL(req.response)
         document.getElementById("img").src = url
         setTimeout(update,client_delay)
         }
      })
   }
</script>