Sha256: dca0a06ea1c3fd72962ee41c3bc6c7d465a0127200c5647797af491517e29a25

Contents?: true

Size: 728 Bytes

Versions: 6

Compression:

Stored size: 728 Bytes

Contents

# frozen_string_literal: true

module Loco
  class Sender
    def initialize recipient, data = {}
      @recipients = [*recipient]
      @data = data
    end

    def emit
      uuids.each do |uuid|
        NotificationCenterChannel.broadcast_to uuid, @data
      end
    end

    private

      def uuids
        @recipients.map do |r|
          if r.is_a? String
            r
          elsif r.is_a? Hub
            recipients_from_hub r
          else
            WsConnectionManager.new(r).connected_uuids
          end
        end.flatten.uniq
      end

      def recipients_from_hub hub
        hub.raw_members.map do |m|
          WsConnectionManager.new(m).connected_uuids
        end.flatten.uniq
      end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
loco-rails-3.0.6 lib/loco/sender.rb
loco-rails-3.0.5 lib/loco/sender.rb
loco-rails-3.0.4 lib/loco/sender.rb
loco-rails-3.0.3 lib/loco/sender.rb
loco-rails-3.0.2 lib/loco/sender.rb
loco-rails-3.0.1 lib/loco/sender.rb