anycable-rails 1.3.2 → 1.3.4

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
  SHA256:
3
- metadata.gz: dab047473c94bb62b658e08d1aa99a4d64d9b0ab3fad5b7e335e19398a9d8c21
4
- data.tar.gz: 6ad5f84e8a4af9ee01f1e277c6c235b7c8d2d313ef369b54739051d499980360
3
+ metadata.gz: 6200d2863868ed23ac3bcc19478e4310bc4097bfff5884eb5c427ef9c41ec6be
4
+ data.tar.gz: a33f42cd90e362301dc90f5957b77787cec29e28c3aeee9782d3d81c582301f4
5
5
  SHA512:
6
- metadata.gz: 3cadd3ebe73ebbd8ce2c2854cd663407a86195cb05ec2d9f4d85a512465ea0b6cba28e70b6eb49ca0b114be18943d67bee465ce795496f44bd84ed3f996dfc6a
7
- data.tar.gz: d07f875b9508e296188420166f9a1071a3fdec4a1cd5766c8ccc9cc277f49a25cd6eb3b3045b8ff59fc3057c2bb2d083a417f2c6641cbfe8929bfabe61be51bd
6
+ metadata.gz: 2f89b8b32dca31e58df2ad57f926b6ef7f2619dd5286d630e393cd7e306fd247cba46e4aa1ce76304bb75486ba52127b0d819dae10093e0a835a5e11c9b02ece
7
+ data.tar.gz: 5fc0c51cb4eb86c5c8bbbbae0c896af8440ec765370ff0c4a69aaa146e3d2465f1b28993f8f213cd7f8d956d684251aecb7eeda8951db14b0dbbc4c035b45507
data/CHANGELOG.md CHANGED
@@ -2,6 +2,16 @@
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
+
9
+ ## 1.3.3 (2022-04-20)
10
+
11
+ - Added `sid` (unique connection identifier) field to the `welcome` message if present. ([@palkan][])
12
+
13
+ - Fixed handling Ruby Logger incompatible loggers. ([@palkan][])
14
+
5
15
  ## 1.3.2 (2022-03-04)
6
16
 
7
17
  - Allow Ruby 2.6.
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "action_cable/channel"
3
+ require "action_cable"
4
4
 
5
5
  ActionCable::Channel::Base.prepend(Module.new do
6
6
  def subscribe_to_channel
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "action_cable/connection"
3
+ require "action_cable"
4
4
  require "anycable/rails/connections/serializable_identification"
5
5
 
6
6
  ActionCable::Connection::Base.include(AnyCable::Rails::Connections::SerializableIdentification)
@@ -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
@@ -1,7 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "action_cable/connection"
4
- require "action_cable/channel"
3
+ require "action_cable"
5
4
 
6
5
  module AnyCable
7
6
  module Rails
@@ -13,8 +12,11 @@ module AnyCable
13
12
  :anycable_socket
14
13
 
15
14
  # Using public :send_welcome_message causes stack level too deep 🤷🏻‍♂️
16
- def public_send_welcome_message
17
- send_welcome_message
15
+ def send_welcome_message
16
+ transmit({
17
+ type: ActionCable::INTERNAL[:message_types][:welcome],
18
+ sid: env["anycable.sid"]
19
+ }.compact)
18
20
  end
19
21
 
20
22
  def public_request
@@ -92,7 +94,7 @@ module AnyCable
92
94
 
93
95
  socket.cstate.write(LOG_TAGS_IDENTIFIER, logger.tags.to_json) unless logger.tags.empty?
94
96
 
95
- conn.public_send_welcome_message
97
+ conn.send_welcome_message
96
98
  rescue ::ActionCable::Connection::Authorization::UnauthorizedError
97
99
  reject_request(
98
100
  ActionCable::INTERNAL[:disconnect_reasons]&.[](:unauthorized) || "unauthorized"
@@ -108,22 +110,24 @@ module AnyCable
108
110
  end
109
111
 
110
112
  def handle_channel_command(identifier, command, data)
111
- # We cannot use subscriptions#execute_command here,
112
- # since we MUST return true of false, depending on the status
113
- # of execution
114
- channel = conn.subscriptions.fetch(identifier)
115
- case command
116
- when "subscribe"
117
- channel.handle_subscribe
118
- !channel.rejected?
119
- when "unsubscribe"
120
- conn.subscriptions.remove_subscription(channel)
121
- true
122
- when "message"
123
- channel.perform_action ActiveSupport::JSON.decode(data)
124
- true
125
- else
126
- 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
127
131
  end
128
132
  # Support rescue_from
129
133
  # https://github.com/rails/rails/commit/d2571e560c62116f60429c933d0c41a0e249b58b
@@ -20,13 +20,14 @@ module AnyCable
20
20
  AnyCable.logger = ::ActionCable.server.config.logger
21
21
 
22
22
  AnyCable.configure_server do
23
- AnyCable.logger = ActiveSupport::TaggedLogging.new(::ActionCable.server.config.logger)
23
+ server_logger = AnyCable.logger = ::ActionCable.server.config.logger
24
+ AnyCable.logger = ActiveSupport::TaggedLogging.new(server_logger) if server_logger.is_a?(::Logger)
24
25
  # Broadcast server logs to STDOUT in development
25
26
  if ::Rails.env.development? &&
26
27
  !ActiveSupport::Logger.logger_outputs_to?(::Rails.logger, $stdout)
27
28
  console = ActiveSupport::Logger.new($stdout)
28
- console.formatter = ::Rails.logger.formatter
29
- console.level = ::Rails.logger.level
29
+ console.formatter = ::Rails.logger.formatter if ::Rails.logger.respond_to?(:formatter)
30
+ console.level = ::Rails.logger.level if ::Rails.logger.respond_to?(:level)
30
31
  AnyCable.logger.extend(ActiveSupport::Logger.broadcast(console))
31
32
  end
32
33
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module AnyCable
4
4
  module Rails
5
- VERSION = "1.3.2"
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.2
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-03-04 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
@@ -205,7 +205,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
205
205
  - !ruby/object:Gem::Version
206
206
  version: '0'
207
207
  requirements: []
208
- rubygems_version: 3.2.22
208
+ rubygems_version: 3.3.7
209
209
  signing_key:
210
210
  specification_version: 4
211
211
  summary: Rails adapter for AnyCable