xmppify 0.0.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/app/assets/javascripts/xmpp/index.js +0 -0
- data/app/assets/javascripts/xmpp/scripts/checkplayer.js +12 -0
- data/app/assets/javascripts/xmpp/scripts/crossdomain.xml +7 -0
- data/app/assets/javascripts/xmpp/scripts/flXHR.js +2 -0
- data/app/assets/javascripts/xmpp/scripts/flXHR.swf +0 -0
- data/app/assets/javascripts/xmpp/scripts/flXHR.vbs +44 -0
- data/app/assets/javascripts/xmpp/scripts/flensed.js +12 -0
- data/app/assets/javascripts/xmpp/scripts/strophe.flxhr.js +31 -0
- data/app/assets/javascripts/xmpp/scripts/strophe.js +3538 -0
- data/app/assets/javascripts/xmpp/scripts/swfobject.js +5 -0
- data/app/assets/javascripts/xmpp/scripts/updateplayer.swf +0 -0
- data/app/assets/javascripts/xmpp/scripts/xmpp.js.coffee +386 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/LICENSE.txt +19 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/README.markdown +95 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/archive/README.markdown +14 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/archive/iso8601_support.js +32 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/archive/strophe.archive.js +88 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/caps/README.markdown +53 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/caps/sha1.js +202 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/caps/strophe.CAPS.coffee +153 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/caps/strophe.CAPS.js +88 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/caps/strophe.caps.jsonly.js +240 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/chatstates/strophe.chatstates.js +80 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/cmds/README.markdown +47 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/cmds/spec/GetUrlComamndSpec.js +66 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/cmds/spec/strophe.cmds.spec.coffee +145 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/cmds/spec/support/jasmine.json +16 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/cmds/src/strophe.cmds.coffee +265 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/cmds/src/strophe.cmds.js +403 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/dataforms/README.markdown +82 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/dataforms/spec/strophe.x.coffee +715 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/dataforms/src/strophe.x.coffee +443 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/dataforms/src/strophe.x.js +854 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/disco/.gitignore +1 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/disco/README.markdown +0 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/disco/convert.js +13 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/disco/jasmine.json +11 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/disco/lib/strophe.disco.js +137 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/disco/public/javascript/strophe.disco.js +137 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/01_querying_information.xml +6 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/02_result_set_for_information_request.xml +22 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/03_target_entity_does_not_exist.xml +10 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/04_service_unavailable.xml +11 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/09_querying_specific_jid_and_node_combination.xml +7 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/10_jid_and_node_result.xml +12 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/11_requesting_all_items.xml +6 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/12_result_set_for_all_items.xml +23 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/13_empty_result_set.xml +7 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/17_service_returns_nodes.xml +16 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/18_requesting_further_nodes.xml +7 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/24_jid_and_node_error.xml +11 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/DiscoNodeSpec.js +50 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/SpecHelper.js +51 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/Stanzas.js +0 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/strophe.disco.spec.helper.js +54 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/strophe.disco.spec.js +0 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/support/jasmine.json +13 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/disco/strophe.disco.js +232 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/epic/public/javascript/jquery.epic.js +61 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/epic/spec/SpecHelper.js +9 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/epic/spec/jquery.epic.js +39 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/epic/spec/support/jasmine.json +22 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/iexdomain/iexdomain.js +36 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/joap/README.markdown +117 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/joap/buster.js +23 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/joap/jid.coffee +64 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/joap/jid.js +92 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/joap/spec/browserSetup.coffee +1 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/joap/spec/jid.spec.coffee +96 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/joap/spec/strophe.joap.spec.coffee +461 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/joap/strophe.joap.coffee +304 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/joap/strophe.joap.js +522 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/mam/LICENSE.txt +19 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/mam/README.markdown +52 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/mam/strophe.mam.js +62 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/muc/LICENSE.txt +20 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/muc/strophe.muc.js +1003 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/ping/README.markdown +28 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/ping/strophe.ping.js +68 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/private/README.markdown +16 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/private/strophe.private.js +192 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/pubsub/strophe.pubsub.js +555 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/receipts/strophe.receipts.js +155 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/register/README.markdown +44 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/register/strophe.register.js +431 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/roster/public/javascript/strophe.roster.js +40 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/roster/spec/strophe.roster.spec.js +65 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/roster/spec/support/jasmine.json +15 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/roster/strophe.roster.js +438 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/rpc/.gitignore +6 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/rpc/README.md +113 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/rpc/buster.js +11 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/rpc/lib/strophe.js +4198 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/rpc/spec/strophe.rpc.spec.helper.js +38 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/rpc/spec/strophe.rpc.spec.js +262 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/rpc/strophe.rpc.js +464 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/rsm/strophe.rsm.js +52 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/serverdate/strophe.serverdate.js +58 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/vcard/examples/index.html +17 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/vcard/examples/strophevcard.js +0 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/vcard/strophe.vcard.coffee +44 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/vcard/strophe.vcard.js +66 -0
- data/app/assets/stylesheets/xmpp/index.css +0 -0
- data/app/controllers/omniauth_callbacks_controller.rb +15 -0
- data/app/controllers/ruby_bosh.rb +221 -0
- data/app/models/identity.rb +3 -0
- data/app/models/user.rb +40 -0
- data/bin/rails +8 -0
- data/db/migrate/20140329065635_create_users.rb +10 -0
- data/db/migrate/20140329070238_create_identities.rb +11 -0
- data/lib/xmppify/version.rb +3 -0
- data/lib/xmppify.rb +6 -0
- data/xmppify.gemspec +23 -0
- metadata +197 -0
@@ -0,0 +1,240 @@
|
|
1
|
+
/**
|
2
|
+
* Entity Capabilities (XEP-0115)
|
3
|
+
*
|
4
|
+
* Depends on disco plugin.
|
5
|
+
*
|
6
|
+
* See: http://xmpp.org/extensions/xep-0115.html
|
7
|
+
*
|
8
|
+
* Authors:
|
9
|
+
* - Michael Weibel <michael.weibel@gmail.com>
|
10
|
+
*
|
11
|
+
* Copyright:
|
12
|
+
* - Michael Weibel <michael.weibel@gmail.com>
|
13
|
+
*/
|
14
|
+
|
15
|
+
Strophe.addConnectionPlugin('caps', {
|
16
|
+
/** Constant: HASH
|
17
|
+
* Hash used
|
18
|
+
*
|
19
|
+
* Currently only sha-1 is supported.
|
20
|
+
*/
|
21
|
+
HASH: 'sha-1',
|
22
|
+
/** Variable: node
|
23
|
+
* Client which is being used.
|
24
|
+
*
|
25
|
+
* Can be overwritten as soon as Strophe has been initialized.
|
26
|
+
*/
|
27
|
+
node: 'http://strophe.im/strophejs/',
|
28
|
+
/** PrivateVariable: _ver
|
29
|
+
* Own generated version string
|
30
|
+
*/
|
31
|
+
_ver: '',
|
32
|
+
/** PrivateVariable: _connection
|
33
|
+
* Strophe connection
|
34
|
+
*/
|
35
|
+
_connection: null,
|
36
|
+
/** PrivateVariable: _knownCapabilities
|
37
|
+
* A hashtable containing version-strings and their capabilities, serialized
|
38
|
+
* as string.
|
39
|
+
*
|
40
|
+
* TODO: Maybe those caps shouldn't be serialized.
|
41
|
+
*/
|
42
|
+
_knownCapabilities: {},
|
43
|
+
/** PrivateVariable: _jidVerIndex
|
44
|
+
* A hashtable containing jids and their versions for better lookup of capabilities.
|
45
|
+
*/
|
46
|
+
_jidVerIndex: {},
|
47
|
+
|
48
|
+
/** Function: init
|
49
|
+
* Initialize plugin:
|
50
|
+
* - Add caps namespace
|
51
|
+
* - Add caps feature to disco plugin
|
52
|
+
* - Add handler for caps stanzas
|
53
|
+
*
|
54
|
+
* Parameters:
|
55
|
+
* (Strophe.Connection) conn - Strophe connection
|
56
|
+
*/
|
57
|
+
init: function(conn) {
|
58
|
+
this._connection = conn;
|
59
|
+
|
60
|
+
Strophe.addNamespace('CAPS', 'http://jabber.org/protocol/caps');
|
61
|
+
|
62
|
+
if (!this._connection.disco) {
|
63
|
+
throw "Caps plugin requires the disco plugin to be installed.";
|
64
|
+
}
|
65
|
+
|
66
|
+
this._connection.disco.addFeature(Strophe.NS.CAPS);
|
67
|
+
this._connection.addHandler(this._delegateCapabilities.bind(this), Strophe.NS.CAPS);
|
68
|
+
},
|
69
|
+
|
70
|
+
/** Function: generateCapsAttrs
|
71
|
+
* Returns the attributes for generating the "c"-stanza containing the own version
|
72
|
+
*
|
73
|
+
* Returns:
|
74
|
+
* (Object) - attributes
|
75
|
+
*/
|
76
|
+
generateCapsAttrs: function() {
|
77
|
+
return {
|
78
|
+
'xmlns': Strophe.NS.CAPS,
|
79
|
+
'hash': this.HASH,
|
80
|
+
'node': this.node,
|
81
|
+
'ver': this.generateVer()
|
82
|
+
};
|
83
|
+
},
|
84
|
+
|
85
|
+
/** Function: generateVer
|
86
|
+
* Returns the base64 encoded version string (encoded itself with sha1)
|
87
|
+
*
|
88
|
+
* Returns:
|
89
|
+
* (String) - version
|
90
|
+
*/
|
91
|
+
generateVer: function() {
|
92
|
+
if (this._ver !== "") {
|
93
|
+
return this._ver;
|
94
|
+
}
|
95
|
+
|
96
|
+
var ver = "",
|
97
|
+
identities = this._connection.disco._identities.sort(this._sortIdentities),
|
98
|
+
identitiesLen = identities.length,
|
99
|
+
features = this._connection.disco._features.sort(),
|
100
|
+
featuresLen = features.length;
|
101
|
+
for(var i = 0; i < identitiesLen; i++) {
|
102
|
+
var curIdent = identities[i];
|
103
|
+
ver += curIdent.category + "/" + curIdent.type + "/" + curIdent.lang + "/" + curIdent.name + "<";
|
104
|
+
}
|
105
|
+
for(var i = 0; i < featuresLen; i++) {
|
106
|
+
ver += features[i] + '<';
|
107
|
+
}
|
108
|
+
|
109
|
+
this._ver = b64_sha1(ver);
|
110
|
+
return this._ver;
|
111
|
+
},
|
112
|
+
|
113
|
+
/** Function: getCapabilitiesByJid
|
114
|
+
* Returns serialized capabilities of a jid (if available).
|
115
|
+
* Otherwise null.
|
116
|
+
*
|
117
|
+
* Parameters:
|
118
|
+
* (String) jid - Jabber id
|
119
|
+
*
|
120
|
+
* Returns:
|
121
|
+
* (String|null) - capabilities, serialized; or null when not available.
|
122
|
+
*/
|
123
|
+
getCapabilitiesByJid: function(jid) {
|
124
|
+
if (this._jidVerIndex[jid]) {
|
125
|
+
return this._knownCapabilities[this._jidVerIndex[jid]];
|
126
|
+
}
|
127
|
+
return null;
|
128
|
+
},
|
129
|
+
|
130
|
+
/** PrivateFunction: _delegateCapabilities
|
131
|
+
* Checks if the version has already been saved.
|
132
|
+
* If yes: do nothing.
|
133
|
+
* If no: Request capabilities
|
134
|
+
*
|
135
|
+
* Parameters:
|
136
|
+
* (Strophe.Builder) stanza - Stanza
|
137
|
+
*
|
138
|
+
* Returns:
|
139
|
+
* (Boolean)
|
140
|
+
*/
|
141
|
+
_delegateCapabilities: function(stanza) {
|
142
|
+
var from = stanza.getAttribute('from'),
|
143
|
+
c = stanza.querySelector('c'),
|
144
|
+
ver = c.getAttribute('ver'),
|
145
|
+
node = c.getAttribute('node');
|
146
|
+
if (!this._knownCapabilities[ver]) {
|
147
|
+
return this._requestCapabilities(from, node, ver);
|
148
|
+
} else {
|
149
|
+
this._jidVerIndex[from] = ver;
|
150
|
+
}
|
151
|
+
if (!this._jidVerIndex[from] || !this._jidVerIndex[from] !== ver) {
|
152
|
+
this._jidVerIndex[from] = ver;
|
153
|
+
}
|
154
|
+
return true;
|
155
|
+
},
|
156
|
+
|
157
|
+
/** PrivateFunction: _requestCapabilities
|
158
|
+
* Requests capabilities from the one which sent the caps-info stanza.
|
159
|
+
* This is done using disco info.
|
160
|
+
*
|
161
|
+
* Additionally, it registers a handler for handling the reply.
|
162
|
+
*
|
163
|
+
* Parameters:
|
164
|
+
* (String) to - Destination jid
|
165
|
+
* (String) node - Node attribute of the caps-stanza
|
166
|
+
* (String) ver - Version of the caps-stanza
|
167
|
+
*
|
168
|
+
* Returns:
|
169
|
+
* (Boolean) - true
|
170
|
+
*/
|
171
|
+
_requestCapabilities: function(to, node, ver) {
|
172
|
+
if (to !== this._connection.jid) {
|
173
|
+
var id = this._connection.disco.info(to, node + '#' + ver);
|
174
|
+
this._connection.addHandler(this._handleDiscoInfoReply.bind(this), Strophe.NS.DISCO_INFO, 'iq', 'result', id, to);
|
175
|
+
}
|
176
|
+
return true;
|
177
|
+
},
|
178
|
+
|
179
|
+
/** PrivateFunction: _handleDiscoInfoReply
|
180
|
+
* Parses the disco info reply and adds the version & it's capabilities to the _knownCapabilities variable.
|
181
|
+
* Additionally, it adds the jid & the version to the _jidVerIndex variable for a better lookup.
|
182
|
+
*
|
183
|
+
* Parameters:
|
184
|
+
* (Strophe.Builder) stanza - Disco info stanza
|
185
|
+
*
|
186
|
+
* Returns:
|
187
|
+
* (Boolean) - false, to automatically remove the handler.
|
188
|
+
*/
|
189
|
+
_handleDiscoInfoReply: function(stanza) {
|
190
|
+
var query = stanza.querySelector('query'),
|
191
|
+
node = query.getAttribute('node').split('#'),
|
192
|
+
ver = node[1],
|
193
|
+
from = stanza.getAttribute('from');
|
194
|
+
if (!this._knownCapabilities[ver]) {
|
195
|
+
var childNodes = query.childNodes,
|
196
|
+
childNodesLen = childNodes.length;
|
197
|
+
this._knownCapabilities[ver] = [];
|
198
|
+
for(var i = 0; i < childNodesLen; i++) {
|
199
|
+
var node = childNodes[i];
|
200
|
+
this._knownCapabilities[ver].push({name: node.nodeName, attributes: node.attributes});
|
201
|
+
}
|
202
|
+
this._jidVerIndex[from] = ver;
|
203
|
+
} else if (!this._jidVerIndex[from] || !this._jidVerIndex[from] !== ver) {
|
204
|
+
this._jidVerIndex[from] = ver;
|
205
|
+
}
|
206
|
+
return false;
|
207
|
+
},
|
208
|
+
|
209
|
+
/** PrivateFunction: _sortIdentities
|
210
|
+
* Sorts two identities according the sorting requirements in XEP-0115.
|
211
|
+
*
|
212
|
+
* Parameters:
|
213
|
+
* (Object) a - Identity a
|
214
|
+
* (Object) b - Identity b
|
215
|
+
*
|
216
|
+
* Returns:
|
217
|
+
* (Integer) - 1, 0 or -1; according to which one's greater.
|
218
|
+
*/
|
219
|
+
_sortIdentities: function(a, b) {
|
220
|
+
if (a.category > b.category) {
|
221
|
+
return 1;
|
222
|
+
}
|
223
|
+
if (a.category < b.category) {
|
224
|
+
return -1;
|
225
|
+
}
|
226
|
+
if (a.type > b.type) {
|
227
|
+
return 1;
|
228
|
+
}
|
229
|
+
if (a.type < b.type) {
|
230
|
+
return -1;
|
231
|
+
}
|
232
|
+
if (a.lang > b.lang) {
|
233
|
+
return 1;
|
234
|
+
}
|
235
|
+
if (a.lang < b.lang) {
|
236
|
+
return -1;
|
237
|
+
}
|
238
|
+
return 0;
|
239
|
+
}
|
240
|
+
});
|
@@ -0,0 +1,80 @@
|
|
1
|
+
/**
|
2
|
+
* Chat state notifications (XEP 0085) plugin
|
3
|
+
* @see http://xmpp.org/extensions/xep-0085.html
|
4
|
+
*/
|
5
|
+
Strophe.addConnectionPlugin('chatstates',
|
6
|
+
{
|
7
|
+
init: function (connection)
|
8
|
+
{
|
9
|
+
this._connection = connection;
|
10
|
+
|
11
|
+
Strophe.addNamespace('CHATSTATES', 'http://jabber.org/protocol/chatstates');
|
12
|
+
},
|
13
|
+
|
14
|
+
statusChanged: function (status)
|
15
|
+
{
|
16
|
+
if (status === Strophe.Status.CONNECTED
|
17
|
+
|| status === Strophe.Status.ATTACHED)
|
18
|
+
{
|
19
|
+
this._connection.addHandler(this._notificationReceived.bind(this),
|
20
|
+
Strophe.NS.CHATSTATES, "message");
|
21
|
+
}
|
22
|
+
},
|
23
|
+
|
24
|
+
addActive: function(message)
|
25
|
+
{
|
26
|
+
return message.c('active', {xmlns: Strophe.NS.CHATSTATES}).up();
|
27
|
+
},
|
28
|
+
|
29
|
+
_notificationReceived: function(message)
|
30
|
+
{
|
31
|
+
var composing = $(message).find('composing'),
|
32
|
+
paused = $(message).find('paused'),
|
33
|
+
active = $(message).find('active'),
|
34
|
+
jid = $(message).attr('from');
|
35
|
+
|
36
|
+
if (composing.length > 0)
|
37
|
+
{
|
38
|
+
$(document).trigger('composing.chatstates', jid);
|
39
|
+
}
|
40
|
+
|
41
|
+
if (paused.length > 0)
|
42
|
+
{
|
43
|
+
$(document).trigger('paused.chatstates', jid);
|
44
|
+
}
|
45
|
+
|
46
|
+
if (active.length > 0)
|
47
|
+
{
|
48
|
+
$(document).trigger('active.chatstates', jid);
|
49
|
+
}
|
50
|
+
|
51
|
+
return true;
|
52
|
+
},
|
53
|
+
|
54
|
+
sendActive: function(jid, type)
|
55
|
+
{
|
56
|
+
this._sendNotification(jid, type, 'active');
|
57
|
+
},
|
58
|
+
|
59
|
+
sendComposing: function(jid, type)
|
60
|
+
{
|
61
|
+
this._sendNotification(jid, type, 'composing');
|
62
|
+
},
|
63
|
+
|
64
|
+
sendPaused: function(jid, type)
|
65
|
+
{
|
66
|
+
this._sendNotification(jid, type, 'paused');
|
67
|
+
},
|
68
|
+
|
69
|
+
_sendNotification: function(jid, type, notification)
|
70
|
+
{
|
71
|
+
if (!type) type = 'chat';
|
72
|
+
|
73
|
+
this._connection.send($msg(
|
74
|
+
{
|
75
|
+
to: jid,
|
76
|
+
type: type
|
77
|
+
})
|
78
|
+
.c(notification, {xmlns: Strophe.NS.CHATSTATES}));
|
79
|
+
}
|
80
|
+
});
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# strophe.cmds.js
|
2
|
+
|
3
|
+
strophe.cmds.js is a plugin to provide Ad-Hoc Commands
|
4
|
+
( [XEP-0050](http://xmpp.org/extensions/xep-0050.html) ).
|
5
|
+
|
6
|
+
## Usage
|
7
|
+
|
8
|
+
### Client side
|
9
|
+
|
10
|
+
cmd = new Strophe.Commands.RemoteCommand(conn, jid, node);
|
11
|
+
|
12
|
+
cmd.execute({
|
13
|
+
|
14
|
+
success: function(res, cmd){
|
15
|
+
|
16
|
+
proccessFields( cmd.form.fields );
|
17
|
+
doSomething();
|
18
|
+
resp = new Strophe.x.Form();
|
19
|
+
cmd.complete({ responseForm: resp });
|
20
|
+
|
21
|
+
error: myErrorFunction
|
22
|
+
|
23
|
+
}});
|
24
|
+
|
25
|
+
You can also use the interactive GUI mode
|
26
|
+
|
27
|
+
cmd.execute({gui:true});
|
28
|
+
|
29
|
+
### Server side
|
30
|
+
|
31
|
+
## Dependencies
|
32
|
+
|
33
|
+
- strophe.disco.js
|
34
|
+
- strophe.x.js
|
35
|
+
- jQuery
|
36
|
+
- jQueryUI (for GUI mode)
|
37
|
+
|
38
|
+
## ToDo
|
39
|
+
|
40
|
+
- Write specs for UI commands
|
41
|
+
- Write better documentation
|
42
|
+
|
43
|
+
## Authors
|
44
|
+
|
45
|
+
- [amaierhofer](https://github.com/amaierhofer)
|
46
|
+
- [tjahma](https://github.com/tjahma)
|
47
|
+
- [flosse](https://github.com/flosse)
|
@@ -0,0 +1,66 @@
|
|
1
|
+
describe("GetUrlCommand", function() {
|
2
|
+
var mockGetUrl = function(onSuccess, onError) {
|
3
|
+
var mockData = ['http://www.google.com', 'chrome://newtab'];
|
4
|
+
onSuccess.call(this,mockData);
|
5
|
+
}, c;
|
6
|
+
|
7
|
+
beforeEach(function() {
|
8
|
+
c = mockConnection();
|
9
|
+
iq = { type: 'set', to: 'n@d/r2', from: 'n@d/r1', id: 'ab6fa'};
|
10
|
+
success = jasmine.createSpy('success');
|
11
|
+
});
|
12
|
+
|
13
|
+
it("called with no urls", function() {
|
14
|
+
c.cmds.add(Strophe.Commands.create('getUrls', mockGetUrl));
|
15
|
+
spyon(c,'send',function(res) { expect(res.find('url').length).toEqual(0); });
|
16
|
+
c.cmds.exec('n@d/r', 'getUrls');
|
17
|
+
});
|
18
|
+
|
19
|
+
it("called with no urls also calls callback", function() {
|
20
|
+
c.cmds.add(Strophe.Commands.create('getUrls', mockGetUrl));
|
21
|
+
spyon(c,'send',function(req) {
|
22
|
+
var res = $iq({type: 'result', id: req.attr('id')});
|
23
|
+
c._dataRecv(createRequest(res));
|
24
|
+
});
|
25
|
+
c.cmds.execute('n@d/r', 'getUrls', { success: success});
|
26
|
+
expect(success).toHaveBeenCalled();
|
27
|
+
});
|
28
|
+
it("#GetUrls calls callback and sends urls in response", function() {
|
29
|
+
var req = $iq(iq).c('command', { xmlns: Strophe.NS.COMMANDS, node: 'getUrls' });
|
30
|
+
c.cmds.add(Strophe.Commands.create('getUrls', mockGetUrl));
|
31
|
+
spyon(c,'send',function(res) {
|
32
|
+
expect(res.find('url').length).toEqual(2);
|
33
|
+
});
|
34
|
+
receive(c,req);
|
35
|
+
});
|
36
|
+
|
37
|
+
it("#SetUrls calls callback with urls received in request", function() {
|
38
|
+
var req = $iq(iq).c('command', { xmlns: Strophe.NS.COMMANDS, node: 'setUrls' });
|
39
|
+
req.c('url').t('http://www.google.com').up();
|
40
|
+
req.c('url').t('chrome://newtab');
|
41
|
+
|
42
|
+
var callback = jasmine.createSpy('callback').andCallFake(function(onSuccess,onError) {
|
43
|
+
expect($(this.req).find('url').length).toEqual(2);
|
44
|
+
onSuccess.call(this,{});
|
45
|
+
});
|
46
|
+
var cmd = Strophe.Commands.create('setUrls', callback);
|
47
|
+
c.cmds.add(cmd);
|
48
|
+
spyon(c,'send',function(res) {
|
49
|
+
expect(res.find('command').attr('status')).toEqual('completed');
|
50
|
+
});
|
51
|
+
receive(c,req);
|
52
|
+
expect(cmd.callback).toHaveBeenCalled();
|
53
|
+
});
|
54
|
+
|
55
|
+
it("populates request for known command", function() {
|
56
|
+
var cmd = Strophe.Commands.create('setUrls', function() {});
|
57
|
+
var urls = ['http://www.google.com', 'chrome://newtab'];
|
58
|
+
c.cmds.add(cmd);
|
59
|
+
spyon(c,'send',function(res) {
|
60
|
+
expect(res.find('url').length).toEqual(2);
|
61
|
+
expect(res.find('url:eq(0)').text()).toEqual('http://www.google.com');
|
62
|
+
});
|
63
|
+
c.cmds.execute('n@d/r', 'setUrls', {data:urls});
|
64
|
+
});
|
65
|
+
|
66
|
+
});
|
@@ -0,0 +1,145 @@
|
|
1
|
+
describe "Commands", ->
|
2
|
+
|
3
|
+
beforeEach ->
|
4
|
+
@c = mockConnection()
|
5
|
+
@iq =
|
6
|
+
to: "n@d/r2"
|
7
|
+
from: "n@d/r1"
|
8
|
+
type: "get"
|
9
|
+
id: "abc"
|
10
|
+
|
11
|
+
it "disco#info includes command feature", ->
|
12
|
+
req = $iq(@iq).c("query", xmlns: Strophe.NS.DISCO_INFO)
|
13
|
+
spyon @c, "send", (res) ->
|
14
|
+
feat = ( ($ f).attr("var") for f in res.find "feature" )
|
15
|
+
(expect Strophe.NS.COMMANDS in feat).toBeTruthy()
|
16
|
+
receive @c, req
|
17
|
+
|
18
|
+
it "disco#items includes added commands", ->
|
19
|
+
@c.cmds.add { node: "a" }
|
20
|
+
req = $iq(@iq).c "query",
|
21
|
+
xmlns: Strophe.NS.DISCO_ITEMS
|
22
|
+
node: Strophe.NS.COMMANDS
|
23
|
+
|
24
|
+
spyon @c, "send", (res) ->
|
25
|
+
items = $(res[0]).find "item[node='a']"
|
26
|
+
expect(items.first().attr("node")).toEqual "a"
|
27
|
+
expect(items.first().attr("jid")).toEqual "n@d/r2"
|
28
|
+
|
29
|
+
receive @c, req
|
30
|
+
|
31
|
+
it "responds to command execution", ->
|
32
|
+
@c.cmds.add
|
33
|
+
node: "a"
|
34
|
+
name: "aName"
|
35
|
+
|
36
|
+
iq = $iq(type: "set").c("command",{
|
37
|
+
action: "execute"
|
38
|
+
node: "a"
|
39
|
+
xmlns: Strophe.NS.COMMANDS })
|
40
|
+
|
41
|
+
spyon @c, "send", (res) ->
|
42
|
+
expect(res.find("command").attr("status")).toEqual "completed"
|
43
|
+
receive @c, iq
|
44
|
+
|
45
|
+
it "responds with notFound for unknown command", ->
|
46
|
+
iq = $iq(type: "set").c "command",
|
47
|
+
action: "execute"
|
48
|
+
node: "a"
|
49
|
+
xmlns: Strophe.NS.COMMANDS
|
50
|
+
|
51
|
+
spyon @c, "send", (res) -> expect(res.find("item-not-found").length).toEqual 1
|
52
|
+
receive @c, iq
|
53
|
+
|
54
|
+
it "can execute command", ->
|
55
|
+
console.warn "exec"
|
56
|
+
spyon @c, "send", (req) ->
|
57
|
+
expect(req.find("command").attr("node")).toEqual "aCmd"
|
58
|
+
expect(req.find("command").attr("action")).toEqual "execute"
|
59
|
+
|
60
|
+
@c.cmds.execute "n@d/r", "aCmd"
|
61
|
+
expect(@c.send).toHaveBeenCalled()
|
62
|
+
|
63
|
+
it "can execute command with data", ->
|
64
|
+
@c.cmds.add
|
65
|
+
name: "foo"
|
66
|
+
node: "foo"
|
67
|
+
item: "foo"
|
68
|
+
|
69
|
+
spyon @c, "send", (req) ->
|
70
|
+
expect(req.find("command").attr("node")).toEqual "foo"
|
71
|
+
expect(req.find("command").attr("action")).toEqual "execute"
|
72
|
+
expect(req.find("foo").size()).toEqual 2
|
73
|
+
expect(req.find("command foo").size()).toEqual 0
|
74
|
+
|
75
|
+
@c.cmds.execute "n@d/r", "foo", { data: [ "foo", "bar" ] }
|
76
|
+
expect(@c.send).toHaveBeenCalled()
|
77
|
+
|
78
|
+
describe "Command", ->
|
79
|
+
|
80
|
+
beforeEach ->
|
81
|
+
@c = mockConnection()
|
82
|
+
@c.cmds.add name: "foo", node: "foo"
|
83
|
+
@cmd = new Strophe.Commands.RemoteCommand @c, "n@d/r", "foo"
|
84
|
+
|
85
|
+
it "has the correct properties", ->
|
86
|
+
(expect @cmd.jid).toEqual "n@d/r"
|
87
|
+
(expect @cmd.node).toEqual "foo"
|
88
|
+
|
89
|
+
it "can be converted to an iq object", ->
|
90
|
+
|
91
|
+
iq = $iq(to: "n@d/r", type: "set").c "command",
|
92
|
+
xmlns: Strophe.NS.COMMANDS
|
93
|
+
node: "foo"
|
94
|
+
action: "execute"
|
95
|
+
|
96
|
+
(expect @cmd.toIQ().toString()).toEqual iq.toString()
|
97
|
+
|
98
|
+
it "can be executed", ->
|
99
|
+
spyon @c, "send", (req) ->
|
100
|
+
expect(req.find("command").attr("node")).toEqual "foo"
|
101
|
+
expect(req.find("command").attr("action")).toEqual "execute"
|
102
|
+
|
103
|
+
@cmd.execute()
|
104
|
+
expect(@c.send).toHaveBeenCalled()
|
105
|
+
|
106
|
+
it "can be canceled", ->
|
107
|
+
@cmd.execute()
|
108
|
+
spyon @c, "send", (req) ->
|
109
|
+
expect(req.find("command").attr("action")).toEqual "cancel"
|
110
|
+
|
111
|
+
@cmd.cancel()
|
112
|
+
expect(@c.send).toHaveBeenCalled()
|
113
|
+
|
114
|
+
it "can exectute the 'next' action", ->
|
115
|
+
@cmd.execute()
|
116
|
+
spyon @c, "send", (req) ->
|
117
|
+
expect(req.find("command").attr("action")).toEqual "next"
|
118
|
+
|
119
|
+
@cmd.next()
|
120
|
+
expect(@c.send).toHaveBeenCalled()
|
121
|
+
|
122
|
+
it "can exectute the 'prev' action", ->
|
123
|
+
@cmd.execute()
|
124
|
+
spyon @c, "send", (req) ->
|
125
|
+
expect(req.find("command").attr("action")).toEqual "prev"
|
126
|
+
|
127
|
+
@cmd.prev()
|
128
|
+
expect(@c.send).toHaveBeenCalled()
|
129
|
+
|
130
|
+
it "can exectute the 'complete' action", ->
|
131
|
+
@cmd.execute()
|
132
|
+
spyon @c, "send", (req) ->
|
133
|
+
expect(req.find("command").attr("action")).toEqual "complete"
|
134
|
+
|
135
|
+
@cmd.complete()
|
136
|
+
expect(@c.send).toHaveBeenCalled()
|
137
|
+
|
138
|
+
it "holds all allowed actions based on the current stage", ->
|
139
|
+
|
140
|
+
spyon @c, "send", (res) ->
|
141
|
+
console.log res
|
142
|
+
expect(res.find("command").attr("status")).toEqual "completed"
|
143
|
+
receive @c, @cmd.toIQ()
|
144
|
+
|
145
|
+
(expect @cmd.actions).toEqual []
|
@@ -0,0 +1,16 @@
|
|
1
|
+
{
|
2
|
+
"src_dir" : "/public/javascript/",
|
3
|
+
"spec_dir" : "/spec/",
|
4
|
+
|
5
|
+
"server":{
|
6
|
+
"port":8124
|
7
|
+
},
|
8
|
+
"externals":[
|
9
|
+
"http://localhost/jslibs/jquery.js",
|
10
|
+
"http://localhost/jslibs/underscore.js",
|
11
|
+
"http://localhost/jslibs/strophe.js",
|
12
|
+
"http://localhost/jslibs/strophe.roster.js",
|
13
|
+
"http://localhost/jslibs/strophe.disco.js",
|
14
|
+
"http://localhost/jslibs/SpecHelper.js"
|
15
|
+
]
|
16
|
+
}
|