xmpp4r-simple 0.8.1 → 0.8.4

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,29 @@
1
+ xmpp4r-simple (0.8.3)
2
+
3
+ [ Blaine Cook ]
4
+ * Catch broken connections and attempt to reconnect 3 times.
5
+
6
+ -- Blaine Cook <blaine@obvious.com> Fri, 23 Dec 2006 00:12:09 -0800
7
+
8
+
9
+ xmpp4r-simple (0.8.3)
10
+
11
+ [ Blaine Cook ]
12
+ * Update presence_updates to only store one presence_update per user.
13
+ Changes methods, will break code that uses presence_updates if not updated
14
+ correspondingly, check the documenation for the new semantics.
15
+
16
+ -- Blaine Cook <blaine@obvious.com> Thu, 07 Dec 2006 12:45:52 -0800
17
+
18
+
19
+ xmpp4r-simple (0.8.2)
20
+
21
+ [ Blaine Cook ]
22
+ * Add presence_updates?, received_messages?, and new_subscriptions? methods.
23
+
24
+ -- Blaine Cook <blaine@obvious.com> Wed, 06 Dec 2006 09:40:28 -0800
25
+
26
+
1
27
  xmpp4r-simple (0.8.1)
2
28
 
3
29
  [ Blaine Cook ]
data/Rakefile CHANGED
@@ -25,7 +25,7 @@ require 'rcov/rcovtask'
25
25
  spec = Gem::Specification.new do |s|
26
26
  s.add_dependency('xmpp4r', '>= 0.3.0')
27
27
  s.name = "xmpp4r-simple"
28
- s.version = "0.8.1"
28
+ s.version = "0.8.4"
29
29
  s.author = "Blaine Cook"
30
30
  s.email = "romeda@gmail.com"
31
31
  s.homepage = "http://xmpp4r-simple.rubyforge.org/"
data/lib/xmpp4r-simple.rb CHANGED
@@ -212,6 +212,12 @@ module Jabber
212
212
  dequeue(:received_messages, &block)
213
213
  end
214
214
 
215
+ # Returns true if there are unprocessed received messages waiting in the
216
+ # queue, false otherwise.
217
+ def received_messages?
218
+ !queue(:received_messages).empty?
219
+ end
220
+
215
221
  # Returns an array of presence updates received since the last time
216
222
  # presence_updates was called. Passing a block will yield each update in
217
223
  # turn, allowing you to break part-way through processing (especially
@@ -220,11 +226,28 @@ module Jabber
220
226
  #
221
227
  # e.g.:
222
228
  #
223
- # jabber.presence_updates do |friend, old_presence, new_presence|
224
- # puts "Received presence update from #{friend.to_s}: #{new_presence}"
229
+ # jabber.presence_updates do |friend, new_presence|
230
+ # puts "Received presence update from #{friend}: #{new_presence}"
225
231
  # end
226
232
  def presence_updates(&block)
227
- dequeue(:presence_updates, &block)
233
+ updates = []
234
+ @presence_mutex.synchronize do
235
+ dequeue(:presence_updates) do |friend|
236
+ presence = @presence_updates[friend]
237
+ next unless presence
238
+ new_update = [friend, presence[0], presence[1]]
239
+ yield new_update if block_given?
240
+ updates << new_update
241
+ @presence_updates.delete(friend)
242
+ end
243
+ end
244
+ return updates
245
+ end
246
+
247
+ # Returns true if there are unprocessed presence updates waiting in the
248
+ # queue, false otherwise.
249
+ def presence_updates?
250
+ !queue(:presence_updates).empty?
228
251
  end
229
252
 
230
253
  # Returns an array of subscription notifications received since the last
@@ -242,6 +265,12 @@ module Jabber
242
265
  dequeue(:new_subscriptions, &block)
243
266
  end
244
267
 
268
+ # Returns true if there are unprocessed presence updates waiting in the
269
+ # queue, false otherwise.
270
+ def new_subscriptions?
271
+ !queue(:new_subscriptions).empty?
272
+ end
273
+
245
274
  # Returns an array of subscription notifications received since the last
