actioncable 5.0.7.2 → 5.1.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +13 -169
  3. data/MIT-LICENSE +1 -1
  4. data/README.md +18 -15
  5. data/lib/action_cable.rb +9 -9
  6. data/lib/action_cable/channel/base.rb +17 -19
  7. data/lib/action_cable/channel/broadcasting.rb +2 -2
  8. data/lib/action_cable/channel/callbacks.rb +1 -1
  9. data/lib/action_cable/channel/naming.rb +2 -1
  10. data/lib/action_cable/channel/periodic_timers.rb +1 -1
  11. data/lib/action_cable/channel/streams.rb +7 -7
  12. data/lib/action_cable/connection.rb +0 -2
  13. data/lib/action_cable/connection/authorization.rb +6 -6
  14. data/lib/action_cable/connection/base.rb +20 -21
  15. data/lib/action_cable/connection/client_socket.rb +16 -16
  16. data/lib/action_cable/connection/identification.rb +1 -1
  17. data/lib/action_cable/connection/internal_channel.rb +2 -2
  18. data/lib/action_cable/connection/message_buffer.rb +2 -0
  19. data/lib/action_cable/connection/stream.rb +5 -5
  20. data/lib/action_cable/connection/stream_event_loop.rb +2 -2
  21. data/lib/action_cable/connection/subscriptions.rb +12 -10
  22. data/lib/action_cable/connection/tagged_logger_proxy.rb +2 -2
  23. data/lib/action_cable/connection/web_socket.rb +5 -3
  24. data/lib/action_cable/engine.rb +4 -4
  25. data/lib/action_cable/gem_version.rb +3 -3
  26. data/lib/action_cable/helpers/action_cable_helper.rb +1 -1
  27. data/lib/action_cable/remote_connections.rb +2 -2
  28. data/lib/action_cable/server.rb +1 -1
  29. data/lib/action_cable/server/base.rb +5 -5
  30. data/lib/action_cable/server/broadcasting.rb +7 -3
  31. data/lib/action_cable/server/configuration.rb +3 -19
  32. data/lib/action_cable/server/worker.rb +3 -3
  33. data/lib/action_cable/subscription_adapter.rb +1 -0
  34. data/lib/action_cable/subscription_adapter/async.rb +1 -1
  35. data/lib/action_cable/subscription_adapter/channel_prefix.rb +26 -0
  36. data/lib/action_cable/subscription_adapter/evented_redis.rb +13 -5
  37. data/lib/action_cable/subscription_adapter/postgresql.rb +4 -4
  38. data/lib/action_cable/subscription_adapter/redis.rb +9 -7
  39. data/lib/action_cable/subscription_adapter/subscriber_map.rb +1 -1
  40. data/lib/action_cable/version.rb +1 -1
  41. data/lib/assets/compiled/action_cable.js +554 -567
  42. data/lib/rails/generators/channel/USAGE +2 -2
  43. data/lib/rails/generators/channel/channel_generator.rb +9 -9
  44. data/lib/rails/generators/channel/templates/assets/cable.js +1 -1
  45. metadata +13 -33
  46. data/lib/action_cable/connection/faye_client_socket.rb +0 -48
  47. data/lib/action_cable/connection/faye_event_loop.rb +0 -44
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA256:
3
- metadata.gz: 1ee3d1102059bedcc5ad921ef625016fad5415c99cefbec0eced71935b94c282
4
- data.tar.gz: e79965fac70838822e54e60768b0daf3f846582574f213b36c6e2cf2a44d4564
2
+ SHA1:
3
+ metadata.gz: e6a1923cc070932c10fd67f43091b790c221df82
4
+ data.tar.gz: 4f8a716a47aeb4fcd7557e8fb9efd3f2629394a6
5
5
  SHA512:
6
- metadata.gz: bb979e416083f480d596d0946252af8b444c6a5aaedd927ba5b339408ea1ae9eca28f858b0539696b39467d0f38dfc34959b3d5f0b079747c1aa75b6e838cbd9
7
- data.tar.gz: 38fd77b3eed559c9ceed9699c58c0d0fdcd07cd86315e5d0932eaa7d712fbbb7794b30a2ae51b6c31c912e4dbbe76726513c2a9805637cdd1e5fad561a6b9f45
6
+ metadata.gz: f46c1ea1a1d68ce4b833fa58c287be8b658e0e599c2507e68c216a403f4e19a831a5e50a37dcb5c9f0125d5e545641ac9fa19feceeaeb4d3e3e53a459d8029d0
7
+ data.tar.gz: 1495844434cdb511bec8e32976eced1a9c8c7657c6c6a6509ac9c6e8215294d1b850a08d00bca5c3ab83423ae0b34359bb137acea9c067c6d842b045c42ba59f
@@ -1,89 +1,18 @@
1
- ## Rails 5.0.7.2 (March 11, 2019) ##
1
+ ## Rails 5.1.0.beta1 (February 23, 2017) ##
2
2
 
