<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Sinatra JRuby-Rack Multipart/Streaming Demo</title>
    <link rel="stylesheet" href="http://yui.yahooapis.com/2.8.0r4/build/reset/reset-min.css" type="text/css" media="screen, projection">
    <link rel="stylesheet" href="style.css" type="text/css" media="screen, projection">
    <link rel="shortcut icon" href="favicon.ico">
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
    <script type="text/javascript" src="js/DUI.js"></script>
    <script type="text/javascript" src="js/Stream.js"></script>
  </head>
  <body>
    <div id="content">
      <h1>Sinatra JRuby-Rack Streaming Demo</h1>
      <div>
        <% if defined?($servlet_context) %>
        <p>
          Current Server Time: <span id="servertime">Unknown</span>
          <input id="starttime" type="button" name="starttime" value="Click to stream server time"/>
          <script type="text/javascript">
            $('#starttime').click(function() {
              $(this).fadeOut();
              var timeStream = new DUI.Stream();
              timeStream.listen('application/json', function(payload) {
                var t = jQuery.parseJSON(payload);
                $('#servertime').text(t.currentTime);
              });
              timeStream.load('servertime');
              $(this).data('stream', timeStream);
            });
          </script>
        </p>
        <% else %>
          <p>In order to run this demo, you need to run Trinidad or some other JRuby-Rack-enabled application.</p>
        <% end %>
      </div>
    </div>
  </body>
</html>
