js/supportchat.js

Wed, 10 Mar 2010 18:12:33 +0000

author
Matthew Wild <mwild1@gmail.com>
date
Wed, 10 Mar 2010 18:12:33 +0000
changeset 12
7b0df9aad29c
parent 9
6677316d8834
child 13
7ae5a537d7f1
permissions
-rw-r--r--

Connecting to the XMPP server

12
7b0df9aad29c Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents: 9
diff changeset
1 /* Config */
7b0df9aad29c Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents: 9
diff changeset
2 var LOGIN_DOMAIN = "anon.localhost";
7b0df9aad29c Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents: 9
diff changeset
3 var BOSH_URL = "/http-bind";
7b0df9aad29c Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents: 9
diff changeset
4
7b0df9aad29c Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents: 9
diff changeset
5 /*** Helper functions */
7b0df9aad29c Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents: 9
diff changeset
6
7b0df9aad29c Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents: 9
diff changeset
7 /*** XMPP handling */
7b0df9aad29c Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents: 9
diff changeset
8 var conn = null;
7b0df9aad29c Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents: 9
diff changeset
9
7b0df9aad29c Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents: 9
diff changeset
10 /* Called by Strophe when status of connection changes
7b0df9aad29c Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents: 9
diff changeset
11 (from disconnected to connected, vice-versa, etc.)
7b0df9aad29c Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents: 9
diff changeset
12 */
7b0df9aad29c Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents: 9
diff changeset
13 function handle_connection_status(status, err)
7b0df9aad29c Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents: 9
diff changeset
14 {
7b0df9aad29c Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents: 9
diff changeset
15 if(status != Strophe.Status.CONNECTING && status != Strophe.Status.AUTHENTICATING)
7b0df9aad29c Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents: 9
diff changeset
16 set_busy_status(false);
7b0df9aad29c Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents: 9
diff changeset
17 else if(status != Strophe.Status.CONNECTED)
7b0df9aad29c Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents: 9
diff changeset
18 set_busy_status(true);
7b0df9aad29c Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents: 9
diff changeset
19
7b0df9aad29c Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents: 9
diff changeset
20 if(err)
7b0df9aad29c Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents: 9
diff changeset
21 alert(err); //FIXME: Handle gracefully
7b0df9aad29c Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents: 9
diff changeset
22
7b0df9aad29c Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents: 9
diff changeset
23 if(status == Strophe.Status.CONNECTED)
7b0df9aad29c Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents: 9
diff changeset
24 {
7b0df9aad29c Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents: 9
diff changeset
25 //FIXME: Join MUC
7b0df9aad29c Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents: 9
diff changeset
26 alert("Connected!");
7b0df9aad29c Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents: 9
diff changeset
27 }
7b0df9aad29c Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents: 9
diff changeset
28 }
7b0df9aad29c Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents: 9
diff changeset
29
7b0df9aad29c Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents: 9
diff changeset
30 /* Initiate the connection to the XMPP server */
7b0df9aad29c Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents: 9
diff changeset
31 function start_connection()
7b0df9aad29c Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents: 9
diff changeset
32 {
7b0df9aad29c Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents: 9
diff changeset
33 conn = new Strophe.Connection(BOSH_URL);
7b0df9aad29c Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents: 9
diff changeset
34 var ret = true;
7b0df9aad29c Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents: 9
diff changeset
35 try
7b0df9aad29c Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents: 9
diff changeset
36 {
7b0df9aad29c Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents: 9
diff changeset
37 conn.connect(LOGIN_DOMAIN, null, handle_connection_status, 50);
7b0df9aad29c Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents: 9
diff changeset
38 }
7b0df9aad29c Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents: 9
diff changeset
39 catch(e)
7b0df9aad29c Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents: 9
diff changeset
40 {
7b0df9aad29c Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents: 9
diff changeset
41 ret = false;
7b0df9aad29c Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents: 9
diff changeset
42 }
7b0df9aad29c Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents: 9
diff changeset
43 return ret;
7b0df9aad29c Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents: 9
diff changeset
44 }
7b0df9aad29c Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents: 9
diff changeset
45
7b0df9aad29c Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents: 9
diff changeset
46
7b0df9aad29c Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents: 9
diff changeset
47 /*** UI handling */
7b0df9aad29c Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents: 9
diff changeset
48
7b0df9aad29c Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents: 9
diff changeset
49 /* Handle the user submitting the question form */
7
53201a5347f9 Add dummy event handler for question submit
Matthew Wild <mwild1@gmail.com>
parents: 4
diff changeset
50 function on_question_submit()
53201a5347f9 Add dummy event handler for question submit
Matthew Wild <mwild1@gmail.com>
parents: 4
diff changeset
51 {
9
6677316d8834 Example question submit handler until BOSH backend integrated
Matthew Wild <mwild1@gmail.com>
parents: 7
diff changeset
52 var question_type = $("#support-question-type").val();
6677316d8834 Example question submit handler until BOSH backend integrated
Matthew Wild <mwild1@gmail.com>
parents: 7
diff changeset
53 var question_submitter = $("#support-question-name").val();
6677316d8834 Example question submit handler until BOSH backend integrated
Matthew Wild <mwild1@gmail.com>
parents: 7
diff changeset
54 var question_text = $("#support-question-text").val();
6677316d8834 Example question submit handler until BOSH backend integrated
Matthew Wild <mwild1@gmail.com>
parents: 7
diff changeset
55
6677316d8834 Example question submit handler until BOSH backend integrated
Matthew Wild <mwild1@gmail.com>
parents: 7
diff changeset
56 alert(question_name + " submitted a " + question_type + " question:\n " + question_text);
7
53201a5347f9 Add dummy event handler for question submit
Matthew Wild <mwild1@gmail.com>
parents: 4
diff changeset
57 }
53201a5347f9 Add dummy event handler for question submit
Matthew Wild <mwild1@gmail.com>
parents: 4
diff changeset
58
12
7b0df9aad29c Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents: 9
diff changeset
59 /* Update the UI according to whether we are
7b0df9aad29c Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents: 9
diff changeset
60 waiting on a network operation
7b0df9aad29c Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents: 9
diff changeset
61 */
7b0df9aad29c Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents: 9
diff changeset
62 function set_busy_status(status)
7b0df9aad29c Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents: 9
diff changeset
63 {
7b0df9aad29c Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents: 9
diff changeset
64 //FIXME
7b0df9aad29c Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents: 9
diff changeset
65 }
7b0df9aad29c Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents: 9
diff changeset
66
3
de7fbf06cfa5 Add skeleton supportchat.js
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
67 function display_ui()
de7fbf06cfa5 Add skeleton supportchat.js
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
68 {
de7fbf06cfa5 Add skeleton supportchat.js
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
69 // Display pop-up, showing question form
12
7b0df9aad29c Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents: 9
diff changeset
70 if(start_connection())
7b0df9aad29c Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents: 9
diff changeset
71 {
7b0df9aad29c Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents: 9
diff changeset
72 $("#support-chat").show();
7b0df9aad29c Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents: 9
diff changeset
73 $("#support-question-submit").click(on_question_submit);
7b0df9aad29c Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents: 9
diff changeset
74 }
3
de7fbf06cfa5 Add skeleton supportchat.js
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
75 }
de7fbf06cfa5 Add skeleton supportchat.js
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
76
de7fbf06cfa5 Add skeleton supportchat.js
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
77 $(display_ui); //FIXME (debugging)

mercurial