xmppify 0.0.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (120) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +17 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE.txt +22 -0
  5. data/README.md +29 -0
  6. data/Rakefile +1 -0
  7. data/app/assets/javascripts/xmpp/index.js +0 -0
  8. data/app/assets/javascripts/xmpp/scripts/checkplayer.js +12 -0
  9. data/app/assets/javascripts/xmpp/scripts/crossdomain.xml +7 -0
  10. data/app/assets/javascripts/xmpp/scripts/flXHR.js +2 -0
  11. data/app/assets/javascripts/xmpp/scripts/flXHR.swf +0 -0
  12. data/app/assets/javascripts/xmpp/scripts/flXHR.vbs +44 -0
  13. data/app/assets/javascripts/xmpp/scripts/flensed.js +12 -0
  14. data/app/assets/javascripts/xmpp/scripts/strophe.flxhr.js +31 -0
  15. data/app/assets/javascripts/xmpp/scripts/strophe.js +3538 -0
  16. data/app/assets/javascripts/xmpp/scripts/swfobject.js +5 -0
  17. data/app/assets/javascripts/xmpp/scripts/updateplayer.swf +0 -0
  18. data/app/assets/javascripts/xmpp/scripts/xmpp.js.coffee +386 -0
  19. data/app/assets/javascripts/xmpp/strophejs-plugins/LICENSE.txt +19 -0
  20. data/app/assets/javascripts/xmpp/strophejs-plugins/README.markdown +95 -0
  21. data/app/assets/javascripts/xmpp/strophejs-plugins/archive/README.markdown +14 -0
  22. data/app/assets/javascripts/xmpp/strophejs-plugins/archive/iso8601_support.js +32 -0
  23. data/app/assets/javascripts/xmpp/strophejs-plugins/archive/strophe.archive.js +88 -0
  24. data/app/assets/javascripts/xmpp/strophejs-plugins/caps/README.markdown +53 -0
  25. data/app/assets/javascripts/xmpp/strophejs-plugins/caps/sha1.js +202 -0
  26. data/app/assets/javascripts/xmpp/strophejs-plugins/caps/strophe.CAPS.coffee +153 -0
  27. data/app/assets/javascripts/xmpp/strophejs-plugins/caps/strophe.CAPS.js +88 -0
  28. data/app/assets/javascripts/xmpp/strophejs-plugins/caps/strophe.caps.jsonly.js +240 -0
  29. data/app/assets/javascripts/xmpp/strophejs-plugins/chatstates/strophe.chatstates.js +80 -0
  30. data/app/assets/javascripts/xmpp/strophejs-plugins/cmds/README.markdown +47 -0
  31. data/app/assets/javascripts/xmpp/strophejs-plugins/cmds/spec/GetUrlComamndSpec.js +66 -0
  32. data/app/assets/javascripts/xmpp/strophejs-plugins/cmds/spec/strophe.cmds.spec.coffee +145 -0
  33. data/app/assets/javascripts/xmpp/strophejs-plugins/cmds/spec/support/jasmine.json +16 -0
  34. data/app/assets/javascripts/xmpp/strophejs-plugins/cmds/src/strophe.cmds.coffee +265 -0
  35. data/app/assets/javascripts/xmpp/strophejs-plugins/cmds/src/strophe.cmds.js +403 -0
  36. data/app/assets/javascripts/xmpp/strophejs-plugins/dataforms/README.markdown +82 -0
  37. data/app/assets/javascripts/xmpp/strophejs-plugins/dataforms/spec/strophe.x.coffee +715 -0
  38. data/app/assets/javascripts/xmpp/strophejs-plugins/dataforms/src/strophe.x.coffee +443 -0
  39. data/app/assets/javascripts/xmpp/strophejs-plugins/dataforms/src/strophe.x.js +854 -0
  40. data/app/assets/javascripts/xmpp/strophejs-plugins/disco/.gitignore +1 -0
  41. data/app/assets/javascripts/xmpp/strophejs-plugins/disco/README.markdown +0 -0
  42. data/app/assets/javascripts/xmpp/strophejs-plugins/disco/convert.js +13 -0
  43. data/app/assets/javascripts/xmpp/strophejs-plugins/disco/jasmine.json +11 -0
  44. data/app/assets/javascripts/xmpp/strophejs-plugins/disco/lib/strophe.disco.js +137 -0
  45. data/app/assets/javascripts/xmpp/strophejs-plugins/disco/public/javascript/strophe.disco.js +137 -0
  46. data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/01_querying_information.xml +6 -0
  47. data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/02_result_set_for_information_request.xml +22 -0
  48. data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/03_target_entity_does_not_exist.xml +10 -0
  49. data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/04_service_unavailable.xml +11 -0
  50. data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/09_querying_specific_jid_and_node_combination.xml +7 -0
  51. data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/10_jid_and_node_result.xml +12 -0
  52. data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/11_requesting_all_items.xml +6 -0
  53. data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/12_result_set_for_all_items.xml +23 -0
  54. data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/13_empty_result_set.xml +7 -0
  55. data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/17_service_returns_nodes.xml +16 -0
  56. data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/18_requesting_further_nodes.xml +7 -0
  57. data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/24_jid_and_node_error.xml +11 -0
  58. data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/DiscoNodeSpec.js +50 -0
  59. data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/SpecHelper.js +51 -0
  60. data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/Stanzas.js +0 -0
  61. data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/strophe.disco.spec.helper.js +54 -0
  62. data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/strophe.disco.spec.js +0 -0
  63. data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/support/jasmine.json +13 -0
  64. data/app/assets/javascripts/xmpp/strophejs-plugins/disco/strophe.disco.js +232 -0
  65. data/app/assets/javascripts/xmpp/strophejs-plugins/epic/public/javascript/jquery.epic.js +61 -0
  66. data/app/assets/javascripts/xmpp/strophejs-plugins/epic/spec/SpecHelper.js +9 -0
  67. data/app/assets/javascripts/xmpp/strophejs-plugins/epic/spec/jquery.epic.js +39 -0
  68. data/app/assets/javascripts/xmpp/strophejs-plugins/epic/spec/support/jasmine.json +22 -0
  69. data/app/assets/javascripts/xmpp/strophejs-plugins/iexdomain/iexdomain.js +36 -0
  70. data/app/assets/javascripts/xmpp/strophejs-plugins/joap/README.markdown +117 -0
  71. data/app/assets/javascripts/xmpp/strophejs-plugins/joap/buster.js +23 -0
  72. data/app/assets/javascripts/xmpp/strophejs-plugins/joap/jid.coffee +64 -0
  73. data/app/assets/javascripts/xmpp/strophejs-plugins/joap/jid.js +92 -0
  74. data/app/assets/javascripts/xmpp/strophejs-plugins/joap/spec/browserSetup.coffee +1 -0
  75. data/app/assets/javascripts/xmpp/strophejs-plugins/joap/spec/jid.spec.coffee +96 -0
  76. data/app/assets/javascripts/xmpp/strophejs-plugins/joap/spec/strophe.joap.spec.coffee +461 -0
  77. data/app/assets/javascripts/xmpp/strophejs-plugins/joap/strophe.joap.coffee +304 -0
  78. data/app/assets/javascripts/xmpp/strophejs-plugins/joap/strophe.joap.js +522 -0
  79. data/app/assets/javascripts/xmpp/strophejs-plugins/mam/LICENSE.txt +19 -0
  80. data/app/assets/javascripts/xmpp/strophejs-plugins/mam/README.markdown +52 -0
  81. data/app/assets/javascripts/xmpp/strophejs-plugins/mam/strophe.mam.js +62 -0
  82. data/app/assets/javascripts/xmpp/strophejs-plugins/muc/LICENSE.txt +20 -0
  83. data/app/assets/javascripts/xmpp/strophejs-plugins/muc/strophe.muc.js +1003 -0
  84. data/app/assets/javascripts/xmpp/strophejs-plugins/ping/README.markdown +28 -0
  85. data/app/assets/javascripts/xmpp/strophejs-plugins/ping/strophe.ping.js +68 -0
  86. data/app/assets/javascripts/xmpp/strophejs-plugins/private/README.markdown +16 -0
  87. data/app/assets/javascripts/xmpp/strophejs-plugins/private/strophe.private.js +192 -0
  88. data/app/assets/javascripts/xmpp/strophejs-plugins/pubsub/strophe.pubsub.js +555 -0
  89. data/app/assets/javascripts/xmpp/strophejs-plugins/receipts/strophe.receipts.js +155 -0
  90. data/app/assets/javascripts/xmpp/strophejs-plugins/register/README.markdown +44 -0
  91. data/app/assets/javascripts/xmpp/strophejs-plugins/register/strophe.register.js +431 -0
  92. data/app/assets/javascripts/xmpp/strophejs-plugins/roster/public/javascript/strophe.roster.js +40 -0
  93. data/app/assets/javascripts/xmpp/strophejs-plugins/roster/spec/strophe.roster.spec.js +65 -0
  94. data/app/assets/javascripts/xmpp/strophejs-plugins/roster/spec/support/jasmine.json +15 -0
  95. data/app/assets/javascripts/xmpp/strophejs-plugins/roster/strophe.roster.js +438 -0
  96. data/app/assets/javascripts/xmpp/strophejs-plugins/rpc/.gitignore +6 -0
  97. data/app/assets/javascripts/xmpp/strophejs-plugins/rpc/README.md +113 -0
  98. data/app/assets/javascripts/xmpp/strophejs-plugins/rpc/buster.js +11 -0
  99. data/app/assets/javascripts/xmpp/strophejs-plugins/rpc/lib/strophe.js +4198 -0
  100. data/app/assets/javascripts/xmpp/strophejs-plugins/rpc/spec/strophe.rpc.spec.helper.js +38 -0
  101. data/app/assets/javascripts/xmpp/strophejs-plugins/rpc/spec/strophe.rpc.spec.js +262 -0
  102. data/app/assets/javascripts/xmpp/strophejs-plugins/rpc/strophe.rpc.js +464 -0
  103. data/app/assets/javascripts/xmpp/strophejs-plugins/rsm/strophe.rsm.js +52 -0
  104. data/app/assets/javascripts/xmpp/strophejs-plugins/serverdate/strophe.serverdate.js +58 -0
  105. data/app/assets/javascripts/xmpp/strophejs-plugins/vcard/examples/index.html +17 -0
  106. data/app/assets/javascripts/xmpp/strophejs-plugins/vcard/examples/strophevcard.js +0 -0
  107. data/app/assets/javascripts/xmpp/strophejs-plugins/vcard/strophe.vcard.coffee +44 -0
  108. data/app/assets/javascripts/xmpp/strophejs-plugins/vcard/strophe.vcard.js +66 -0
  109. data/app/assets/stylesheets/xmpp/index.css +0 -0
  110. data/app/controllers/omniauth_callbacks_controller.rb +15 -0
  111. data/app/controllers/ruby_bosh.rb +221 -0
  112. data/app/models/identity.rb +3 -0
  113. data/app/models/user.rb +40 -0
  114. data/bin/rails +8 -0
  115. data/db/migrate/20140329065635_create_users.rb +10 -0
  116. data/db/migrate/20140329070238_create_identities.rb +11 -0
  117. data/lib/xmppify/version.rb +3 -0
  118. data/lib/xmppify.rb +6 -0
  119. data/xmppify.gemspec +23 -0
  120. metadata +197 -0
