Module: Supabase::Realtime::Socket

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

Instance Method Details

#closeObject

Raises:

  • (NotImplementedError)


25
# File 'lib/supabase/realtime/socket.rb', line 25

def close;   raise NotImplementedError; end

#close_callbacksObject



36
# File 'lib/supabase/realtime/socket.rb', line 36

def close_callbacks;   @close_callbacks   ||= []; end

#connectObject

The minimum surface. Including it gives default no-op implementations so subclasses can override piecemeal.

Raises:

  • (NotImplementedError)


24
# File 'lib/supabase/realtime/socket.rb', line 24

def connect; raise NotImplementedError; end

#connected?Boolean

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)


27
# File 'lib/supabase/realtime/socket.rb', line 27

def connected?; raise NotImplementedError; end

#error_callbacksObject



37
# File 'lib/supabase/realtime/socket.rb', line 37

def error_callbacks;   @error_callbacks   ||= []; end

#message_callbacksObject



34
# File 'lib/supabase/realtime/socket.rb', line 34

def message_callbacks; @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 on_message(&blk); message_callbacks << blk; end

#on_open(&blk) ⇒ Object



30
# File 'lib/supabase/realtime/socket.rb', line 30

def on_open(&blk);    open_callbacks    << blk; end

#open_callbacksObject



35
# File 'lib/supabase/realtime/socket.rb', line 35

def open_callbacks;    @open_callbacks    ||= []; end

#send(_payload) ⇒ Object

Raises:

  • (NotImplementedError)


26
# File 'lib/supabase/realtime/socket.rb', line 26

def send(_payload); raise NotImplementedError; end