Module: Rage::SSE

Defined in:
lib/rage/sse/sse.rb

Defined Under Namespace

Classes: ConnectionProxy, Message

Class Method Summary collapse

Class Method Details

.message(data, id: nil, event: nil, retry: nil) ⇒ Message

A factory method for creating Server-Sent Events.

Examples:

render sse: Rage::SSE.message(current_user.profile, id: current_user.id)

Parameters:

  • data (String, #to_json)

    The data field for the SSE event. If the object provided is not a string, it will be serialized to JSON.

  • id (String, nil) (defaults to: nil)

    The id field for the SSE event. This can be used to track messages.

  • event (String, nil) (defaults to: nil)

    The event field for the SSE event. This can be used to define custom event types.

  • retry (Integer, nil) (defaults to: nil)

    The retry field for the SSE event, in milliseconds. This value is used to instruct the client how long to wait before attempting to reconnect.

Returns:

  • (Message)

    The formatted SSE event.



13
14
15
# File 'lib/rage/sse/sse.rb', line 13

def self.message(data, id: nil, event: nil, retry: nil)
  Message.new(data:, id:, event:, retry:)
end