1876 characters | 53 lines | 1.83 KB
DOWNLOAD | RAW | EMBED | CREATE NEW VERSION OF THIS PASTE | REPORT ABUSE | x
  1. <!doctype html>
  2.     <head>
  3.         <title>SVG Streaming Client</title>
  4.  
  5.         <script src="http://code.jquery.com/jquery-git.js"></script>
  6.         <script>
  7.             function start_stream() {
  8.                 stream_sink             = $("#stream_sink")[0].getContext("2d");
  9.                 stream_source           = new Image();
  10.                 stream_source.onload    = function() {
  11.                     clear_sink();
  12.                     stream_sink.drawImage(stream_source, 0, 0, stream_source.width, stream_source.height);
  13.                 };
  14.            
  15.                 return setInterval(update_stream, (1000 / $("#fps").val()));
  16.             }
  17.            
  18.             function clear_sink() {
  19.                 stream_sink.fillStyle = "#454A41";
  20.                 stream_sink.fillRect(0, 0, 640, 480);
  21.             }
  22.            
  23.             function update_sink(data, text_status, jqXHR) {
  24.                 stream_source.src = data;
  25.             }
  26.            
  27.             function update_stream() {
  28.                 $.ajax({
  29.                     url:        $("#stream").val(),
  30.                     success:    update_sink,
  31.                     dataType:   "text"});
  32.             }
  33.            
  34.             $(function(){
  35.                 interval_id = start_stream();
  36.                 $("#fps").change(function() {
  37.                     clearInterval(interval_id)
  38.                     interval_id = setInterval(update_stream, (1000 / $("#fps").val()));
  39.                 });
  40.             });
  41.         </script>
  42.     </head>
  43.     <section>
  44.         <canvas id="stream_sink" width="640" height="480"></canvas>
  45.         <form>
  46.             <label for="stream">Stream</label>: <input id="stream" type="text" value="clock.svg">
  47.             <label for="stream">FPS</label>: <input id="fps" type="range" min="0" max="1000" step="5" value="1">
  48.         </form>
  49.     </section>
  50. </body>
  51. </html>