3
- * No changes.
3
+ * Redis subscription adapters now support `channel_prefix` option in `cable.yml`
4
4
 
5
+ Avoids channel name collisions when multiple apps use the same Redis server.
5
6
 
6
- ## Rails 5.0.7.1 (November 27, 2018) ##
7
-
8
- * No changes.
9
-
10
-
11
- ## Rails 5.0.7 (March 29, 2018) ##
12
-
13
- * No changes.
14
-
15
-
16
- ## Rails 5.0.6 (September 07, 2017) ##
17
-
18
- * No changes.
19
-
20
-
21
- ## Rails 5.0.6.rc1 (August 24, 2017) ##
22
-
23
- * No changes.
24
-
25
-
26
- ## Rails 5.0.5 (July 31, 2017) ##
27
-
28
- * No changes.
29
-
30
-
31
- ## Rails 5.0.5.rc2 (July 25, 2017) ##
32
-
33
- * No changes.
34
-
35
-
36
- ## Rails 5.0.5.rc1 (July 19, 2017) ##
37
-
38
- * No changes.
39
-
40
-
41
- ## Rails 5.0.4 (June 19, 2017) ##
42
-
43
- * No changes.
44
-
45
-
46
- ## Rails 5.0.3 (May 12, 2017) ##
47
-
48
- * No changes.
49
-
50
-
51
- ## Rails 5.0.2 (March 01, 2017) ##
52
-
53
- * No changes.
54
-
55
-
56
- ## Rails 5.0.1 (December 21, 2016) ##
57
-
58
- * No changes.
59
-
60
-
61
- ## Rails 5.0.1.rc2 (December 10, 2016) ##
62
-
63
- * No changes.
64
-
65
-
66
- ## Rails 5.0.1.rc1 (December 01, 2016) ##
7
+ *Chad Ingram*
67
8
 
68
9
  * Permit same-origin connections by default.
69
10
 
70
- New option `config.action_cable.allow_same_origin_as_host = false`
71
- to disable.
11
+ Added new option `config.action_cable.allow_same_origin_as_host = false`
12
+ to disable this behaviour.
72
13
 
73
14
  *Dávid Halász*, *Matthew Draper*
74
15
 
75
- * Fixed and added a workaround to avoid race condition, when one
76
- thread closed the IO, when an another thread was still trying read
77
- from IO on a connection.
78
-
79
- *Matthew Draper*
80
-
81
- * Shutdown pubsub connection before classes are reloaded, to avoid
82
- hangups caused by pubsub still holding reference to Active Record
83
- connection from the pool, and Active Record trying to cleanup the pool.
84
-
85
- *Jon Moss*
86
-
87
16
  * Prevent race where the client could receive and act upon a
88
17
  subscription confirmation before the channel's `subscribed` method
89
18
  completed.
@@ -92,110 +21,25 @@
92
21
 
93
22
  *Vladimir Dementyev*
94
23
 
95
- * Buffer writes to websocket connections, to avoid blocking threads
24
+ * Buffer now writes to WebSocket connections, to avoid blocking threads
96
25
  that could be doing more useful things.
97
26
 
98
27
  *Matthew Draper*, *Tinco Andringa*
99
28
 
100
- * Invocation of channel action is now prevented, if subscription
101
- connection was rejected.
102
-
103
- Fixes #23757.
104
-
105
- *Jon Moss*
106
-
107
- * Protect against concurrent writes to a websocket connection from
29
+ * Protect against concurrent writes to a WebSocket connection from
108
30
  multiple threads; the underlying OS write is not always threadsafe.
109
31
 
110
32
  *Tinco Andringa*
111
33
 
112
- * Close hijacked socket when connection is shut down.
113
-
114
- Fixes #25613.
115
-
116
- *Tinco Andringa*
117
-
118
-
119
- ## Rails 5.0.0 (June 30, 2016) ##
120
-
121
- * Fix development reloading support: new cable connections are now correctly
122
- dispatched to the reloaded channel class, instead of using a cached reference
123
- to the originally-loaded version.
124
-
125
- *Matthew Draper*
126
-
127
- * WebSocket protocol negotiation.
128
-
129
- Introduces an Action Cable protocol version that moves independently
130
- of and, hopefully, more slowly than Action Cable itself. Client sockets
131
- negotiate a protocol with the Cable server using WebSockets' native
132
- subprotocol support:
133
- * https://tools.ietf.org/html/rfc6455#section-1.9
134
- * https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API/Writing_WebSocket_servers#Subprotocols
135
-
136
- If they can't negotiate a compatible protocol (usually due to upgrading
137
- the Cable server with a browser still running old JavaScript) then the
138
- client knows to disconnect, cease retrying, and tell the app that it hit
139
- a protocol mismatch.
140
-
141
- This allows us to evolve the Action Cable message format, handshaking,
142
- pings, acknowledgements, and more without breaking older clients'
143
- expectations of server behavior.
144
-
145
- *Daniel Rhodes*
146
-
147
- * Pubsub: automatic stream decoding.
148
-
149
- stream_for @room, coder: ActiveSupport::JSON do |message|
150
- # `message` is a Ruby hash here instead of a JSON string
151
-
152
- The `coder` must respond to `#decode`. Defaults to `coder: nil`
153
- which skips decoding entirely.
154
-
155
- *Jeremy Daer*
156
-
157
- * Add ActiveSupport::Notifications to ActionCable::Channel.
34
+ * Add `ActiveSupport::Notifications` hook to `Broadcaster#broadcast`.
158
35
 
159
36
  *Matthew Wear*
160
37
 
161
- * Safely support autoloading and class unloading, by preventing concurrent
162
- loads, and disconnecting all cables during reload.
163
-
164
- *Matthew Draper*
165
-
166
- * Ensure ActionCable behaves correctly for non-string queue names.
167
-
168
- *Jay Hayes*
169
-
170
- * Added `em_redis_connector` and `redis_connector` to
171
- `ActionCable::SubscriptionAdapter::EventedRedis` and added `redis_connector`
172
- to `ActionCable::SubscriptionAdapter::Redis`, so you can overwrite with your
173
- own initializers. This is used when you want to use different-than-standard
174
- Redis adapters, like for Makara distributed Redis.
175
-
176
- *DHH*
177
-
178
- * Support PostgreSQL pubsub adapter.
179
-
180
- *Jon Moss*
181
-
182
- * Remove EventMachine dependency.
183
-
184
- *Matthew Draper*
185
-
186
- * Remove Celluloid dependency.
187
-
188
- *Mike Perham*
38
+ * Close hijacked socket when connection is shut down.
189
39
 
190
- * Create notion of an `ActionCable::SubscriptionAdapter`.
191
- Separate out Redis functionality into
192
- `ActionCable::SubscriptionAdapter::Redis`, and add a
193
- PostgreSQL adapter as well. Configuration file for
194
- ActionCable was changed from`config/redis/cable.yml` to
195
- `config/cable.yml`.
40
+ Fixes #25613.
196
41
 
197
- *Jon Moss*
42
+ *Tinco Andringa*
198
43
 
199
- * Added to Rails!
200
44
 
