Class: ActionCable::Server::Broadcasting::Broadcaster

Inherits:
Object
  • Object
show all
Defined in:
actioncable/lib/action_cable/server/broadcasting.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(server, broadcasting, coder:) ⇒ Broadcaster

Returns a new instance of Broadcaster.


35
36
37
# File 'actioncable/lib/action_cable/server/broadcasting.rb', line 35

def initialize(server, broadcasting, coder:)
  @server, @broadcasting, @coder = server, broadcasting, coder
end

Instance Attribute Details

#broadcastingObject (readonly)

Returns the value of attribute broadcasting


33
34
35
# File 'actioncable/lib/action_cable/server/broadcasting.rb', line 33

def broadcasting
  @broadcasting
end

#coderObject (readonly)

Returns the value of attribute coder


33
34
35
# File 'actioncable/lib/action_cable/server/broadcasting.rb', line 33

def coder
  @coder
end

#serverObject (readonly)

Returns the value of attribute server


33
34
35
# File 'actioncable/lib/action_cable/server/broadcasting.rb', line 33

def server
  @server
end

Instance Method Details

#broadcast(message) ⇒ Object


39
40
41
42
43
# File 'actioncable/lib/action_cable/server/broadcasting.rb', line 39

def broadcast(message)
  server.logger.info "[ActionCable] Broadcasting to #{broadcasting}: #{message.inspect}"
  encoded = coder ? coder.encode(message) : message
  server.pubsub.broadcast broadcasting, encoded
end