Sha256: a128182841077b362bd55ea58f3149aff5c040b06188db0b126ecdae3aac3f3a

Contents?: true

Size: 1.02 KB

Versions: 5

Compression:

Stored size: 1.02 KB

Contents

require "cable_ready"

module Cubism
  class Broadcaster
    include CableReady::Broadcaster
    include CableReady::StreamIdentifier

    attr_reader :resource

    def initialize(resource:)
      @resource = resource
    end

    def broadcast
      resource.cubicle_element_ids.to_a.each do |element_id|
        /cubicle-(?<block_key>.+)/ =~ element_id
        block = Cubism.store[block_key].block
        view_context = Cubism.store[block_key].context
        html = view_context.capture(users_for(resource, element_id), &block)

        cable_ready[Cubism::PresenceChannel].inner_html(
          selector: "cubicle-element##{element_id}[identifier='#{signed_stream_identifier(resource.to_global_id.to_s)}']",
          html: html
        ).broadcast_to(resource)
      end
    end

    private

    def users_for(resource, element_id)
      users = Cubism.user_class.find(resource.present_users.members)
      users.reject! { |user| user.id == resource.excluded_user_id_for_element_id[element_id].to_i }

      users
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
cubism-0.1.0.pre8 lib/cubism/broadcaster.rb~
cubism-0.1.0.pre7 lib/cubism/broadcaster.rb~
cubism-0.1.0.pre6 lib/cubism/broadcaster.rb~
cubism-0.1.0.pre5 lib/cubism/broadcaster.rb
cubism-0.1.0.pre4 lib/cubism/broadcaster.rb