ably 1.2.1 → 1.2.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.
Files changed (73) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/.rspec_parallel +3 -0
  3. data/.github/workflows/check.yml +24 -4
  4. data/.github/workflows/docs.yml +36 -0
  5. data/CHANGELOG.md +26 -0
  6. data/INTRO.md +14 -0
  7. data/ably.gemspec +1 -0
  8. data/lib/ably/auth.rb +26 -23
  9. data/lib/ably/models/auth_details.rb +9 -6
  10. data/lib/ably/models/channel_details.rb +69 -0
  11. data/lib/ably/models/channel_metrics.rb +107 -0
  12. data/lib/ably/models/channel_occupancy.rb +50 -0
  13. data/lib/ably/models/channel_options.rb +26 -3
  14. data/lib/ably/models/channel_state_change.rb +45 -15
  15. data/lib/ably/models/channel_status.rb +63 -0
  16. data/lib/ably/models/cipher_params.rb +36 -13
  17. data/lib/ably/models/connection_details.rb +91 -10
  18. data/lib/ably/models/connection_state_change.rb +54 -15
  19. data/lib/ably/models/delta_extras.rb +6 -7
  20. data/lib/ably/models/device_details.rb +60 -21
  21. data/lib/ably/models/device_push_details.rb +27 -19
  22. data/lib/ably/models/error_info.rb +59 -17
  23. data/lib/ably/models/http_paginated_response.rb +27 -5
  24. data/lib/ably/models/idiomatic_ruby_wrapper.rb +3 -2
  25. data/lib/ably/models/message.rb +64 -24
  26. data/lib/ably/models/message_encoders/base.rb +6 -0
  27. data/lib/ably/models/paginated_result.rb +29 -14
  28. data/lib/ably/models/presence_message.rb +72 -22
  29. data/lib/ably/models/protocol_message.rb +0 -4
  30. data/lib/ably/models/push_channel_subscription.rb +40 -15
  31. data/lib/ably/models/stats.rb +76 -40
  32. data/lib/ably/models/stats_types.rb +16 -40
  33. data/lib/ably/models/token_details.rb +34 -12
  34. data/lib/ably/models/token_request.rb +63 -2
  35. data/lib/ably/modules/async_wrapper.rb +1 -0
  36. data/lib/ably/modules/enum.rb +2 -0
  37. data/lib/ably/modules/event_emitter.rb +14 -1
  38. data/lib/ably/modules/model_common.rb +5 -0
  39. data/lib/ably/modules/state_emitter.rb +2 -0
  40. data/lib/ably/modules/state_machine.rb +4 -0
  41. data/lib/ably/realtime/channel/channel_properties.rb +9 -2
  42. data/lib/ably/realtime/channel/publisher.rb +2 -0
  43. data/lib/ably/realtime/channel/push_channel.rb +17 -10
  44. data/lib/ably/realtime/channel.rb +79 -42
  45. data/lib/ably/realtime/channels.rb +4 -3
  46. data/lib/ably/realtime/client/incoming_message_dispatcher.rb +6 -14
  47. data/lib/ably/realtime/client.rb +53 -32
  48. data/lib/ably/realtime/connection/connection_manager.rb +4 -0
  49. data/lib/ably/realtime/connection/websocket_transport.rb +4 -2
  50. data/lib/ably/realtime/connection.rb +94 -55
  51. data/lib/ably/realtime/presence.rb +61 -36
  52. data/lib/ably/realtime/push/admin.rb +16 -2
  53. data/lib/ably/realtime/push.rb +15 -3
  54. data/lib/ably/rest/channel/push_channel.rb +0 -3
  55. data/lib/ably/rest/channel.rb +33 -18
  56. data/lib/ably/rest/channels.rb +6 -3
  57. data/lib/ably/rest/client.rb +41 -35
  58. data/lib/ably/rest/presence.rb +27 -12
  59. data/lib/ably/rest/push/admin.rb +4 -0
  60. data/lib/ably/rest/push/device_registrations.rb +13 -2
  61. data/lib/ably/rest/push.rb +2 -0
  62. data/lib/ably/util/crypto.rb +14 -10
  63. data/lib/ably/version.rb +1 -1
  64. data/spec/acceptance/realtime/connection_spec.rb +0 -15
  65. data/spec/acceptance/realtime/message_spec.rb +3 -3
  66. data/spec/acceptance/rest/channel_spec.rb +18 -0
  67. data/spec/unit/models/channel_details_spec.rb +30 -0
  68. data/spec/unit/models/channel_metrics_spec.rb +42 -0
  69. data/spec/unit/models/channel_occupancy_spec.rb +17 -0
  70. data/spec/unit/models/channel_status_spec.rb +36 -0
  71. data/spec/unit/models/protocol_message_spec.rb +0 -26
  72. data/spec/unit/realtime/incoming_message_dispatcher_spec.rb +0 -38
  73. metadata +32 -3