201
- *DHH*
45
+ Please check [5-0-stable](https://github.com/rails/rails/blob/5-0-stable/actioncable/CHANGELOG.md) for previous changes.
@@ -1,4 +1,4 @@
1
- Copyright (c) 2015-2016 Basecamp, LLC
1
+ Copyright (c) 2015-2017 Basecamp, LLC
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -7,7 +7,6 @@ and scalable. It's a full-stack offering that provides both a client-side
7
7
  JavaScript framework and a server-side Ruby framework. You have access to your full
8
8
  domain model written with Active Record or your ORM of choice.
9
9
 
10
-
11
10
  ## Terminology
12
11
 
13
12
  A single Action Cable server can handle multiple connection instances. It has one
@@ -52,7 +51,7 @@ module ApplicationCable
52
51
  self.current_user = find_verified_user
53
52
  end
54
53
 
55
- protected
54
+ private
56
55
  def find_verified_user
57
56
  if current_user = User.find_by(id: cookies.signed[:user_id])
58
57
  current_user
@@ -86,12 +85,17 @@ end
86
85
 
87
86
  The client-side needs to setup a consumer instance of this connection. That's done like so:
88
87
 
89
- ```coffeescript
90
- # app/assets/javascripts/cable.coffee
91
- #= require action_cable
88
+ ```js
89
+ // app/assets/javascripts/cable.js
90
+ //= require action_cable
91
+ //= require_self
92
+ //= require_tree ./channels
92
93
 
93
- @App = {}
94
- App.cable = ActionCable.createConsumer("ws://cable.example.com")
94
+ (function() {
95
+ this.App || (this.App = {});
96
+
97
+ App.cable = ActionCable.createConsumer("ws://cable.example.com");
98
+ }).call(this);
95
99
  ```
96
100
 
97
101
  The `ws://cable.example.com` address must point to your Action Cable server(s), and it
@@ -163,7 +167,7 @@ App.cable.subscriptions.create "AppearanceChannel",
163
167
  buttonSelector = "[data-behavior~=appear_away]"
164
168
 
165
169
  install: ->
166
- $(document).on "page:change.appearance", =>
170
+ $(document).on "turbolinks:load.appearance", =>
167
171
  @appear()
168
172
 
169
173
  $(document).on "click.appearance", buttonSelector, =>
@@ -293,8 +297,7 @@ The rebroadcast will be received by all connected clients, _including_ the clien
293
297
 
294
298
  ### More complete examples
295
299
 
296
- See the [rails/actioncable-examples](http://github.com/rails/actioncable-examples) repository for a full example of how to setup Action Cable in a Rails app, and how to add channels.
297
-
300
+ See the [rails/actioncable-examples](https://github.com/rails/actioncable-examples) repository for a full example of how to setup Action Cable in a Rails app, and how to add channels.
298
301
 
299
302
  ## Configuration
300
303
 
@@ -383,11 +386,11 @@ App.cable = ActionCable.createConsumer()
383
386
 
384
387
  ### Other Configurations
385
388
 
386
- The other common option to configure is the log tags applied to the per-connection logger. Here's close to what we're using in Basecamp:
389
+ The other common option to configure is the log tags applied to the per-connection logger. Here's an example that uses the user account id if available, else "no-account" while tagging:
387
390
 
388
391
  ```ruby
389
- Rails.application.config.action_cable.log_tags = [
390
- -> request { request.env['bc.account_id'] || "no-account" },
392
+ config.action_cable.log_tags = [
393
+ -> request { request.env['user_account_id'] || "no-account" },
391
394
  :action_cable,
392
395
  -> request { request.uuid }
393
396
  ]
@@ -413,7 +416,7 @@ run ActionCable.server
413
416
  ```
414
417
 
415
418
  Then you start the server using a binstub in bin/cable ala:
416
- ```
419
+ ```sh
417
420
  #!/bin/bash
418
421
  bundle exec puma -p 28080 cable/config.ru
419
422
  ```
@@ -435,7 +438,7 @@ For every instance of your server you create and for every worker your server sp
435
438
 
436
439
  ### Notes
437
440
 
438
- Beware that currently the cable server will _not_ auto-reload any changes in the framework. As we've discussed, long-running cable connections mean long-running objects. We don't yet have a way of reloading the classes of those objects in a safe manner. So when you change your channels, or the model your channels use, you must restart the cable server.
441
+ Beware that currently, the cable server will _not_ auto-reload any changes in the framework. As we've discussed, long-running cable connections mean long-running objects. We don't yet have a way of reloading the classes of those objects in a safe manner. So when you change your channels, or the model your channels use, you must restart the cable server.
439
442
 
440
443
  We'll get all this abstracted properly when the framework is integrated into Rails.
441
444
 
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright (c) 2015-2016 Basecamp, LLC
2
+ # Copyright (c) 2015-2017 Basecamp, LLC
3
3
  #
4
4
  # Permission is hereby granted, free of charge, to any person obtaining
5
5
  # a copy of this software and associated documentation files (the
@@ -21,21 +21,21 @@
21
21
  # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
22
  #++
23
23
 
24
- require 'active_support'
25
- require 'active_support/rails'
26
- require 'action_cable/version'
24
+ require "active_support"
25
+ require "active_support/rails"
26
+ require "action_cable/version"
27
27
 
28
28
  module ActionCable
29
29
  extend ActiveSupport::Autoload
30
30
 
31
31
  INTERNAL = {
32
32
  message_types: {
33
- welcome: 'welcome'.freeze,
34
- ping: 'ping'.freeze,
35
- confirmation: 'confirm_subscription'.freeze,
36
- rejection: 'reject_subscription'.freeze
33
+ welcome: "welcome".freeze,
34
+ ping: "ping".freeze,
35
+ confirmation: "confirm_subscription".freeze,
36
+ rejection: "reject_subscription".freeze
37
37
  },
38
- default_mount_path: '/cable'.freeze,
38
+ default_mount_path: "/cable".freeze,
39
39
  protocols: ["actioncable-v1-json".freeze, "actioncable-unsupported".freeze].freeze
40
40
  }
41
41
 
@@ -1,4 +1,4 @@
1
- require 'set'
1
+ require "set"
2
2
 
3
3
  module ActionCable
4
4
  module Channel
@@ -122,16 +122,16 @@ module ActionCable
122
122
  end
123
123
  end
124
124
 
125
- protected
125
+ private
126
126
  # action_methods are cached and there is sometimes need to refresh
127
127
  # them. ::clear_action_methods! allows you to do that, so next time
128
128
  # you run action_methods, they will be recalculated.
129
- def clear_action_methods!
129
+ def clear_action_methods! # :doc:
130
130
  @action_methods = nil
131
131
  end
132
132
 
133
133
  # Refresh the cached action_methods when a new action_method is added.
134
- def method_added(name)
134
+ def method_added(name) # :doc:
135
135
  super
136
136
  clear_action_methods!
137
137
  end
@@ -189,24 +189,23 @@ module ActionCable
189
189
  end
190
190
  end
191
191
 
192
-
193
- protected
192
+ private
194
193
  # Called once a consumer has become a subscriber of the channel. Usually the place to setup any streams
195
194
  # you want this channel to be sending to the subscriber.
196
- def subscribed
195
+ def subscribed # :doc:
197
196
  # Override in subclasses
198
197
  end
199
198
 
200
199
  # Called once a consumer has cut its cable connection. Can be used for cleaning up connections or marking
201
200
  # users as offline or the like.
202
- def unsubscribed
201
+ def unsubscribed # :doc:
203
202
  # Override in subclasses
204
203
  end
205
204
 
206
205
  # Transmit a hash of data to the subscriber. The hash will automatically be wrapped in a JSON envelope with
207
206
  # the proper channel identifier marked as the recipient.
208
- def transmit(data, via: nil)
209
- logger.info "#{self.class.name} transmitting #{data.inspect.truncate(300)}".tap { |m| m << " (via #{via})" if via }
207
+ def transmit(data, via: nil) # :doc:
208
+ logger.debug "#{self.class.name} transmitting #{data.inspect.truncate(300)}".tap { |m| m << " (via #{via})" if via }
210
209
 
211
210
  payload = { channel_class: self.class.name, data: data, via: via }
212
211
  ActiveSupport::Notifications.instrument("transmit.action_cable", payload) do
@@ -214,33 +213,32 @@ module ActionCable
214
213
  end
215
214
  end
216
215
 
217
- def ensure_confirmation_sent
216
+ def ensure_confirmation_sent # :doc:
218
217
  return if subscription_rejected?
219
218
  @defer_subscription_confirmation_counter.decrement
220
219
  transmit_subscription_confirmation unless defer_subscription_confirmation?
221
220
  end
222
221
 
223
- def defer_subscription_confirmation!
222
+ def defer_subscription_confirmation! # :doc:
224
223
  @defer_subscription_confirmation_counter.increment
225
224
  end
226
225
 
227
- def defer_subscription_confirmation?
226
+ def defer_subscription_confirmation? # :doc:
228
227
  @defer_subscription_confirmation_counter.value > 0
229
228
  end
230
229
 
231
- def subscription_confirmation_sent?
230
+ def subscription_confirmation_sent? # :doc:
232
231
  @subscription_confirmation_sent
233
232
  end
234
233
 
235
- def reject
234
+ def reject # :doc:
236
235
  @reject_subscription = true
237
236
  end
238
237
 
239
- def subscription_rejected?
238
+ def subscription_rejected? # :doc:
240
239
  @reject_subscription
241
240
  end
242
241
 
243
- private
244
242
  def delegate_connection_identifiers
245
243
  connection.identifiers.each do |identifier|
246
244
  define_singleton_method(identifier) do
@@ -250,7 +248,7 @@ module ActionCable
250
248
  end
251
249
 
252
250
  def extract_action(data)
253
- (data['action'].presence || :receive).to_sym
251
+ (data["action"].presence || :receive).to_sym
254
252
  end
255
253
 
256
254
  def processable_action?(action)
@@ -269,7 +267,7 @@ module ActionCable
269
267
 
270
268
  def action_signature(action, data)
271
269
  "#{self.class.name}##{action}".tap do |signature|
272
- if (arguments = data.except('action')).any?
270
+ if (arguments = data.except("action")).any?
273
271
  signature << "(#{arguments.inspect})"
274
272
  end
275
273
  end