# HG changeset patch # User Matthew Wild # Date 1268244753 0 # Node ID 7b0df9aad29ccd47ee3e914b1f837cc643080e6c # Parent bf6a0898e613ac5d5be0bd591ec17e871e500702 Connecting to the XMPP server diff -r bf6a0898e613 -r 7b0df9aad29c js/supportchat.js --- a/js/supportchat.js Wed Mar 10 12:03:47 2010 +0000 +++ b/js/supportchat.js Wed Mar 10 18:12:33 2010 +0000 @@ -1,3 +1,52 @@ +/* Config */ +var LOGIN_DOMAIN = "anon.localhost"; +var BOSH_URL = "/http-bind"; + +/*** Helper functions */ + +/*** XMPP handling */ +var conn = null; + +/* Called by Strophe when status of connection changes + (from disconnected to connected, vice-versa, etc.) +*/ +function handle_connection_status(status, err) +{ + if(status != Strophe.Status.CONNECTING && status != Strophe.Status.AUTHENTICATING) + set_busy_status(false); + else if(status != Strophe.Status.CONNECTED) + set_busy_status(true); + + if(err) + alert(err); //FIXME: Handle gracefully + + if(status == Strophe.Status.CONNECTED) + { + //FIXME: Join MUC + alert("Connected!"); + } +} + +/* Initiate the connection to the XMPP server */ +function start_connection() +{ + conn = new Strophe.Connection(BOSH_URL); + var ret = true; + try + { + conn.connect(LOGIN_DOMAIN, null, handle_connection_status, 50); + } + catch(e) + { + ret = false; + } + return ret; +} + + +/*** UI handling */ + +/* Handle the user submitting the question form */ function on_question_submit() { var question_type = $("#support-question-type").val(); @@ -7,11 +56,22 @@ alert(question_name + " submitted a " + question_type + " question:\n " + question_text); } +/* Update the UI according to whether we are + waiting on a network operation +*/ +function set_busy_status(status) +{ + //FIXME +} + function display_ui() { // Display pop-up, showing question form - $("#support-chat").show(); - $("#support-question-submit").click(on_question_submit); + if(start_connection()) + { + $("#support-chat").show(); + $("#support-question-submit").click(on_question_submit); + } } $(display_ui); //FIXME (debugging)