@@ -3,22 +3,7 @@ require 'ably/realtime/channel/publisher'
3
3
 
4
4
  module Ably
5
5
  module Realtime
6
- # Client for the Ably Realtime API
7
- #
8
- # @!attribute [r] client_id
9
- # (see Ably::Rest::Client#client_id)
10
- # @!attribute [r] auth_options
11
- # (see Ably::Rest::Client#auth_options)
12
- # @!attribute [r] environment
13
- # (see Ably::Rest::Client#environment)
14
- # @!attribute [r] channels
15
- # @return [Aby::Realtime::Channels] The collection of {Ably::Realtime::Channel}s that have been created
16
- # @!attribute [r] encoders
17
- # (see Ably::Rest::Client#encoders)
18
- # @!attribute [r] protocol
19
- # (see Ably::Rest::Client#protocol)
20
- # @!attribute [r] protocol_binary?
21
- # (see Ably::Rest::Client#protocol_binary?)
6
+ # A client that extends the functionality of the {Ably::Realtime::Client} and provides additional realtime-specific features.
22
7
  #
23
8
  class Client
24
9
  include Ably::Modules::AsyncWrapper
@@ -29,19 +14,33 @@ module Ably
29
14
 
30
15
  DOMAIN = 'realtime.ably.io'
31
16
 
32
- # The collection of {Ably::Realtime::Channel}s that have been created
17
+ # A {Aby::Realtime::Channels} object.
18
+ #
19
+ # @spec RTC3, RTS1
20
+ #
33
21
  # @return [Aby::Realtime::Channels]
22
+ #
34
23
  attr_reader :channels
35
24
 
36
- # (see Ably::Rest::Client#auth)
25
+ # An {Ably::Auth} object.
26
+ #
27
+ # @spec RTC4
28
+ #
29
+ # @return [Ably::Auth]
30
+ #
37
31
  attr_reader :auth
38
32
 
39
- # The underlying connection for this client
33
+ # A {Aby::Realtime::Connection} object.
34
+ #
35
+ # @spec RTC2
36
+ #
40
37
  # @return [Aby::Realtime::Connection]
38
+ #
41
39
  attr_reader :connection
42
40
 
43
41
  # The {Ably::Rest::Client REST client} instantiated with the same credentials and configuration that is used for all REST operations such as authentication
44
42
  # @return [Ably::Rest::Client]
43
+
45
44
  # @private
46
45
  attr_reader :rest_client
47
46
 
@@ -78,8 +77,10 @@ module Ably
78
77
 
79
78
  # Creates a {Ably::Realtime::Client Realtime Client} and configures the {Ably::Auth} object for the connection.
80
79
  #
81
- # @param (see Ably::Rest::Client#initialize)
82
- # @option options (see Ably::Rest::Client#initialize)
80
+ # @spec RSC1
81
+ #
82
+ # @param (see {Ably::Rest::Client#initialize})
83
+ # @option options (see Ably::Rest::Client#initialize) An options {Hash} object.
83
84
  # @option options [Proc] :auth_callback when provided, the Proc will be called with the token params hash as the first argument, whenever a new token is required.
84
85
  # Whilst the proc is called synchronously, it does not block the EventMachine reactor as it is run in a separate thread.
85
86
  # The Proc should return a token string, {Ably::Models::TokenDetails} or JSON equivalent, {Ably::Models::TokenRequest} or JSON equivalent
@@ -97,10 +98,10 @@ module Ably
97
98
  # @return [Ably::Realtime::Client]
98
99
  #
99
100
  # @example
100
- # # create a new client authenticating with basic auth
101
+ # # Constructs a {Ably::Realtime::Client} object using an Ably API key or token string.
101
102
  # client = Ably::Realtime::Client.new('key.id:secret')
102
103
  #
103
- # # create a new client and configure a client ID used for presence
104
+ # # Constructs a {Ably::Realtime::Client} object using an Ably options object.
104
105
  # client = Ably::Realtime::Client.new(key: 'key.id:secret', client_id: 'john')
105
106
  #
106
107
  def initialize(options)
@@ -141,9 +142,13 @@ module Ably
141
142
  channels.get(name, channel_options)
142
143
  end
143
144
 
144
- # Retrieve the Ably service time
145
+ # Retrieves the time from the Ably service as milliseconds since the Unix epoch. Clients that do not have access
146
+ # to a sufficiently well maintained time source and wish to issue Ably {Ably::Models::TokenRequests} with
147
+ # a more accurate timestamp should use the queryTime property instead of this method.
148
+ #
149
+ # @spec RTC6a
145
150
  #