@@ -0,0 +1,555 @@
1
+ /*
2
+ This program is distributed under the terms of the MIT license.
3
+ Please see the LICENSE file for details.
4
+
5
+ Copyright 2008, Stanziq Inc.
6
+
7
+ Overhauled in October 2009 by Liam Breck [How does this affect copyright?]
8
+ */
9
+
10
+ /** File: strophe.pubsub.js
11
+ * A Strophe plugin for XMPP Publish-Subscribe.
12
+ *
13
+ * Provides Strophe.Connection.pubsub object,
14
+ * parially implementing XEP 0060.
15
+ *
16
+ * Strophe.Builder.prototype methods should probably move to strophe.js
17
+ */
18
+
19
+ /** Function: Strophe.Builder.form
20
+ * Add an options form child element.
21
+ *
22
+ * Does not change the current element.
23
+ *
24
+ * Parameters:
25
+ * (String) ns - form namespace.
26
+ * (Object) options - form properties.
27
+ *
28
+ * Returns:
29
+ * The Strophe.Builder object.
30
+ */
31
+ Strophe.Builder.prototype.form = function (ns, options)
32
+ {
33
+ var aX = this.node.appendChild(Strophe.xmlElement('x', {"xmlns": "jabber:x:data", "type": "submit"}));
34
+ aX.appendChild(Strophe.xmlElement('field', {"var":"FORM_TYPE", "type": "hidden"}))
35
+ .appendChild(Strophe.xmlElement('value'))
36
+ .appendChild(Strophe.xmlTextNode(ns));
37
+
38
+ for (var i in options) {
39
+ aX.appendChild(Strophe.xmlElement('field', {"var": i}))
40
+ .appendChild(Strophe.xmlElement('value'))
41
+ .appendChild(Strophe.xmlTextNode(options[i]));
42
+ }
43
+ return this;
44
+ };
45
+
46
+ /** Function: Strophe.Builder.list
47
+ * Add many child elements.
48
+ *
49
+ * Does not change the current element.
50
+ *
51
+ * Parameters:
52
+ * (String) tag - tag name for children.
53
+ * (Array) array - list of objects with format:
54
+ * { attrs: { [string]:[string], ... }, // attributes of each tag element
55
+ * data: [string | XML_element] } // contents of each tag element
56
+ *
57
+ * Returns:
58
+ * The Strophe.Builder object.
59
+ */
60
+ Strophe.Builder.prototype.list = function (tag, array)
61
+ {
62
+ for (var i=0; i < array.length; ++i) {
63
+ this.c(tag, array[i].attrs);
64
+
65
+ this.node.appendChild(array[i].data.cloneNode
66
+ ? array[i].data.cloneNode(true)
67
+ : Strophe.xmlTextNode(array[i].data));
68
+ this.up();
69
+ }
70
+ return this;
71
+ };
72
+
73
+ Strophe.Builder.prototype.children = function (object) {
74
+ var key, value;
75
+ for (key in object) {
76
+ if (!object.hasOwnProperty(key)) continue;
77
+ value = object[key];
78
+ if (Array.isArray(value)) {
79
+ this.list(key, value);
80
+ } else if (typeof value === 'string') {
81
+ this.c(key, {}, value);
82
+ } else if (typeof value === 'number') {
83
+ this.c(key, {}, ""+value);
84
+ } else if (typeof value === 'object') {
85
+ this.c(key).children(value).up();
86
+ } else {
87
+ this.c(key).up();
88
+ }
89
+ }
90
+ return this;
91
+ };
92
+
93
+ // TODO Ideas Adding possible conf values?
94
+ /* Extend Strophe.Connection to have member 'pubsub'.
95
+ */
96
+ Strophe.addConnectionPlugin('pubsub', {
97
+ /*
98
+ Extend connection object to have plugin name 'pubsub'.
99
+ */
100
+ _connection: null,
101
+ _autoService: true,
102
+ service: null,
103
+ jid: null,
104
+
105
+ //The plugin must have the init function.
106
+ init: function(conn) {
107
+
108
+ this._connection = conn;
109
+
110
+ /*
111
+ Function used to setup plugin.
112
+ */
113
+
114
+ /* extend name space
115
+ * NS.PUBSUB - XMPP Publish Subscribe namespace
116
+ * from XEP 60.
117
+ *
118
+ * NS.PUBSUB_SUBSCRIBE_OPTIONS - XMPP pubsub
119
+ * options namespace from XEP 60.
120
+ */
121
+ Strophe.addNamespace('PUBSUB',"http://jabber.org/protocol/pubsub");
122
+ Strophe.addNamespace('PUBSUB_SUBSCRIBE_OPTIONS',
123
+ Strophe.NS.PUBSUB+"#subscribe_options");
124
+ Strophe.addNamespace('PUBSUB_ERRORS',Strophe.NS.PUBSUB+"#errors");
125
+ Strophe.addNamespace('PUBSUB_EVENT',Strophe.NS.PUBSUB+"#event");
126
+ Strophe.addNamespace('PUBSUB_OWNER',Strophe.NS.PUBSUB+"#owner");
127
+ Strophe.addNamespace('PUBSUB_AUTO_CREATE',
128
+ Strophe.NS.PUBSUB+"#auto-create");
129
+ Strophe.addNamespace('PUBSUB_PUBLISH_OPTIONS',
130
+ Strophe.NS.PUBSUB+"#publish-options");
131
+ Strophe.addNamespace('PUBSUB_NODE_CONFIG',
132
+ Strophe.NS.PUBSUB+"#node_config");
133
+ Strophe.addNamespace('PUBSUB_CREATE_AND_CONFIGURE',
134
+ Strophe.NS.PUBSUB+"#create-and-configure");
135
+ Strophe.addNamespace('PUBSUB_SUBSCRIBE_AUTHORIZATION',
136
+ Strophe.NS.PUBSUB+"#subscribe_authorization");
137
+ Strophe.addNamespace('PUBSUB_GET_PENDING',
138
+ Strophe.NS.PUBSUB+"#get-pending");
139
+ Strophe.addNamespace('PUBSUB_MANAGE_SUBSCRIPTIONS',
140
+ Strophe.NS.PUBSUB+"#manage-subscriptions");
141
+ Strophe.addNamespace('PUBSUB_META_DATA',
142
+ Strophe.NS.PUBSUB+"#meta-data");
143
+ Strophe.addNamespace('ATOM', "http://www.w3.org/2005/Atom");
144
+
145
+ if (conn.disco)
146
+ conn.disco.addFeature(Strophe.NS.PUBSUB);
147
+
148
+ },
149
+
150
+ // Called by Strophe on connection event
151
+ statusChanged: function (status, condition) {
152
+ var that = this._connection;
153
+ if (this._autoService && (status === Strophe.Status.CONNECTED || status === Strophe.Status.ATTACHED)) {
154
+ this.service = 'pubsub.'+Strophe.getDomainFromJid(that.jid);
155
+ this.jid = that.jid;
156
+ }
157
+ },
158
+
159
+ /***Function
160
+
161
+ Parameters:
162
+ (String) jid - The node owner's jid.
163
+ (String) service - The name of the pubsub service.
164
+ */
165
+ connect: function (jid, service) {
166
+ var that = this._connection;
167
+ if (service === undefined) {
168
+ service = jid;
169
+ jid = undefined;
170
+ }
171
+ this.jid = jid || that.jid;
172
+ this.service = service || null;
173
+ this._autoService = false;
174
+ },
175
+
176
+ /***Function
177
+
178
+ Create a pubsub node on the given service with the given node
179
+ name.
180
+
181
+ Parameters:
182
+ (String) node - The name of the pubsub node.
183
+ (Dictionary) options - The configuration options for the node.
184
+ (Function) call_back - Used to determine if node
185
+ creation was sucessful.
186
+
187
+ Returns:
188
+ Iq id used to send subscription.
189
+ */
190
+ createNode: function(node,options, call_back) {
191
+ var that = this._connection;
192
+
193
+ var iqid = that.getUniqueId("pubsubcreatenode");
194
+
195
+ var iq = $iq({from:this.jid, to:this.service, type:'set', id:iqid})
196
+ .c('pubsub', {xmlns:Strophe.NS.PUBSUB})
197
+ .c('create',{node:node});
198
+ if(options) {
199
+ iq.up().c('configure').form(Strophe.NS.PUBSUB_NODE_CONFIG, options);
200
+ }
201
+
202
+ that.addHandler(call_back, null, 'iq', null, iqid, null);
203
+ that.send(iq.tree());
204
+
205
+ return iqid;
206
+ },
207
+
208
+ /** Function: deleteNode
209
+ * Delete a pubsub node.
210
+ *
211
+ * Parameters:
212
+ * (String) node - The name of the pubsub node.
213
+ * (Function) call_back - Called on server response.
214
+ *
215
+ * Returns:
216
+ * Iq id
217
+ */
218
+ deleteNode: function(node, call_back) {
219
+ var that = this._connection;
220
+ var iqid = that.getUniqueId("pubsubdeletenode");
221
+
222
+ var iq = $iq({from:this.jid, to:this.service, type:'set', id:iqid})
223
+ .c('pubsub', {xmlns:Strophe.NS.PUBSUB_OWNER})
224
+ .c('delete', {node:node});
225
+
226
+ that.addHandler(call_back, null, 'iq', null, iqid, null);
227
+ that.send(iq.tree());
228
+
229
+ return iqid;
230
+ },
231
+
232
+ /** Function
233
+ *
234
+ * Get all nodes that currently exist.
235
+ *
236
+ * Parameters:
237
+ * (Function) success - Used to determine if node creation was sucessful.
238
+ * (Function) error - Used to determine if node
239
+ * creation had errors.
240
+ */
241
+ discoverNodes: function(success, error, timeout) {
242
+
243
+ //ask for all nodes
244
+ var iq = $iq({from:this.jid, to:this.service, type:'get'})
245
+ .c('query', { xmlns:Strophe.NS.DISCO_ITEMS });
246
+
247
+ return this._connection.sendIQ(iq.tree(),success, error, timeout);
248
+ },
249
+
250
+ /** Function: getConfig
251
+ * Get node configuration form.
252
+ *
253
+ * Parameters:
254
+ * (String) node - The name of the pubsub node.
255
+ * (Function) call_back - Receives config form.
256
+ *
257
+ * Returns:
258
+ * Iq id
259
+ */
260
+ getConfig: function (node, call_back) {
261
+ var that = this._connection;
262
+ var iqid = that.getUniqueId("pubsubconfigurenode");
263
+
264
+ var iq = $iq({from:this.jid, to:this.service, type:'get', id:iqid})
265
+ .c('pubsub', {xmlns:Strophe.NS.PUBSUB_OWNER})
266
+ .c('configure', {node:node});
267
+
268
+ that.addHandler(call_back, null, 'iq', null, iqid, null);
269
+ that.send(iq.tree());
270
+
271
+ return iqid;
272
+ },
273
+
274
+ /**
275
+ * Parameters:
276
+ * (Function) call_back - Receives subscriptions.
277
+ *
278
+ * http://xmpp.org/extensions/tmp/xep-0060-1.13.html
279
+ * 8.3 Request Default Node Configuration Options
280
+ *
281
+ * Returns:
282
+ * Iq id
283
+ */
284
+ getDefaultNodeConfig: function(call_back) {
285
+ var that = this._connection;
286
+ var iqid = that.getUniqueId("pubsubdefaultnodeconfig");
287
+
288
+ var iq = $iq({from:this.jid, to:this.service, type:'get', id:iqid})
289
+ .c('pubsub', {'xmlns':Strophe.NS.PUBSUB_OWNER})
290
+ .c('default');
291
+
292
+ that.addHandler(call_back, null, 'iq', null, iqid, null);
293
+ that.send(iq.tree());
294
+
295
+ return iqid;
296
+ },
297
+
298
+ /***Function
299
+ Subscribe to a node in order to receive event items.
300
+
301
+ Parameters:
302
+ (String) node - The name of the pubsub node.
303
+ (Array) options - The configuration options for the node.
304
+ (Function) event_cb - Used to recieve subscription events.
305
+ (Function) success - callback function for successful node creation.
306
+ (Function) error - error callback function.
307
+ (Boolean) barejid - use barejid creation was sucessful.
308
+
309
+ Returns:
310
+ Iq id used to send subscription.
311
+ */
312
+ subscribe: function(node, options, event_cb, success, error, barejid) {
313
+ var that = this._connection;
314
+ var iqid = that.getUniqueId("subscribenode");
315
+
316
+ var jid = this.jid;
317
+ if(barejid)
318
+ jid = Strophe.getBareJidFromJid(jid);
319
+
320
+ var iq = $iq({from:this.jid, to:this.service, type:'set', id:iqid})
321
+ .c('pubsub', { xmlns:Strophe.NS.PUBSUB })
322
+ .c('subscribe', {'node':node, 'jid':jid});
323
+ if(options) {
324
+ iq.up().c('options').form(Strophe.NS.PUBSUB_SUBSCRIBE_OPTIONS, options);
325
+ }
326
+
327
+ //add the event handler to receive items
328
+ that.addHandler(event_cb, null, 'message', null, null, null);
329
+ that.sendIQ(iq.tree(), success, error);
330
+ return iqid;
331
+ },
332
+
333
+ /***Function
334
+ Unsubscribe from a node.
335
+
336
+ Parameters:
337
+ (String) node - The name of the pubsub node.
338
+ (Function) success - callback function for successful node creation.
339
+ (Function) error - error callback function.
340
+
341
+ */
342
+ unsubscribe: function(node, jid, subid, success, error) {
343
+ var that = this._connection;
344
+ var iqid = that.getUniqueId("pubsubunsubscribenode");
345
+
346
+ var iq = $iq({from:this.jid, to:this.service, type:'set', id:iqid})
347
+ .c('pubsub', { xmlns:Strophe.NS.PUBSUB })
348
+ .c('unsubscribe', {'node':node, 'jid':jid});
349
+ if (subid) iq.attrs({subid:subid});
350
+
351
+ that.sendIQ(iq.tree(), success, error);
352
+ return iqid;
353
+ },
354
+
355
+ /***Function
356
+
357
+ Publish and item to the given pubsub node.
358
+
359
+ Parameters:
360
+ (String) node - The name of the pubsub node.
361
+ (Array) items - The list of items to be published.
362
+ (Function) call_back - Used to determine if node
363
+ creation was sucessful.
364
+ */
365
+ publish: function(node, items, call_back) {
366
+ var that = this._connection;
367
+ var iqid = that.getUniqueId("pubsubpublishnode");
368
+
369
+ var iq = $iq({from:this.jid, to:this.service, type:'set', id:iqid})
370
+ .c('pubsub', { xmlns:Strophe.NS.PUBSUB })
371
+ .c('publish', { node:node, jid:this.jid })
372
+ .c('item').c("value",items);
373
+
374
+ that.addHandler(call_back, null, 'iq', null, iqid, null);
375
+ that.send(iq.tree());
376
+
377
+ return iqid;
378
+ },
379
+
380
+ /*Function: items
381
+ Used to retrieve the persistent items from the pubsub node.
382
+
383
+ */
384
+ items: function(node, success, error, timeout) {
385
+ //ask for all items
386
+ var iq = $iq({from:this.jid, to:this.service, type:'get'})
387
+ .c('pubsub', { xmlns:Strophe.NS.PUBSUB })
388
+ .c('items', {node:node});
389
+
390
+ return this._connection.sendIQ(iq.tree(), success, error, timeout);
391
+ },
392
+
393
+ /** Function: getSubscriptions
394
+ * Get subscriptions of a JID.
395
+ *
396
+ * Parameters:
397
+ * (Function) call_back - Receives subscriptions.
398
+ *
399
+ * http://xmpp.org/extensions/tmp/xep-0060-1.13.html
400
+ * 5.6 Retrieve Subscriptions
401
+ *
402
+ * Returns:
403
+ * Iq id
404
+ */
405
+ getSubscriptions: function(call_back, timeout) {
406
+ var that = this._connection;
407
+ var iqid = that.getUniqueId("pubsubsubscriptions");
408
+
409
+ var iq = $iq({from:this.jid, to:this.service, type:'get', id:iqid})
410
+ .c('pubsub', {'xmlns':Strophe.NS.PUBSUB})
411
+ .c('subscriptions');
412
+
413
+ that.addHandler(call_back, null, 'iq', null, iqid, null);
414
+ that.send(iq.tree());
415
+
416
+ return iqid;
417
+ },
418
+
419
+ /** Function: getNodeSubscriptions
420
+ * Get node subscriptions of a JID.
421
+ *
422
+ * Parameters:
423
+ * (Function) call_back - Receives subscriptions.
424
+ *
425
+ * http://xmpp.org/extensions/tmp/xep-0060-1.13.html
426
+ * 5.6 Retrieve Subscriptions
427
+ *
428
+ * Returns:
429
+ * Iq id
430
+ */
431
+ getNodeSubscriptions: function(node, call_back) {
432
+ var that = this._connection;
433
+ var iqid = that.getUniqueId("pubsubsubscriptions");
434
+
435
+ var iq = $iq({from:this.jid, to:this.service, type:'get', id:iqid})
436
+ .c('pubsub', {'xmlns':Strophe.NS.PUBSUB_OWNER})
437
+ .c('subscriptions', {'node':node});
438
+
439
+ that.addHandler(call_back, null, 'iq', null, iqid, null);
440
+ that.send(iq.tree());
441
+
442
+ return iqid;
443
+ },
444
+
445
+ /** Function: getSubOptions
446
+ * Get subscription options form.
447
+ *
448
+ * Parameters:
449
+ * (String) node - The name of the pubsub node.
450
+ * (String) subid - The subscription id (optional).
451
+ * (Function) call_back - Receives options form.
452
+ *
453
+ * Returns:
454
+ * Iq id
455
+ */
456
+ getSubOptions: function(node, subid, call_back) {
457
+ var that = this._connection;
458
+ var iqid = that.getUniqueId("pubsubsuboptions");
459
+
460
+ var iq = $iq({from:this.jid, to:this.service, type:'get', id:iqid})
461
+ .c('pubsub', {xmlns:Strophe.NS.PUBSUB})
462
+ .c('options', {node:node, jid:this.jid});
463
+ if (subid) iq.attrs({subid:subid});
464
+
465
+ that.addHandler(call_back, null, 'iq', null, iqid, null);
466
+ that.send(iq.tree());
467
+
468
+ return iqid;
469
+ },
470
+
471
+ /**
472
+ * Parameters:
473
+ * (String) node - The name of the pubsub node.
474
+ * (Function) call_back - Receives subscriptions.
475
+ *
476
+ * http://xmpp.org/extensions/tmp/xep-0060-1.13.html
477
+ * 8.9 Manage Affiliations - 8.9.1.1 Request
478
+ *
479
+ * Returns:
480
+ * Iq id
481
+ */
482
+ getAffiliations: function(node, call_back) {
483
+ var that = this._connection;
484
+ var iqid = that.getUniqueId("pubsubaffiliations");
485
+
486
+ if (typeof node === 'function') {
487
+ call_back = node;
488
+ node = undefined;
489
+ }
490
+
491
+ var attrs = {}, xmlns = {'xmlns':Strophe.NS.PUBSUB};
492
+ if (node) {
493
+ attrs.node = node;
494
+ xmlns = {'xmlns':Strophe.NS.PUBSUB_OWNER};
495
+ }
496
+
497
+ var iq = $iq({from:this.jid, to:this.service, type:'get', id:iqid})
498
+ .c('pubsub', xmlns).c('affiliations', attrs);
499
+
500
+ that.addHandler(call_back, null, 'iq', null, iqid, null);
501
+ that.send(iq.tree());
502
+
503
+ return iqid;
504
+ },
505
+
506
+ /**
507
+ * Parameters:
508
+ * (String) node - The name of the pubsub node.
509
+ * (Function) call_back - Receives subscriptions.
510
+ *
511
+ * http://xmpp.org/extensions/tmp/xep-0060-1.13.html
512
+ * 8.9.2 Modify Affiliation - 8.9.2.1 Request
513
+ *
514
+ * Returns:
515
+ * Iq id
516
+ */
517
+ setAffiliation: function(node, jid, affiliation, call_back) {
518
+ var that = this._connection;
519
+ var iqid = thiat.getUniqueId("pubsubaffiliations");
520
+
521
+ var iq = $iq({from:this.jid, to:this.service, type:'set', id:iqid})
522
+ .c('pubsub', {'xmlns':Strophe.NS.PUBSUB_OWNER})
523
+ .c('affiliations', {'node':node})
524
+ .c('affiliation', {'jid':jid, 'affiliation':affiliation});
525
+
526
+ that.addHandler(call_back, null, 'iq', null, iqid, null);
527
+ that.send(iq.tree());
528
+
529
+ return iqid;
530
+ },
531
+
532
+ /** Function: publishAtom
533
+ */
534
+ publishAtom: function(node, atoms, call_back) {
535
+ if (!Array.isArray(atoms))
536
+ atoms = [atoms];
537
+
538
+ var i, atom, entries = [];
539
+ for (i = 0; i < atoms.length; i++) {
540
+ atom = atoms[i];
541
+
542
+ atom.updated = atom.updated || (new Date()).toISOString();
543
+ if (atom.published && atom.published.toISOString)
544
+ atom.published = atom.published.toISOString();
545
+
546
+ entries.push({
547
+ data: $build("entry", { xmlns:Strophe.NS.ATOM })
548
+ .children(atom).tree(),
549
+ attrs:(atom.id ? { id:atom.id } : {}),
550
+ });
551
+ }
552
+ return this.publish(node, entries, call_back);
553
+ },
554
+
555
+ });
@@ -0,0 +1,155 @@
1
+ Strophe.addConnectionPlugin('receipts', {
2
+ _conn: null,
3
+ _msgQueue: {},
4
+ _retries: {},
5
+ _resendCount: 10,
6
+ _resendTime: 9000,
7
+
8
+ init: function(conn) {
9
+ this._conn = conn;
10
+ Strophe.addNamespace('RECEIPTS', 'urn:xmpp:receipts');
11
+ },
12
+
13
+
14
+ statusChanged: function (status) {
15
+ if (status === Strophe.Status.CONNECTED || status === Strophe.Status.ATTACHED) {
16
+ // set up handlers for receipts
17
+ //this._conn.addHandler(this._onRequestReceived.bind(this), Strophe.NS.RECEIPTS, "message");
18
+ var that = this;
19
+ setTimeout(function(){that.resendQueue();},5000);
20
+ }
21
+ },
22
+
23
+ /*
24
+ _onRequestReceived: function(msg){
25
+ this._processReceipt(msg);
26
+ return true;
27
+ },
28
+ * */
29
+
30
+ /* sendMessage
31
+ ** sends a message with a receipt and stores the message in the queue
32
+ ** in case a receipt is never received
33
+ **
34
+ ** msg should be a builder
35
+ */
36
+ sendMessage: function(msg) {
37
+ var id = this._conn.getUniqueId();
38
+
39
+ msg.tree().setAttribute('id', id);
40
+
41
+ var request = Strophe.xmlElement('request', {'xmlns': Strophe.NS.RECEIPTS});
42
+ msg.tree().appendChild(request);
43
+
44
+ this._msgQueue[id] = msg;
45
+ this._retries[id] = 0;
46
+
47
+ this._conn.send(msg);
48
+
49
+ this.resendMessage(id);
50
+
51
+ return id;
52
+
53
+ },
54
+
55
+ /*
56
+ ** resend queued message
57
+ */
58
+ resendMessage: function(id){
59
+ var that = this;
60
+ setTimeout(function(){
61
+ if (that._msgQueue[id]){
62
+ // if we are disconnected, dont increment retries count and retry later
63
+ if (!that._conn.connected) {
64
+ that.resendMessage(id);
65
+ return;
66
+ }
67
+ that._retries[id]++;
68
+ if (that._retries[id] > that._resendCount) {
69
+ //TODO: use mod_rest to force injection of the message
70
+ //console.debug('message could not be delivered after ' + that._resendCount + ' attempts');
71
+ return;
72
+ }
73
+
74
+ // FIX: use our actual jid in case we disconnected and changed jid
75
+ that._msgQueue[id].tree().setAttribute('from', that._conn.jid);
76
+
77
+ that._conn.send(that._msgQueue[id]);
78
+ that.resendMessage(id);
79
+ }
80
+ },this._resendTime);
81
+ },
82
+
83
+ /* addMessageHandler
84
+ ** add a message handler that handles XEP-0184 message receipts
85
+ */
86
+ addReceiptHandler: function(handler, type, from, options) {
87
+ var that = this;
88
+
89
+ var proxyHandler = function(msg) {
90
+ that._processReceipt(msg);
91
+
92
+ // call original handler
93
+ return handler(msg);
94
+ };
95
+
96
+ this._conn.addHandler(proxyHandler, Strophe.NS.RECEIPTS, 'message',
97
+ type, null, from, options);
98
+ },
99
+
100
+ /*
101
+ * process a XEP-0184 message receipts
102
+ * send recept on request
103
+ * remove msg from queue on received
104
+ */
105
+ _processReceipt: function(msg){
106
+ var id = msg.getAttribute('id'),
107
+ from = msg.getAttribute('from'),
108
+ req = msg.getElementsByTagName('request'),
109
+ rec = msg.getElementsByTagName('received');
110
+
111
+ // check for request in message
112
+ if (req.length > 0) {
113
+ // send receipt
114
+ var out = $msg({to: from, from: this._conn.jid, id: this._conn.getUniqueId()}),
115
+ request = Strophe.xmlElement('received', {'xmlns': Strophe.NS.RECEIPTS, 'id': id});
116
+ out.tree().appendChild(request);
117
+ this._conn.send(out);
118
+ }
119
+ // check for received
120
+ if (rec.length > 0) {
121
+ var recv_id = rec[0].getAttribute('id');
122
+ if (recv_id) { // delete msg from queue
123
+ delete this._msgQueue[recv_id];
124
+ delete this._retries[recv_id];
125
+ }
126
+ }
127
+ },
128
+
129
+ resendQueue: function(){
130
+ if (!this._conn.connected) {
131
+ var that = this;
132
+ setTimeout(function(){that.resendQueue();},5000);
133
+ return;
134
+ }
135
+ for (var id in this._msgQueue) {
136
+ if (this._msgQueue.hasOwnProperty(id)) {
137
+ this._conn.send(this._msgQueue[id]);
138
+ }
139
+ }
140
+ },
141
+
142
+ getUnreceivedMsgs: function() {
143
+ var msgs = [];
144
+ for (var id in this._msgQueue) {
145
+ if (this._msgQueue.hasOwnProperty(id)) {
146
+ msgs.push(this._msgQueue[id]);
147
+ }
148
+ }
149
+ return msgs;
150
+ },
151
+
152
+ clearMessages: function() {
153
+ this._msgQueue = {};
154
+ }
155
+ });