action_cable_client 1.2.4 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d277286f584837f71576421701bae3c0975e4eb7
4
- data.tar.gz: 78a1268989c024534d62f7518bca9ef7138f8c50
3
+ metadata.gz: 9df9f344f461e4863351dd7c78b1174923e9686c
4
+ data.tar.gz: 9e0ee80e83d868a1b86b16bf7ab23edc108ba6ca
5
5
  SHA512:
6
- metadata.gz: 167fbe1af85644521eeacd4cf5236a7970c237b929a31090ba0e39bbb79de3d99248bba8bd09bad2b6e651c293188c802eaaffaf293798c23debf69fe48e19ea
7
- data.tar.gz: d543bf29866e065d3313d0dc03f7f28061aaf3be6676a2b6c7d61b82c10f840892d421ea0bc432270830bbd77f79b5f243d9d78c1829a884c4e7646c75565ef7
6
+ metadata.gz: 803df93ecb11cb0cee7125b90bfe77ca16b44792b4b6fdebf857929208a106d57a7acfb1afccf8cd3ccc3c87d9cd3cfec094c7d22429ffdd91710be0f9117332
7
+ data.tar.gz: a1ed9a6dfc18d3845190c395aab13812300a868891a65024be39238485d5823cfd1c511522a337ff80f4131d43808394c8379fc202ed77a1fff7ab13f49f12cb
@@ -1,5 +1,10 @@
1
+ ## 1.2.6
2
+ * subscribed now is a callback instead of a boolean
3
+ * subscribed? tells whether or not the client is subscribed to the channel
4
+ * added subscribed callback which signifies when the client can start sending messages on the channel
5
+
1
6
  ## 1.2.4
2
- * Support Ruby 2.2.2
7
+ * [#3](https://github.com/NullVoxPopuli/action_cable_client/pull/3) Support Ruby 2.2.2 (@NullVoxPopuli)
3
8
 
4
9
  ## 1.2.3
5
10
  * The ping message received from the action cable server changed from being identity: _ping to type: ping
data/README.md CHANGED
@@ -42,6 +42,7 @@ This example is compatible with [this version of a small Rails app with Action C
42
42
  The available hooks to tie in to are:
43
43
  - `disconnected {}`
44
44
  - `connected {}`
45
+ - `subscribed {}`
45
46
  - `errored { |msg| }`
46
47
  - `received { |msg }`
47
48
 
@@ -21,13 +21,10 @@ class ActionCableClient
21
21
  attr_reader :_message_factory
22
22
  # The queue should store entries in the format:
23
23
  # [ action, data ]
24
- attr_accessor :message_queue, :subscribed
25
-
26
- alias subscribed? subscribed
24
+ attr_accessor :message_queue, :_subscribed, :_subscribed_callaback
27
25
 
28
26
  def_delegator :_websocket_client, :disconnect, :disconnected
29
27
  def_delegator :_websocket_client, :errback, :errored
30
- def_delegator :_websocket_client, :connection_completed, :connected?
31
28
  def_delegator :_websocket_client, :send_msg, :send_msg
32
29
 
33
30
  # @param [String] uri - e.g.: ws://domain:port
@@ -40,7 +37,7 @@ class ActionCableClient
40
37
  @_uri = uri
41
38
  @_queued_send = queued_send
42
39
  @message_queue = []
43
- @subscribed = false
40
+ @_subscribed = false
44
41
 
45
42
  @_message_factory = MessageFactory.new(channel)
46
43
  # NOTE:
@@ -95,6 +92,28 @@ class ActionCableClient
95
92
  end
96
93
  end
97
94
 
95
+ # callback when the client receives a confirm_subscription message
96
+ # from the action_cable server.
97
+ # This is only called once, and signifies that you can now send
98
+ # messages on the channel
99
+ #
100
+ # @param [Proc] block - code to run after subscribing to the channel is confirmed
101
+ #
102
+ # @example
103
+ # client = ActionCableClient.new(uri, 'RoomChannel')
104
+ # client.connected {}
105
+ # client.subscribed do
106
+ # # do things after successful subscription confirmation
107
+ # end
108
+ def subscribed(&block)
109
+ self._subscribed_callaback = block
110
+ end
111
+
112
+ # @return [Boolean] is the client subscribed to the channel?
113
+ def subscribed?
114
+ _subscribed
115
+ end
116
+
98
117
  private
99
118
 
100
119
  # @param [WebSocket::Frame::Incoming::Client] message - the websockt message object
@@ -147,7 +166,10 @@ class ActionCableClient
147
166
  # {"identifier" => "_ping","type" => "confirm_subscription"}
148
167
  def check_for_subscribe_confirmation(message)
149
168
  message_type = message[Message::TYPE_KEY]
150
- self.subscribed = true if Message::TYPE_CONFIRM_SUBSCRIPTION == message_type
169
+ if Message::TYPE_CONFIRM_SUBSCRIPTION == message_type
170
+ self._subscribed = true
171
+ _subscribed_callaback.call if _subscribed_callaback
172
+ end
151
173
  end
152
174
 
153
175
  # {"identifier" => "_ping","message" => 1460201942}
@@ -177,7 +199,8 @@ class ActionCableClient
177
199
  # can't send messages if we aren't subscribed
178
200
  if subscribed?
179
201
  msg = _message_factory.create(Commands::MESSAGE, action, data)
180
- send_msg(msg.to_json)
202
+ json = msg.to_json
203
+ send_msg(json)
181
204
  end
182
205
  end
183
206
  end
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  class ActionCableClient
3
- VERSION = '1.2.4'
3
+ VERSION = '1.3.0'
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: action_cable_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.4
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - L. Preston Sego III
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-29 00:00:00.000000000 Z
11
+ date: 2016-05-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -129,6 +129,6 @@ rubyforge_project:
129
129
  rubygems_version: 2.5.1
130
130
  signing_key:
131
131
  specification_version: 4
132
- summary: ActionCableClient-1.2.4
132
+ summary: ActionCableClient-1.3.0
133
133
  test_files: []
134
134
  has_rdoc: