text: var stompClient = null;
  
  function setConnected(connected) {
      $("#connect").prop("disabled", connected);
      $("#disconnect").prop("disabled", !connected);
      if (connected) {
          $("#conversation").show();
      }
      else {
          $("#conversation").hide();
      }
      $("#messages").html("");
  }
  
  function connect() {
      var socket = new SockJS('/chat');
      stompClient = Stomp.over(socket);
      stompClient.connect({}, function (frame) {
          setConnected(true);
          console.log('Connected: ' + frame);
          stompClient.subscribe('/topic/greetings', function (greeting) {
              showMessage(JSON.parse(greeting.body).content);
          });
          // Connect
          stompClient.subscribe('/user/queue/reply', function(connectionDetails) {
              connectionId = JSON.parse(connectionDetails.body).connectionId;
              showMessage('connected: ' + connectionId);
              stompClient.subscribe('/queue/' + connectionId, function(greeting) {
                  showMessage(JSON.parse(greeting.body).content);
              });
          });
          stompClient.send("/app/connect", {}, JSON.stringify({'user': $('#user').val()}));
      });
  }
  
  function disconnect() {
      if (stompClient !== null) {
          stompClient.disconnect();
      }
      setConnected(false);
      console.log("Disconnected");
  }
  
  function sendMessage() {
      stompClient.send("/app/message", {}, JSON.stringify({'message': $("#message").val()}));
      $("#message").val("");
  }
  
  function showMessage(message) {
      $("#messages").append("<tr><td>" + message + "</td></tr>");
  }
  
  $(function () {
      $("form").on('submit', function (e) {
          e.preventDefault();
      });
      $( "#connect" ).click(function() { connect(); });
      $( "#disconnect" ).click(function() { disconnect(); });
      $( "#send" ).click(function() { sendMessage(); });
  });
  
  