em-xmpp 0.0.11 → 0.0.12
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/xmig +40 -37
- data/em-xmpp.gemspec +1 -0
- data/lib/em-xmpp.rb +0 -2
- data/lib/em-xmpp/component.rb +18 -0
- data/lib/em-xmpp/connection.rb +35 -103
- data/lib/em-xmpp/context.rb +37 -19
- data/lib/em-xmpp/entity.rb +219 -223
- data/lib/em-xmpp/evented.rb +183 -0
- data/lib/em-xmpp/handler.rb +89 -86
- data/lib/em-xmpp/helpers.rb +39 -38
- data/lib/em-xmpp/namespaces.rb +1 -0
- data/lib/em-xmpp/non-em.rb +95 -0
- data/lib/em-xmpp/version.rb +1 -1
- data/lib/em-xmpp/xml_builder.rb +160 -0
- data/lib/em-xmpp/xml_parser.rb +344 -0
- data/samples/hello.rb +6 -3
- data/samples/non-em-hello.rb +90 -0
- metadata +25 -9
- data/lib/em-xmpp/connector.rb +0 -244
data/lib/em-xmpp/entity.rb
CHANGED
@@ -1,11 +1,13 @@
|
|
1
1
|
|
2
2
|
require 'em-xmpp/jid'
|
3
3
|
require 'em-xmpp/namespaces'
|
4
|
+
require 'em-xmpp/xml_builder'
|
4
5
|
require 'fiber'
|
5
6
|
|
6
7
|
module EM::Xmpp
|
7
8
|
class Entity
|
8
9
|
include Namespaces
|
10
|
+
include XmlBuilder
|
9
11
|
attr_reader :jid, :connection
|
10
12
|
|
11
13
|
def initialize(connection, jid)
|
@@ -55,11 +57,11 @@ module EM::Xmpp
|
|
55
57
|
end
|
56
58
|
|
57
59
|
# sends some plain message to the entity (use type = 'chat')
|
58
|
-
def say(body, type='chat',
|
59
|
-
msg = connection.message_stanza(:to => jid, :type => type
|
60
|
-
|
61
|
-
|
62
|
-
|
60
|
+
def say(body, type='chat', *args, &blk)
|
61
|
+
msg = connection.message_stanza({:to => jid, :type => type},
|
62
|
+
x('body',body),
|
63
|
+
*args
|
64
|
+
)
|
63
65
|
connection.send_stanza msg, &blk
|
64
66
|
end
|
65
67
|
|
@@ -84,14 +86,12 @@ module EM::Xmpp
|
|
84
86
|
item_fields = {:jid => jid.bare}
|
85
87
|
item_fields[:name] = display_name if display_name
|
86
88
|
|
87
|
-
query = connection.iq_stanza(:type => 'set'
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
end
|
94
|
-
end
|
89
|
+
query = connection.iq_stanza({:type => 'set'},
|
90
|
+
x('query',{:xmlns => Roster},
|
91
|
+
x('item',item_fields),
|
92
|
+
groups.map { |grp| x('group',grp) }
|
93
|
+
)
|
94
|
+
)
|
95
95
|
|
96
96
|
send_iq_stanza_fibered query
|
97
97
|
end
|
@@ -100,11 +100,11 @@ module EM::Xmpp
|
|
100
100
|
def remove_from_roster
|
101
101
|
item_fields = {:jid => jid.bare, :subscription => 'remove'}
|
102
102
|
|
103
|
-
query = connection.iq_stanza(:type => 'set'
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
103
|
+
query = connection.iq_stanza({:type => 'set'},
|
104
|
+
x('query',{:xmlns => Roster},
|
105
|
+
x('item',item_fields)
|
106
|
+
)
|
107
|
+
)
|
108
108
|
|
109
109
|
send_iq_stanza_fibered query
|
110
110
|
end
|
@@ -114,18 +114,14 @@ module EM::Xmpp
|
|
114
114
|
def discover_infos(node=nil)
|
115
115
|
hash = {'xmlns' => Namespaces::DiscoverInfos}
|
116
116
|
hash['node'] = node if node
|
117
|
-
iq = connection.iq_stanza('to'=>jid
|
118
|
-
xml.query(hash)
|
119
|
-
end
|
117
|
+
iq = connection.iq_stanza({'to'=>jid}, x('query', hash))
|
120
118
|
send_iq_stanza_fibered iq
|
121
119
|
end
|
122
120
|
|
123
121
|
# discovers items (disco#items) of an entity
|
124
122
|
# can optionally specify a node to discover
|
125
123
|
def discover_items(node=nil)
|
126
|
-
iq = connection.iq_stanza('to'=>jid.to_s
|
127
|
-
xml.query('xmlns' => Namespaces::DiscoverItems)
|
128
|
-
end
|
124
|
+
iq = connection.iq_stanza({'to'=>jid.to_s}, x('query', 'xmlns' => Namespaces::DiscoverItems))
|
129
125
|
send_iq_stanza_fibered iq
|
130
126
|
end
|
131
127
|
|
@@ -170,13 +166,13 @@ module EM::Xmpp
|
|
170
166
|
'hash' => filedesc[:md5],
|
171
167
|
'date' => filedesc[:date]
|
172
168
|
}
|
173
|
-
iq = connection.iq_stanza('to'=>jid,'type'=>'set') do
|
174
|
-
|
175
|
-
|
176
|
-
|
169
|
+
iq = connection.iq_stanza('to'=>jid,'type'=>'set') do
|
170
|
+
x('si',{:xmlns => EM::Xmpp::Namespaces::StreamInitiation, :id => sid}.merge(si_args)) do
|
171
|
+
x('file', {:xmlns => EM::Xmpp::Namespaces::FileTransfer}.merge(file_args)) do
|
172
|
+
x('desc', filedesc[:description])
|
177
173
|
end
|
178
|
-
|
179
|
-
connection.build_submit_form(
|
174
|
+
x('feature', :xmlns => EM::Xmpp::Namespaces::FeatureNeg) do
|
175
|
+
connection.build_submit_form(form)
|
180
176
|
end
|
181
177
|
end
|
182
178
|
end
|
@@ -184,10 +180,10 @@ module EM::Xmpp
|
|
184
180
|
end
|
185
181
|
|
186
182
|
def negotiation_reply(reply_id,form)
|
187
|
-
iq = connection.iq_stanza('to'=>jid,'type'=>'result','id'=>reply_id) do
|
188
|
-
|
189
|
-
|
190
|
-
connection.build_submit_form(
|
183
|
+
iq = connection.iq_stanza('to'=>jid,'type'=>'result','id'=>reply_id) do
|
184
|
+
x('si', :xmlns => EM::Xmpp::Namespaces::StreamInitiation) do
|
185
|
+
x('feature', :xmlns => EM::Xmpp::Namespaces::FeatureNeg) do
|
186
|
+
connection.build_submit_form(form)
|
191
187
|
end
|
192
188
|
end
|
193
189
|
end
|
@@ -214,11 +210,11 @@ module EM::Xmpp
|
|
214
210
|
end
|
215
211
|
|
216
212
|
def publish_data(item)
|
217
|
-
iq = connection.iq_stanza('type' => 'set','to' => jid) do
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
213
|
+
iq = connection.iq_stanza({'type' => 'set','to' => jid}) do
|
214
|
+
x('pubsub',{'xmlns' => EM::Xmpp::Namespaces::PubSub}) do
|
215
|
+
x('publish',:node => EM::Xmpp::Namespaces::AvatarData) do
|
216
|
+
x('item', :id => item.id) do
|
217
|
+
x('data', {:xmnls => EM::Xmpp::Namespaces::AvatarData}, item.b64)
|
222
218
|
end
|
223
219
|
end
|
224
220
|
end
|
@@ -227,12 +223,12 @@ module EM::Xmpp
|
|
227
223
|
end
|
228
224
|
|
229
225
|
def publish_metadata(item)
|
230
|
-
iq = connection.iq_stanza('type' => 'set','to' => jid) do
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
226
|
+
iq = connection.iq_stanza('type' => 'set','to' => jid) do
|
227
|
+
x('pubsub', :xmlns => EM::Xmpp::Namespaces::PubSub) do
|
228
|
+
x('publish', :node => EM::Xmpp::Namespaces::AvatarMetaData) do
|
229
|
+
x('item', :id => item.id) do
|
230
|
+
x('metadata',{:xmnls => EM::Xmpp::Namespaces::AvatarMetaData}) do
|
231
|
+
x('info', :width => item.width, :height => item.height, :bytes => item.bytes, :type => item.mime, :id => item.id)
|
236
232
|
end
|
237
233
|
end
|
238
234
|
end
|
@@ -240,13 +236,13 @@ module EM::Xmpp
|
|
240
236
|
end
|
241
237
|
send_iq_stanza_fibered iq
|
242
238
|
end
|
243
|
-
|
239
|
+
|
244
240
|
def remove
|
245
|
-
iq = connection.iq_stanza('type' => 'set','to' => jid) do
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
241
|
+
iq = connection.iq_stanza('type' => 'set','to' => jid) do
|
242
|
+
x('pubsub', :xmlns => EM::Xmpp::Namespaces::PubSub) do
|
243
|
+
x('publish', :node => EM::Xmpp::Namespaces::AvatarMetaData) do
|
244
|
+
x('item', :id => "current") do
|
245
|
+
x('metadata', :xmlns => EM::Xmpp::Namespaces::AvatarMetaData)
|
250
246
|
end
|
251
247
|
end
|
252
248
|
end
|
@@ -269,22 +265,22 @@ module EM::Xmpp
|
|
269
265
|
# requests the list of subscriptions on this PubSub service
|
270
266
|
# returns the iq context for the answer
|
271
267
|
def service_subscriptions
|
272
|
-
iq = connection.iq_stanza('to'=>jid.bare
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
268
|
+
iq = connection.iq_stanza({'to'=>jid.bare},
|
269
|
+
x('pubsub',{:xmlns => EM::Xmpp::Namespaces::PubSub},
|
270
|
+
x('subscriptions')
|
271
|
+
)
|
272
|
+
)
|
277
273
|
send_iq_stanza_fibered iq
|
278
274
|
end
|
279
275
|
|
280
276
|
# requests the list of affiliations for this PubSub service
|
281
277
|
# returns the iq context for the answer
|
282
278
|
def service_affiliations
|
283
|
-
iq = connection.iq_stanza('to'=>jid.bare
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
279
|
+
iq = connection.iq_stanza({'to'=>jid.bare},
|
280
|
+
x('pubsub',{:xmlns => EM::Xmpp::Namespaces::PubSub},
|
281
|
+
x('affiliations')
|
282
|
+
)
|
283
|
+
)
|
288
284
|
send_iq_stanza_fibered iq
|
289
285
|
end
|
290
286
|
|
@@ -295,11 +291,11 @@ module EM::Xmpp
|
|
295
291
|
params['subid'] = subscription_id if subscription_id
|
296
292
|
subscribee = connection.jid.bare
|
297
293
|
|
298
|
-
iq = connection.iq_stanza('to'=>jid.bare,'type'=>'get'
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
294
|
+
iq = connection.iq_stanza({'to'=>jid.bare,'type'=>'get'},
|
295
|
+
x('pubsub',{:xmlns => EM::Xmpp::Namespaces::PubSub},
|
296
|
+
x('options',{'node' => node_id, 'jid'=>subscribee}.merge(params))
|
297
|
+
)
|
298
|
+
)
|
303
299
|
|
304
300
|
send_iq_stanza_fibered iq
|
305
301
|
end
|
@@ -310,13 +306,13 @@ module EM::Xmpp
|
|
310
306
|
def configure_subscription(form)
|
311
307
|
subscribee = connection.jid.bare
|
312
308
|
|
313
|
-
iq = connection.iq_stanza('to'=>jid.bare,'type'=>'set'
|
314
|
-
|
315
|
-
|
316
|
-
connection.build_submit_form(
|
317
|
-
|
318
|
-
|
319
|
-
|
309
|
+
iq = connection.iq_stanza({'to'=>jid.bare,'type'=>'set'},
|
310
|
+
x('pubsub',{:xmlns => EM::Xmpp::Namespaces::PubSub},
|
311
|
+
x('options',{'node' => node_id, 'jid'=>subscribee},
|
312
|
+
connection.build_submit_form(form)
|
313
|
+
)
|
314
|
+
)
|
315
|
+
)
|
320
316
|
|
321
317
|
send_iq_stanza_fibered iq
|
322
318
|
end
|
@@ -326,11 +322,11 @@ module EM::Xmpp
|
|
326
322
|
def default_subscription_configuration
|
327
323
|
subscribee = connection.jid.bare
|
328
324
|
args = {'node' => node_id} if node_id
|
329
|
-
iq = connection.iq_stanza('to'=>jid.bare,'type'=>'get'
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
325
|
+
iq = connection.iq_stanza({'to'=>jid.bare,'type'=>'get'},
|
326
|
+
x('pubsub',{:xmlns => EM::Xmpp::Namespaces::PubSub},
|
327
|
+
x('default',args)
|
328
|
+
)
|
329
|
+
)
|
334
330
|
|
335
331
|
send_iq_stanza_fibered iq
|
336
332
|
end
|
@@ -341,11 +337,11 @@ module EM::Xmpp
|
|
341
337
|
def subscribe
|
342
338
|
subscribee = connection.jid.bare
|
343
339
|
|
344
|
-
iq = connection.iq_stanza('to'=>jid.bare,'type'=>'set'
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
340
|
+
iq = connection.iq_stanza({'to'=>jid.bare,'type'=>'set'},
|
341
|
+
x('pubsub',{:xmlns => EM::Xmpp::Namespaces::PubSub},
|
342
|
+
x('subscribe','node' => node_id, 'jid'=>subscribee)
|
343
|
+
)
|
344
|
+
)
|
349
345
|
|
350
346
|
send_iq_stanza_fibered iq
|
351
347
|
end
|
@@ -356,14 +352,14 @@ module EM::Xmpp
|
|
356
352
|
def subscribe_and_configure(form)
|
357
353
|
subscribee = connection.jid.bare
|
358
354
|
|
359
|
-
iq = connection.iq_stanza('to'=>jid.bare,'type'=>'set'
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
connection.build_submit_form(
|
364
|
-
|
365
|
-
|
366
|
-
|
355
|
+
iq = connection.iq_stanza({'to'=>jid.bare,'type'=>'set'},
|
356
|
+
x('pubsub',{:xmlns => EM::Xmpp::Namespaces::PubSub},
|
357
|
+
x('subscribe','node' => node_id, 'jid'=>subscribee),
|
358
|
+
x('options',
|
359
|
+
connection.build_submit_form(form)
|
360
|
+
)
|
361
|
+
)
|
362
|
+
)
|
367
363
|
|
368
364
|
send_iq_stanza_fibered iq
|
369
365
|
end
|
@@ -377,11 +373,11 @@ module EM::Xmpp
|
|
377
373
|
params['subid'] = subscription_id if subscription_id
|
378
374
|
subscribee = connection.jid.bare
|
379
375
|
|
380
|
-
iq = connection.iq_stanza('to'=>jid.bare,'type'=>'set'
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
376
|
+
iq = connection.iq_stanza({'to'=>jid.bare,'type'=>'set'},
|
377
|
+
x('pubsub',{:xmlns => EM::Xmpp::Namespaces::PubSub},
|
378
|
+
x('unsubscribe',{'node' => node_id, 'jid'=>subscribee}.merge(params))
|
379
|
+
)
|
380
|
+
)
|
385
381
|
|
386
382
|
send_iq_stanza_fibered iq
|
387
383
|
end
|
@@ -394,49 +390,46 @@ module EM::Xmpp
|
|
394
390
|
def items(max_items=nil,item_ids=nil)
|
395
391
|
params = {}
|
396
392
|
params['max_items'] = max_items if max_items
|
397
|
-
iq = connection.iq_stanza('to'=>jid.bare
|
398
|
-
|
399
|
-
|
400
|
-
if item_ids.respond_to?(:
|
401
|
-
item_ids.
|
402
|
-
|
393
|
+
iq = connection.iq_stanza({'to'=>jid.bare},
|
394
|
+
x('pubsub',{:xmlns => EM::Xmpp::Namespaces::PubSub},
|
395
|
+
x('items',{'node' => node_id}.merge(params),
|
396
|
+
if item_ids.respond_to?(:map)
|
397
|
+
item_ids.map do |item_id|
|
398
|
+
x('item','id' => item_id)
|
403
399
|
end
|
404
400
|
end
|
405
|
-
|
406
|
-
|
407
|
-
|
401
|
+
)
|
402
|
+
)
|
403
|
+
)
|
408
404
|
|
409
405
|
send_iq_stanza_fibered iq
|
410
406
|
end
|
411
407
|
|
412
408
|
# publishes a payload to the pubsub node
|
413
|
-
# if the item_payload
|
414
|
-
# then
|
415
|
-
#
|
416
|
-
# node with the payload
|
417
|
-
# otherwise it is just serialized in an entry node
|
409
|
+
# if the item_payload exists
|
410
|
+
# then inserted to item node,
|
411
|
+
# otherwise an entry node with *entry_args inserted
|
418
412
|
#
|
419
413
|
# item_id is an optional ID to identify the payload, otherwise, the
|
420
414
|
# pubsub service will attribute an ID
|
421
415
|
#
|
422
416
|
# returns the iq context for the answer
|
423
|
-
def publish(item_payload,item_id=nil)
|
417
|
+
def publish(item_payload,item_id=nil,*entry_args)
|
424
418
|
params = {}
|
425
419
|
params['id'] = item_id if item_id
|
426
|
-
iq = connection.iq_stanza('to'=>jid.bare,'type'=>'set'
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
420
|
+
iq = connection.iq_stanza({'to'=>jid.bare,'type'=>'set'},
|
421
|
+
x('pubsub',{:xmlns => EM::Xmpp::Namespaces::PubSub},
|
422
|
+
x('publish',{:node => node_id},
|
423
|
+
x('item',params,
|
424
|
+
if item_payload
|
425
|
+
item_payload
|
431
426
|
else
|
432
|
-
|
433
|
-
item.entry(item_payload)
|
434
|
-
end
|
427
|
+
x('entry',*entry_args)
|
435
428
|
end
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
429
|
+
)
|
430
|
+
)
|
431
|
+
)
|
432
|
+
)
|
440
433
|
|
441
434
|
send_iq_stanza_fibered iq
|
442
435
|
end
|
@@ -445,13 +438,13 @@ module EM::Xmpp
|
|
445
438
|
#
|
446
439
|
# returns the iq context for the answer
|
447
440
|
def retract(item_id=nil)
|
448
|
-
iq = connection.iq_stanza('to'=>jid.bare,'type'=>'set'
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
441
|
+
iq = connection.iq_stanza({'to'=>jid.bare,'type'=>'set'},
|
442
|
+
x('pubsub',{:xmlns => EM::Xmpp::Namespaces::PubSub},
|
443
|
+
x('retract',{:node => node_id},
|
444
|
+
x('item',:id => item_id)
|
445
|
+
)
|
446
|
+
)
|
447
|
+
)
|
455
448
|
|
456
449
|
send_iq_stanza_fibered iq
|
457
450
|
end
|
@@ -460,11 +453,11 @@ module EM::Xmpp
|
|
460
453
|
#
|
461
454
|
# returns the iq context for the answer
|
462
455
|
def create
|
463
|
-
iq = connection.iq_stanza('to'=>jid.bare,'type'=>'set'
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
456
|
+
iq = connection.iq_stanza({'to'=>jid.bare,'type'=>'set'},
|
457
|
+
x('pubsub',{:xmlns => EM::Xmpp::Namespaces::PubSub},
|
458
|
+
x('create',:node => node_id)
|
459
|
+
)
|
460
|
+
)
|
468
461
|
|
469
462
|
send_iq_stanza_fibered iq
|
470
463
|
end
|
@@ -474,11 +467,11 @@ module EM::Xmpp
|
|
474
467
|
#
|
475
468
|
# returns the iq context for the answer
|
476
469
|
def purge
|
477
|
-
iq = connection.iq_stanza('to'=>jid.bare,'type'=>'set'
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
470
|
+
iq = connection.iq_stanza({'to'=>jid.bare,'type'=>'set'},
|
471
|
+
x('pubsub',{:xmlns => EM::Xmpp::Namespaces::PubSubOwner},
|
472
|
+
x('purge',:node => node_id)
|
473
|
+
)
|
474
|
+
)
|
482
475
|
|
483
476
|
send_iq_stanza_fibered iq
|
484
477
|
end
|
@@ -486,37 +479,37 @@ module EM::Xmpp
|
|
486
479
|
# requests the list of subscriptions on this pubsub node (for the owner)
|
487
480
|
# returns the iq context for the answer
|
488
481
|
def subscriptions
|
489
|
-
iq = connection.iq_stanza('to'=>jid.bare
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
482
|
+
iq = connection.iq_stanza({'to'=>jid.bare},
|
483
|
+
x('pubsub',{:xmlns => EM::Xmpp::Namespaces::PubSubOwner},
|
484
|
+
x('subscriptions',:node => node_id)
|
485
|
+
)
|
486
|
+
)
|
494
487
|
send_iq_stanza_fibered iq
|
495
488
|
end
|
496
489
|
|
497
490
|
# requests the list of affiliations on this pubsub node (for the owner)
|
498
491
|
# returns the iq context for the answer
|
499
492
|
def affiliations
|
500
|
-
iq = connection.iq_stanza('to'=>jid.bare
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
493
|
+
iq = connection.iq_stanza({'to'=>jid.bare},
|
494
|
+
x('pubsub',{:xmlns => EM::Xmpp::Namespaces::PubSubOwner},
|
495
|
+
x('affiliations',:node => node_id)
|
496
|
+
)
|
497
|
+
)
|
505
498
|
send_iq_stanza_fibered iq
|
506
499
|
end
|
507
500
|
|
508
501
|
# changes the subscription status of a pubsub node (for the owner)
|
509
502
|
# returns the iq context for the answer
|
510
503
|
def modify_subscriptions(subs)
|
511
|
-
iq = connection.iq_stanza('to'=>jid.bare,'type'=>'set'
|
512
|
-
|
513
|
-
|
514
|
-
subs.
|
515
|
-
|
504
|
+
iq = connection.iq_stanza({'to'=>jid.bare,'type'=>'set'},
|
505
|
+
x('pubsub',{:xmlns => EM::Xmpp::Namespaces::PubSubOwner},
|
506
|
+
x('subscriptions',{:node => node_id},
|
507
|
+
subs.map do |s|
|
508
|
+
x('subscription',:jid => s.jid, :subscription => s.subscription, :subid => s.sub_id)
|
516
509
|
end
|
517
|
-
|
518
|
-
|
519
|
-
|
510
|
+
)
|
511
|
+
)
|
512
|
+
)
|
520
513
|
send_iq_stanza_fibered iq
|
521
514
|
end
|
522
515
|
|
@@ -524,15 +517,15 @@ module EM::Xmpp
|
|
524
517
|
# returns the iq context for the answer
|
525
518
|
def modify_affiliations(affs)
|
526
519
|
affs = [affs].flatten
|
527
|
-
iq = connection.iq_stanza('to'=>jid.bare,'type'=>'set'
|
528
|
-
|
529
|
-
|
530
|
-
affs.
|
531
|
-
|
520
|
+
iq = connection.iq_stanza({'to'=>jid.bare,'type'=>'set'},
|
521
|
+
x('pubsub',{:xmlns => EM::Xmpp::Namespaces::PubSubOwner},
|
522
|
+
x('affiliations',{:node => node_id},
|
523
|
+
affs.map do |s|
|
524
|
+
x('affiliation',:jid => s.jid, :affiliation => s.affiliation)
|
532
525
|
end
|
533
|
-
|
534
|
-
|
535
|
-
|
526
|
+
)
|
527
|
+
)
|
528
|
+
)
|
536
529
|
send_iq_stanza_fibered iq
|
537
530
|
end
|
538
531
|
|
@@ -558,13 +551,13 @@ module EM::Xmpp
|
|
558
551
|
#
|
559
552
|
# returns the iq context for the answer
|
560
553
|
def delete(redirect_uri=nil)
|
561
|
-
iq = connection.iq_stanza('to'=>jid.bare,'type'=>'set'
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
554
|
+
iq = connection.iq_stanza({'to'=>jid.bare,'type'=>'set'},
|
555
|
+
x('pubsub',{:xmlns => EM::Xmpp::Namespaces::PubSubOwner},
|
556
|
+
x('delete',{:node => node_id},
|
557
|
+
x_if(redirect_uri,'redirect',:uri => redirect_uri)
|
558
|
+
)
|
559
|
+
)
|
560
|
+
)
|
568
561
|
|
569
562
|
send_iq_stanza_fibered iq
|
570
563
|
end
|
@@ -573,14 +566,14 @@ module EM::Xmpp
|
|
573
566
|
#
|
574
567
|
# returns the iq context for the answer
|
575
568
|
def create_and_configure(form)
|
576
|
-
iq = connection.iq_stanza('to'=>jid.bare,'type'=>'set'
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
connection.build_submit_form(
|
581
|
-
|
582
|
-
|
583
|
-
|
569
|
+
iq = connection.iq_stanza({'to'=>jid.bare,'type'=>'set'},
|
570
|
+
x('pubsub',{:xmlns => EM::Xmpp::Namespaces::PubSub},
|
571
|
+
x('create','node' => node_id),
|
572
|
+
x('configure',
|
573
|
+
connection.build_submit_form(form)
|
574
|
+
)
|
575
|
+
)
|
576
|
+
)
|
584
577
|
|
585
578
|
send_iq_stanza_fibered iq
|
586
579
|
end
|
@@ -590,11 +583,11 @@ module EM::Xmpp
|
|
590
583
|
#
|
591
584
|
# returns the iq context for the answer
|
592
585
|
def configuration_options
|
593
|
-
iq = connection.iq_stanza('to'=>jid.bare
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
|
586
|
+
iq = connection.iq_stanza({'to'=>jid.bare},
|
587
|
+
x('pubsub',{:xmlns => EM::Xmpp::Namespaces::PubSubOwner},
|
588
|
+
x('configure','node' => node_id)
|
589
|
+
)
|
590
|
+
)
|
598
591
|
|
599
592
|
send_iq_stanza_fibered iq
|
600
593
|
end
|
@@ -603,13 +596,13 @@ module EM::Xmpp
|
|
603
596
|
#
|
604
597
|
# returns the iq context for the answer
|
605
598
|
def configure(form)
|
606
|
-
iq = connection.iq_stanza('to'=>jid.bare,'type'=>'set'
|
607
|
-
|
608
|
-
|
609
|
-
connection.build_submit_form(
|
610
|
-
|
611
|
-
|
612
|
-
|
599
|
+
iq = connection.iq_stanza({'to'=>jid.bare,'type'=>'set'},
|
600
|
+
x('pubsub',{:xmlns => EM::Xmpp::Namespaces::PubSubOwner},
|
601
|
+
x('configure',{'node' => node_id},
|
602
|
+
connection.build_submit_form(form)
|
603
|
+
)
|
604
|
+
)
|
605
|
+
)
|
613
606
|
|
614
607
|
send_iq_stanza_fibered iq
|
615
608
|
end
|
@@ -618,11 +611,11 @@ module EM::Xmpp
|
|
618
611
|
#
|
619
612
|
# returns the iq context for the answer
|
620
613
|
def default_configuration
|
621
|
-
iq = connection.iq_stanza('to'=>jid.bare
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
|
614
|
+
iq = connection.iq_stanza({'to'=>jid.bare},
|
615
|
+
x('pubsub',{:xmlns => EM::Xmpp::Namespaces::PubSubOwner},
|
616
|
+
x('default')
|
617
|
+
)
|
618
|
+
)
|
626
619
|
|
627
620
|
send_iq_stanza_fibered iq
|
628
621
|
end
|
@@ -647,19 +640,21 @@ module EM::Xmpp
|
|
647
640
|
|
648
641
|
# Join a MUC.
|
649
642
|
def join(nick,pass=nil,historysize=0,&blk)
|
650
|
-
pres = connection.presence_stanza('to'=> muc(nick).to_s) do
|
651
|
-
|
652
|
-
|
653
|
-
|
643
|
+
pres = connection.presence_stanza('to'=> muc(nick).to_s) do
|
644
|
+
nodes = []
|
645
|
+
nodes << x('password', pass) if pass
|
646
|
+
nodes << x('x', 'xmlns' => Namespaces::Muc) do
|
647
|
+
x('history', 'maxchars' => historysize.to_s)
|
654
648
|
end
|
649
|
+
nodes
|
655
650
|
end
|
656
651
|
connection.send_stanza pres, &blk
|
657
652
|
end
|
658
653
|
|
659
654
|
# Leave a MUC.
|
660
655
|
def part(nick,msg=nil)
|
661
|
-
pres = connection.presence_stanza('to'=> muc(nick).to_s,'type'=>'unavailable') do
|
662
|
-
|
656
|
+
pres = connection.presence_stanza('to'=> muc(nick).to_s,'type'=>'unavailable') do
|
657
|
+
x('status', msg) if msg
|
663
658
|
end
|
664
659
|
connection.send_stanza pres
|
665
660
|
end
|
@@ -669,22 +664,23 @@ module EM::Xmpp
|
|
669
664
|
join(nick)
|
670
665
|
end
|
671
666
|
|
672
|
-
# Say some message in the muc.
|
667
|
+
# Say some message in the muc.
|
673
668
|
def say(body, xmlproc=nil, &blk)
|
674
|
-
msg = connection.message_stanza(:to => jid, :type => 'groupchat') do
|
675
|
-
|
676
|
-
|
669
|
+
msg = connection.message_stanza(:to => jid, :type => 'groupchat') do
|
670
|
+
nodes = []
|
671
|
+
nodes << x('body',body,&xmlproc)
|
672
|
+
nodes << xmlproc.call if xmlproc
|
673
|
+
nodes
|
677
674
|
end
|
678
675
|
connection.send_stanza msg, &blk
|
679
676
|
end
|
680
677
|
|
681
678
|
private
|
682
|
-
|
683
679
|
def set_role(role,nick,reason=nil,&blk)
|
684
|
-
iq = connection.iq_stanza(:to => jid,:type => 'set') do
|
685
|
-
|
686
|
-
|
687
|
-
|
680
|
+
iq = connection.iq_stanza(:to => jid,:type => 'set') do
|
681
|
+
x('query', 'xmlns' => Namespaces::MucAdmin) do
|
682
|
+
x('item', 'nick' => nick, 'role' => role) do
|
683
|
+
x('reason',reason) if reason
|
688
684
|
end
|
689
685
|
end
|
690
686
|
end
|
@@ -692,10 +688,10 @@ module EM::Xmpp
|
|
692
688
|
end
|
693
689
|
|
694
690
|
def set_affiliation(affiliation,affiliated_jid,reason=nil,&blk)
|
695
|
-
iq = connection.iq_stanza(:to => jid,:type => 'set') do
|
696
|
-
|
697
|
-
|
698
|
-
|
691
|
+
iq = connection.iq_stanza(:to => jid,:type => 'set') do
|
692
|
+
x('query','xmlns' => Namespaces::MucAdmin) do
|
693
|
+
x('item', 'affiliation' => affiliation, 'jid' => affiliated_jid) do
|
694
|
+
x('reason', reason) if reason
|
699
695
|
end
|
700
696
|
end
|
701
697
|
end
|
@@ -815,18 +811,18 @@ module EM::Xmpp
|
|
815
811
|
|
816
812
|
# sets the room subject (Message Of The Day)
|
817
813
|
def motd(subject,&blk)
|
818
|
-
msg = connection.message_stanza(:to => jid) do
|
819
|
-
|
814
|
+
msg = connection.message_stanza(:to => jid) do
|
815
|
+
x('subject',subject)
|
820
816
|
end
|
821
817
|
connection.send_stanza msg, &blk
|
822
818
|
end
|
823
819
|
|
824
820
|
# invites someone (based on his jid) to the MUC
|
825
821
|
def invite(invited_jid,reason="no reason",&blk)
|
826
|
-
msg = connection.message_stanza(:to => jid) do
|
827
|
-
|
828
|
-
x
|
829
|
-
|
822
|
+
msg = connection.message_stanza(:to => jid) do
|
823
|
+
x('x', 'xmlns' => Namespaces::MucUser) do
|
824
|
+
x('invite', 'to' => invited_jid.to_s) do
|
825
|
+
x('reason', reason) if reason
|
830
826
|
end
|
831
827
|
end
|
832
828
|
end
|