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. Raises ProtocolError if the frame isn’t well-formed JSON.
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/supabase/realtime/message.rb', line 24 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 raise Errors::ProtocolError, "Malformed Phoenix frame: #{e.}" 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 |