146
- # @yield [Time] The time as reported by the Ably service
151
+ # @yield [Time] The time as milliseconds since the Unix epoch.
147
152
  # @return [Ably::Util::SafeDeferrable]
148
153
  #
149
154
  def time(&success_callback)
@@ -152,12 +157,15 @@ module Ably
152
157
  end
153
158
  end
154
159
 
155
- # Retrieve the stats for the application
160
+ # Queries the REST /stats API and retrieves your application's usage statistics.
161
+ # Returns a {Ably::Util::SafeDeferrable} object, containing an array of {Ably::Models::Stats} objects. See the Stats docs.
162
+ #
163
+ # @spec RTC5
156
164
  #
157
165
  # @param (see Ably::Rest::Client#stats)
158
166
  # @option options (see Ably::Rest::Client#stats)
159
167
  #
160
- # @yield [Ably::Models::PaginatedResult<Ably::Models::Stats>] An Array of Stats
168
+ # @yield [Ably::Models::PaginatedResult<Ably::Models::Stats>] A {Ably::Util::SafeDeferrable} object containing an array of {Ably::Models::Stats} objects.
161
169
  #
162
170
  # @return [Ably::Util::SafeDeferrable]
163
171
  #
@@ -167,26 +175,38 @@ module Ably
167
175
  end
168
176
  end
169
177
 
178
+ # Calls {Connection#close} and causes the connection to close, entering the closing state.
179
+ # Once closed, the library will not attempt to re-establish the connection without an explicit call to {Connection#connect}.
180
+ # @spec RTN12
170
181
  # (see Ably::Realtime::Connection#close)
171
182
  def close(&block)
172
183
  connection.close(&block)
173
184
  end
174
185
 
186
+ # Calls {Ably::Realtime::Connection#connect} and causes the connection to open, entering the connecting
187
+ # state. Explicitly calling connect() is unnecessary unless the autoConnect property is disabled.
188
+ # @spec RTN11
175
189
  # (see Ably::Realtime::Connection#connect)
176
190
  def connect(&block)
177
191
  connection.connect(&block)
178
192
  end
179
193
 
180
- # Push notification object for publishing and managing push notifications
194
+ # A {Ably::Realtime::Push} object.
181
195
  # @return [Ably::Realtime::Push]
182
196
  def push
183
197
  @push ||= Push.new(self)
184
198
  end
185
199
 
186
- # (see Ably::Rest::Client#request)
200
+ # Makes a REST request to a provided path. This is provided as a convenience for developers who wish to use REST
201
+ # API functionality that is either not documented or is not yet included in the public API, without having to
202
+ # directly handle features such as authentication, paging, fallback hosts, MsgPack and JSON support.
203
+ #
204
+ # @spec RTC9
205
+ #
206
+ # (see {Ably::Rest::Client#request})
187
207
  # @yield [Ably::Models::HttpPaginatedResponse<>] An Array of Stats
188
208
  #
189
- # @return [Ably::Util::SafeDeferrable]
209
+ # @return [Ably::Util::SafeDeferrable] An {Ably::Util::SafeDeferrable} response object returned by the HTTP request, containing an empty or JSON-encodable object.
190
210
  def request(method, path, params = {}, body = nil, headers = {}, &callback)
191
211
  async_wrap(callback) do
192
212
  rest_client.request(method, path, params, body, headers, async_blocking_operations: true)
@@ -303,8 +323,9 @@ module Ably
303
323
  @fallback_endpoints[fallback_endpoint_index % @fallback_endpoints.count]
304
324
  end
305
325
 
306
- # The local device detilas
307
- # @return [Ably::Models::LocalDevice]
326
+ # Retrieves a {Ably::Models::LocalDevice} object that represents the current state of the device as a target for push notifications.
327
+ # @spec RSH8
328
+ # @return [Ably::Models::LocalDevice] A {Ably::Models::LocalDevice} object.
308
329
  #
309
330
  # @note This is unsupported in the Ruby library
310
331
  def device
@@ -270,7 +270,9 @@ module Ably::Realtime
270
270
  end
271
271
 
272
272
  # Number of consecutive attempts for provided state
273
+ #
273
274
  # @return [Integer]
275
+ #
274
276
  # @api private
275
277
  def retry_count_for_state(state)
276
278
  retries_for_state(state, ignore_states: [:connecting]).count
@@ -356,7 +358,9 @@ module Ably::Realtime
356
358
  end
357
359
 
358
360
  # Timers used to manage connection state, for internal use by the client library
361
+ #
359
362
  # @return [Hash]
