Fri, 16 Apr 2010 18:43:48 +0100
xmpp_muc.js: Support for callback on occupant leave
19
41a3c9d41e6a
Add MUC library to be used for conversing with helpers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1 | // Wraps a function so that its 'this' is always 'context' when called |
41a3c9d41e6a
Add MUC library to be used for conversing with helpers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2 | var recontext = function (context, f) { return function () { return f.apply(context, arguments); }; }; |
41a3c9d41e6a
Add MUC library to be used for conversing with helpers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3 | |
41
d22dee1f3dba
xmpp_muc.js: Add get_child() function
Matthew Wild <mwild1@gmail.com>
parents:
36
diff
changeset
|
4 | // Returns a child element given a tag name and xmlns |
d22dee1f3dba
xmpp_muc.js: Add get_child() function
Matthew Wild <mwild1@gmail.com>
parents:
36
diff
changeset
|
5 | function get_child(stanza, name, xmlns) |
d22dee1f3dba
xmpp_muc.js: Add get_child() function
Matthew Wild <mwild1@gmail.com>
parents:
36
diff
changeset
|
6 | { |
d22dee1f3dba
xmpp_muc.js: Add get_child() function
Matthew Wild <mwild1@gmail.com>
parents:
36
diff
changeset
|
7 | var children = stanza.getElementsByTagName(name); |
d22dee1f3dba
xmpp_muc.js: Add get_child() function
Matthew Wild <mwild1@gmail.com>
parents:
36
diff
changeset
|
8 | for(var i=0;i<=children.length;i++) |
d22dee1f3dba
xmpp_muc.js: Add get_child() function
Matthew Wild <mwild1@gmail.com>
parents:
36
diff
changeset
|
9 | { |
d22dee1f3dba
xmpp_muc.js: Add get_child() function
Matthew Wild <mwild1@gmail.com>
parents:
36
diff
changeset
|
10 | if(children[i].getAttribute("xmlns") == xmlns || !xmlns) |
d22dee1f3dba
xmpp_muc.js: Add get_child() function
Matthew Wild <mwild1@gmail.com>
parents:
36
diff
changeset
|
11 | return children[i]; |
d22dee1f3dba
xmpp_muc.js: Add get_child() function
Matthew Wild <mwild1@gmail.com>
parents:
36
diff
changeset
|
12 | } |
d22dee1f3dba
xmpp_muc.js: Add get_child() function
Matthew Wild <mwild1@gmail.com>
parents:
36
diff
changeset
|
13 | return null; |
d22dee1f3dba
xmpp_muc.js: Add get_child() function
Matthew Wild <mwild1@gmail.com>
parents:
36
diff
changeset
|
14 | } |
d22dee1f3dba
xmpp_muc.js: Add get_child() function
Matthew Wild <mwild1@gmail.com>
parents:
36
diff
changeset
|
15 | |
d22dee1f3dba
xmpp_muc.js: Add get_child() function
Matthew Wild <mwild1@gmail.com>
parents:
36
diff
changeset
|
16 | |
d22dee1f3dba
xmpp_muc.js: Add get_child() function
Matthew Wild <mwild1@gmail.com>
parents:
36
diff
changeset
|
17 | |
19
41a3c9d41e6a
Add MUC library to be used for conversing with helpers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
18 | var MUC = function (conn, callbacks) |
41a3c9d41e6a
Add MUC library to be used for conversing with helpers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
19 | { |
41a3c9d41e6a
Add MUC library to be used for conversing with helpers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
20 | /* Set our properties */ |
41a3c9d41e6a
Add MUC library to be used for conversing with helpers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
21 | this.conn = conn; |
41a3c9d41e6a
Add MUC library to be used for conversing with helpers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
22 | this.callbacks = callbacks; |
41a3c9d41e6a
Add MUC library to be used for conversing with helpers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
23 | |
41a3c9d41e6a
Add MUC library to be used for conversing with helpers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
24 | this.occupants = {}; |
41a3c9d41e6a
Add MUC library to be used for conversing with helpers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
25 | |
41a3c9d41e6a
Add MUC library to be used for conversing with helpers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
26 | /* Initialize stanza handlers */ |
41a3c9d41e6a
Add MUC library to be used for conversing with helpers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
27 | conn.addHandler(recontext(this, this.handle_join), null, "presence", null, null, null); |
57
42f5669be677
xmpp_muc.js: Support for callback on occupant leave
matthew@heavyhorse.vm.bytemark.co.uk
parents:
48
diff
changeset
|
28 | conn.addHandler(recontext(this, this.handle_leave), null, "presence", "unavailable", null, null); |
19
41a3c9d41e6a
Add MUC library to be used for conversing with helpers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
29 | conn.addHandler(recontext(this, this.handle_error), null, "presence", "error", null, null); |
25
2651c3a7e621
Add support for handling incoming messages to the MUC library
Matthew Wild <mwild1@gmail.com>
parents:
20
diff
changeset
|
30 | conn.addHandler(recontext(this, this.handle_message), null, "message", "groupchat", null, null); |
19
41a3c9d41e6a
Add MUC library to be used for conversing with helpers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
31 | |
41a3c9d41e6a
Add MUC library to be used for conversing with helpers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
32 | /* Return newly-created object */ |
41a3c9d41e6a
Add MUC library to be used for conversing with helpers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
33 | return this; |
41a3c9d41e6a
Add MUC library to be used for conversing with helpers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
34 | } |
41a3c9d41e6a
Add MUC library to be used for conversing with helpers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
35 | |
41a3c9d41e6a
Add MUC library to be used for conversing with helpers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
36 | MUC.prototype = |
41a3c9d41e6a
Add MUC library to be used for conversing with helpers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
37 | { |
41a3c9d41e6a
Add MUC library to be used for conversing with helpers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
38 | /** General methods */ |
41a3c9d41e6a
Add MUC library to be used for conversing with helpers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
39 | |
41a3c9d41e6a
Add MUC library to be used for conversing with helpers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
40 | join: function (jid, nick, status_text) |
41a3c9d41e6a
Add MUC library to be used for conversing with helpers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
41 | { |
41a3c9d41e6a
Add MUC library to be used for conversing with helpers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
42 | this.jid = jid; |
41a3c9d41e6a
Add MUC library to be used for conversing with helpers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
43 | this.nick = nick; |
41a3c9d41e6a
Add MUC library to be used for conversing with helpers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
44 | var pres = $pres({to: jid+'/'+nick}); |
41a3c9d41e6a
Add MUC library to be used for conversing with helpers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
45 | if(status) |
41a3c9d41e6a
Add MUC library to be used for conversing with helpers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
46 | pres.c("status").t(status); |
41a3c9d41e6a
Add MUC library to be used for conversing with helpers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
47 | return this.send_stanza(pres); |
41a3c9d41e6a
Add MUC library to be used for conversing with helpers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
48 | }, |
41a3c9d41e6a
Add MUC library to be used for conversing with helpers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
49 | |
41a3c9d41e6a
Add MUC library to be used for conversing with helpers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
50 | part: function (status_text) |
41a3c9d41e6a
Add MUC library to be used for conversing with helpers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
51 | { |
41a3c9d41e6a
Add MUC library to be used for conversing with helpers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
52 | var pres = $pres({to: this.jid+'/'+this.nick, type: "unavailable"}); |
41a3c9d41e6a
Add MUC library to be used for conversing with helpers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
53 | if(status) |
41a3c9d41e6a
Add MUC library to be used for conversing with helpers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
54 | pres.c("status").t(status); |
41a3c9d41e6a
Add MUC library to be used for conversing with helpers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
55 | return this.send_stanza(pres); |
41a3c9d41e6a
Add MUC library to be used for conversing with helpers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
56 | }, |
41a3c9d41e6a
Add MUC library to be used for conversing with helpers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
57 | |
41a3c9d41e6a
Add MUC library to be used for conversing with helpers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
58 | send_message: function (message) |
41a3c9d41e6a
Add MUC library to be used for conversing with helpers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
59 | { |
41a3c9d41e6a
Add MUC library to be used for conversing with helpers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
60 | return this.send_stanza($msg({to: this.jid, type: "groupchat"}) |
41a3c9d41e6a
Add MUC library to be used for conversing with helpers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
61 | .c("body").t(message||"")); |
41a3c9d41e6a
Add MUC library to be used for conversing with helpers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
62 | }, |
41a3c9d41e6a
Add MUC library to be used for conversing with helpers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
63 | |
20
bd1d350ab61c
Add to the MUC library support for sending private messages
Matthew Wild <mwild1@gmail.com>
parents:
19
diff
changeset
|
64 | send_private_message: function (nick, message) |
bd1d350ab61c
Add to the MUC library support for sending private messages
Matthew Wild <mwild1@gmail.com>
parents:
19
diff
changeset
|
65 | { |
bd1d350ab61c
Add to the MUC library support for sending private messages
Matthew Wild <mwild1@gmail.com>
parents:
19
diff
changeset
|
66 | return this.send_stanza($msg({to: this.jid+"/"+nick, type: "chat"}) |
bd1d350ab61c
Add to the MUC library support for sending private messages
Matthew Wild <mwild1@gmail.com>
parents:
19
diff
changeset
|
67 | .c("body").t(message||"")); |
bd1d350ab61c
Add to the MUC library support for sending private messages
Matthew Wild <mwild1@gmail.com>
parents:
19
diff
changeset
|
68 | }, |
bd1d350ab61c
Add to the MUC library support for sending private messages
Matthew Wild <mwild1@gmail.com>
parents:
19
diff
changeset
|
69 | |
36
562ff07a3968
Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents:
25
diff
changeset
|
70 | send_invite: function (jid, message) |
562ff07a3968
Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents:
25
diff
changeset
|
71 | { |
562ff07a3968
Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents:
25
diff
changeset
|
72 | return this.send_stanza($msg({to: jid}) |
562ff07a3968
Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents:
25
diff
changeset
|
73 | .c("x", { xmlns: "http://jabber.org/protocol/muc#user" }) |
562ff07a3968
Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents:
25
diff
changeset
|
74 | .c("invite", { to: jid }) |
562ff07a3968
Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents:
25
diff
changeset
|
75 | .c("reason").t(message||"")); |
562ff07a3968
Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents:
25
diff
changeset
|
76 | }, |
562ff07a3968
Large commit - reorganises directory structure, lots of small fixes
Matthew Wild <mwild1@gmail.com>
parents:
25
diff
changeset
|
77 | |
19
41a3c9d41e6a
Add MUC library to be used for conversing with helpers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
78 | send_stanza: function (stanza) |
41a3c9d41e6a
Add MUC library to be used for conversing with helpers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
79 | { |
41a3c9d41e6a
Add MUC library to be used for conversing with helpers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
80 | return this.conn.send(stanza.tree()); |
41a3c9d41e6a
Add MUC library to be used for conversing with helpers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
81 | }, |
41a3c9d41e6a
Add MUC library to be used for conversing with helpers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
82 | |
41a3c9d41e6a
Add MUC library to be used for conversing with helpers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
83 | /** Incoming stanza handlers */ |
41a3c9d41e6a
Add MUC library to be used for conversing with helpers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
84 | |
41a3c9d41e6a
Add MUC library to be used for conversing with helpers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
85 | handle_join: function (stanza) |
41a3c9d41e6a
Add MUC library to be used for conversing with helpers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
86 | { |
41a3c9d41e6a
Add MUC library to be used for conversing with helpers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
87 | var nick = Strophe.getResourceFromJid(stanza.getAttribute("from")); |
41a3c9d41e6a
Add MUC library to be used for conversing with helpers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
88 | if(stanza.getAttribute("type") != "unavailable" && stanza.getAttribute("type") != "error" |
41a3c9d41e6a
Add MUC library to be used for conversing with helpers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
89 | && Strophe.getBareJidFromJid(stanza.getAttribute("from")) == this.jid) |
41a3c9d41e6a
Add MUC library to be used for conversing with helpers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
90 | if(!this.occupants[nick]) |
41a3c9d41e6a
Add MUC library to be used for conversing with helpers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
91 | { |
41a3c9d41e6a
Add MUC library to be used for conversing with helpers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
92 | var text = stanza.getElementsByTagName("status")[0]; |
41a3c9d41e6a
Add MUC library to be used for conversing with helpers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
93 | if(text) text = Strophe.getText(text); |
42
815816ceb1ad
xmpp_muc.js: Prepare occupant object with nick, status, role and affiliation
Matthew Wild <mwild1@gmail.com>
parents:
41
diff
changeset
|
94 | this.occupants[nick] = { nick: nick, status: text }; |
815816ceb1ad
xmpp_muc.js: Prepare occupant object with nick, status, role and affiliation
Matthew Wild <mwild1@gmail.com>
parents:
41
diff
changeset
|
95 | var item = get_child(stanza, "x", "http://jabber.org/protocol/muc#user"); |
815816ceb1ad
xmpp_muc.js: Prepare occupant object with nick, status, role and affiliation
Matthew Wild <mwild1@gmail.com>
parents:
41
diff
changeset
|
96 | if(item) |
815816ceb1ad
xmpp_muc.js: Prepare occupant object with nick, status, role and affiliation
Matthew Wild <mwild1@gmail.com>
parents:
41
diff
changeset
|
97 | { |
815816ceb1ad
xmpp_muc.js: Prepare occupant object with nick, status, role and affiliation
Matthew Wild <mwild1@gmail.com>
parents:
41
diff
changeset
|
98 | item = item.getElementsByTagName("item")[0]; |
815816ceb1ad
xmpp_muc.js: Prepare occupant object with nick, status, role and affiliation
Matthew Wild <mwild1@gmail.com>
parents:
41
diff
changeset
|
99 | this.occupants[nick].affiliation = item.getAttribute("affiliation"); |
815816ceb1ad
xmpp_muc.js: Prepare occupant object with nick, status, role and affiliation
Matthew Wild <mwild1@gmail.com>
parents:
41
diff
changeset
|
100 | this.occupants[nick].role = item.getAttribute("role"); |
815816ceb1ad
xmpp_muc.js: Prepare occupant object with nick, status, role and affiliation
Matthew Wild <mwild1@gmail.com>
parents:
41
diff
changeset
|
101 | } |
19
41a3c9d41e6a
Add MUC library to be used for conversing with helpers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
102 | if(this.callbacks.joined) |
42
815816ceb1ad
xmpp_muc.js: Prepare occupant object with nick, status, role and affiliation
Matthew Wild <mwild1@gmail.com>
parents:
41
diff
changeset
|
103 | this.callbacks.joined(stanza, this, this.occupants[nick]); |
19
41a3c9d41e6a
Add MUC library to be used for conversing with helpers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
104 | if(this.status_handler) |
41a3c9d41e6a
Add MUC library to be used for conversing with helpers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
105 | { |
41a3c9d41e6a
Add MUC library to be used for conversing with helpers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
106 | this.status_handler(stanza); |
41a3c9d41e6a
Add MUC library to be used for conversing with helpers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
107 | } |
41a3c9d41e6a
Add MUC library to be used for conversing with helpers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
108 | } |
41a3c9d41e6a
Add MUC library to be used for conversing with helpers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
109 | return true; |
41a3c9d41e6a
Add MUC library to be used for conversing with helpers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
110 | }, |
41a3c9d41e6a
Add MUC library to be used for conversing with helpers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
111 | |
57
42f5669be677
xmpp_muc.js: Support for callback on occupant leave
matthew@heavyhorse.vm.bytemark.co.uk
parents:
48
diff
changeset
|
112 | handle_leave: function (stanza) |
42f5669be677
xmpp_muc.js: Support for callback on occupant leave
matthew@heavyhorse.vm.bytemark.co.uk
parents:
48
diff
changeset
|
113 | { |
42f5669be677
xmpp_muc.js: Support for callback on occupant leave
matthew@heavyhorse.vm.bytemark.co.uk
parents:
48
diff
changeset
|
114 | var nick = Strophe.getResourceFromJid(stanza.getAttribute("from")); |
42f5669be677
xmpp_muc.js: Support for callback on occupant leave
matthew@heavyhorse.vm.bytemark.co.uk
parents:
48
diff
changeset
|
115 | if(Strophe.getBareJidFromJid(stanza.getAttribute("from")) == this.jid) |
42f5669be677
xmpp_muc.js: Support for callback on occupant leave
matthew@heavyhorse.vm.bytemark.co.uk
parents:
48
diff
changeset
|
116 | if(this.occupants[nick]) |
42f5669be677
xmpp_muc.js: Support for callback on occupant leave
matthew@heavyhorse.vm.bytemark.co.uk
parents:
48
diff
changeset
|
117 | { |
42f5669be677
xmpp_muc.js: Support for callback on occupant leave
matthew@heavyhorse.vm.bytemark.co.uk
parents:
48
diff
changeset
|
118 | var text = stanza.getElementsByTagName("status")[0]; |
42f5669be677
xmpp_muc.js: Support for callback on occupant leave
matthew@heavyhorse.vm.bytemark.co.uk
parents:
48
diff
changeset
|
119 | if(text) |
42f5669be677
xmpp_muc.js: Support for callback on occupant leave
matthew@heavyhorse.vm.bytemark.co.uk
parents:
48
diff
changeset
|
120 | { |
42f5669be677
xmpp_muc.js: Support for callback on occupant leave
matthew@heavyhorse.vm.bytemark.co.uk
parents:
48
diff
changeset
|
121 | text = Strophe.getText(text); |
42f5669be677
xmpp_muc.js: Support for callback on occupant leave
matthew@heavyhorse.vm.bytemark.co.uk
parents:
48
diff
changeset
|
122 | this.occupants[nick].status = text; |
42f5669be677
xmpp_muc.js: Support for callback on occupant leave
matthew@heavyhorse.vm.bytemark.co.uk
parents:
48
diff
changeset
|
123 | } |
42f5669be677
xmpp_muc.js: Support for callback on occupant leave
matthew@heavyhorse.vm.bytemark.co.uk
parents:
48
diff
changeset
|
124 | if(this.callbacks.left) |
42f5669be677
xmpp_muc.js: Support for callback on occupant leave
matthew@heavyhorse.vm.bytemark.co.uk
parents:
48
diff
changeset
|
125 | this.callbacks.left(stanza, this, this.occupants[nick]); |
42f5669be677
xmpp_muc.js: Support for callback on occupant leave
matthew@heavyhorse.vm.bytemark.co.uk
parents:
48
diff
changeset
|
126 | if(this.status_handler) |
42f5669be677
xmpp_muc.js: Support for callback on occupant leave
matthew@heavyhorse.vm.bytemark.co.uk
parents:
48
diff
changeset
|
127 | { |
42f5669be677
xmpp_muc.js: Support for callback on occupant leave
matthew@heavyhorse.vm.bytemark.co.uk
parents:
48
diff
changeset
|
128 | this.status_handler(stanza); |
42f5669be677
xmpp_muc.js: Support for callback on occupant leave
matthew@heavyhorse.vm.bytemark.co.uk
parents:
48
diff
changeset
|
129 | } |
42f5669be677
xmpp_muc.js: Support for callback on occupant leave
matthew@heavyhorse.vm.bytemark.co.uk
parents:
48
diff
changeset
|
130 | delete this.occupants[nick]; |
42f5669be677
xmpp_muc.js: Support for callback on occupant leave
matthew@heavyhorse.vm.bytemark.co.uk
parents:
48
diff
changeset
|
131 | } |
42f5669be677
xmpp_muc.js: Support for callback on occupant leave
matthew@heavyhorse.vm.bytemark.co.uk
parents:
48
diff
changeset
|
132 | return true; |
42f5669be677
xmpp_muc.js: Support for callback on occupant leave
matthew@heavyhorse.vm.bytemark.co.uk
parents:
48
diff
changeset
|
133 | }, |
42f5669be677
xmpp_muc.js: Support for callback on occupant leave
matthew@heavyhorse.vm.bytemark.co.uk
parents:
48
diff
changeset
|
134 | |
19
41a3c9d41e6a
Add MUC library to be used for conversing with helpers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
135 | handle_error: function (stanza) |
41a3c9d41e6a
Add MUC library to be used for conversing with helpers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
136 | { |
41a3c9d41e6a
Add MUC library to be used for conversing with helpers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
137 | if(this.callbacks.error |
41a3c9d41e6a
Add MUC library to be used for conversing with helpers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
138 | && Strophe.getBareJidFromJid(stanza.getAttribute("from")) == this.jid) |
41a3c9d41e6a
Add MUC library to be used for conversing with helpers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
139 | { |
41a3c9d41e6a
Add MUC library to be used for conversing with helpers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
140 | var e = stanza.getElementsByTagName("error"); |
41a3c9d41e6a
Add MUC library to be used for conversing with helpers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
141 | if(e.length > 0) |
41a3c9d41e6a
Add MUC library to be used for conversing with helpers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
142 | { |
41a3c9d41e6a
Add MUC library to be used for conversing with helpers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
143 | var err = null; |
41a3c9d41e6a
Add MUC library to be used for conversing with helpers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
144 | Strophe.forEachChild(e[0], null, function (child) |
41a3c9d41e6a
Add MUC library to be used for conversing with helpers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
145 | { |
41a3c9d41e6a
Add MUC library to be used for conversing with helpers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
146 | if(child.getAttribute("xmlns") == "urn:ietf:params:xml:ns:xmpp-stanzas") |
41a3c9d41e6a
Add MUC library to be used for conversing with helpers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
147 | err = child.nodeName; |
41a3c9d41e6a
Add MUC library to be used for conversing with helpers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
148 | }); |
41a3c9d41e6a
Add MUC library to be used for conversing with helpers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
149 | this.callbacks.error(stanza, this, err); |
41a3c9d41e6a
Add MUC library to be used for conversing with helpers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
150 | } |
41a3c9d41e6a
Add MUC library to be used for conversing with helpers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
151 | } |
41a3c9d41e6a
Add MUC library to be used for conversing with helpers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
152 | return true; |
25
2651c3a7e621
Add support for handling incoming messages to the MUC library
Matthew Wild <mwild1@gmail.com>
parents:
20
diff
changeset
|
153 | }, |
2651c3a7e621
Add support for handling incoming messages to the MUC library
Matthew Wild <mwild1@gmail.com>
parents:
20
diff
changeset
|
154 | |
2651c3a7e621
Add support for handling incoming messages to the MUC library
Matthew Wild <mwild1@gmail.com>
parents:
20
diff
changeset
|
155 | handle_message: function (stanza) |
2651c3a7e621
Add support for handling incoming messages to the MUC library
Matthew Wild <mwild1@gmail.com>
parents:
20
diff
changeset
|
156 | { |
2651c3a7e621
Add support for handling incoming messages to the MUC library
Matthew Wild <mwild1@gmail.com>
parents:
20
diff
changeset
|
157 | if(!this.callbacks.message) |
2651c3a7e621
Add support for handling incoming messages to the MUC library
Matthew Wild <mwild1@gmail.com>
parents:
20
diff
changeset
|
158 | return true; |
2651c3a7e621
Add support for handling incoming messages to the MUC library
Matthew Wild <mwild1@gmail.com>
parents:
20
diff
changeset
|
159 | |
2651c3a7e621
Add support for handling incoming messages to the MUC library
Matthew Wild <mwild1@gmail.com>
parents:
20
diff
changeset
|
160 | if(stanza.getAttribute("type") == "groupchat" && Strophe.getBareJidFromJid(stanza.getAttribute("from")) == this.jid) |
2651c3a7e621
Add support for handling incoming messages to the MUC library
Matthew Wild <mwild1@gmail.com>
parents:
20
diff
changeset
|
161 | { |
2651c3a7e621
Add support for handling incoming messages to the MUC library
Matthew Wild <mwild1@gmail.com>
parents:
20
diff
changeset
|
162 | var body = stanza.getElementsByTagName("body"); |
2651c3a7e621
Add support for handling incoming messages to the MUC library
Matthew Wild <mwild1@gmail.com>
parents:
20
diff
changeset
|
163 | if(body.length > 0 && stanza.getElementsByTagName("delay").length == 0) |
2651c3a7e621
Add support for handling incoming messages to the MUC library
Matthew Wild <mwild1@gmail.com>
parents:
20
diff
changeset
|
164 | this.callbacks.message(stanza, this, Strophe.getResourceFromJid(stanza.getAttribute("from")), Strophe.getText(body[0])); |
2651c3a7e621
Add support for handling incoming messages to the MUC library
Matthew Wild <mwild1@gmail.com>
parents:
20
diff
changeset
|
165 | } |
2651c3a7e621
Add support for handling incoming messages to the MUC library
Matthew Wild <mwild1@gmail.com>
parents:
20
diff
changeset
|
166 | return true; |
19
41a3c9d41e6a
Add MUC library to be used for conversing with helpers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
167 | } |
25
2651c3a7e621
Add support for handling incoming messages to the MUC library
Matthew Wild <mwild1@gmail.com>
parents:
20
diff
changeset
|
168 | |
19
41a3c9d41e6a
Add MUC library to be used for conversing with helpers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
169 | }; |