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

Inherits:
Object
  • Object
show all
Defined in:
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.



38
39
40
# File 'lib/action_cable/server/broadcasting.rb', line 38

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

Instance Attribute Details

#broadcastingObject (readonly)

Returns the value of attribute broadcasting.



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

def broadcasting
  @broadcasting
end

#coderObject (readonly)

Returns the value of attribute coder.



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

def coder
  @coder
end

#serverObject (readonly)

Returns the value of attribute server.



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

def server
  @server
end

Instance Method Details

#broadcast(message) ⇒ Object



42
43
44
45
46
47
48
49
50
# File 'lib/action_cable/server/broadcasting.rb', line 42

def broadcast(message)
  server.logger.debug "[ActionCable] Broadcasting to #{broadcasting}: #{message.inspect}"

  payload = { broadcasting: broadcasting, message: message, coder: coder }
  ActiveSupport::Notifications.instrument("broadcast.action_cable", payload) do
    encoded = coder ? coder.encode(message) : message
    server.pubsub.broadcast broadcasting, encoded
  end
end