ably 1.2.5 → 1.2.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/check.yml +1 -1
- data/CHANGELOG.md +17 -0
- data/README.md +24 -7
- data/SPEC.md +1722 -853
- data/ably.gemspec +1 -1
- data/lib/ably/auth.rb +19 -11
- data/lib/ably/models/protocol_message.rb +5 -26
- data/lib/ably/modules/safe_deferrable.rb +2 -2
- data/lib/ably/modules/state_emitter.rb +1 -1
- data/lib/ably/realtime/auth.rb +4 -0
- data/lib/ably/realtime/channel/channel_manager.rb +51 -48
- data/lib/ably/realtime/channel/channel_properties.rb +9 -0
- data/lib/ably/realtime/channel/channel_state_machine.rb +2 -0
- data/lib/ably/realtime/channel.rb +4 -3
- data/lib/ably/realtime/channels.rb +20 -0
- data/lib/ably/realtime/client/incoming_message_dispatcher.rb +14 -13
- data/lib/ably/realtime/client.rb +14 -6
- data/lib/ably/realtime/connection/connection_manager.rb +21 -22
- data/lib/ably/realtime/connection.rb +77 -109
- data/lib/ably/realtime/presence/members_map.rb +41 -92
- data/lib/ably/realtime/presence/presence_manager.rb +12 -17
- data/lib/ably/realtime/presence.rb +15 -6
- data/lib/ably/realtime/push.rb +0 -27
- data/lib/ably/realtime/recovery_key_context.rb +36 -0
- data/lib/ably/rest/client.rb +4 -6
- data/lib/ably/rest/push/admin.rb +1 -1
- data/lib/ably/rest/push.rb +0 -19
- data/lib/ably/util/ably_extensions.rb +29 -0
- data/lib/ably/util/crypto.rb +2 -2
- data/lib/ably/util/safe_deferrable.rb +1 -1
- data/lib/ably/version.rb +5 -7
- data/spec/acceptance/realtime/channel_history_spec.rb +8 -12
- data/spec/acceptance/realtime/channel_spec.rb +474 -300
- data/spec/acceptance/realtime/client_spec.rb +1 -1
- data/spec/acceptance/realtime/connection_failures_spec.rb +8 -25
- data/spec/acceptance/realtime/connection_spec.rb +28 -120
- data/spec/acceptance/realtime/message_spec.rb +23 -52
- data/spec/acceptance/realtime/presence_spec.rb +123 -92
- data/spec/acceptance/rest/channel_spec.rb +2 -2
- data/spec/acceptance/rest/client_spec.rb +9 -2
- data/spec/acceptance/rest/message_spec.rb +8 -11
- data/spec/acceptance/rest/push_admin_spec.rb +20 -15
- data/spec/shared/client_initializer_behaviour.rb +1 -1
- data/spec/support/markdown_spec_formatter.rb +1 -1
- data/spec/unit/models/protocol_message_spec.rb +0 -78
- data/spec/unit/models/token_details_spec.rb +4 -2
- data/spec/unit/realtime/channels_spec.rb +1 -1
- data/spec/unit/realtime/connection_spec.rb +0 -30
- data/spec/unit/realtime/recovery_key_context_spec.rb +36 -0
- data/spec/unit/util/crypto_spec.rb +15 -15
- metadata +9 -9
- data/spec/acceptance/realtime/push_spec.rb +0 -27
- data/spec/acceptance/rest/push_spec.rb +0 -25
data/lib/ably/realtime/push.rb
CHANGED
@@ -20,33 +20,6 @@ module Ably
|
|
20
20
|
def admin
|
21
21
|
@admin ||= Admin.new(self)
|
22
22
|
end
|
23
|
-
|
24
|
-
# Activates the device for push notifications with FCM or APNS, obtaining a unique identifier from them.
|
25
|
-
# Subsequently registers the device with Ably and stores the deviceIdentityToken in local storage.
|
26
|
-
#
|
27
|
-
# @spec RSH2a
|
28
|
-
#
|
29
|
-
# @note This is unsupported in the Ruby library
|
30
|
-
#
|
31
|
-
def activate(*arg)
|
32
|
-
raise_unsupported
|
33
|
-
end
|
34
|
-
|
35
|
-
# Deactivates the device from receiving push notifications with Ably and FCM or APNS.
|
36
|
-
#
|
37
|
-
# @spec RSH2b
|
38
|
-
#
|
39
|
-
# @note This is unsupported in the Ruby library
|
40
|
-
#
|
41
|
-
def deactivate(*arg)
|
42
|
-
raise_unsupported
|
43
|
-
end
|
44
|
-
|
45
|
-
private
|
46
|
-
|
47
|
-
def raise_unsupported
|
48
|
-
raise Ably::Exceptions::PushNotificationsNotSupported, 'This device does not support receiving or subscribing to push notifications. All PushChannel methods are unavailable'
|
49
|
-
end
|
50
23
|
end
|
51
24
|
end
|
52
25
|
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'json'
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module Ably
|
5
|
+
module Realtime
|
6
|
+
class RecoveryKeyContext
|
7
|
+
attr_reader :connection_key
|
8
|
+
attr_reader :msg_serial
|
9
|
+
attr_reader :channel_serials
|
10
|
+
|
11
|
+
def initialize(connection_key, msg_serial, channel_serials)
|
12
|
+
@connection_key = connection_key
|
13
|
+
@msg_serial = msg_serial
|
14
|
+
@channel_serials = channel_serials
|
15
|
+
if @channel_serials.nil?
|
16
|
+
@channel_serials = {}
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def to_json
|
21
|
+
{ 'connection_key' => @connection_key, 'msg_serial' => @msg_serial, 'channel_serials' => @channel_serials }.to_json
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.from_json(obj, logger = nil)
|
25
|
+
begin
|
26
|
+
data = JSON.load obj
|
27
|
+
self.new data['connection_key'], data['msg_serial'], data['channel_serials']
|
28
|
+
rescue => e
|
29
|
+
logger.warn "unable to decode recovery key, found error #{e}" unless logger.nil?
|
30
|
+
return nil
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/lib/ably/rest/client.rb
CHANGED
@@ -16,6 +16,7 @@ module Ably
|
|
16
16
|
include Ably::Modules::Conversions
|
17
17
|
include Ably::Modules::HttpHelpers
|
18
18
|
extend Forwardable
|
19
|
+
using Ably::Util::AblyExtensions
|
19
20
|
|
20
21
|
# Default Ably domain for REST
|
21
22
|
DOMAIN = 'rest.ably.io'
|
@@ -186,7 +187,7 @@ module Ably
|
|
186
187
|
|
187
188
|
@agent = options.delete(:agent) || Ably::AGENT
|
188
189
|
@realtime_client = options.delete(:realtime_client)
|
189
|
-
@tls = options.
|
190
|
+
@tls = options.delete_with_default(:tls, true)
|
190
191
|
@environment = options.delete(:environment) # nil is production
|
191
192
|
@environment = nil if [:production, 'production'].include?(@environment)
|
192
193
|
@protocol = options.delete(:protocol) || :msgpack
|
@@ -200,10 +201,7 @@ module Ably
|
|
200
201
|
@log_retries_as_info = options.delete(:log_retries_as_info)
|
201
202
|
@max_message_size = options.delete(:max_message_size) || MAX_MESSAGE_SIZE
|
202
203
|
@max_frame_size = options.delete(:max_frame_size) || MAX_FRAME_SIZE
|
203
|
-
|
204
|
-
if (@idempotent_rest_publishing = options.delete(:idempotent_rest_publishing)).nil?
|
205
|
-
@idempotent_rest_publishing = Ably::PROTOCOL_VERSION.to_f > 1.1
|
206
|
-
end
|
204
|
+
@idempotent_rest_publishing = options.delete_with_default(:idempotent_rest_publishing, true)
|
207
205
|
|
208
206
|
if options[:fallback_hosts_use_default] && options[:fallback_hosts]
|
209
207
|
raise ArgumentError, "fallback_hosts_use_default cannot be set to try when fallback_hosts is also provided"
|
@@ -599,7 +597,7 @@ module Ably
|
|
599
597
|
end
|
600
598
|
unless options[:send_auth_header] == false
|
601
599
|
request.headers[:authorization] = auth.auth_header
|
602
|
-
|
600
|
+
# RSA7e2
|
603
601
|
options[:headers].to_h.merge(auth.extra_auth_headers).map do |key, val|
|
604
602
|
request.headers[key] = val
|
605
603
|
end
|
data/lib/ably/rest/push/admin.rb
CHANGED
@@ -21,7 +21,7 @@ module Ably::Rest
|
|
21
21
|
|
22
22
|
# Publish a push message directly to a single recipient
|
23
23
|
#
|
24
|
-
# @param recipient [Hash] A recipient device, client_id or raw APNS/
|
24
|
+
# @param recipient [Hash] A recipient device, client_id or raw APNS/FCM/web target. Refer to push documentation
|
25
25
|
# @param data [Hash] The notification payload data and fields. Refer to push documentation
|
26
26
|
#
|
27
27
|
# @return [void]
|
data/lib/ably/rest/push.rb
CHANGED
@@ -20,25 +20,6 @@ module Ably
|
|
20
20
|
def admin
|
21
21
|
@admin ||= Admin.new(self)
|
22
22
|
end
|
23
|
-
|
24
|
-
# Activate this device for push notifications by registering with the push transport such as GCM/APNS
|
25
|
-
#
|
26
|
-
# @note This is unsupported in the Ruby library
|
27
|
-
def activate(*arg)
|
28
|
-
raise_unsupported
|
29
|
-
end
|
30
|
-
|
31
|
-
# Deactivate this device for push notifications by removing the registration with the push transport such as GCM/APNS
|
32
|
-
#
|
33
|
-
# @note This is unsupported in the Ruby library
|
34
|
-
def deactivate(*arg)
|
35
|
-
raise_unsupported
|
36
|
-
end
|
37
|
-
|
38
|
-
private
|
39
|
-
def raise_unsupported
|
40
|
-
raise Ably::Exceptions::PushNotificationsNotSupported, 'This device does not support receiving or subscribing to push notifications. All PushChannel methods are unavailable'
|
41
|
-
end
|
42
23
|
end
|
43
24
|
end
|
44
25
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Ably::Util
|
4
|
+
module AblyExtensions
|
5
|
+
refine Object do
|
6
|
+
def nil_or_empty?
|
7
|
+
self.nil? || self.empty?
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
refine Hash do
|
12
|
+
def fetch_with_default(key, default)
|
13
|
+
value = self.fetch(key, default)
|
14
|
+
if value.nil?
|
15
|
+
return default
|
16
|
+
end
|
17
|
+
return value
|
18
|
+
end
|
19
|
+
|
20
|
+
def delete_with_default(key, default)
|
21
|
+
value = self.delete(key)
|
22
|
+
if value.nil?
|
23
|
+
return default
|
24
|
+
end
|
25
|
+
return value
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/lib/ably/util/crypto.rb
CHANGED
@@ -83,8 +83,8 @@ module Ably::Util
|
|
83
83
|
cipher.key = key
|
84
84
|
iv = encrypt_options[:iv] || fixed_iv || cipher.random_iv
|
85
85
|
cipher.iv = iv
|
86
|
-
|
87
|
-
iv << cipher.
|
86
|
+
iv << cipher.update(payload) unless payload.empty?
|
87
|
+
iv << cipher.final
|
88
88
|
end
|
89
89
|
|
90
90
|
# Decrypt payload using configured Cipher
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module Ably::Util
|
2
2
|
# SafeDeferrable class provides a Deferrable that is safe to use for for public interfaces
|
3
|
-
# of this client library.
|
3
|
+
# of this client library. Any exceptions raised in the success or failure callbacks are
|
4
4
|
# caught and logged to the provided logger.
|
5
5
|
#
|
6
6
|
# An exception in a callback provided by a developer should not break this client library
|
data/lib/ably/version.rb
CHANGED
@@ -1,9 +1,7 @@
|
|
1
1
|
module Ably
|
2
|
-
VERSION = '1.2.
|
3
|
-
|
4
|
-
|
5
|
-
#
|
6
|
-
|
7
|
-
VERSION.gsub(/\.\d+$/, '').to_f
|
8
|
-
end
|
2
|
+
VERSION = '1.2.6'
|
3
|
+
# The level of compatibility with the Ably service that this SDK supports.
|
4
|
+
# Also referred to as the 'wire protocol version'.
|
5
|
+
# spec : CSV2
|
6
|
+
PROTOCOL_VERSION = '2'
|
9
7
|
end
|
@@ -184,26 +184,22 @@ describe Ably::Realtime::Channel, '#history', :event_machine do
|
|
184
184
|
end
|
185
185
|
|
186
186
|
context 'when channel receives update event after an attachment' do
|
187
|
+
old_attach_serial = ""
|
188
|
+
new_attach_serial = "xxxx-xxxx-1"
|
187
189
|
before do
|
188
190
|
channel.on(:attached) do
|
189
|
-
channel.
|
190
|
-
|
191
|
-
|
192
|
-
client.connection.__incoming_protocol_msgbus__.publish :protocol_message, attached_message
|
193
|
-
end
|
191
|
+
old_attach_serial = channel.properties.attach_serial
|
192
|
+
attached_message = Ably::Models::ProtocolMessage.new(action: 11, channel: channel_name, flags: 0, channel_serial: new_attach_serial)
|
193
|
+
client.connection.__incoming_protocol_msgbus__.publish :protocol_message, attached_message
|
194
194
|
end
|
195
195
|
end
|
196
196
|
|
197
197
|
it 'updates attach_serial' do
|
198
|
-
rest_channel.publish event, message_before_attach
|
199
|
-
|
200
198
|
channel.on(:update) do
|
201
|
-
channel.
|
202
|
-
|
203
|
-
|
204
|
-
end
|
199
|
+
expect(channel.properties.attach_serial).not_to eq(old_attach_serial)
|
200
|
+
expect(channel.properties.attach_serial).to eq(new_attach_serial)
|
201
|
+
stop_reactor
|
205
202
|
end
|
206
|
-
|
207
203
|
channel.attach
|
208
204
|
end
|
209
205
|
end
|