246
275
  # time subscription_requests was called. Passing a block will yield each update
247
276
  # in turn, allowing you to break part-way through processing (especially
@@ -256,7 +285,6 @@ module Jabber
256
285
  def subscription_requests(&block)
257
286
  dequeue(:subscription_requests, &block)
258
287
  end
259
-
260
288
 
261
289
  # Returns true if auto-accept subscriptions (friend requests) is enabled
262
290
  # (default), false otherwise.
@@ -284,7 +312,17 @@ module Jabber
284
312
 
285
313
  # Send a Jabber stanza over-the-wire.
286
314
  def send!(msg)
287
- client.send(msg)
315
+ attempts = 0
316
+ begin
317
+ attempts += 1
318
+ client.send(msg)
319
+ rescue Errno::EPIPE, IOError => e
320
+ sleep 0.33
321
+ disconnect
322
+ reconnect
323
+ retry unless attempts > 3
324
+ raise e
325
+ end
288
326
  end
289
327
 
290
328
  # Use this to force the client to reconnect after a force_disconnect.
@@ -367,8 +405,21 @@ module Jabber
367
405
  end
368
406
  end
369
407
 
408
+ @presence_updates = {}
409
+ @presence_mutex = Mutex.new
370
410
  roster.add_presence_callback do |roster_item, old_presence, new_presence|
371
- queue(:presence_updates) << [roster_item, old_presence, new_presence]
411
+ simple_jid = roster_item.jid.strip.to_s
412
+ presence = case new_presence.type
413
+ when nil: new_presence.show || :online
414
+ when :unavailable: :unavailable
415
+ else
416
+ nil
417
+ end
418
+
419
+ if presence && @presence_updates[simple_jid] != presence
420
+ queue(:presence_updates) << simple_jid
421
+ @presence_mutex.synchronize { @presence_updates[simple_jid] = [presence, new_presence.status] }
422
+ end
372
423
  end
373
424
  end
374
425
 
@@ -397,9 +448,9 @@ module Jabber
397
448
  @queues[queue]
398
449
  end
399
450
 
400
- def dequeue(queue, non_blocking = true, &block)
451
+ def dequeue(queue, non_blocking = true, max_items = 100, &block)
401
452
  queue_items = []
402
- loop do
453
+ max_items.times do
403
454
  queue_item = queue(queue).pop(non_blocking) rescue nil
404
455
  break if queue_item.nil?
405
456
  queue_items << queue_item
@@ -145,6 +145,7 @@ class JabberSimpleTest < Test::Unit::TestCase
145
145
  def test_presence_updates_should_be_received
146
146
 
147
147
  @client2.add(@client1)
148
+ @client1.add(@client2)
148
149
 
149
150
  assert_before(60) { assert @client2.subscribed_to?(@jid1) }
150
151
  assert_before(60) { assert_equal 0, @client2.presence_updates.size }
@@ -158,9 +159,9 @@ class JabberSimpleTest < Test::Unit::TestCase
158
159
  end
159
160
 
160
161
  new_status = new_statuses.first
161
- assert_equal @jid1, new_status[0].jid.strip.to_s
162
- assert_equal "Doing something else.", new_status[2].status
163
- assert_equal :away, new_status[2].show
162
+ assert_equal @jid1, new_status[0]
163
+ assert_equal "Doing something else.", new_status[2]
164
+ assert_equal :away, new_status[1]
164
165
  end
165
166
 
166
167
  def test_disable_auto_accept_subscription_requests
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.11
3
3
  specification_version: 1
4
4
  name: xmpp4r-simple
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.8.1
7
- date: 2006-12-05 00:00:00 -08:00
6
+ version: 0.8.4
7
+ date: 2006-12-23 00:00:00 -08:00
8
8
  summary: A simplified Jabber client library.
9
9
  require_paths:
10
10
  - lib