anycable-rails 1.3.3 → 1.3.4

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 249493f023d0c0b2e8f85bba263132f7b8bb440073184f68949e83b5911b191a
4
- data.tar.gz: 055c60c21507d7307f73121948e134087d624f907d4435ad1ac0526337158464
3
+ metadata.gz: 6200d2863868ed23ac3bcc19478e4310bc4097bfff5884eb5c427ef9c41ec6be
4
+ data.tar.gz: a33f42cd90e362301dc90f5957b77787cec29e28c3aeee9782d3d81c582301f4
5
5
  SHA512:
6
- metadata.gz: 2aee411822afddc35aeecbf85490f413e2c6b899107b3a849e25a449cf19baf13885cad9e52bbc25ab85b08316b865ff60f0fc0f558f0ebffc0a175e5d983f30
7
- data.tar.gz: e5933e165ca975e9ce32ec867b177583cc8e0718a9aa8f1f9435bbb515500a4f0de9e7cd82b34e7e0f9d1cf8db40114f0fedb49923ef63bfce418a9dd1cd7a76
6
+ metadata.gz: 2f89b8b32dca31e58df2ad57f926b6ef7f2619dd5286d630e393cd7e306fd247cba46e4aa1ce76304bb75486ba52127b0d819dae10093e0a835a5e11c9b02ece
7
+ data.tar.gz: 5fc0c51cb4eb86c5c8bbbbae0c896af8440ec765370ff0c4a69aaa146e3d2465f1b28993f8f213cd7f8d956d684251aecb7eeda8951db14b0dbbc4c035b45507
data/CHANGELOG.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  ## master
4
4
 
5
+ ## 1.3.4 (2022-06-28)
6
+
7
+ - Add support and backport for Connection command callbacks. ([@palkan][])
8
+
5
9
  ## 1.3.3 (2022-04-20)
6
10
 
7
11
  - Added `sid` (unique connection identifier) field to the `welcome` message if present. ([@palkan][])
@@ -28,3 +28,63 @@ ActionCable::Connection::Base.prepend(Module.new do
28
28
  @request ||= anycable_request_builder.build_rack_request(@env)
29
29
  end
30
30
  end)
31
+
32
+ # Backport command callbacks: https://github.com/rails/rails/pull/44696
33
+ unless ActionCable::Connection::Base.respond_to?(:before_command)
34
+ ActionCable::Connection::Base.include ActiveSupport::Callbacks
35
+ ActionCable::Connection::Base.define_callbacks :command
36
+ ActionCable::Connection::Base.extend(Module.new do
37
+ def before_command(*methods, &block)
38
+ set_callback(:command, :before, *methods, &block)
39
+ end
40
+
41
+ def after_command(*methods, &block)
42
+ set_callback(:command, :after, *methods, &block)
43
+ end
44
+
45
+ def around_command(*methods, &block)
46
+ set_callback(:command, :around, *methods, &block)
47
+ end
48
+ end)
49
+
50
+ ActionCable::Connection::Base.prepend(Module.new do
51
+ def dispatch_websocket_message(websocket_message)
52
+ return super unless websocket.alive?
53
+
54
+ handle_channel_command(decode(websocket_message))
55
+ end
56
+
57
+ def handle_channel_command(payload)
58
+ run_callbacks :command do
59
+ subscriptions.execute_command payload
60
+ end
61
+ end
62
+ end)
63
+ end
64
+
65
+ # Trigger autoload
66
+ test_case_defined = false
67
+
68
+ begin
69
+ ActionCable::Connection::TestCase # rubocop:disable Lint/Void
70
+ test_case_defined = true
71
+ rescue NameError
72
+ end
73
+
74
+ # Backport: https://github.com/rails/rails/pull/45445
75
+ if test_case_defined && !ActionCable::Connection::TestConnection.method_defined?(:transmissions)
76
+ ActionCable::Connection::TestConnection.prepend(Module.new do
77
+ attr_reader :transmissions
78
+
79
+ def initialize(*)
80
+ super
81
+
82
+ @transmissions = []
83
+ @subscriptions = ActionCable::Connection::Subscriptions.new(self)
84
+ end
85
+
86
+ def transmit(cable_message)
87
+ transmissions << cable_message.with_indifferent_access
88
+ end
89
+ end)
90
+ end
@@ -110,22 +110,24 @@ module AnyCable
110
110
  end
111
111
 
112
112
  def handle_channel_command(identifier, command, data)
113
- # We cannot use subscriptions#execute_command here,
114
- # since we MUST return true of false, depending on the status
115
- # of execution
116
- channel = conn.subscriptions.fetch(identifier)
117
- case command
118
- when "subscribe"
119
- channel.handle_subscribe
120
- !channel.rejected?
121
- when "unsubscribe"
122
- conn.subscriptions.remove_subscription(channel)
123
- true
124
- when "message"
125
- channel.perform_action ActiveSupport::JSON.decode(data)
126
- true
127
- else
128
- false
113
+ conn.run_callbacks :command do
114
+ # We cannot use subscriptions#execute_command here,
115
+ # since we MUST return true of false, depending on the status
116
+ # of execution
117
+ channel = conn.subscriptions.fetch(identifier)
118
+ case command
119
+ when "subscribe"
120
+ channel.handle_subscribe
121
+ !channel.rejected?
122
+ when "unsubscribe"
123
+ conn.subscriptions.remove_subscription(channel)
124
+ true
125
+ when "message"
126
+ channel.perform_action ActiveSupport::JSON.decode(data)
127
+ true
128
+ else
129
+ false
130
+ end
129
131
  end
130
132
  # Support rescue_from
131
133
  # https://github.com/rails/rails/commit/d2571e560c62116f60429c933d0c41a0e249b58b
@@ -2,6 +2,6 @@
2
2
 
3
3
  module AnyCable
4
4
  module Rails
5
- VERSION = "1.3.3"
5
+ VERSION = "1.3.4"
6
6
  end
7
7
  end
@@ -28,7 +28,7 @@ default: &default
28
28
  broadcast_adapter: http
29
29
  <%- end -%>
30
30
  # Use the same channel name for WebSocket server, e.g.:
31
- # $ anycable-go --redis-channel="__anycable__"
31
+ # $ anycable-go --redis_channel="__anycable__"
32
32
  redis_channel: "__anycable__"
33
33
  <%- if redis? -%>
34
34
  # You can use REDIS_URL env var to configure Redis URL.
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: anycable-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.3
4
+ version: 1.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - palkan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-04-20 00:00:00.000000000 Z
11
+ date: 2022-06-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: anycable