Module: AnyCable::Rails
- Defined in:
- lib/anycable/rails.rb,
lib/anycable/rails/ext.rb,
lib/anycable/rails/rack.rb,
lib/anycable/rails/helper.rb,
lib/anycable/rails/channel.rb,
lib/anycable/rails/ext/jwt.rb,
lib/anycable/rails/railtie.rb,
lib/anycable/rails/version.rb,
lib/anycable/rails/connection.rb,
lib/anycable/rails/channel_state.rb,
lib/anycable/rails/pubsub_channel.rb,
lib/anycable/rails/next/connection.rb,
lib/anycable/rails/channel/presence.rb,
lib/anycable/rails/object_serializer.rb,
lib/anycable/rails/connection_factory.rb,
lib/anycable/rails/socket_id_tracking.rb,
lib/anycable/rails/middlewares/executor.rb,
lib/anycable/rails/middlewares/log_tagging.rb,
lib/anycable/rails/connections/session_proxy.rb,
lib/anycable/rails/connections/persistent_session.rb,
lib/anycable/rails/next/connection/persistent_session.rb,
lib/anycable/rails/connections/serializable_identification.rb
Overview
Rails handler for AnyCable
Defined Under Namespace
Modules: Channel, ChannelState, ConnectionState, Connections, Ext, Extension, Helper, Middlewares, ObjectSerializer, Rack, SocketIdTrackingController, SocketIdTrackingJob
Classes: Connection, ConnectionFactory, Current, PubSubChannel, Railtie, Server
Constant Summary
collapse
- ADAPTER_ALIASES =
%w[any_cable anycable].freeze
- VERSION =
"1.6.1"
Class Method Summary
collapse
Class Method Details
.broadcasting_to_others(socket_id: nil, &block) ⇒ Object
52
53
54
55
56
57
58
|
# File 'lib/anycable/rails.rb', line 52
def broadcasting_to_others(socket_id: nil, &block)
if socket_id
with_socket_id(socket_id) { with_broadcast_options(to_others: true, &block) }
else
with_broadcast_options(to_others: true, &block)
end
end
|
.compatible_adapter?(adapter) ⇒ Boolean
33
34
35
|
# File 'lib/anycable/rails.rb', line 33
def compatible_adapter?(adapter)
ADAPTER_ALIASES.include?(adapter)
end
|
.enabled? ⇒ Boolean
28
29
30
31
|
# File 'lib/anycable/rails.rb', line 28
def enabled?
adapter = ::ActionCable.server.config.cable&.fetch("adapter", nil)
compatible_adapter?(adapter)
end
|
.extend_adapter!(adapter) ⇒ Object
79
80
81
|
# File 'lib/anycable/rails.rb', line 79
def extend_adapter!(adapter)
adapter.extend(Extension)
end
|
.signed_stream_name(streamables) ⇒ Object
60
61
62
|
# File 'lib/anycable/rails.rb', line 60
def signed_stream_name(streamables)
Streams.signed(stream_name_from(streamables))
end
|
.stream_name_from(streamables) ⇒ Object
64
65
66
67
68
69
70
|
# File 'lib/anycable/rails.rb', line 64
def stream_name_from(streamables)
if streamables.is_a?(Array)
streamables.map { |streamable| stream_name_from(streamable) }.join(":")
else
streamables.then { |streamable| streamable.try(:to_gid_param) || streamable.to_param }
end
end
|
.with_broadcast_options(**options) ⇒ Object
44
45
46
47
48
49
50
|
# File 'lib/anycable/rails.rb', line 44
def with_broadcast_options(**options)
old_options = current_broadcast_options
self.current_broadcast_options = options.reverse_merge(old_options || {})
yield
ensure
self.current_broadcast_options = old_options
end
|
.with_socket_id(socket_id) ⇒ Object
37
38
39
40
41
42
|
# File 'lib/anycable/rails.rb', line 37
def with_socket_id(socket_id)
old_socket_id, self.current_socket_id = current_socket_id, socket_id
yield
ensure
self.current_socket_id = old_socket_id
end
|