Module: Supabase::Realtime::Transformers

Defined in:
lib/supabase/realtime/transformers.rb

Overview

Mirrors realtime-py’s ‘realtime.transformers`. Today this is a single helper used to derive the HTTP endpoint from the WebSocket URL so callers can hit the realtime REST surface (e.g. /api/broadcast, /connections).

Class Method Summary collapse

Class Method Details

.http_endpoint_url(socket_url) ⇒ Object

Converts a realtime socket URL into its HTTP equivalent.

http_endpoint_url("wss://x.supabase.co/realtime/v1/websocket")
# => "https://x.supabase.co/realtime/v1"

Replaces the leading ‘ws`/`wss` scheme with `http`/`https`, strips any `/socket/websocket`, `/socket`, or `/websocket` suffix, and trims trailing slashes. Mirrors py’s regex chain verbatim.



19
20
21
22
23
# File 'lib/supabase/realtime/transformers.rb', line 19

def http_endpoint_url(socket_url)
  url = socket_url.to_s.sub(/\Aws/i, "http")
  url = url.sub(%r{(/socket/websocket|/socket|/websocket)/?\z}i, "")
  url.sub(%r{/+\z}, "")
end

.is_ws_url(url) ⇒ Object

Mirrors supabase-py’s utils.is_ws_url: accepts ws/wss and http/https (which Client#normalize_url upgrades to ws/wss). Any other scheme — or an unparseable string — returns false.



28
29
30
31
32
33
# File 'lib/supabase/realtime/transformers.rb', line 28

def is_ws_url(url)
  scheme = URI.parse(url.to_s).scheme&.downcase
  %w[ws wss http https].include?(scheme)
rescue URI::InvalidURIError
  false
end