Thu, 18 Mar 2010 15:48:51 +0000
Remove "connected!" pop-up used for testing
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 | |
7b0df9aad29c
Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents:
9
diff
changeset
|
24 | /* Initiate the connection to the XMPP server */ |
7b0df9aad29c
Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents:
9
diff
changeset
|
25 | function start_connection() |
7b0df9aad29c
Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents:
9
diff
changeset
|
26 | { |
7b0df9aad29c
Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents:
9
diff
changeset
|
27 | conn = new Strophe.Connection(BOSH_URL); |
7b0df9aad29c
Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents:
9
diff
changeset
|
28 | var ret = true; |
7b0df9aad29c
Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents:
9
diff
changeset
|
29 | try |
7b0df9aad29c
Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents:
9
diff
changeset
|
30 | { |
7b0df9aad29c
Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents:
9
diff
changeset
|
31 | conn.connect(LOGIN_DOMAIN, null, handle_connection_status, 50); |
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 | catch(e) |
7b0df9aad29c
Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents:
9
diff
changeset
|
34 | { |
7b0df9aad29c
Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents:
9
diff
changeset
|
35 | ret = false; |
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 | return ret; |
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 | |
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 | /*** UI handling */ |
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 | /* 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
|
44 | function on_question_submit() |
53201a5347f9
Add dummy event handler for question submit
Matthew Wild <mwild1@gmail.com>
parents:
4
diff
changeset
|
45 | { |
9
6677316d8834
Example question submit handler until BOSH backend integrated
Matthew Wild <mwild1@gmail.com>
parents:
7
diff
changeset
|
46 | var question_type = $("#support-question-type").val(); |
13 | 47 | var question_name = $("#support-question-name").val(); |
9
6677316d8834
Example question submit handler until BOSH backend integrated
Matthew Wild <mwild1@gmail.com>
parents:
7
diff
changeset
|
48 | 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
|
49 | |
6677316d8834
Example question submit handler until BOSH backend integrated
Matthew Wild <mwild1@gmail.com>
parents:
7
diff
changeset
|
50 | 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
|
51 | } |
53201a5347f9
Add dummy event handler for question submit
Matthew Wild <mwild1@gmail.com>
parents:
4
diff
changeset
|
52 | |
12
7b0df9aad29c
Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents:
9
diff
changeset
|
53 | /* Update the UI according to whether we are |
7b0df9aad29c
Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents:
9
diff
changeset
|
54 | waiting on a network operation |
7b0df9aad29c
Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents:
9
diff
changeset
|
55 | */ |
7b0df9aad29c
Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents:
9
diff
changeset
|
56 | function set_busy_status(status) |
7b0df9aad29c
Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents:
9
diff
changeset
|
57 | { |
7b0df9aad29c
Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents:
9
diff
changeset
|
58 | //FIXME |
7b0df9aad29c
Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents:
9
diff
changeset
|
59 | } |
7b0df9aad29c
Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents:
9
diff
changeset
|
60 | |
3 | 61 | function display_ui() |
62 | { | |
63 | // Display pop-up, showing question form | |
12
7b0df9aad29c
Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents:
9
diff
changeset
|
64 | if(start_connection()) |
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 | $("#support-chat").show(); |
7b0df9aad29c
Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents:
9
diff
changeset
|
67 | $("#support-question-submit").click(on_question_submit); |
7b0df9aad29c
Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents:
9
diff
changeset
|
68 | } |
3 | 69 | } |
70 | ||
71 | $(display_ui); //FIXME (debugging) |