<% content_for :page_title do %>
  Event bus debugging page
<% end %>
<h1>Event bus debugging page</h1>

<form>
<textarea style="width:100%; height: 10em" id="websocket-message-content"></textarea>
<button type="button" id="send-to-websocket">Send</button>
</form>

<br>

<p id="PutStuffHere"></p>

<script>
$(function() {
putStuffThere = function (content) {
  $("#PutStuffHere").append(content + "<br>");
};

var dispatcher = new WebSocket('<%= arvados_api_client.discovery[:websocketUrl] %>?api_token=<%= Thread.current[:arvados_api_token] %>');
dispatcher.onmessage = function(event) {
  //putStuffThere(JSON.parse(event.data));
  putStuffThere(event.data);
};

sendStuff = function () {
  dispatcher.send($("#websocket-message-content").val());
};

$("#send-to-websocket").click(sendStuff);
});

</script>