viewer.html 1.55 KB
Newer Older
Neil Gershenfeld's avatar
Neil Gershenfeld committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 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
<html>
<body>
<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>
<script type="text/javascript">
//
// viewer.html
//    screen.js content viewer
//    Neil Gershenfeld
//    2/9/17
//
var client_delay
initialize()
update()
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()
         document.getElementById("img").alt = 'screen transmission ended'
         document.getElementById("img").src = ''
         }
      else {
         var url = window.URL.createObjectURL(req.response)
         document.getElementById("img").src = url
         setTimeout(update,client_delay)
         }
      })
   }
</script>