Class: Supabase::Realtime::Message
- Inherits:
-
Struct
- Object
- Struct
- Supabase::Realtime::Message
- Defined in:
- lib/supabase/realtime/message.rb
Overview
A Phoenix Channel frame: { event, topic, payload, ref, join_ref }. Used both for outbound pushes and parsed inbound messages.
Instance Attribute Summary collapse
-
#event ⇒ Object
Returns the value of attribute event.
-
#join_ref ⇒ Object
Returns the value of attribute join_ref.
-
#payload ⇒ Object
Returns the value of attribute payload.
-
#ref ⇒ Object
Returns the value of attribute ref.
-
#topic ⇒ Object
Returns the value of attribute topic.
Class Method Summary collapse
-
.parse(raw) ⇒ Object
Parse a raw JSON frame received on the WebSocket into a Message.
Instance Method Summary collapse
Instance Attribute Details
#event ⇒ Object
Returns the value of attribute event
11 12 13 |
# File 'lib/supabase/realtime/message.rb', line 11 def event @event end |
#join_ref ⇒ Object
Returns the value of attribute join_ref
11 12 13 |
# File 'lib/supabase/realtime/message.rb', line 11 def join_ref @join_ref end |
#payload ⇒ Object
Returns the value of attribute payload
11 12 13 |
# File 'lib/supabase/realtime/message.rb', line 11 def payload @payload end |
#ref ⇒ Object
Returns the value of attribute ref
11 12 13 |
# File 'lib/supabase/realtime/message.rb', line 11 def ref @ref end |
#topic ⇒ Object
Returns the value of attribute topic
11 12 13 |
# File 'lib/supabase/realtime/message.rb', line 11 def topic @topic end |
Class Method Details
.parse(raw) ⇒ Object
Parse a raw JSON frame received on the WebSocket into a Message. Returns nil (and logs a warning) when the frame isn’t well-formed JSON — the caller (read-loop in Client#handle_inbound) treats nil as “skip this frame” so a single garbled byte sequence can’t kill the loop. Closes US-017 / F-C-minor: previously raised ProtocolError and propagated up into the socket adapter, taking down the read thread on first bad frame.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/supabase/realtime/message.rb', line 28 def self.parse(raw) json = JSON.parse(raw) new( event: json["event"], topic: json["topic"], payload: json["payload"] || {}, ref: json["ref"], join_ref: json["join_ref"] ) rescue JSON::ParserError => e msg = "[Supabase::Realtime] Skipping malformed Phoenix frame: #{e.}" if defined?(@logger) && @logger.respond_to?(:warn) @logger.warn(msg) else warn(msg) end nil end |
Instance Method Details
#to_json ⇒ Object
12 13 14 15 16 17 18 19 20 |
# File 'lib/supabase/realtime/message.rb', line 12 def to_json(*) JSON.generate( "event" => event, "topic" => topic, "payload" => payload, "ref" => ref, "join_ref" => join_ref ) end |