Sha256: 613f47147c241925d490ddd005551b3500120dac04f600eb19474d6d7bd0cac8

Contents?: true

Size: 1.25 KB

Versions: 9

Compression:

Stored size: 1.25 KB

Contents

# frozen_string_literal: true

require "anycable-rails"

module ActionCable
  module SubscriptionAdapter
    # AnyCable subscription adapter delegates broadcasts
    # to AnyCable
    class AnyCable < Base
      ACTION_CABLE_SERVER_ERROR_MESSAGE = <<~STR
        Looks like you are trying to connect to Rails Action Cable server, not an AnyCable one.

        Please make sure your client is configured to connect to AnyCable server.

        See https://docs.anycable.io/troubleshooting
      STR

      def initialize(*)
      end

      def broadcast(channel, payload, **options)
        options.merge!(::AnyCable::Rails.current_broadcast_options || {})
        to_others = options.delete(:to_others)
        options[:exclude_socket] ||= ::AnyCable::Rails.current_socket_id if to_others
        ::AnyCable.broadcast(channel, payload, **options.compact)
      end

      def subscribe(*)
        raise NotImplementedError, ACTION_CABLE_SERVER_ERROR_MESSAGE
      end

      def unsubscribe(*)
        raise NotImplementedError, ACTION_CABLE_SERVER_ERROR_MESSAGE
      end

      def shutdown
        # nothing to do
        # we only need this method for development,
        # 'cause code reloading triggers `server.restart` -> `pubsub.shutdown`
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
anycable-rails-core-1.5.6 lib/action_cable/subscription_adapter/any_cable.rb
anycable-rails-core-1.6.0.rc.1 lib/action_cable/subscription_adapter/any_cable.rb
anycable-rails-core-1.5.5 lib/action_cable/subscription_adapter/any_cable.rb
anycable-rails-core-1.5.4 lib/action_cable/subscription_adapter/any_cable.rb
anycable-rails-core-1.5.3 lib/action_cable/subscription_adapter/any_cable.rb
anycable-rails-core-1.5.2 lib/action_cable/subscription_adapter/any_cable.rb
anycable-rails-core-1.5.1 lib/action_cable/subscription_adapter/any_cable.rb
anycable-rails-core-1.5.0 lib/action_cable/subscription_adapter/any_cable.rb
anycable-rails-core-1.5.0.rc.1 lib/action_cable/subscription_adapter/any_cable.rb