anycable-rails 1.3.3 → 1.3.5

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: 75584d70f4f8d966a74cfee8d0741bc5072aabcbab60a7fecc2c4532d7a9719c
4
+ data.tar.gz: a4efe6de0db26e8f91a896350a142aa483d9305798fafc3e758b29c522e7cf3a
5
5
  SHA512:
6
- metadata.gz: 2aee411822afddc35aeecbf85490f413e2c6b899107b3a849e25a449cf19baf13885cad9e52bbc25ab85b08316b865ff60f0fc0f558f0ebffc0a175e5d983f30
7
- data.tar.gz: e5933e165ca975e9ce32ec867b177583cc8e0718a9aa8f1f9435bbb515500a4f0de9e7cd82b34e7e0f9d1cf8db40114f0fedb49923ef63bfce418a9dd1cd7a76
6
+ metadata.gz: 64e79d37168a1d299d700cf86444e74e424a360b6d22fe6eb682ef0cba4ea648526a4ea603a5a032a709ed5308856df2d7cb8dedd634668afde239673ef89dd7
7
+ data.tar.gz: aabcd20cbc91c4733d4978c9c99cf5d0574775badf9ef67fffea8a4a9b825c3b6e6b76c3581a4a75a3058f7ce3fb762a2b69dea4a8b2be935f0b75ea7e09fa0d
data/CHANGELOG.md CHANGED
@@ -2,6 +2,14 @@
2
2
 
3
3
  ## master
4
4
 
5
+ ## 1.3.5 (2023-01-04)
6
+
7
+ - Make misconfiguration error more informative. ([@palkan][])
8
+
9
+ ## 1.3.4 (2022-06-28)
10
+
11
+ - Add support and backport for Connection command callbacks. ([@palkan][])
12
+
5
13
  ## 1.3.3 (2022-04-20)
6
14
 
7
15
  - Added `sid` (unique connection identifier) field to the `welcome` message if present. ([@palkan][])
data/MIT-LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright 2017-2022 palkan
1
+ Copyright 2017-2023 palkan
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
@@ -7,6 +7,14 @@ module ActionCable
7
7
  # AnyCable subscription adapter delegates broadcasts
8
8
  # to AnyCable
9
9
  class AnyCable < Base
10
+ ACTION_CABLE_SERVER_ERROR_MESSAGE = <<~STR
11
+ Looks like you're trying to connect to Rails Action Cable server, not an AnyCable one.
12
+
13
+ Please make sure your client is configured to connect to AnyCable server.
14
+
15
+ See https://docs.anycable.io/troubleshooting
16
+ STR
17
+
10
18
  def initialize(*)
11
19
  end
12
20
 
@@ -14,6 +22,14 @@ module ActionCable
14
22
  ::AnyCable.broadcast(channel, payload)
15
23
  end
16
24
 
25
+ def subscribe(*)
26
+ raise NotImplementedError, ACTION_CABLE_SERVER_ERROR_MESSAGE
27
+ end
28
+
29
+ def unsubscribe(*)
30
+ raise NotImplementedError, ACTION_CABLE_SERVER_ERROR_MESSAGE
31
+ end
32
+
17
33
  def shutdown
18
34
  # nothing to do
19
35
  # we only need this method for development,
@@ -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.5"
6
6
  end
7
7
  end
@@ -68,8 +68,8 @@ end
68
68
  if defined?(::Rails) && ::Rails.application && ::Rails.application.initialized?
69
69
  puts("\n**************************************************")
70
70
  puts(
71
- "⛔️ WARNING: AnyCable loaded after application initialization. Might not work correctly.\n"\
72
- "Please, make sure to remove `require: false` in your Gemfile or "\
71
+ "⛔️ WARNING: AnyCable loaded after application initialization. Might not work correctly.\n" \
72
+ "Please, make sure to remove `require: false` in your Gemfile or " \
73
73
  "require manually in `environment.rb` before `Rails.application.initialize!`"
74
74
  )
75
75
  puts("**************************************************\n\n")
@@ -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.5
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: 2023-01-04 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.3.7
208
+ rubygems_version: 3.3.11
209
209
  signing_key:
210
210
  specification_version: 4
211
211
  summary: Rails adapter for AnyCable