class OpenUI::Rails::Stream::Transports::ActionCable

Broadcasts envelope hashes over Action Cable.

The stream name is supplied by the host (the Gem does not invent a tenant-scoping scheme). Pair it with a channel that dispatches each received payload as an ‘openui:envelope` event on the page. See the “Transports” section of the README. Authorization for the subscription stays in the host’s channel.

‘cable:` is the Action Cable server (or a test double that responds to `#broadcast`), injectable so this can be exercised without a running Action Cable server.

Attributes

stream_name[R]

Public Class Methods

new(stream_name, cable: nil) click to toggle source
# File lib/openui/rails/stream/transports/action_cable.rb, line 21
def initialize(stream_name, cable: nil)
  if stream_name.nil? || stream_name.to_s.empty?
    raise ConfigurationError, "a stream_name is required"
  end

  @stream_name = stream_name.to_s
  @cable = cable
end

Public Instance Methods

broadcast(envelope) click to toggle source

@return [Object] the result of the underlying broadcast

# File lib/openui/rails/stream/transports/action_cable.rb, line 31
def broadcast(envelope)
  server.broadcast(stream_name, envelope.to_h)
end