$(document).ready(function(){

  var client;

  $('#connect_form').submit(function() {
    var url = $("#connect_url").val();
    var login = $("#connect_login").val();
    var passcode = $("#connect_passcode").val();
    var destination = $("#destination").val();

    var client = Stomp.client(url);

    // this allows to display debug logs directly on the web page
    client.debug = function(str) {
      $("#debug").append(str + "\n");
    };
    // the client is notified when it is connected to the server.
    client.onconnect = function(frame) {
      debug("connected to Stomp");
      $('#connect').fadeOut({ duration: 'fast' });
      $('#connect').remove();
      $('#send_form_input').removeAttr('disabled');
      
      client.send(destination, {foo: 1}, "hello, world!");
      
      client.subscribe(destination);
    };
    // the client is notified when it is disconnected from the server.
    client.ondisconnect = function() {
      debug("disconnected from Stomp");
    };
    // the client is notified every time it receives a message from the server
    client.onreceive = function(message) {
      debug("received " + message);
    };

    // First thing is to connect with the credentials
    client.connect(login, passcode);

    // FIXME simutate opening the web socket
    //client.onopen();
    // FIXME simulate CONNECTED response from the server
    //client.onmessage(Stomp.frame("CONNECTED")); // => trigges a call to client.onconnect()

    // Oonce the client is connected, it can send messages to the server

    // Then, the client subscribes to a destination
    //client.subscribe(destination);

    // FIXME simulates receiving a message
    //var message = Stomp.frame("MESSAGE", {destination: destination, foo: 1},
    //                      "hello, world!");
    //client.onmessage(message); // => triggers a call to client.onreceive()

    // The client can unsubscribe from the destination to stop receive messages
    //client.unsubscribe(destination)

    // Finally, it disconnects from the server
    //client.disconnect(); // => triggers a call to client.ondisconnect()

    return false;
  });
  
  $('#send_form').submit(function() {
    alert("Not implemented yet :)");
    return false;
  });
  
});
@@ -36,16 +36,29 @@
 r client
+, destination
 ;%0A%0A  $('
@@ -228,20 +228,16 @@
 ();%0A    
-var 
 destinat
@@ -272,20 +272,16 @@
 );%0A%0A    
-var 
 client =
@@ -733,74 +733,8 @@
    %0A
-      client.send(destination, %7Bfoo: 1%7D, %22hello, world!%22);%0A      %0A
     
@@ -1062,35 +1062,61 @@
     
-debug(%22received %22 + message
+$(%22#messages%22).append(%22%3Cp%3E%22 + message.body + %22%3C/p%3E%5Cn%22
 );%0A 
@@ -2157,38 +2157,91 @@
     
-alert(%22Not implemented yet :)%22
+var text = $('#send_form_input').val();%0A    client.send(destination, %7Bfoo: 1%7D, text
 );%0A 

send and display messages