Thu, 18 Mar 2010 15:52:05 +0000
Update Strophe.js to 1.0.1 (fixes some issues)
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 | |
16
ebc14a22a0c1
Switch to using a table of config options (will allow for easier configuration later)
Matthew Wild <mwild1@gmail.com>
parents:
15
diff
changeset
|
3 | var support_config = { |
ebc14a22a0c1
Switch to using a table of config options (will allow for easier configuration later)
Matthew Wild <mwild1@gmail.com>
parents:
15
diff
changeset
|
4 | login_domain: "anon.localhost", |
ebc14a22a0c1
Switch to using a table of config options (will allow for easier configuration later)
Matthew Wild <mwild1@gmail.com>
parents:
15
diff
changeset
|
5 | bosh_url: "/http-bind", |
ebc14a22a0c1
Switch to using a table of config options (will allow for easier configuration later)
Matthew Wild <mwild1@gmail.com>
parents:
15
diff
changeset
|
6 | team_rooms: { |
ebc14a22a0c1
Switch to using a table of config options (will allow for easier configuration later)
Matthew Wild <mwild1@gmail.com>
parents:
15
diff
changeset
|
7 | "Sales": "sales@support.localhost", |
ebc14a22a0c1
Switch to using a table of config options (will allow for easier configuration later)
Matthew Wild <mwild1@gmail.com>
parents:
15
diff
changeset
|
8 | "Technical": "technical@support.localhost" |
ebc14a22a0c1
Switch to using a table of config options (will allow for easier configuration later)
Matthew Wild <mwild1@gmail.com>
parents:
15
diff
changeset
|
9 | } |
ebc14a22a0c1
Switch to using a table of config options (will allow for easier configuration later)
Matthew Wild <mwild1@gmail.com>
parents:
15
diff
changeset
|
10 | }; |
12
7b0df9aad29c
Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents:
9
diff
changeset
|
11 | |
7b0df9aad29c
Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents:
9
diff
changeset
|
12 | /*** XMPP handling */ |
7b0df9aad29c
Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents:
9
diff
changeset
|
13 | var conn = null; |
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 | /* Called by Strophe when status of connection changes |
7b0df9aad29c
Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents:
9
diff
changeset
|
16 | (from disconnected to connected, vice-versa, etc.) |
7b0df9aad29c
Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents:
9
diff
changeset
|
17 | */ |
7b0df9aad29c
Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents:
9
diff
changeset
|
18 | function handle_connection_status(status, err) |
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(status != Strophe.Status.CONNECTING && status != Strophe.Status.AUTHENTICATING) |
7b0df9aad29c
Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents:
9
diff
changeset
|
21 | set_busy_status(false); |
7b0df9aad29c
Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents:
9
diff
changeset
|
22 | else if(status != Strophe.Status.CONNECTED) |
7b0df9aad29c
Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents:
9
diff
changeset
|
23 | set_busy_status(true); |
15 | 24 | |
12
7b0df9aad29c
Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents:
9
diff
changeset
|
25 | if(err) |
7b0df9aad29c
Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents:
9
diff
changeset
|
26 | alert(err); //FIXME: Handle gracefully |
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 | /* Initiate the connection to the XMPP server */ |
7b0df9aad29c
Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents:
9
diff
changeset
|
30 | function start_connection() |
7b0df9aad29c
Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents:
9
diff
changeset
|
31 | { |
16
ebc14a22a0c1
Switch to using a table of config options (will allow for easier configuration later)
Matthew Wild <mwild1@gmail.com>
parents:
15
diff
changeset
|
32 | conn = new Strophe.Connection(support_config.bosh_url); |
12
7b0df9aad29c
Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents:
9
diff
changeset
|
33 | var ret = true; |
7b0df9aad29c
Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents:
9
diff
changeset
|
34 | try |
7b0df9aad29c
Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents:
9
diff
changeset
|
35 | { |
16
ebc14a22a0c1
Switch to using a table of config options (will allow for easier configuration later)
Matthew Wild <mwild1@gmail.com>
parents:
15
diff
changeset
|
36 | conn.connect(support_config.login_domain, null, handle_connection_status, 50); |
12
7b0df9aad29c
Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents:
9
diff
changeset
|
37 | } |
7b0df9aad29c
Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents:
9
diff
changeset
|
38 | catch(e) |
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 | ret = false; |
7b0df9aad29c
Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents:
9
diff
changeset
|
41 | } |
7b0df9aad29c
Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents:
9
diff
changeset
|
42 | return ret; |
7b0df9aad29c
Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents:
9
diff
changeset
|
43 | } |
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 | /*** UI handling */ |
7b0df9aad29c
Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents:
9
diff
changeset
|
47 | |
7b0df9aad29c
Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents:
9
diff
changeset
|
48 | /* 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
|
49 | function on_question_submit() |
53201a5347f9
Add dummy event handler for question submit
Matthew Wild <mwild1@gmail.com>
parents:
4
diff
changeset
|
50 | { |
9
6677316d8834
Example question submit handler until BOSH backend integrated
Matthew Wild <mwild1@gmail.com>
parents:
7
diff
changeset
|
51 | var question_type = $("#support-question-type").val(); |
13 | 52 | 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
|
53 | 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
|
54 | |
6677316d8834
Example question submit handler until BOSH backend integrated
Matthew Wild <mwild1@gmail.com>
parents:
7
diff
changeset
|
55 | 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
|
56 | } |
53201a5347f9
Add dummy event handler for question submit
Matthew Wild <mwild1@gmail.com>
parents:
4
diff
changeset
|
57 | |
12
7b0df9aad29c
Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents:
9
diff
changeset
|
58 | /* Update the UI according to whether we are |
7b0df9aad29c
Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents:
9
diff
changeset
|
59 | waiting on a network operation |
7b0df9aad29c
Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents:
9
diff
changeset
|
60 | */ |
7b0df9aad29c
Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents:
9
diff
changeset
|
61 | function set_busy_status(status) |
7b0df9aad29c
Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents:
9
diff
changeset
|
62 | { |
7b0df9aad29c
Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents:
9
diff
changeset
|
63 | //FIXME |
7b0df9aad29c
Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents:
9
diff
changeset
|
64 | } |
7b0df9aad29c
Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents:
9
diff
changeset
|
65 | |
3 | 66 | function display_ui() |
67 | { | |
68 | // Display pop-up, showing question form | |
12
7b0df9aad29c
Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents:
9
diff
changeset
|
69 | if(start_connection()) |
7b0df9aad29c
Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents:
9
diff
changeset
|
70 | { |
7b0df9aad29c
Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents:
9
diff
changeset
|
71 | $("#support-chat").show(); |
7b0df9aad29c
Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents:
9
diff
changeset
|
72 | $("#support-question-submit").click(on_question_submit); |
7b0df9aad29c
Connecting to the XMPP server
Matthew Wild <mwild1@gmail.com>
parents:
9
diff
changeset
|
73 | } |
3 | 74 | } |
75 | ||
76 | $(display_ui); //FIXME (debugging) |