363
+ #
360
364
  def timers
361
365
  @timers
362
366
  end
@@ -31,7 +31,9 @@ module Ably::Realtime
31
31
 
32
32
  # Disconnect the socket transport connection and write all pending text.
33
33
  # If Disconnected state is not automatically emitted, it will be emitted automatically
34
+ #
34
35
  # @return [void]
36
+ #
35
37
  # @api public
36
38
  def disconnect
37
39
  close_connection_after_writing
@@ -133,15 +135,15 @@ module Ably::Realtime
133
135
  !connecting? && !connected?
134
136
  end
135
137
 
136
- # @!attribute [r] __incoming_protocol_msgbus__
137
138
  # @return [Ably::Util::PubSub] Websocket Transport internal incoming protocol message bus
139
+ #
138
140
  # @api private
139
141
  def __incoming_protocol_msgbus__
140
142
  @__incoming_protocol_msgbus__ ||= create_pub_sub_message_bus
141
143
  end
142
144
 
143
- # @!attribute [r] __outgoing_protocol_msgbus__
144
145
  # @return [Ably::Util::PubSub] Websocket Transport internal outgoing protocol message bus
146
+ #
145
147
  # @api private
146
148
  def __outgoing_protocol_msgbus__
147
149
  @__outgoing_protocol_msgbus__ ||= create_pub_sub_message_bus
@@ -2,39 +2,7 @@ require 'securerandom'
2
2
 
3
3
  module Ably
4
4
  module Realtime
5
- # The Connection class represents the connection associated with an Ably Realtime instance.
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
- # ConnectionState
46
- # The permited states for this connection
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
- # ConnectionEvent
59
- # The permitted connection events that are emitted for this connection
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 in presence events and messages
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 this connection, assigned by Ably
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 to recover or resume a connection
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
- # When a connection failure occurs this attribute contains the Ably Exception
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 closed state, from any state except
169
- # the failed state. Once closed, the library will not attempt to re-establish the
170
- # connection without a call to {Connection#connect}.
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
- # Causes the library to attempt connection. If it was previously explicitly
187
- # closed by the user, or was closed as a result of an unrecoverable error, a new connection will be opened.
188
- # Succeeds when connection is established i.e. state is @Connected@
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
- # Note that if the connection remains in the disconnected ans suspended states indefinitely,
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
- # Sends a ping to Ably and yields the provided block when a heartbeat ping request is echoed from the server.
227
- # This can be useful for measuring true roundtrip client to Ably server latency for a simple message, or checking that an underlying transport is responding currently.
228
- # The elapsed time in seconds is passed as an argument to the block and represents the time taken to echo a ping heartbeat once the connection is in the `:connected` state.
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
- # @!attribute [r] recovery_key
316
- # @return [String] recovery key that can be used by another client to recover this connection with the :recover option
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
- # Presence provides access to presence operations and state for the associated Channel
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
- # Enter the specified client_id into this channel. The given client will be added to the
94
- # presence set and presence subscribers will see a corresponding presence message.
95
- # This method is provided to support connections (e.g. connections from application
96
- # server instances) that act on behalf of multiple client_ids. In order to be able to
97
- # enter the channel with this method, the client library must have been instanced
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 optional data (eg a status message) for this member
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
- # Leave a given client_id from this channel. This client will be removed from the
155
- # presence set and presence subscribers will see a leave message for this client.
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
- # @param (see Presence#enter_client)
158
+ # @spec RTP15
158
159
  #
159
- # @yield (see Presence#enter_client)
160
- # @return (see Presence#enter_client)
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
- # Update the presence data for this client. If the client is not already a member of
170
- # the presence set it will be added, and presence subscribers will see an enter or
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
- # @param (see Presence#enter)
175
+ # @spec RTP9
174
176
  #
175
- # @yield (see Presence#enter)
176
- # @return (see Presence#enter)
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
- # Update the presence data for a specified client_id into this channel.
201
- # If the client is not already a member of the presence set it will be added, and
202
- # presence subscribers will see an enter or update message for this client.
203
- # As with {#enter_client}, the connection must be authenticated in a way that
204
- # enables it to represent an arbitrary clientId.
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
- # Get the presence members for this Channel.
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
- # @param (see Ably::Realtime::Presence::MembersMap#get)
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
- # Subscribe to presence events on the associated Channel.
256
- # This implicitly attaches the Channel if it is not already attached.
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
- # Return the presence messages history for the channel
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
- # @param (see Ably::Rest::Presence#history)
282
- # @option options (see Ably::Rest::Presence#history)
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
- # Returns true when the initial member SYNC following channel attach is completed
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
- # Manage device registrations
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
- # Manage channel subscriptions for devices or clients
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