Sha256: 67bd6b9797af1dd660e66459b9f2bb8d521fc624acb2c9f207c888b31618cb17

Contents?: true

Size: 1.58 KB

Versions: 1

Compression:

Stored size: 1.58 KB

Contents

# frozen_string_literal: true

module CableReady
  class Channel < OperationBuilder
    attr_reader :identifier

    def broadcast(clear: true)
      raise("Action Cable must be enabled to use broadcast") unless defined?(ActionCable)
      clients_received = ActionCable.server.broadcast identifier, {
        "cableReady" => true,
        "operations" => operations_payload,
        "version" => CableReady::VERSION
      }
      reset! if clear
      clients_received
    end

    def broadcast_to(model, clear: true)
      raise("Action Cable must be enabled to use broadcast_to") unless defined?(ActionCable)
      clients_received = identifier.broadcast_to model, {
        "cableReady" => true,
        "operations" => operations_payload,
        "version" => CableReady::VERSION
      }
      reset! if clear
      clients_received
    end

    def broadcast_later(clear: true, queue: nil)
      raise("Action Cable must be enabled to use broadcast_later") unless defined?(ActionCable)
      CableReadyBroadcastJob
        .set(queue: queue ? queue.to_sym : CableReady.config.broadcast_job_queue)
        .perform_later(identifier: identifier, operations: operations_payload)
      reset! if clear
    end

    def broadcast_later_to(model, clear: true, queue: nil)
      raise("Action Cable must be enabled to use broadcast_later_to") unless defined?(ActionCable)
      CableReadyBroadcastJob
        .set(queue: queue ? queue.to_sym : CableReady.config.broadcast_job_queue)
        .perform_later(identifier: identifier.name, operations: operations_payload, model: model)
      reset! if clear
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
cable_ready-5.0.0.pre10 lib/cable_ready/channel.rb