Module: Supabase::Realtime::Socket
- Included in:
- Supabase::Realtime::Sockets::AsyncWebsocket, Supabase::Realtime::Sockets::WebsocketClientSimple, TestSocket
- Defined in:
- lib/supabase/realtime/socket.rb
Overview
Transport interface that Client talks to. A real implementation wraps a WebSocket; TestSocket stays in-memory for specs.
Implementations must provide:
- `connect` — open the underlying transport
- `close` — tear it down
- `send(payload)` — push one raw JSON frame to the server
- `connected?` — boolean state predicate
- `on_message(&blk)` — register an inbound-frame callback (raw JSON string)
- `on_open(&blk)` — register an on-open callback
- `on_close(&blk)` — register an on-close callback
The Client never assumes a specific WebSocket library; bring your own (websocket-client-simple for sync, async-websocket for async, etc.) by implementing this interface.
Instance Method Summary collapse
- #close ⇒ Object
- #close_callbacks ⇒ Object
-
#connect ⇒ Object
The minimum surface.
- #connected? ⇒ Boolean
- #error_callbacks ⇒ Object
- #message_callbacks ⇒ Object
- #on_close(&blk) ⇒ Object
- #on_error(&blk) ⇒ Object
- #on_message(&blk) ⇒ Object
- #on_open(&blk) ⇒ Object
- #open_callbacks ⇒ Object
- #send(_payload) ⇒ Object
Instance Method Details
#close ⇒ Object
25 |
# File 'lib/supabase/realtime/socket.rb', line 25 def close; raise NotImplementedError; end |
#close_callbacks ⇒ Object
36 |
# File 'lib/supabase/realtime/socket.rb', line 36 def close_callbacks; @close_callbacks ||= []; end |
#connect ⇒ Object
The minimum surface. Including it gives default no-op implementations so subclasses can override piecemeal.
24 |
# File 'lib/supabase/realtime/socket.rb', line 24 def connect; raise NotImplementedError; end |
#connected? ⇒ Boolean
27 |
# File 'lib/supabase/realtime/socket.rb', line 27 def connected?; raise NotImplementedError; end |
#error_callbacks ⇒ Object
37 |
# File 'lib/supabase/realtime/socket.rb', line 37 def error_callbacks; @error_callbacks ||= []; end |
#message_callbacks ⇒ Object
34 |
# File 'lib/supabase/realtime/socket.rb', line 34 def ; @message_callbacks ||= []; end |
#on_close(&blk) ⇒ Object
31 |
# File 'lib/supabase/realtime/socket.rb', line 31 def on_close(&blk); close_callbacks << blk; end |
#on_error(&blk) ⇒ Object
32 |
# File 'lib/supabase/realtime/socket.rb', line 32 def on_error(&blk); error_callbacks << blk; end |
#on_message(&blk) ⇒ Object
29 |
# File 'lib/supabase/realtime/socket.rb', line 29 def (&blk); << blk; end |
#on_open(&blk) ⇒ Object
30 |
# File 'lib/supabase/realtime/socket.rb', line 30 def on_open(&blk); open_callbacks << blk; end |
#open_callbacks ⇒ Object
35 |
# File 'lib/supabase/realtime/socket.rb', line 35 def open_callbacks; @open_callbacks ||= []; end |
#send(_payload) ⇒ Object
26 |
# File 'lib/supabase/realtime/socket.rb', line 26 def send(_payload); raise NotImplementedError; end |