ably 1.2.2 → 1.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/.rspec_parallel +3 -0
- data/.github/workflows/check.yml +13 -2
- data/.github/workflows/docs.yml +36 -0
- data/CHANGELOG.md +18 -0
- data/INTRO.md +14 -0
- data/lib/ably/auth.rb +26 -23
- data/lib/ably/models/auth_details.rb +9 -6
- data/lib/ably/models/channel_details.rb +15 -5
- data/lib/ably/models/channel_metrics.rb +31 -8
- data/lib/ably/models/channel_occupancy.rb +10 -3
- data/lib/ably/models/channel_options.rb +26 -3
- data/lib/ably/models/channel_state_change.rb +45 -15
- data/lib/ably/models/channel_status.rb +14 -4
- data/lib/ably/models/cipher_params.rb +36 -13
- data/lib/ably/models/connection_details.rb +91 -10
- data/lib/ably/models/connection_state_change.rb +54 -15
- data/lib/ably/models/delta_extras.rb +6 -7
- data/lib/ably/models/device_details.rb +60 -21
- data/lib/ably/models/device_push_details.rb +27 -19
- data/lib/ably/models/error_info.rb +59 -17
- data/lib/ably/models/http_paginated_response.rb +27 -5
- data/lib/ably/models/idiomatic_ruby_wrapper.rb +3 -2
- data/lib/ably/models/message.rb +64 -24
- data/lib/ably/models/message_encoders/base.rb +6 -0
- data/lib/ably/models/paginated_result.rb +29 -14
- data/lib/ably/models/presence_message.rb +72 -22
- data/lib/ably/models/protocol_message.rb +0 -4
- data/lib/ably/models/push_channel_subscription.rb +40 -15
- data/lib/ably/models/stats.rb +76 -40
- data/lib/ably/models/stats_types.rb +16 -40
- data/lib/ably/models/token_details.rb +34 -12
- data/lib/ably/models/token_request.rb +63 -2
- data/lib/ably/modules/async_wrapper.rb +1 -0
- data/lib/ably/modules/enum.rb +2 -0
- data/lib/ably/modules/event_emitter.rb +14 -1
- data/lib/ably/modules/model_common.rb +5 -0
- data/lib/ably/modules/state_emitter.rb +2 -0
- data/lib/ably/modules/state_machine.rb +4 -0
- data/lib/ably/realtime/channel/channel_properties.rb +9 -2
- data/lib/ably/realtime/channel/publisher.rb +2 -0
- data/lib/ably/realtime/channel/push_channel.rb +17 -10
- data/lib/ably/realtime/channel.rb +79 -42
- data/lib/ably/realtime/channels.rb +4 -3
- data/lib/ably/realtime/client/incoming_message_dispatcher.rb +6 -14
- data/lib/ably/realtime/client.rb +53 -32
- data/lib/ably/realtime/connection/connection_manager.rb +4 -0
- data/lib/ably/realtime/connection/websocket_transport.rb +4 -2
- data/lib/ably/realtime/connection.rb +94 -55
- data/lib/ably/realtime/presence.rb +61 -36
- data/lib/ably/realtime/push/admin.rb +16 -2
- data/lib/ably/realtime/push.rb +15 -3
- data/lib/ably/rest/channel/push_channel.rb +0 -3
- data/lib/ably/rest/channel.rb +29 -21
- data/lib/ably/rest/channels.rb +6 -3
- data/lib/ably/rest/client.rb +41 -35
- data/lib/ably/rest/presence.rb +27 -12
- data/lib/ably/rest/push/admin.rb +4 -0
- data/lib/ably/rest/push/device_registrations.rb +13 -2
- data/lib/ably/rest/push.rb +2 -0
- data/lib/ably/util/crypto.rb +14 -10
- data/lib/ably/version.rb +1 -1
- data/spec/acceptance/realtime/connection_spec.rb +0 -15
- data/spec/acceptance/realtime/message_spec.rb +3 -3
- data/spec/unit/models/protocol_message_spec.rb +0 -26
- data/spec/unit/realtime/incoming_message_dispatcher_spec.rb +0 -38
- metadata +6 -3
@@ -2,39 +2,7 @@ require 'securerandom'
|
|
2
2
|
|
3
3
|
module Ably
|
4
4
|
module Realtime
|
5
|
-
#
|
6
|
-
# The Connection object exposes the lifecycle and parameters of the realtime connection.
|
7
|
-
#
|
8
|
-
# Connections will always be in one of the following states:
|
9
|
-
#
|
10
|
-
# initialized: 0
|
11
|
-
# connecting: 1
|
12
|
-
# connected: 2
|
13
|
-
# disconnected: 3
|
14
|
-
# suspended: 4
|
15
|
-
# closing: 5
|
16
|
-
# closed: 6
|
17
|
-
# failed: 7
|
18
|
-
#
|
19
|
-
# Note that the states are available as Enum-like constants:
|
20
|
-
#
|
21
|
-
# Connection::STATE.Initialized
|
22
|
-
# Connection::STATE.Connecting
|
23
|
-
# Connection::STATE.Connected
|
24
|
-
# Connection::STATE.Disconnected
|
25
|
-
# Connection::STATE.Suspended
|
26
|
-
# Connection::STATE.Closing
|
27
|
-
# Connection::STATE.Closed
|
28
|
-
# Connection::STATE.Failed
|
29
|
-
#
|
30
|
-
# @example
|
31
|
-
# client = Ably::Realtime::Client.new('key.id:secret')
|
32
|
-
# client.connection.on(:connected) do
|
33
|
-
# puts "Connected with connection ID: #{client.connection.id}"
|
34
|
-
# end
|
35
|
-
#
|
36
|
-
# @!attribute [r] state
|
37
|
-
# @return [Ably::Realtime::Connection::STATE] connection state
|
5
|
+
# Enables the management of a connection to Ably.
|
38
6
|
#
|
39
7
|
class Connection
|
40
8
|
include Ably::Modules::EventEmitter
|
@@ -42,8 +10,50 @@ module Ably
|
|
42
10
|
include Ably::Modules::SafeYield
|
43
11
|
extend Ably::Modules::Enum
|
44
12
|
|
45
|
-
#
|
46
|
-
#
|
13
|
+
# The current {Ably::Realtime::Connection::STATE} of the connection.
|
14
|
+
# Describes the realtime [Connection]{@link Connection} object states.
|
15
|
+
#
|
16
|
+
# @spec RTN4d
|
17
|
+
#
|
18
|
+
# INITIALIZED A connection with this state has been initialized but no connection has yet been attempted.
|
19
|
+
# CONNECTING A connection attempt has been initiated. The connecting state is entered as soon as the library
|
20
|
+
# has completed initialization, and is reentered each time connection is re-attempted following disconnection.
|
21
|
+
# CONNECTED A connection exists and is active.
|
22
|
+
# DISCONNECTED A temporary failure condition. No current connection exists because there is no network connectivity
|
23
|
+
# or no host is available. The disconnected state is entered if an established connection is dropped,
|
24
|
+
# or if a connection attempt was unsuccessful. In the disconnected state the library will periodically
|
25
|
+
# attempt to open a new connection (approximately every 15 seconds), anticipating that the connection
|
26
|
+
# will be re-established soon and thus connection and channel continuity will be possible.
|
27
|
+
# In this state, developers can continue to publish messages as they are automatically placed
|
28
|
+
# in a local queue, to be sent as soon as a connection is reestablished. Messages published by
|
29
|
+
# other clients while this client is disconnected will be delivered to it upon reconnection,
|
30
|
+
# so long as the connection was resumed within 2 minutes. After 2 minutes have elapsed, recovery
|
31
|
+
# is no longer possible and the connection will move to the SUSPENDED state.
|
32
|
+
# SUSPENDED A long term failure condition. No current connection exists because there is no network connectivity
|
33
|
+
# or no host is available. The suspended state is entered after a failed connection attempt if
|
34
|
+
# there has then been no connection for a period of two minutes. In the suspended state, the library
|
35
|
+
# will periodically attempt to open a new connection every 30 seconds. Developers are unable to
|
36
|
+
# publish messages in this state. A new connection attempt can also be triggered by an explicit
|
37
|
+
# call to {Ably::Realtime::Connection#connect}. Once the connection has been re-established,
|
38
|
+
# channels will be automatically re-attached. The client has been disconnected for too long for them
|
39
|
+
# to resume from where they left off, so if it wants to catch up on messages published by other clients
|
40
|
+
# while it was disconnected, it needs to use the History API.
|
41
|
+
# CLOSING An explicit request by the developer to close the connection has been sent to the Ably service.
|
42
|
+
# If a reply is not received from Ably within a short period of time, the connection is forcibly
|
43
|
+
# terminated and the connection state becomes CLOSED.
|
44
|
+
# CLOSED The connection has been explicitly closed by the client. In the closed state, no reconnection attempts
|
45
|
+
# are made automatically by the library, and clients may not publish messages. No connection state is
|
46
|
+
# preserved by the service or by the library. A new connection attempt can be triggered by an explicit
|
47
|
+
# call to {Ably::Realtime::Connection#connect}, which results in a new connection.
|
48
|
+
# FAILED This state is entered if the client library encounters a failure condition that it cannot recover from.
|
49
|
+
# This may be a fatal connection error received from the Ably service, for example an attempt to connect
|
50
|
+
# with an incorrect API key, or a local terminal error, for example the token in use has expired
|
51
|
+
# and the library does not have any way to renew it. In the failed state, no reconnection attempts
|
52
|
+
# are made automatically by the library, and clients may not publish messages. A new connection attempt
|
53
|
+
# can be triggered by an explicit call to {Ably::Realtime::Connection#connect}.
|
54
|
+
#
|
55
|
+
# @return [Ably::Realtime::Connection::STATE]
|
56
|
+
#
|
47
57
|
STATE = ruby_enum('STATE',
|
48
58
|
:initialized,
|
49
59
|
:connecting,
|
@@ -55,8 +65,10 @@ module Ably
|
|
55
65
|
:failed
|
56
66
|
)
|
57
67
|
|
58
|
-
#
|
59
|
-
#
|
68
|
+
# Describes the events emitted by a {Ably::Realtime::Connection} object. An event is either an UPDATE or a {Ably::Realtime::Connection::STATE}.
|
69
|
+
#
|
70
|
+
# UPDATE RTN4h An event for changes to connection conditions for which the {Ably::Realtime::Connection::STATE} does not change.
|
71
|
+
#
|
60
72
|
EVENT = ruby_enum('EVENT',
|
61
73
|
STATE.to_sym_arr + [:update]
|
62
74
|
)
|
@@ -82,20 +94,41 @@ module Ably
|
|
82
94
|
# Max number of messages to bundle in a single ProtocolMessage
|
83
95
|
MAX_PROTOCOL_MESSAGE_BATCH_SIZE = 50
|
84
96
|
|
85
|
-
# A unique public identifier for this connection, used to identify this member
|
97
|
+
# A unique public identifier for this connection, used to identify this member.
|
98
|
+
#
|
99
|
+
# @spec RTN8
|
100
|
+
#
|
86
101
|
# @return [String]
|
102
|
+
#
|
87
103
|
attr_reader :id
|
88
104
|
|
89
|
-
# A unique private connection key used to recover
|
105
|
+
# A unique private connection key used to recover or resume a connection, assigned by Ably.
|
106
|
+
# When recovering a connection explicitly, the recoveryKey is used in the recover client options as it contains
|
107
|
+
# both the key and the last message serial. This private connection key can also be used by other REST clients
|
108
|
+
# to publish on behalf of this client. See the publishing over REST on behalf of a realtime client docs for more info.
|
109
|
+
#
|
110
|
+
# @spec RTN9
|
111
|
+
#
|
90
112
|
# @return [String]
|
113
|
+
#
|
91
114
|
attr_reader :key
|
92
115
|
|
93
|
-
# The serial number of the last message to be received on this connection, used
|
116
|
+
# The serial number of the last message to be received on this connection, used automatically by the library when
|
117
|
+
# recovering or resuming a connection. When recovering a connection explicitly, the recoveryKey is used in
|
118
|
+
# the recover client options as it contains both the key and the last message serial.
|
119
|
+
#
|
120
|
+
# @spec RTN10
|
121
|
+
#
|
94
122
|
# @return [Integer]
|
123
|
+
#
|
95
124
|
attr_reader :serial
|
96
125
|
|
97
|
-
#
|
126
|
+
# An {Ably::Models::ErrorInfo} object describing the last error received if a connection failure occurs.
|
127
|
+
#
|
128
|
+
# @spec RTN14a
|
129
|
+
#
|
98
130
|
# @return [Ably::Models::ErrorInfo,Ably::Exceptions::BaseAblyException]
|
131
|
+
#
|
99
132
|
attr_reader :error_reason
|
100
133
|
|
101
134
|
# Connection details of the currently established connection
|
@@ -165,9 +198,11 @@ module Ably
|
|
165
198
|
@current_host = client.endpoint.host
|
166
199
|
end
|
167
200
|
|
168
|
-
# Causes the connection to close, entering the
|
169
|
-
#
|
170
|
-
#
|
201
|
+
# Causes the connection to close, entering the {Ably::Realtime::Connection::STATE} CLOSING state.
|
202
|
+
# Once closed, the library does not attempt to re-establish the connection without an explicit call to
|
203
|
+
# {Ably::Realtime::Connection#connect}.
|
204
|
+
#
|
205
|
+
# @spec RTN12
|
171
206
|
#
|
172
207
|
# @yield block is called as soon as this connection is in the Closed state
|
173
208
|
#
|
@@ -183,13 +218,11 @@ module Ably
|
|
183
218
|
deferrable_for_state_change_to(STATE.Closed, &success_block)
|
184
219
|
end
|
185
220
|
|
186
|
-
#
|
187
|
-
#
|
188
|
-
#
|
189
|
-
# Fails when state becomes either @Closing@, @Closed@ or @Failed@
|
221
|
+
# Explicitly calling connect() is unnecessary unless the autoConnect attribute of
|
222
|
+
# the ClientOptions object is false. Unless already connected or connecting,
|
223
|
+
# this method causes the connection to open, entering the {Ably::Realtime::Connection::STATE} CONNECTING state.
|
190
224
|
#
|
191
|
-
#
|
192
|
-
# the Deferrable or block provided may never be called
|
225
|
+
# @spec RTC1b, RTN3, RTN11
|
193
226
|
#
|
194
227
|
# @yield block is called as soon as this connection is in the Connected state
|
195
228
|
#
|
@@ -223,9 +256,11 @@ module Ably
|
|
223
256
|
end
|
224
257
|
end
|
225
258
|
|
226
|
-
#
|
227
|
-
#
|
228
|
-
#
|
259
|
+
# When connected, sends a heartbeat ping to the Ably server and executes the callback with any error
|
260
|
+
# and the response time in milliseconds when a heartbeat ping request is echoed from the server.
|
261
|
+
# This can be useful for measuring true round-trip latency to the connected Ably server.
|
262
|
+
#
|
263
|
+
# @spec RTN13
|
229
264
|
#
|
230
265
|
# @yield [Integer] if a block is passed to this method, then this block will be called once the ping heartbeat is received with the time elapsed in seconds.
|
231
266
|
# If the ping is not received within an acceptable timeframe, the block will be called with +nil+ as he first argument
|
@@ -312,8 +347,12 @@ module Ably
|
|
312
347
|
end
|
313
348
|
end
|
314
349
|
|
315
|
-
#
|
316
|
-
#
|
350
|
+
# The recovery key string can be used by another client to recover this connection's state in the recover client options property. See connection state recover options for more information.
|
351
|
+
#
|
352
|
+
# @spec RTN16b, RTN16c
|
353
|
+
#
|
354
|
+
# @return [String]
|
355
|
+
#
|
317
356
|
def recovery_key
|
318
357
|
"#{key}:#{serial}:#{client_msg_serial}" if connection_resumable?
|
319
358
|
end
|
@@ -1,5 +1,6 @@
|
|
1
1
|
module Ably::Realtime
|
2
|
-
#
|
2
|
+
# Enables the presence set to be entered and subscribed to, and the historic presence set to be retrieved for a channel.
|
3
|
+
#
|
3
4
|
class Presence
|
4
5
|
include Ably::Modules::Conversions
|
5
6
|
include Ably::Modules::EventEmitter
|
@@ -90,15 +91,14 @@ module Ably::Realtime
|
|
90
91
|
end
|
91
92
|
end
|
92
93
|
|
93
|
-
#
|
94
|
-
#
|
95
|
-
#
|
96
|
-
#
|
97
|
-
#
|
98
|
-
# either with a key, or with a token bound to the wildcard client_id
|
94
|
+
# Enters the presence set of the channel for a given clientId. Enables a single client to update presence on behalf
|
95
|
+
# of any number of clients using a single connection. The library must have been instantiated with an API key
|
96
|
+
# or a token bound to a wildcard clientId. An optional callback may be provided to notify of the success or failure of the operation.
|
97
|
+
#
|
98
|
+
# @spec RTP4, RTP14, RTP15
|
99
99
|
#
|
100
100
|
# @param [String] client_id id of the client
|
101
|
-
# @param [String,Hash,nil] data
|
101
|
+
# @param [String,Hash,nil] data The payload associated with the presence member. A JSON object of arbitrary key-value pairs that may contain metadata, and/or ancillary payloads.
|
102
102
|
#
|
103
103
|
# @yield [Ably::Realtime::Presence] On success, will call the block with this {Ably::Realtime::Presence} object
|
104
104
|
# @return [Ably::Util::SafeDeferrable] Deferrable that supports both success (callback) and failure (errback) callbacks
|
@@ -151,13 +151,16 @@ module Ably::Realtime
|
|
151
151
|
end
|
152
152
|
end
|
153
153
|
|
154
|
-
#
|
155
|
-
#
|
154
|
+
# Leaves the presence set of the channel for a given clientId. Enables a single client to update presence on behalf
|
155
|
+
# of any number of clients using a single connection. The library must have been instantiated with an API key
|
156
|
+
# or a token bound to a wildcard clientId. An optional callback may be provided to notify of the success or failure of the operation.
|
156
157
|
#
|
157
|
-
# @
|
158
|
+
# @spec RTP15
|
158
159
|
#
|
159
|
-
# @
|
160
|
-
#
|
160
|
+
# @param (see {Ably::Realtime::Presence#enter_client})
|
161
|
+
#
|
162
|
+
# @yield (see {Ably::Realtime::Presence#enter_client})
|
163
|
+
# @return (see {Ably::Realtime::Presence#enter_client})
|
161
164
|
#
|
162
165
|
def leave_client(client_id, data = nil, &success_block)
|
163
166
|
ensure_supported_client_id client_id
|
@@ -166,14 +169,15 @@ module Ably::Realtime
|
|
166
169
|
send_presence_action_for_client(Ably::Models::PresenceMessage::ACTION.Leave, client_id, data, &success_block)
|
167
170
|
end
|
168
171
|
|
169
|
-
#
|
170
|
-
#
|
171
|
-
# update message for this client.
|
172
|
+
# Updates the data payload for a presence member. If called before entering the presence set, this is treated as
|
173
|
+
# an {Ably::Realtime::Presence::STATE.Entered} event. An optional callback may be provided to notify of the success or failure of the operation.
|
172
174
|
#
|
173
|
-
# @
|
175
|
+
# @spec RTP9
|
174
176
|
#
|
175
|
-
# @
|
176
|
-
#
|
177
|
+
# @param (see {Ably::Realtime::Presence#enter})
|
178
|
+
#
|
179
|
+
# @yield (see {Ably::Realtime::Presence#enter})
|
180
|
+
# @return (see {Ably::Realtime::Presence#enter})
|
177
181
|
#
|
178
182
|
def update(data = nil, &success_block)
|
179
183
|
deferrable = create_deferrable
|
@@ -197,11 +201,12 @@ module Ably::Realtime
|
|
197
201
|
end
|
198
202
|
end
|
199
203
|
|
200
|
-
#
|
201
|
-
#
|
202
|
-
#
|
203
|
-
#
|
204
|
-
#
|
204
|
+
# Updates the data payload for a presence member using a given clientId. Enables a single client to update presence
|
205
|
+
# on behalf of any number of clients using a single connection. The library must have been instantiated with an API
|
206
|
+
# key or a token bound to a wildcard clientId. An optional callback may be provided to notify of the success
|
207
|
+
# or failure of the operation.
|
208
|
+
#
|
209
|
+
# @spec RTP15
|
205
210
|
#
|
206
211
|
# @param (see Presence#enter_client)
|
207
212
|
#
|
@@ -215,12 +220,16 @@ module Ably::Realtime
|
|
215
220
|
send_presence_action_for_client(Ably::Models::PresenceMessage::ACTION.Update, client_id, data, &success_block)
|
216
221
|
end
|
217
222
|
|
218
|
-
#
|
223
|
+
# Retrieves the current members present on the channel and the metadata for each member, such as their
|
224
|
+
# {Ably::Models::ProtocolMessage::ACTION} and ID. Returns an array of {Ably::Models::PresenceMessage} objects.
|
225
|
+
#
|
226
|
+
# @spec RTP11, RTP11c1, RTP11c2, RTP11c3
|
227
|
+
#
|
228
|
+
# @param (see {Ably::Realtime::Presence::MembersMap#get})
|
229
|
+
# @option options (see {Ably::Realtime::Presence::MembersMap#get})
|
230
|
+
# @yield (see {Ably::Realtime::Presence::MembersMap#get})
|
219
231
|
#
|
220
|
-
# @
|
221
|
-
# @option options (see Ably::Realtime::Presence::MembersMap#get)
|
222
|
-
# @yield (see Ably::Realtime::Presence::MembersMap#get)
|
223
|
-
# @return (see Ably::Realtime::Presence::MembersMap#get)
|
232
|
+
# @return (see {Ably::Realtime::Presence::MembersMap#get})
|
224
233
|
#
|
225
234
|
def get(options = {}, &block)
|
226
235
|
deferrable = create_deferrable
|
@@ -252,8 +261,11 @@ module Ably::Realtime
|
|
252
261
|
end
|
253
262
|
end
|
254
263
|
|
255
|
-
#
|
256
|
-
#
|
264
|
+
# Registers a listener that is called each time a {Ably::Models::PresenceMessage} is received on the channel,
|
265
|
+
# such as a new member entering the presence set. A callback may optionally be passed in to this call to be notified
|
266
|
+
# of success or failure of the channel {Ably::Realtime::Channel#attach} operation.
|
267
|
+
#
|
268
|
+
# @spec RTP6a, RTP6b
|
257
269
|
#
|
258
270
|
# @param actions [Ably::Models::PresenceMessage::ACTION] Optional, the state change action to subscribe to. Defaults to all presence actions
|
259
271
|
# @yield [Ably::Models::PresenceMessage] For each presence state change event, the block is called
|
@@ -266,7 +278,9 @@ module Ably::Realtime
|
|
266
278
|
end
|
267
279
|
|
268
280
|
# Unsubscribe the matching block for presence events on the associated Channel.
|
269
|
-
# If a block is not provided, all subscriptions will be unsubscribed
|
281
|
+
# If a block is not provided, all subscriptions will be unsubscribed {Ably::Models::PresenceMessage} for the channel.
|
282
|
+
#
|
283
|
+
# @spec RTP7a, RTP7b, RTE5
|
270
284
|
#
|
271
285
|
# @param actions [Ably::Models::PresenceMessage::ACTION] Optional, the state change action to subscribe to. Defaults to all presence actions
|
272
286
|
#
|
@@ -276,10 +290,15 @@ module Ably::Realtime
|
|
276
290
|
super
|
277
291
|
end
|
278
292
|
|
279
|
-
#
|
293
|
+
# Retrieves a {Ably::Models::PaginatedResult} object, containing an array of historical
|
294
|
+
# {Ably::Models::PresenceMessage} objects for the channel. If the channel is configured to persist messages,
|
295
|
+
# then presence messages can be retrieved from history for up to 72 hours in the past. If not, presence messages
|
296
|
+
# can only be retrieved from history for up to two minutes in the past.
|
280
297
|
#
|
281
|
-
# @
|
282
|
-
#
|
298
|
+
# @spec RTP12c, RTP12a
|
299
|
+
#
|
300
|
+
# @param (see {Ably::Rest::Presence#history})
|
301
|
+
# @option options (see {Ably::Rest::Presence#history})
|
283
302
|
#
|
284
303
|
# @yield [Ably::Models::PaginatedResult<Ably::Models::PresenceMessage>] First {Ably::Models::PaginatedResult page} of {Ably::Models::PresenceMessage} objects accessible with {Ably::Models::PaginatedResult#items #items}.
|
285
304
|
#
|
@@ -306,7 +325,13 @@ module Ably::Realtime
|
|
306
325
|
client.logger
|
307
326
|
end
|
308
327
|
|
309
|
-
#
|
328
|
+
# Indicates whether the presence set synchronization between Ably and the clients on the channel has been completed.
|
329
|
+
# Set to true when the sync is complete.
|
330
|
+
#
|
331
|
+
# @spec RTP13
|
332
|
+
#
|
333
|
+
# return [Boolean]
|
334
|
+
#
|
310
335
|
def sync_complete?
|
311
336
|
members.sync_complete?
|
312
337
|
end
|
@@ -5,6 +5,7 @@ module Ably::Realtime
|
|
5
5
|
class Push
|
6
6
|
# Class providing push notification administrative functionality
|
7
7
|
# for registering devices and attaching to channels etc.
|
8
|
+
#
|
8
9
|
class Admin
|
9
10
|
include Ably::Modules::AsyncWrapper
|
10
11
|
include Ably::Modules::Conversions
|
@@ -20,9 +21,14 @@ module Ably::Realtime
|
|
20
21
|
@client = push.client
|
21
22
|
end
|
22
23
|
|
24
|
+
# Sends a push notification directly to a device, or a group of devices sharing the same clientId.
|
25
|
+
#
|
23
26
|
# (see Ably::Rest::Push#publish)
|
24
27
|
#
|
28
|
+
# @spec RSH1a
|
29
|
+
#
|
25
30
|
# @yield Block is invoked upon successful publish of the message
|
31
|
+
#
|
26
32
|
# @return [Ably::Util::SafeDeferrable]
|
27
33
|
#
|
28
34
|
def publish(recipient, data, &callback)
|
@@ -36,14 +42,22 @@ module Ably::Realtime
|
|
36
42
|
end
|
37
43
|
end
|
38
44
|
|
39
|
-
#
|
45
|
+
# A {Ably::Realtime::Push::DeviceRegistrations} object.
|
46
|
+
#
|
47
|
+
# @spec RSH1b
|
48
|
+
#
|
40
49
|
# @return [Ably::Realtime::Push::DeviceRegistrations]
|
50
|
+
#
|
41
51
|
def device_registrations
|
42
52
|
@device_registrations ||= DeviceRegistrations.new(self)
|
43
53
|
end
|
44
54
|
|
45
|
-
#
|
55
|
+
# A {Ably::Realtime::Push::ChannelSubscriptions} object.
|
56
|
+
#
|
57
|
+
# @spec RSH1c
|
58
|
+
#
|
46
59
|
# @return [Ably::Realtime::Push::ChannelSubscriptions]
|
60
|
+
#
|
47
61
|
def channel_subscriptions
|
48
62
|
@channel_subscriptions ||= ChannelSubscriptions.new(self)
|
49
63
|
end
|
data/lib/ably/realtime/push.rb
CHANGED
@@ -11,27 +11,39 @@ module Ably
|
|
11
11
|
@client = client
|
12
12
|
end
|
13
13
|
|
14
|
-
# Admin
|
14
|
+
# A {Ably::Realtime::Push::Admin} object.
|
15
|
+
#
|
16
|
+
# @spec RSH1
|
17
|
+
#
|
15
18
|
# @return [Ably::Realtime::Push::Admin]
|
19
|
+
#
|
16
20
|
def admin
|
17
21
|
@admin ||= Admin.new(self)
|
18
22
|
end
|
19
23
|
|
20
|
-
#
|
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
|
21
28
|
#
|
22
29
|
# @note This is unsupported in the Ruby library
|
30
|
+
#
|
23
31
|
def activate(*arg)
|
24
32
|
raise_unsupported
|
25
33
|
end
|
26
34
|
|
27
|
-
#
|
35
|
+
# Deactivates the device from receiving push notifications with Ably and FCM or APNS.
|
36
|
+
#
|
37
|
+
# @spec RSH2b
|
28
38
|
#
|
29
39
|
# @note This is unsupported in the Ruby library
|
40
|
+
#
|
30
41
|
def deactivate(*arg)
|
31
42
|
raise_unsupported
|
32
43
|
end
|
33
44
|
|
34
45
|
private
|
46
|
+
|
35
47
|
def raise_unsupported
|
36
48
|
raise Ably::Exceptions::PushNotificationsNotSupported, 'This device does not support receiving or subscribing to push notifications. All PushChannel methods are unavailable'
|
37
49
|
end
|
data/lib/ably/rest/channel.rb
CHANGED
@@ -1,12 +1,7 @@
|
|
1
1
|
module Ably
|
2
2
|
module Rest
|
3
|
-
#
|
4
|
-
# Channels are the "unit" of message distribution; clients attach to channels to subscribe to messages, and every message broadcast by the service is associated with a unique channel.
|
3
|
+
# Enables messages to be published and historic messages to be retrieved for a channel.
|
5
4
|
#
|
6
|
-
# @!attribute [r] name
|
7
|
-
# @return {String} channel name
|
8
|
-
# @!attribute [r] options
|
9
|
-
# @return {Hash} channel options configured for this channel, see {#initialize} for channel_options
|
10
5
|
class Channel
|
11
6
|
include Ably::Modules::Conversions
|
12
7
|
|
@@ -15,9 +10,14 @@ module Ably
|
|
15
10
|
# @api private
|
16
11
|
attr_reader :client
|
17
12
|
|
18
|
-
|
13
|
+
# The channel name.
|
14
|
+
# @return [String]
|
15
|
+
attr_reader :name
|
19
16
|
|
20
|
-
|
17
|
+
attr_reader :options
|
18
|
+
|
19
|
+
# A {Ably::Rest::Channel::PushChannel} object
|
20
|
+
# @spec RSH4
|
21
21
|
# @return [Ably::Rest::Channel::PushChannel]
|
22
22
|
# @api private
|
23
23
|
attr_reader :push
|
@@ -39,7 +39,10 @@ module Ably
|
|
39
39
|
@push = PushChannel.new(self)
|
40
40
|
end
|
41
41
|
|
42
|
-
#
|
42
|
+
# Publishes a message to the channel. A callback may optionally be passed in to this call to be notified of success or failure of the operation.
|
43
|
+
#
|
44
|
+
# @spec RSL1
|
45
|
+
#
|
43
46
|
# @param name [String, Array<Ably::Models::Message|Hash>, Ably::Models::Message, nil] The event name of the message to publish, or an Array of [Ably::Model::Message] objects or [Hash] objects with +:name+ and +:data+ pairs, or a single Ably::Model::Message object
|
44
47
|
# @param data [String, Array, Hash, nil] The message payload unless an Array of [Ably::Model::Message] objects passed in the first argument, in which case an optional hash of query parameters
|
45
48
|
# @param attributes [Hash, nil] Optional additional message attributes such as :extras, :id, :client_id or :connection_id, applied when name attribute is nil or a string (Deprecated, will be removed in 2.0 in favour of constructing a Message object)
|
@@ -112,15 +115,19 @@ module Ably
|
|
112
115
|
[201, 204].include?(response.status)
|
113
116
|
end
|
114
117
|
|
115
|
-
#
|
118
|
+
# Retrieves a {Ably::Models::PaginatedResult} object, containing an array of historical {Ably::Models::Message}
|
119
|
+
# objects for the channel. If the channel is configured to persist messages, then messages can be retrieved from
|
120
|
+
# history for up to 72 hours in the past. If not, messages can only be retrieved from history for up to two minutes in the past.
|
121
|
+
#
|
122
|
+
# @spec RSL2a
|
116
123
|
#
|
117
124
|
# @param [Hash] options the options for the message history request
|
118
|
-
# @option options [Integer,Time] :start
|
119
|
-
# @option options [Integer,Time] :end
|
120
|
-
# @option options [Symbol] :direction
|
121
|
-
# @option options [Integer] :limit
|
125
|
+
# @option options [Integer,Time] :start The time from which messages are retrieved, specified as milliseconds since the Unix epoch. RSL2b1
|
126
|
+
# @option options [Integer,Time] :end The time until messages are retrieved, specified as milliseconds since the Unix epoch. RSL2b1
|
127
|
+
# @option options [Symbol] :direction The order for which messages are returned in. Valid values are backwards which orders messages from most recent to oldest, or forwards which orders messages from oldest to most recent. The default is backwards. RSL2b2
|
128
|
+
# @option options [Integer] :limit An upper limit on the number of messages returned. The default is 100, and the maximum is 1000. RSL2b3
|
122
129
|
#
|
123
|
-
# @return [Ably::Models::PaginatedResult<Ably::Models::Message>]
|
130
|
+
# @return [Ably::Models::PaginatedResult<Ably::Models::Message>] A {Ably::Models::PaginatedResult} object containing an array of {Ably::Models::Message} objects.
|
124
131
|
#
|
125
132
|
def history(options = {})
|
126
133
|
url = "#{base_path}/messages"
|
@@ -146,14 +153,15 @@ module Ably
|
|
146
153
|
end
|
147
154
|
end
|
148
155
|
|
149
|
-
#
|
150
|
-
#
|
156
|
+
# A {Ably::Rest::Presence} object.
|
157
|
+
# @spec RSL3
|
151
158
|
# @return [Ably::Rest::Presence]
|
152
159
|
def presence
|
153
160
|
@presence ||= Presence.new(client, self)
|
154
161
|
end
|
155
162
|
|
156
|
-
# Sets
|
163
|
+
# Sets the {Ably::Models::ChannelOptions} for the channel.
|
164
|
+
# @spec RSL7
|
157
165
|
# @param channel_options [Hash, Ably::Models::ChannelOptions] A hash of options or a {Ably::Models::ChannelOptions}
|
158
166
|
# @return [Ably::Models::ChannelOptions]
|
159
167
|
def set_options(channel_options)
|
@@ -161,9 +169,9 @@ module Ably
|
|
161
169
|
end
|
162
170
|
alias options= set_options
|
163
171
|
|
164
|
-
#
|
165
|
-
#
|
166
|
-
# @return [Ably::Models::ChannelDetails]
|
172
|
+
# Retrieves a {Ably::Models::ChannelDetails} object for the channel, which includes status and occupancy metrics.
|
173
|
+
# @spec RSL8
|
174
|
+
# @return [Ably::Models::ChannelDetails] A {Ably::Models::ChannelDetails} object.
|
167
175
|
def status
|
168
176
|
Ably::Models::ChannelDetails.new(client.get(base_path).body)
|
169
177
|
end
|
data/lib/ably/rest/channels.rb
CHANGED
@@ -8,24 +8,26 @@ module Ably
|
|
8
8
|
super client, Ably::Rest::Channel
|
9
9
|
end
|
10
10
|
|
11
|
-
# @!method get(name, channel_options = {})
|
12
11
|
# Return a {Ably::Rest::Channel} for the given name
|
13
12
|
#
|
14
13
|
# @param name [String] The name of the channel
|
15
14
|
# @param channel_options [Hash] Channel options, currently reserved for Encryption options
|
16
|
-
#
|
15
|
+
#
|
16
|
+
# @return [Ably::Rest::Channel]
|
17
|
+
#
|
17
18
|
def get(*args)
|
18
19
|
super
|
19
20
|
end
|
20
21
|
|
21
|
-
# @!method fetch(name, &missing_block)
|
22
22
|
# Return a {Ably::Rest::Channel} for the given name if it exists, else the block will be called.
|
23
23
|
# This method is intentionally similar to {http://ruby-doc.org/core-2.1.3/Hash.html#method-i-fetch Hash#fetch} providing a simple way to check if a channel exists or not without creating one
|
24
24
|
#
|
25
25
|
# @param name [String] The name of the channel
|
26
26
|
# @yield [options] (optional) if a missing_block is passed to this method and no channel exists matching the name, this block is called
|
27
27
|
# @yieldparam [String] name of the missing channel
|
28
|
+
#
|
28
29
|
# @return [Ably::Rest::Channel]
|
30
|
+
#
|
29
31
|
def fetch(*args)
|
30
32
|
super
|
31
33
|
end
|
@@ -36,6 +38,7 @@ module Ably
|
|
36
38
|
# {Ably::Rest::Channel} object. Explicitly release channels to free up resources if required
|
37
39
|
#
|
38
40
|
# @return [void]
|
41
|
+
#
|
39
42
|
def release(*args)
|
40
43
|
super
|
41
44
|
end
|