Class: Jason::Broadcaster

Inherits:
Object
  • Object
show all
Defined in:
lib/jason/broadcaster.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(channel) ⇒ Broadcaster

Returns a new instance of Broadcaster.



4
5
6
# File 'lib/jason/broadcaster.rb', line 4

def initialize(channel)
  @channel = channel
end

Instance Attribute Details

#channelObject (readonly)

Returns the value of attribute channel.



2
3
4
# File 'lib/jason/broadcaster.rb', line 2

def channel
  @channel
end

Instance Method Details

#broadcast(message) ⇒ Object



12
13
14
15
16
17
18
19
# File 'lib/jason/broadcaster.rb', line 12

def broadcast(message)
  if Jason.transport_service == :action_cable
    ActionCable.server.broadcast(channel, message)
  elsif Jason.transport_service == :pusher
    $redis_jason.rpush("jason:outbound_message_queue", { channel: pusher_channel_name, name: 'changed', data: message }.to_json)
    Jason::OutboundMessageQueueWorker.perform_async
  end
end

#pusher_channel_nameObject



8
9
10
# File 'lib/jason/broadcaster.rb', line 8

def pusher_channel_name
  "private-#{Jason.pusher_channel_prefix}-#{channel}"
end