action_cable_client 2.0.2 → 3.0.1

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
- SHA1:
3
- metadata.gz: ce107c85e351970c2f8f0b4dec9608c75d78384c
4
- data.tar.gz: cff39593ed8b01083d87c438617e3a8d073559db
2
+ SHA256:
3
+ metadata.gz: ef3930c35f391add154d196da2d779e1e51aab9e710c97e138f743cf8aac8be7
4
+ data.tar.gz: 81e73f0c6aa96c39d2aafac68e03f08f3c15f7920bba10449711dc28cb21bddd
5
5
  SHA512:
6
- metadata.gz: 8fa7c5702425a8494356236f444f10403a8f5bd21ae4029b3d3965c08e5f344830ab83dc05573b2ad32c29012820a215aac6383c26c8d61a542f33f6995311d7
7
- data.tar.gz: c1f15938485dbe86c96abff5e0b922a4c270400f76d7202cc87e194e6513da934f9f5f467f6778edd960b982f8e22c4f0aa2c19427c3cfa48f4a4917eaeb9827
6
+ metadata.gz: 3a8835181f1d80da858441ad174571642791b5491cb734cdb9c9c660248d0d02b611000c18d456a1c20a6dab0502986226b30931e52bd2c1c7948c3242d7b00b
7
+ data.tar.gz: 4c5135c08c26bf4bb12dc3289b5bc024b03efa962b0617f6a21493b44683bec046dc8007971c5eb4cc76a21b69a14b3df996ee09b5fb5becbd0818f02eab9fef
@@ -1,3 +1,11 @@
1
+ ## 3.0.1
2
+
3
+ * [#27](https://github.com/NullVoxPopuli/action_cable_client/pull/27)
4
+ * Implement reconnect
5
+ * Fix issue with subscribing only working on initial connection
6
+ * Additional Tests
7
+ * Drop support for Ruby 2.2
8
+
1
9
  ## 2.0.2
2
10
 
3
11
  * [#24](https://github.com/NullVoxPopuli/action_cable_client/pull/24) Fix bug where action cable client is too fast for the server and doesn't wait for the server's welcome message before initiating a channel subscription (@wpp)
data/README.md CHANGED
@@ -16,9 +16,7 @@ EventMachine.run do
16
16
 
17
17
  uri = "ws://localhost:3000/cable/"
18
18
  client = ActionCableClient.new(uri, 'RoomChannel')
19
- # the connected callback is required, as it triggers
20
- # the actual subscribing to the channel but it can just be
21
- # client.connected {}
19
+ # called whenever a welcome message is received from the server
22
20
  client.connected { puts 'successfully connected.' }
23
21
 
24
22
  # called whenever a message is received from the server
@@ -62,7 +60,7 @@ end
62
60
  To reconnect,
63
61
 
64
62
  ```ruby
65
- client.connect!
63
+ client.reconnect!
66
64
  ```
67
65
 
68
66
  #### Sending additional params
@@ -22,7 +22,8 @@ class ActionCableClient
22
22
  attr_reader :_message_factory
23
23
  # The queue should store entries in the format:
24
24
  # [ action, data ]
25
- attr_accessor :message_queue, :_subscribed, :_subscribed_callback, :_pinged_callback, :_connected_callback
25
+ attr_accessor :message_queue, :_subscribed
26
+ attr_accessor :_subscribed_callback, :_pinged_callback, :_connected_callback, :_disconnected_callback
26
27
 
27
28
  def_delegator :_websocket_client, :onerror, :errored
28
29
  def_delegator :_websocket_client, :send, :send_msg
@@ -58,6 +59,17 @@ class ActionCableClient
58
59
  # - ping - sends a ping
59
60
  # - pong - sends a pong
60
61
  @_websocket_client = WebSocket::EventMachine::Client.connect(uri: @_uri, headers: headers)
62
+
63
+ @_websocket_client.onclose do
64
+ self._subscribed = false
65
+ _disconnected_callback&.call
66
+ end
67
+ end
68
+
69
+ def reconnect!
70
+ uri = URI(@_uri)
71
+ EventMachine.reconnect uri.host, uri.port, @_websocket_client
72
+ @_websocket_client.post_init
61
73
  end
62
74
 
63
75
  # @param [String] action - how the message is being sent
@@ -91,9 +103,8 @@ class ActionCableClient
91
103
  # # do things after the client is connected to the server
92
104
  # end
93
105
  def connected
94
- self._connected_callback = Proc.new do
95
- subscribe
96
- yield
106
+ self._connected_callback = proc do |json|
107
+ yield(json)
97
108
  end
98
109
  end
99
110
 
@@ -128,8 +139,7 @@ class ActionCableClient
128
139
  # # cleanup after the server disconnects from the client
129
140
  # end
130
141
  def disconnected
131
- _websocket_client.onclose do
132
- self._subscribed = false
142
+ self._disconnected_callback = proc do
133
143
  yield
134
144
  end
135
145
  end
@@ -143,11 +153,13 @@ class ActionCableClient
143
153
  # @param [String] message - the websockt message object
144
154
  def handle_received_message(message)
145
155
  return if message.empty?
156
+
146
157
  json = JSON.parse(message)
147
158
 
148
159
  if is_ping?(json)
149
160
  _pinged_callback&.call(json)
150
161
  elsif is_welcome?(json)
162
+ subscribe
151
163
  _connected_callback&.call(json)
152
164
  elsif !subscribed?
153
165
  check_for_subscribe_confirmation(json)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class ActionCableClient
4
- VERSION = '2.0.2'
4
+ VERSION = '3.0.1'
5
5
  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: 2.0.2
4
+ version: 3.0.1
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: 2017-11-29 00:00:00.000000000 Z
11
+ date: 2018-12-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: websocket-eventmachine-client
@@ -25,7 +25,7 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: 1.2.0
27
27
  - !ruby/object:Gem::Dependency
28
- name: rspec
28
+ name: codeclimate-test-reporter
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
@@ -53,7 +53,7 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: codeclimate-test-reporter
56
+ name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - ">="
@@ -106,7 +106,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
106
106
  requirements:
107
107
  - - ">="
108
108
  - !ruby/object:Gem::Version
109
- version: 2.2.2
109
+ version: '2.3'
110
110
  required_rubygems_version: !ruby/object:Gem::Requirement
111
111
  requirements:
112
112
  - - ">="
@@ -114,8 +114,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
114
114
  version: '0'
115
115
  requirements: []
116
116
  rubyforge_project:
117
- rubygems_version: 2.6.11
117
+ rubygems_version: 2.7.6
118
118
  signing_key:
119
119
  specification_version: 4
120
- summary: ActionCableClient-2.0.2
120
+ summary: ActionCableClient-3.0.1
121
121
  test_files: []