anycable-rails 1.3.1 → 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 +4 -4
- data/CHANGELOG.md +15 -1
- data/lib/anycable/rails/action_cable_ext/channel.rb +1 -1
- data/lib/anycable/rails/action_cable_ext/connection.rb +61 -1
- data/lib/anycable/rails/connection.rb +25 -21
- data/lib/anycable/rails/railtie.rb +4 -3
- data/lib/anycable/rails/version.rb +1 -1
- data/lib/generators/anycable/setup/templates/config/anycable.yml.tt +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6200d2863868ed23ac3bcc19478e4310bc4097bfff5884eb5c427ef9c41ec6be
|
4
|
+
data.tar.gz: a33f42cd90e362301dc90f5957b77787cec29e28c3aeee9782d3d81c582301f4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2f89b8b32dca31e58df2ad57f926b6ef7f2619dd5286d630e393cd7e306fd247cba46e4aa1ce76304bb75486ba52127b0d819dae10093e0a835a5e11c9b02ece
|
7
|
+
data.tar.gz: 5fc0c51cb4eb86c5c8bbbbae0c896af8440ec765370ff0c4a69aaa146e3d2465f1b28993f8f213cd7f8d956d684251aecb7eeda8951db14b0dbbc4c035b45507
|
data/CHANGELOG.md
CHANGED
@@ -2,7 +2,21 @@
|
|
2
2
|
|
3
3
|
## master
|
4
4
|
|
5
|
-
## 1.3.
|
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
|
+
|
15
|
+
## 1.3.2 (2022-03-04)
|
16
|
+
|
17
|
+
- Allow Ruby 2.6.
|
18
|
+
|
19
|
+
## 1.3.1 (2022-02-28)
|
6
20
|
|
7
21
|
- Fix Action Cable Channel patch to not change methods signatures. ([@palkan][])
|
8
22
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "action_cable
|
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
|
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
|
17
|
-
|
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.
|
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
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
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 =
|
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
|
@@ -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 --
|
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.
|
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-
|
11
|
+
date: 2022-06-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: anycable
|
@@ -198,14 +198,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
198
198
|
requirements:
|
199
199
|
- - ">="
|
200
200
|
- !ruby/object:Gem::Version
|
201
|
-
version: '2.
|
201
|
+
version: '2.6'
|
202
202
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
203
203
|
requirements:
|
204
204
|
- - ">="
|
205
205
|
- !ruby/object:Gem::Version
|
206
206
|
version: '0'
|
207
207
|
requirements: []
|
208
|
-
rubygems_version: 3.
|
208
|
+
rubygems_version: 3.3.7
|
209
209
|
signing_key:
|
210
210
|
specification_version: 4
|
211
211
|
summary: Rails adapter for AnyCable
|