ably-rest 1.0.5 → 1.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.travis.yml +6 -3
- data/CHANGELOG.md +1 -1
- data/LICENSE +1 -1
- data/README.md +26 -7
- data/SPEC.md +2003 -1605
- data/ably-rest.gemspec +4 -2
- data/lib/submodules/ably-ruby/.editorconfig +14 -0
- data/lib/submodules/ably-ruby/.travis.yml +10 -8
- data/lib/submodules/ably-ruby/CHANGELOG.md +97 -1
- data/lib/submodules/ably-ruby/LICENSE +1 -3
- data/lib/submodules/ably-ruby/README.md +12 -7
- data/lib/submodules/ably-ruby/Rakefile +32 -0
- data/lib/submodules/ably-ruby/SPEC.md +1277 -835
- data/lib/submodules/ably-ruby/ably.gemspec +17 -11
- data/lib/submodules/ably-ruby/lib/ably/auth.rb +34 -8
- data/lib/submodules/ably-ruby/lib/ably/exceptions.rb +10 -4
- data/lib/submodules/ably-ruby/lib/ably/logger.rb +8 -2
- data/lib/submodules/ably-ruby/lib/ably/models/channel_state_change.rb +1 -1
- data/lib/submodules/ably-ruby/lib/ably/models/connection_state_change.rb +1 -1
- data/lib/submodules/ably-ruby/lib/ably/models/device_details.rb +87 -0
- data/lib/submodules/ably-ruby/lib/ably/models/device_push_details.rb +86 -0
- data/lib/submodules/ably-ruby/lib/ably/models/error_info.rb +23 -2
- data/lib/submodules/ably-ruby/lib/ably/models/idiomatic_ruby_wrapper.rb +12 -12
- data/lib/submodules/ably-ruby/lib/ably/models/message.rb +6 -4
- data/lib/submodules/ably-ruby/lib/ably/models/presence_message.rb +6 -4
- data/lib/submodules/ably-ruby/lib/ably/models/protocol_message.rb +32 -2
- data/lib/submodules/ably-ruby/lib/ably/models/push_channel_subscription.rb +89 -0
- data/lib/submodules/ably-ruby/lib/ably/modules/async_wrapper.rb +2 -2
- data/lib/submodules/ably-ruby/lib/ably/modules/conversions.rb +2 -2
- data/lib/submodules/ably-ruby/lib/ably/modules/encodeable.rb +2 -2
- data/lib/submodules/ably-ruby/lib/ably/modules/event_emitter.rb +2 -2
- data/lib/submodules/ably-ruby/lib/ably/modules/exception_codes.rb +128 -0
- data/lib/submodules/ably-ruby/lib/ably/modules/model_common.rb +15 -2
- data/lib/submodules/ably-ruby/lib/ably/modules/safe_deferrable.rb +1 -1
- data/lib/submodules/ably-ruby/lib/ably/modules/safe_yield.rb +1 -1
- data/lib/submodules/ably-ruby/lib/ably/modules/state_emitter.rb +5 -5
- data/lib/submodules/ably-ruby/lib/ably/modules/state_machine.rb +2 -2
- data/lib/submodules/ably-ruby/lib/ably/realtime.rb +1 -0
- data/lib/submodules/ably-ruby/lib/ably/realtime/auth.rb +2 -2
- data/lib/submodules/ably-ruby/lib/ably/realtime/channel.rb +27 -105
- data/lib/submodules/ably-ruby/lib/ably/realtime/channel/channel_manager.rb +4 -8
- data/lib/submodules/ably-ruby/lib/ably/realtime/channel/channel_state_machine.rb +2 -2
- data/lib/submodules/ably-ruby/lib/ably/realtime/channel/publisher.rb +74 -0
- data/lib/submodules/ably-ruby/lib/ably/realtime/channel/push_channel.rb +62 -0
- data/lib/submodules/ably-ruby/lib/ably/realtime/client.rb +91 -3
- data/lib/submodules/ably-ruby/lib/ably/realtime/client/incoming_message_dispatcher.rb +9 -4
- data/lib/submodules/ably-ruby/lib/ably/realtime/client/outgoing_message_dispatcher.rb +1 -1
- data/lib/submodules/ably-ruby/lib/ably/realtime/connection.rb +45 -26
- data/lib/submodules/ably-ruby/lib/ably/realtime/connection/connection_manager.rb +25 -9
- data/lib/submodules/ably-ruby/lib/ably/realtime/connection/websocket_transport.rb +2 -2
- data/lib/submodules/ably-ruby/lib/ably/realtime/presence.rb +7 -7
- data/lib/submodules/ably-ruby/lib/ably/realtime/presence/members_map.rb +9 -9
- data/lib/submodules/ably-ruby/lib/ably/realtime/push.rb +40 -0
- data/lib/submodules/ably-ruby/lib/ably/realtime/push/admin.rb +61 -0
- data/lib/submodules/ably-ruby/lib/ably/realtime/push/channel_subscriptions.rb +108 -0
- data/lib/submodules/ably-ruby/lib/ably/realtime/push/device_registrations.rb +105 -0
- data/lib/submodules/ably-ruby/lib/ably/rest.rb +1 -0
- data/lib/submodules/ably-ruby/lib/ably/rest/channel.rb +54 -18
- data/lib/submodules/ably-ruby/lib/ably/rest/channel/push_channel.rb +62 -0
- data/lib/submodules/ably-ruby/lib/ably/rest/client.rb +171 -41
- data/lib/submodules/ably-ruby/lib/ably/rest/middleware/parse_message_pack.rb +17 -1
- data/lib/submodules/ably-ruby/lib/ably/rest/presence.rb +1 -0
- data/lib/submodules/ably-ruby/lib/ably/rest/push.rb +42 -0
- data/lib/submodules/ably-ruby/lib/ably/rest/push/admin.rb +54 -0
- data/lib/submodules/ably-ruby/lib/ably/rest/push/channel_subscriptions.rb +121 -0
- data/lib/submodules/ably-ruby/lib/ably/rest/push/device_registrations.rb +103 -0
- data/lib/submodules/ably-ruby/lib/ably/version.rb +7 -2
- data/lib/submodules/ably-ruby/spec/acceptance/realtime/auth_spec.rb +253 -49
- data/lib/submodules/ably-ruby/spec/acceptance/realtime/channel_history_spec.rb +33 -21
- data/lib/submodules/ably-ruby/spec/acceptance/realtime/channel_spec.rb +180 -62
- data/lib/submodules/ably-ruby/spec/acceptance/realtime/client_spec.rb +155 -2
- data/lib/submodules/ably-ruby/spec/acceptance/realtime/connection_failures_spec.rb +293 -13
- data/lib/submodules/ably-ruby/spec/acceptance/realtime/connection_spec.rb +142 -39
- data/lib/submodules/ably-ruby/spec/acceptance/realtime/message_spec.rb +38 -36
- data/lib/submodules/ably-ruby/spec/acceptance/realtime/presence_history_spec.rb +12 -3
- data/lib/submodules/ably-ruby/spec/acceptance/realtime/presence_spec.rb +207 -173
- data/lib/submodules/ably-ruby/spec/acceptance/realtime/push_admin_spec.rb +736 -0
- data/lib/submodules/ably-ruby/spec/acceptance/realtime/push_spec.rb +27 -0
- data/lib/submodules/ably-ruby/spec/acceptance/rest/auth_spec.rb +62 -51
- data/lib/submodules/ably-ruby/spec/acceptance/rest/base_spec.rb +2 -2
- data/lib/submodules/ably-ruby/spec/acceptance/rest/channel_spec.rb +79 -4
- data/lib/submodules/ably-ruby/spec/acceptance/rest/channels_spec.rb +6 -0
- data/lib/submodules/ably-ruby/spec/acceptance/rest/client_spec.rb +318 -74
- data/lib/submodules/ably-ruby/spec/acceptance/rest/message_spec.rb +158 -6
- data/lib/submodules/ably-ruby/spec/acceptance/rest/push_admin_spec.rb +952 -0
- data/lib/submodules/ably-ruby/spec/acceptance/rest/push_spec.rb +25 -0
- data/lib/submodules/ably-ruby/spec/acceptance/rest/time_spec.rb +1 -1
- data/lib/submodules/ably-ruby/spec/run_parallel_tests +33 -0
- data/lib/submodules/ably-ruby/spec/shared/client_initializer_behaviour.rb +1 -9
- data/lib/submodules/ably-ruby/spec/spec_helper.rb +3 -1
- data/lib/submodules/ably-ruby/spec/support/debug_failure_helper.rb +9 -5
- data/lib/submodules/ably-ruby/spec/support/event_emitter_helper.rb +31 -0
- data/lib/submodules/ably-ruby/spec/support/event_machine_helper.rb +1 -1
- data/lib/submodules/ably-ruby/spec/support/test_app.rb +2 -2
- data/lib/submodules/ably-ruby/spec/support/test_logger_helper.rb +42 -0
- data/lib/submodules/ably-ruby/spec/unit/logger_spec.rb +11 -12
- data/lib/submodules/ably-ruby/spec/unit/models/device_details_spec.rb +102 -0
- data/lib/submodules/ably-ruby/spec/unit/models/device_push_details_spec.rb +101 -0
- data/lib/submodules/ably-ruby/spec/unit/models/error_info_spec.rb +51 -3
- data/lib/submodules/ably-ruby/spec/unit/models/message_spec.rb +17 -2
- data/lib/submodules/ably-ruby/spec/unit/models/presence_message_spec.rb +1 -1
- data/lib/submodules/ably-ruby/spec/unit/models/push_channel_subscription_spec.rb +86 -0
- data/lib/submodules/ably-ruby/spec/unit/modules/async_wrapper_spec.rb +2 -2
- data/lib/submodules/ably-ruby/spec/unit/modules/enum_spec.rb +1 -1
- data/lib/submodules/ably-ruby/spec/unit/modules/event_emitter_spec.rb +3 -3
- data/lib/submodules/ably-ruby/spec/unit/modules/state_emitter_spec.rb +10 -10
- data/lib/submodules/ably-ruby/spec/unit/realtime/channel_spec.rb +1 -1
- data/lib/submodules/ably-ruby/spec/unit/realtime/client_spec.rb +13 -1
- data/lib/submodules/ably-ruby/spec/unit/realtime/connection_spec.rb +2 -2
- data/lib/submodules/ably-ruby/spec/unit/realtime/presence_spec.rb +1 -1
- data/lib/submodules/ably-ruby/spec/unit/realtime/push_channel_spec.rb +36 -0
- data/lib/submodules/ably-ruby/spec/unit/rest/channel_spec.rb +30 -1
- data/lib/submodules/ably-ruby/spec/unit/rest/client_spec.rb +30 -0
- data/lib/submodules/ably-ruby/spec/unit/rest/push_channel_spec.rb +36 -0
- data/lib/submodules/ably-ruby/spec/unit/util/pub_sub_spec.rb +3 -3
- data/spec/spec_helper.rb +1 -0
- metadata +51 -10
@@ -96,8 +96,7 @@ describe 'Ably::Realtime::Channel Message', :event_machine do
|
|
96
96
|
end
|
97
97
|
|
98
98
|
context 'JSON Array' do
|
99
|
-
|
100
|
-
let(:data) { { 'push' => { 'data' => { 'key' => [ true, false, 55, 'string', { 'Hash' => true }, ['array'] ] } } } }
|
99
|
+
let(:data) { { 'push' => { 'data' => { 'key' => [ true, false, 55, nil, 'string', { 'Hash' => true }, ['array'] ] } } } }
|
101
100
|
|
102
101
|
it 'is encoded and decoded to the same Array' do
|
103
102
|
publish_and_check_extras data
|
@@ -116,7 +115,7 @@ describe 'Ably::Realtime::Channel Message', :event_machine do
|
|
116
115
|
context 'Integer' do
|
117
116
|
let(:data) { 1 }
|
118
117
|
|
119
|
-
it 'is raises an UnsupportedDataType
|
118
|
+
it 'is raises an UnsupportedDataType 40013 exception' do
|
120
119
|
expect { channel.publish 'event', data }.to raise_error(Ably::Exceptions::UnsupportedDataType)
|
121
120
|
stop_reactor
|
122
121
|
end
|
@@ -125,7 +124,7 @@ describe 'Ably::Realtime::Channel Message', :event_machine do
|
|
125
124
|
context 'Float' do
|
126
125
|
let(:data) { 1.1 }
|
127
126
|
|
128
|
-
it 'is raises an UnsupportedDataType
|
127
|
+
it 'is raises an UnsupportedDataType 40013 exception' do
|
129
128
|
expect { channel.publish 'event', data }.to raise_error(Ably::Exceptions::UnsupportedDataType)
|
130
129
|
stop_reactor
|
131
130
|
end
|
@@ -134,7 +133,7 @@ describe 'Ably::Realtime::Channel Message', :event_machine do
|
|
134
133
|
context 'Boolean' do
|
135
134
|
let(:data) { true }
|
136
135
|
|
137
|
-
it 'is raises an UnsupportedDataType
|
136
|
+
it 'is raises an UnsupportedDataType 40013 exception' do
|
138
137
|
expect { channel.publish 'event', data }.to raise_error(Ably::Exceptions::UnsupportedDataType)
|
139
138
|
stop_reactor
|
140
139
|
end
|
@@ -143,7 +142,7 @@ describe 'Ably::Realtime::Channel Message', :event_machine do
|
|
143
142
|
context 'False' do
|
144
143
|
let(:data) { false }
|
145
144
|
|
146
|
-
it 'is raises an UnsupportedDataType
|
145
|
+
it 'is raises an UnsupportedDataType 40013 exception' do
|
147
146
|
expect { channel.publish 'event', data }.to raise_error(Ably::Exceptions::UnsupportedDataType)
|
148
147
|
stop_reactor
|
149
148
|
end
|
@@ -284,7 +283,7 @@ describe 'Ably::Realtime::Channel Message', :event_machine do
|
|
284
283
|
end
|
285
284
|
|
286
285
|
it 'sends and receives the messages on both opened connections and calls the success callbacks for each message published', em_timeout: 10 do
|
287
|
-
check_message_and_callback_counts =
|
286
|
+
check_message_and_callback_counts = lambda do
|
288
287
|
if echos[:client] == expected_echos && echos[:other] == expected_echos
|
289
288
|
# Wait for message backlog to clear
|
290
289
|
EventMachine.add_timer(0.5) do
|
@@ -353,23 +352,25 @@ describe 'Ably::Realtime::Channel Message', :event_machine do
|
|
353
352
|
first_message_protocol_message ||= protocol_message unless protocol_message.messages.empty?
|
354
353
|
end
|
355
354
|
|
356
|
-
channel.
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
355
|
+
channel.attach do
|
356
|
+
channel.subscribe do |message|
|
357
|
+
messages_received << message
|
358
|
+
if messages_received.count == 2
|
359
|
+
# simulate a duplicate protocol message being received
|
360
|
+
EventMachine.next_tick do
|
361
|
+
connection.__incoming_protocol_msgbus__.publish :protocol_message, first_message_protocol_message
|
362
|
+
end
|
362
363
|
end
|
363
364
|
end
|
364
|
-
|
365
|
-
2.times { |i| EventMachine.add_timer(i.to_f / 5) { channel.publish('event', 'data') } }
|
365
|
+
2.times { |i| EventMachine.add_timer(i.to_f / 5) { channel.publish('event', 'data') } }
|
366
366
|
|
367
|
-
|
368
|
-
|
367
|
+
expect(client.logger).to receive(:error) do |*args, &block|
|
368
|
+
expect(args.concat([block ? block.call : nil]).join(',')).to match(/duplicate/)
|
369
369
|
|
370
|
-
|
371
|
-
|
372
|
-
|
370
|
+
EventMachine.add_timer(0.5) do
|
371
|
+
expect(messages_received.count).to eql(2)
|
372
|
+
stop_reactor
|
373
|
+
end
|
373
374
|
end
|
374
375
|
end
|
375
376
|
end
|
@@ -413,30 +414,32 @@ describe 'Ably::Realtime::Channel Message', :event_machine do
|
|
413
414
|
let(:encrypted_channel) { client.channel(channel_name, cipher: cipher_options) }
|
414
415
|
|
415
416
|
it 'encrypts message automatically before they are pushed to the server (#RTL7d)' do
|
416
|
-
encrypted_channel.
|
417
|
+
encrypted_channel.attach do
|
418
|
+
encrypted_channel.__incoming_msgbus__.unsubscribe # remove all subscribe callbacks that could decrypt the message
|
417
419
|
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
420
|
+
encrypted_channel.__incoming_msgbus__.subscribe(:message) do |message|
|
421
|
+
if protocol == :json
|
422
|
+
expect(message['encoding']).to eql(encrypted_encoding)
|
423
|
+
expect(message['data']).to eql(encrypted_data)
|
424
|
+
else
|
425
|
+
# Messages received over binary protocol will not have Base64 encoded data
|
426
|
+
expect(message['encoding']).to eql(encrypted_encoding.gsub(%r{/base64$}, ''))
|
427
|
+
expect(message['data']).to eql(encrypted_data_decoded)
|
428
|
+
end
|
429
|
+
stop_reactor
|
426
430
|
end
|
427
|
-
stop_reactor
|
428
|
-
end
|
429
431
|
|
430
|
-
|
432
|
+
encrypted_channel.publish 'example', encoded_data_decoded
|
433
|
+
end
|
431
434
|
end
|
432
435
|
|
433
436
|
it 'sends and receives messages that are encrypted & decrypted by the Ably library (#RTL7d)' do
|
434
|
-
encrypted_channel.publish 'example', encoded_data_decoded
|
435
437
|
encrypted_channel.subscribe do |message|
|
436
438
|
expect(message.data).to eql(encoded_data_decoded)
|
437
439
|
expect(message.encoding).to be_nil
|
438
440
|
stop_reactor
|
439
441
|
end
|
442
|
+
encrypted_channel.publish 'example', encoded_data_decoded
|
440
443
|
end
|
441
444
|
end
|
442
445
|
end
|
@@ -650,12 +653,11 @@ describe 'Ably::Realtime::Channel Message', :event_machine do
|
|
650
653
|
let(:msgs_received) { [] }
|
651
654
|
|
652
655
|
it 'publishes the message again, later receives the ACK and only one message is ever received from Ably' do
|
653
|
-
on_reconnected =
|
656
|
+
on_reconnected = lambda do |*args|
|
654
657
|
expect(message_state).to be_empty
|
655
658
|
EventMachine.add_timer(2) do
|
656
659
|
expect(message_state).to contain_exactly(:delivered)
|
657
|
-
|
658
|
-
# expect(msgs_received.length).to eql(1)
|
660
|
+
expect(msgs_received.length).to eql(1)
|
659
661
|
stop_reactor
|
660
662
|
end
|
661
663
|
end
|
@@ -71,11 +71,14 @@ describe Ably::Realtime::Presence, 'history', :event_machine do
|
|
71
71
|
end
|
72
72
|
|
73
73
|
context 'and two pages of messages' do
|
74
|
-
let(:wildcard_token) {
|
74
|
+
let(:wildcard_token) { lambda { |token_params| Ably::Rest::Client.new(default_options).auth.request_token(client_id: '*') } }
|
75
75
|
let(:client_one) { auto_close Ably::Realtime::Client.new(default_options.merge(auth_callback: wildcard_token)) }
|
76
76
|
let(:client_two) { auto_close Ably::Realtime::Client.new(default_options.merge(auth_callback: wildcard_token)) }
|
77
77
|
|
78
|
-
|
78
|
+
# TODO: Remove retry logic when presence history regression fixed
|
79
|
+
# https://github.com/ably/realtime/issues/1707
|
80
|
+
#
|
81
|
+
it 'retrieves two pages of messages before channel was attached', retry: 10, :retry_wait => 5 do
|
79
82
|
when_all(*10.times.map { |i| presence_client_two.enter_client("client:#{i}", presence_data_before_attach) }) do
|
80
83
|
when_all(*10.times.map { |i| presence_client_one.enter_client("client:#{i}", presence_data_after_attach) }) do
|
81
84
|
presence_client_one.history(until_attach: true, limit: 5) do |presence_page|
|
@@ -85,7 +88,13 @@ describe Ably::Realtime::Presence, 'history', :event_machine do
|
|
85
88
|
presence_page.next do |presence_next_page|
|
86
89
|
expect(presence_next_page.items.count).to eql(5)
|
87
90
|
expect(presence_next_page.items.map(&:data).uniq.first).to eql(presence_data_before_attach)
|
88
|
-
|
91
|
+
if presence_next_page.has_next?
|
92
|
+
presence_next_page.next do |last|
|
93
|
+
expect(last.items.count).to eql(0)
|
94
|
+
end
|
95
|
+
else
|
96
|
+
expect(presence_next_page).to be_last
|
97
|
+
end
|
89
98
|
stop_reactor
|
90
99
|
end
|
91
100
|
end
|
@@ -14,7 +14,7 @@ describe Ably::Realtime::Presence, :event_machine do
|
|
14
14
|
let(:client_two_id) { random_str }
|
15
15
|
let(:client_two) { auto_close Ably::Realtime::Client.new(client_options.merge(client_id: client_two_id)) }
|
16
16
|
|
17
|
-
let(:wildcard_token) {
|
17
|
+
let(:wildcard_token) { lambda { |token_params| Ably::Rest::Client.new(client_options).auth.request_token(client_id: '*') } }
|
18
18
|
let(:channel_name) { "presence-#{random_str(4)}" }
|
19
19
|
let(:channel_anonymous_client) { anonymous_client.channel(channel_name) }
|
20
20
|
let(:presence_anonymous_client) { channel_anonymous_client.presence }
|
@@ -256,7 +256,7 @@ describe Ably::Realtime::Presence, :event_machine do
|
|
256
256
|
context 'Integer' do
|
257
257
|
let(:data) { 1 }
|
258
258
|
|
259
|
-
it 'raises an UnsupportedDataType
|
259
|
+
it 'raises an UnsupportedDataType 40013 exception' do
|
260
260
|
expect { presence_action(method_name, data) }.to raise_error(Ably::Exceptions::UnsupportedDataType)
|
261
261
|
stop_reactor
|
262
262
|
end
|
@@ -265,7 +265,7 @@ describe Ably::Realtime::Presence, :event_machine do
|
|
265
265
|
context 'Float' do
|
266
266
|
let(:data) { 1.1 }
|
267
267
|
|
268
|
-
it 'raises an UnsupportedDataType
|
268
|
+
it 'raises an UnsupportedDataType 40013 exception' do
|
269
269
|
expect { presence_action(method_name, data) }.to raise_error(Ably::Exceptions::UnsupportedDataType)
|
270
270
|
stop_reactor
|
271
271
|
end
|
@@ -274,7 +274,7 @@ describe Ably::Realtime::Presence, :event_machine do
|
|
274
274
|
context 'Boolean' do
|
275
275
|
let(:data) { true }
|
276
276
|
|
277
|
-
it 'raises an UnsupportedDataType
|
277
|
+
it 'raises an UnsupportedDataType 40013 exception' do
|
278
278
|
expect { presence_action(method_name, data) }.to raise_error(Ably::Exceptions::UnsupportedDataType)
|
279
279
|
stop_reactor
|
280
280
|
end
|
@@ -283,7 +283,7 @@ describe Ably::Realtime::Presence, :event_machine do
|
|
283
283
|
context 'False' do
|
284
284
|
let(:data) { false }
|
285
285
|
|
286
|
-
it 'raises an UnsupportedDataType
|
286
|
+
it 'raises an UnsupportedDataType 40013 exception' do
|
287
287
|
expect { presence_action(method_name, data) }.to raise_error(Ably::Exceptions::UnsupportedDataType)
|
288
288
|
stop_reactor
|
289
289
|
end
|
@@ -1073,12 +1073,12 @@ describe Ably::Realtime::Presence, :event_machine do
|
|
1073
1073
|
context 'message #connection_id' do
|
1074
1074
|
it 'matches the current client connection_id' do
|
1075
1075
|
channel_client_two.attach do
|
1076
|
-
|
1077
|
-
|
1076
|
+
presence_client_two.subscribe do |presence|
|
1077
|
+
expect(presence.connection_id).to eq(client_one.connection.id)
|
1078
|
+
stop_reactor
|
1079
|
+
end
|
1078
1080
|
|
1079
|
-
|
1080
|
-
expect(presence.connection_id).to eq(client_one.connection.id)
|
1081
|
-
stop_reactor
|
1081
|
+
presence_client_one.enter
|
1082
1082
|
end
|
1083
1083
|
end
|
1084
1084
|
end
|
@@ -1128,22 +1128,26 @@ describe Ably::Realtime::Presence, :event_machine do
|
|
1128
1128
|
end
|
1129
1129
|
|
1130
1130
|
it 'updates the data if :data argument provided' do
|
1131
|
-
|
1132
|
-
presence_client_one.
|
1133
|
-
|
1134
|
-
|
1135
|
-
|
1136
|
-
|
1131
|
+
channel_client_one.attach do
|
1132
|
+
presence_client_one.enter('prior') do
|
1133
|
+
presence_client_one.update(data_payload)
|
1134
|
+
end
|
1135
|
+
presence_client_one.subscribe(:update) do |message|
|
1136
|
+
expect(message.data).to eql(data_payload)
|
1137
|
+
stop_reactor
|
1138
|
+
end
|
1137
1139
|
end
|
1138
1140
|
end
|
1139
1141
|
|
1140
1142
|
it 'updates the data to nil if :data argument is not provided (assumes nil value)' do
|
1141
|
-
|
1142
|
-
presence_client_one.
|
1143
|
-
|
1144
|
-
|
1145
|
-
|
1146
|
-
|
1143
|
+
channel_client_one.attach do
|
1144
|
+
presence_client_one.enter('prior') do
|
1145
|
+
presence_client_one.update
|
1146
|
+
end
|
1147
|
+
presence_client_one.subscribe(:update) do |message|
|
1148
|
+
expect(message.data).to be_nil
|
1149
|
+
stop_reactor
|
1150
|
+
end
|
1147
1151
|
end
|
1148
1152
|
end
|
1149
1153
|
|
@@ -1157,39 +1161,45 @@ describe Ably::Realtime::Presence, :event_machine do
|
|
1157
1161
|
|
1158
1162
|
context 'when set to a string' do
|
1159
1163
|
it 'emits the new data for the leave event' do
|
1160
|
-
|
1161
|
-
presence_client_one.
|
1162
|
-
|
1164
|
+
channel_client_one.attach do
|
1165
|
+
presence_client_one.enter enter_data do
|
1166
|
+
presence_client_one.leave data
|
1167
|
+
end
|
1163
1168
|
|
1164
|
-
|
1165
|
-
|
1166
|
-
|
1169
|
+
presence_client_one.subscribe(:leave) do |presence_message|
|
1170
|
+
expect(presence_message.data).to eql(data)
|
1171
|
+
stop_reactor
|
1172
|
+
end
|
1167
1173
|
end
|
1168
1174
|
end
|
1169
1175
|
end
|
1170
1176
|
|
1171
1177
|
context 'when set to nil' do
|
1172
1178
|
it 'emits the last value for the data attribute when leaving' do
|
1173
|
-
|
1174
|
-
presence_client_one.
|
1175
|
-
|
1179
|
+
channel_client_one.attach do
|
1180
|
+
presence_client_one.enter enter_data do
|
1181
|
+
presence_client_one.leave nil
|
1182
|
+
end
|
1176
1183
|
|
1177
|
-
|
1178
|
-
|
1179
|
-
|
1184
|
+
presence_client_one.subscribe(:leave) do |presence_message|
|
1185
|
+
expect(presence_message.data).to eql(enter_data)
|
1186
|
+
stop_reactor
|
1187
|
+
end
|
1180
1188
|
end
|
1181
1189
|
end
|
1182
1190
|
end
|
1183
1191
|
|
1184
1192
|
context 'when not passed as an argument (i.e. nil)' do
|
1185
1193
|
it 'emits the previous value for the data attribute when leaving' do
|
1186
|
-
|
1187
|
-
presence_client_one.
|
1188
|
-
|
1194
|
+
channel_client_one.attach do
|
1195
|
+
presence_client_one.enter enter_data do
|
1196
|
+
presence_client_one.leave
|
1197
|
+
end
|
1189
1198
|
|
1190
|
-
|
1191
|
-
|
1192
|
-
|
1199
|
+
presence_client_one.subscribe(:leave) do |presence_message|
|
1200
|
+
expect(presence_message.data).to eql(enter_data)
|
1201
|
+
stop_reactor
|
1202
|
+
end
|
1193
1203
|
end
|
1194
1204
|
end
|
1195
1205
|
end
|
@@ -1198,38 +1208,42 @@ describe Ably::Realtime::Presence, :event_machine do
|
|
1198
1208
|
it 'does not cache members that have left' do
|
1199
1209
|
enter_ack = false
|
1200
1210
|
|
1201
|
-
|
1202
|
-
presence_client_one.
|
1211
|
+
channel_client_one.attach do
|
1212
|
+
presence_client_one.subscribe(:enter) do
|
1213
|
+
presence_client_one.unsubscribe :enter
|
1203
1214
|
|
1204
|
-
|
1205
|
-
|
1206
|
-
|
1207
|
-
|
1215
|
+
expect(presence_client_one.members).to be_in_sync
|
1216
|
+
expect(presence_client_one.members.send(:members).count).to eql(1)
|
1217
|
+
presence_client_one.leave data
|
1218
|
+
end
|
1208
1219
|
|
1209
|
-
|
1210
|
-
|
1211
|
-
|
1220
|
+
presence_client_one.enter(enter_data) do
|
1221
|
+
enter_ack = true
|
1222
|
+
end
|
1212
1223
|
|
1213
|
-
|
1214
|
-
|
1215
|
-
|
1216
|
-
|
1217
|
-
|
1218
|
-
|
1224
|
+
presence_client_one.subscribe(:leave) do |presence_message|
|
1225
|
+
presence_client_one.unsubscribe :leave
|
1226
|
+
expect(presence_message.data).to eql(data)
|
1227
|
+
expect(presence_client_one.members.send(:members).count).to eql(0)
|
1228
|
+
expect(enter_ack).to eql(true)
|
1229
|
+
stop_reactor
|
1230
|
+
end
|
1219
1231
|
end
|
1220
1232
|
end
|
1221
1233
|
end
|
1222
1234
|
end
|
1223
1235
|
|
1224
1236
|
it 'succeeds and does not emit an event (#RTP10d)' do
|
1225
|
-
channel_client_one.
|
1226
|
-
|
1227
|
-
|
1228
|
-
|
1237
|
+
channel_client_one.attach do
|
1238
|
+
channel_client_one.presence.leave do
|
1239
|
+
# allow enough time for leave event to (not) fire
|
1240
|
+
EventMachine.add_timer(2) do
|
1241
|
+
stop_reactor
|
1242
|
+
end
|
1243
|
+
end
|
1244
|
+
channel_client_one.subscribe(:leave) do
|
1245
|
+
raise "No leave event should fire"
|
1229
1246
|
end
|
1230
|
-
end
|
1231
|
-
channel_client_one.subscribe(:leave) do
|
1232
|
-
raise "No leave event should fire"
|
1233
1247
|
end
|
1234
1248
|
end
|
1235
1249
|
|
@@ -1238,26 +1252,30 @@ describe Ably::Realtime::Presence, :event_machine do
|
|
1238
1252
|
|
1239
1253
|
context ':left event' do
|
1240
1254
|
it 'emits the data defined in enter' do
|
1241
|
-
|
1242
|
-
channel_client_one.presence.
|
1243
|
-
|
1255
|
+
channel_client_two.attach do
|
1256
|
+
channel_client_one.presence.enter('data') do
|
1257
|
+
channel_client_one.presence.leave
|
1258
|
+
end
|
1244
1259
|
|
1245
|
-
|
1246
|
-
|
1247
|
-
|
1260
|
+
channel_client_two.presence.subscribe(:leave) do |message|
|
1261
|
+
expect(message.data).to eql('data')
|
1262
|
+
stop_reactor
|
1263
|
+
end
|
1248
1264
|
end
|
1249
1265
|
end
|
1250
1266
|
|
1251
1267
|
it 'emits the data defined in update' do
|
1252
|
-
|
1253
|
-
channel_client_one.presence.
|
1254
|
-
channel_client_one.presence.
|
1268
|
+
channel_client_two.attach do
|
1269
|
+
channel_client_one.presence.enter('something else') do
|
1270
|
+
channel_client_one.presence.update('data') do
|
1271
|
+
channel_client_one.presence.leave
|
1272
|
+
end
|
1255
1273
|
end
|
1256
|
-
end
|
1257
1274
|
|
1258
|
-
|
1259
|
-
|
1260
|
-
|
1275
|
+
channel_client_two.presence.subscribe(:leave) do |message|
|
1276
|
+
expect(message.data).to eql('data')
|
1277
|
+
stop_reactor
|
1278
|
+
end
|
1261
1279
|
end
|
1262
1280
|
end
|
1263
1281
|
end
|
@@ -1286,17 +1304,19 @@ describe Ably::Realtime::Presence, :event_machine do
|
|
1286
1304
|
end
|
1287
1305
|
|
1288
1306
|
it 'enters a channel and sets the data based on the provided :data option' do
|
1289
|
-
|
1290
|
-
|
1291
|
-
|
1307
|
+
channel_anonymous_client.attach do
|
1308
|
+
client_count.times do |client_id|
|
1309
|
+
presence_client_one.enter_client("client:#{client_id}", data)
|
1310
|
+
end
|
1292
1311
|
|
1293
|
-
|
1294
|
-
|
1295
|
-
|
1296
|
-
|
1312
|
+
presence_anonymous_client.subscribe(:enter) do |presence|
|
1313
|
+
expect(presence.data).to eql(data)
|
1314
|
+
clients << presence
|
1315
|
+
next unless clients.count == 5
|
1297
1316
|
|
1298
|
-
|
1299
|
-
|
1317
|
+
expect(clients.map(&:client_id).uniq.count).to eql(5)
|
1318
|
+
stop_reactor
|
1319
|
+
end
|
1300
1320
|
end
|
1301
1321
|
end
|
1302
1322
|
end
|
@@ -1307,12 +1327,12 @@ describe Ably::Realtime::Presence, :event_machine do
|
|
1307
1327
|
it 'matches the current client connection_id' do
|
1308
1328
|
channel_client_two.attach do
|
1309
1329
|
presence_client_one.enter_client(client_id)
|
1310
|
-
end
|
1311
1330
|
|
1312
|
-
|
1313
|
-
|
1314
|
-
|
1315
|
-
|
1331
|
+
presence_client_two.subscribe do |presence|
|
1332
|
+
expect(presence.client_id).to eq(client_id)
|
1333
|
+
expect(presence.connection_id).to eq(client_one.connection.id)
|
1334
|
+
stop_reactor
|
1335
|
+
end
|
1316
1336
|
end
|
1317
1337
|
end
|
1318
1338
|
end
|
@@ -1341,57 +1361,63 @@ describe Ably::Realtime::Presence, :event_machine do
|
|
1341
1361
|
it 'updates the data attribute for the member when :data option provided' do
|
1342
1362
|
updated_callback_count = 0
|
1343
1363
|
|
1344
|
-
|
1345
|
-
|
1346
|
-
presence_client_one.
|
1347
|
-
|
1364
|
+
channel_anonymous_client.attach do
|
1365
|
+
client_count.times do |client_id|
|
1366
|
+
presence_client_one.enter_client("client:#{client_id}") do
|
1367
|
+
presence_client_one.update_client("client:#{client_id}", data) do
|
1368
|
+
updated_callback_count += 1
|
1369
|
+
end
|
1348
1370
|
end
|
1349
1371
|
end
|
1350
|
-
end
|
1351
1372
|
|
1352
|
-
|
1353
|
-
|
1354
|
-
|
1355
|
-
|
1373
|
+
presence_anonymous_client.subscribe(:update) do |presence|
|
1374
|
+
expect(presence.data).to eql(data)
|
1375
|
+
clients << presence
|
1376
|
+
next unless clients.count == 5
|
1356
1377
|
|
1357
|
-
|
1358
|
-
|
1359
|
-
|
1360
|
-
|
1378
|
+
wait_until(lambda { updated_callback_count == 5 }) do
|
1379
|
+
expect(clients.map(&:client_id).uniq.count).to eql(5)
|
1380
|
+
expect(updated_callback_count).to eql(5)
|
1381
|
+
stop_reactor
|
1382
|
+
end
|
1361
1383
|
end
|
1362
1384
|
end
|
1363
1385
|
end
|
1364
1386
|
|
1365
1387
|
it 'updates the data attribute to null for the member when :data option is not provided (assumed null)' do
|
1366
|
-
|
1367
|
-
presence_client_one.
|
1368
|
-
|
1388
|
+
channel_anonymous_client.attach do
|
1389
|
+
presence_client_one.enter_client('client_1') do
|
1390
|
+
presence_client_one.update_client('client_1')
|
1391
|
+
end
|
1369
1392
|
|
1370
|
-
|
1371
|
-
|
1372
|
-
|
1373
|
-
|
1393
|
+
presence_anonymous_client.subscribe(:update) do |presence|
|
1394
|
+
expect(presence.client_id).to eql('client_1')
|
1395
|
+
expect(presence.data).to be_nil
|
1396
|
+
stop_reactor
|
1397
|
+
end
|
1374
1398
|
end
|
1375
1399
|
end
|
1376
1400
|
|
1377
1401
|
it 'enters if not already entered' do
|
1378
1402
|
updated_callback_count = 0
|
1379
1403
|
|
1380
|
-
|
1381
|
-
|
1382
|
-
|
1404
|
+
channel_anonymous_client.attach do
|
1405
|
+
client_count.times do |client_id|
|
1406
|
+
presence_client_one.update_client("client:#{client_id}", data) do
|
1407
|
+
updated_callback_count += 1
|
1408
|
+
end
|
1383
1409
|
end
|
1384
|
-
end
|
1385
1410
|
|
1386
|
-
|
1387
|
-
|
1388
|
-
|
1389
|
-
|
1411
|
+
presence_anonymous_client.subscribe(:enter) do |presence|
|
1412
|
+
expect(presence.data).to eql(data)
|
1413
|
+
clients << presence
|
1414
|
+
next unless clients.count == 5
|
1390
1415
|
|
1391
|
-
|
1392
|
-
|
1393
|
-
|
1394
|
-
|
1416
|
+
wait_until(lambda { updated_callback_count == 5 }) do
|
1417
|
+
expect(clients.map(&:client_id).uniq.count).to eql(5)
|
1418
|
+
expect(updated_callback_count).to eql(5)
|
1419
|
+
stop_reactor
|
1420
|
+
end
|
1395
1421
|
end
|
1396
1422
|
end
|
1397
1423
|
end
|
@@ -1407,23 +1433,25 @@ describe Ably::Realtime::Presence, :event_machine do
|
|
1407
1433
|
it 'emits the :leave event for each client_id' do
|
1408
1434
|
left_callback_count = 0
|
1409
1435
|
|
1410
|
-
|
1411
|
-
|
1412
|
-
presence_client_one.
|
1413
|
-
|
1436
|
+
channel_anonymous_client.attach do
|
1437
|
+
client_count.times do |client_id|
|
1438
|
+
presence_client_one.enter_client("client:#{client_id}", random_str) do
|
1439
|
+
presence_client_one.leave_client("client:#{client_id}", data) do
|
1440
|
+
left_callback_count += 1
|
1441
|
+
end
|
1414
1442
|
end
|
1415
1443
|
end
|
1416
|
-
end
|
1417
1444
|
|
1418
|
-
|
1419
|
-
|
1420
|
-
|
1421
|
-
|
1445
|
+
presence_anonymous_client.subscribe(:leave) do |presence|
|
1446
|
+
expect(presence.data).to eql(data)
|
1447
|
+
clients << presence
|
1448
|
+
next unless clients.count == 5
|
1422
1449
|
|
1423
|
-
|
1424
|
-
|
1425
|
-
|
1426
|
-
|
1450
|
+
wait_until(lambda { left_callback_count == 5 }) do
|
1451
|
+
expect(clients.map(&:client_id).uniq.count).to eql(5)
|
1452
|
+
expect(left_callback_count).to eql(5)
|
1453
|
+
stop_reactor
|
1454
|
+
end
|
1427
1455
|
end
|
1428
1456
|
end
|
1429
1457
|
end
|
@@ -1431,21 +1459,23 @@ describe Ably::Realtime::Presence, :event_machine do
|
|
1431
1459
|
it 'succeeds if that client_id has not previously entered the channel' do
|
1432
1460
|
left_callback_count = 0
|
1433
1461
|
|
1434
|
-
|
1435
|
-
|
1436
|
-
|
1462
|
+
channel_anonymous_client.attach do
|
1463
|
+
client_count.times do |client_id|
|
1464
|
+
presence_client_one.leave_client("client:#{client_id}") do
|
1465
|
+
left_callback_count += 1
|
1466
|
+
end
|
1437
1467
|
end
|
1438
|
-
end
|
1439
1468
|
|
1440
|
-
|
1441
|
-
|
1442
|
-
|
1443
|
-
|
1469
|
+
presence_anonymous_client.subscribe(:leave) do |presence|
|
1470
|
+
expect(presence.data).to be_nil
|
1471
|
+
clients << presence
|
1472
|
+
next unless clients.count == 5
|
1444
1473
|
|
1445
|
-
|
1446
|
-
|
1447
|
-
|
1448
|
-
|
1474
|
+
wait_until(lambda { left_callback_count == 5 }) do
|
1475
|
+
expect(clients.map(&:client_id).uniq.count).to eql(5)
|
1476
|
+
expect(left_callback_count).to eql(5)
|
1477
|
+
stop_reactor
|
1478
|
+
end
|
1449
1479
|
end
|
1450
1480
|
end
|
1451
1481
|
end
|
@@ -1453,39 +1483,45 @@ describe Ably::Realtime::Presence, :event_machine do
|
|
1453
1483
|
|
1454
1484
|
context 'with a new value in :data option' do
|
1455
1485
|
it 'emits the leave event with the new data value' do
|
1456
|
-
|
1457
|
-
presence_client_one.
|
1458
|
-
|
1486
|
+
channel_client_one.attach do
|
1487
|
+
presence_client_one.enter_client("client:unique", random_str) do
|
1488
|
+
presence_client_one.leave_client("client:unique", data)
|
1489
|
+
end
|
1459
1490
|
|
1460
|
-
|
1461
|
-
|
1462
|
-
|
1491
|
+
presence_client_one.subscribe(:leave) do |presence_message|
|
1492
|
+
expect(presence_message.data).to eql(data)
|
1493
|
+
stop_reactor
|
1494
|
+
end
|
1463
1495
|
end
|
1464
1496
|
end
|
1465
1497
|
end
|
1466
1498
|
|
1467
1499
|
context 'with a nil value in :data option' do
|
1468
1500
|
it 'emits the leave event with the previous value as a convenience' do
|
1469
|
-
|
1470
|
-
presence_client_one.
|
1471
|
-
|
1501
|
+
channel_client_one.attach do
|
1502
|
+
presence_client_one.enter_client("client:unique", data) do
|
1503
|
+
presence_client_one.leave_client("client:unique", nil)
|
1504
|
+
end
|
1472
1505
|
|
1473
|
-
|
1474
|
-
|
1475
|
-
|
1506
|
+
presence_client_one.subscribe(:leave) do |presence_message|
|
1507
|
+
expect(presence_message.data).to eql(data)
|
1508
|
+
stop_reactor
|
1509
|
+
end
|
1476
1510
|
end
|
1477
1511
|
end
|
1478
1512
|
end
|
1479
1513
|
|
1480
1514
|
context 'with no :data option' do
|
1481
1515
|
it 'emits the leave event with the previous value as a convenience' do
|
1482
|
-
|
1483
|
-
presence_client_one.
|
1484
|
-
|
1516
|
+
channel_client_one.attach do
|
1517
|
+
presence_client_one.enter_client("client:unique", data) do
|
1518
|
+
presence_client_one.leave_client("client:unique")
|
1519
|
+
end
|
1485
1520
|
|
1486
|
-
|
1487
|
-
|
1488
|
-
|
1521
|
+
presence_client_one.subscribe(:leave) do |presence_message|
|
1522
|
+
expect(presence_message.data).to eql(data)
|
1523
|
+
stop_reactor
|
1524
|
+
end
|
1489
1525
|
end
|
1490
1526
|
end
|
1491
1527
|
end
|
@@ -1789,7 +1825,7 @@ describe Ably::Realtime::Presence, :event_machine do
|
|
1789
1825
|
clients_entered[:client_two] += 1
|
1790
1826
|
end
|
1791
1827
|
|
1792
|
-
wait_until(
|
1828
|
+
wait_until(lambda { clients_entered[:client_one] + clients_entered[:client_two] == total_members * 2 }) do
|
1793
1829
|
presence_anonymous_client.get(wait_for_sync: true) do |anonymous_members|
|
1794
1830
|
expect(anonymous_members.count).to eq(total_members)
|
1795
1831
|
expect(anonymous_members.map(&:client_id).uniq.count).to eq(total_members)
|
@@ -1886,7 +1922,7 @@ describe Ably::Realtime::Presence, :event_machine do
|
|
1886
1922
|
context 'with no arguments' do
|
1887
1923
|
it 'removes the callback for all presence events' do
|
1888
1924
|
when_all(channel_client_one.attach, channel_client_two.attach) do
|
1889
|
-
subscribe_callback =
|
1925
|
+
subscribe_callback = lambda { raise 'Should not be called' }
|
1890
1926
|
presence_client_two.subscribe(&subscribe_callback)
|
1891
1927
|
presence_client_two.unsubscribe(&subscribe_callback)
|
1892
1928
|
|
@@ -1904,7 +1940,7 @@ describe Ably::Realtime::Presence, :event_machine do
|
|
1904
1940
|
context 'with event name' do
|
1905
1941
|
it 'removes the callback for specified presence event' do
|
1906
1942
|
when_all(channel_client_one.attach, channel_client_two.attach) do
|
1907
|
-
subscribe_callback =
|
1943
|
+
subscribe_callback = lambda { raise 'Should not be called' }
|
1908
1944
|
presence_client_two.subscribe :leave, &subscribe_callback
|
1909
1945
|
presence_client_two.unsubscribe :leave, &subscribe_callback
|
1910
1946
|
|
@@ -2299,7 +2335,7 @@ describe Ably::Realtime::Presence, :event_machine do
|
|
2299
2335
|
presence_events << [presence_message.client_id, presence_message.action.to_sym]
|
2300
2336
|
if presence_message.action == :leave
|
2301
2337
|
expect(presence_message.id).to be_nil
|
2302
|
-
expect(presence_message.timestamp.to_f * 1000).to be_within(
|
2338
|
+
expect(presence_message.timestamp.to_f * 1000).to be_within(200).of(Time.now.to_f * 1000)
|
2303
2339
|
end
|
2304
2340
|
end
|
2305
2341
|
|
@@ -2337,19 +2373,17 @@ describe Ably::Realtime::Presence, :event_machine do
|
|
2337
2373
|
let(:present_only_capability) do
|
2338
2374
|
{ channel_name => ["presence"] }
|
2339
2375
|
end
|
2340
|
-
let(:present_only_callback) {
|
2376
|
+
let(:present_only_callback) { lambda { |token_params| Ably::Rest::Client.new(client_options).auth.request_token(client_id: '*', capability: present_only_capability) } }
|
2341
2377
|
let(:client_one) { auto_close Ably::Realtime::Client.new(client_options.merge(auth_callback: present_only_callback)) }
|
2342
2378
|
|
2343
2379
|
it 'receives presence updates for all presence events generated by the current connection and the presence map is kept up to date (#RTP17a)' do
|
2344
|
-
skip 'This functionality is not yet in sandbox, see https://github.com/ably/realtime/issues/656'
|
2345
|
-
|
2346
2380
|
enter_client_ids = []
|
2347
2381
|
presence_client_one.subscribe(:enter) do |presence_message|
|
2348
2382
|
enter_client_ids << presence_message.client_id
|
2349
2383
|
end
|
2350
2384
|
|
2351
2385
|
leave_client_ids = []
|
2352
|
-
presence_client_one.subscribe(:leave) do
|
2386
|
+
presence_client_one.subscribe(:leave) do |presence_message|
|
2353
2387
|
leave_client_ids << presence_message.client_id
|
2354
2388
|
end
|
2355
2389
|
|
@@ -2751,7 +2785,7 @@ describe Ably::Realtime::Presence, :event_machine do
|
|
2751
2785
|
|
2752
2786
|
context 'channel transitions to the SUSPENDED state' do
|
2753
2787
|
let(:auth_callback) do
|
2754
|
-
|
2788
|
+
lambda do |token_params|
|
2755
2789
|
# Pause to allow presence updates to occur whilst disconnected
|
2756
2790
|
sleep 1
|
2757
2791
|
Ably::Rest::Client.new(client_options).auth.request_token
|