Class SupabaseRealtime

java.lang.Object
com.codename1.cloud.supabase.SupabaseRealtime

public class SupabaseRealtime extends Object

Supabase Realtime over com.codename1.io.WebSocket: Phoenix channels with database change events (postgres_changes).

One socket serves every channel. It joins channels, sends a heartbeat every 25 seconds and rejoins after a reconnect. Reconnects back off exponentially, with jitter, up to a minute apart. When the signed-in session changes, the new access token is pushed to every joined channel. Listeners are called on the EDT. On a port without WebSocket support, isSupported() is false and subscribe() does nothing.

Supabase supabase = new Supabase("https://xyzcompany.supabase.co", "public-anon-key");
supabase.realtime().channel("room1")
        .onPostgresChanges("INSERT", "public", "messages", null, new SupabaseRealtime.ChangeListener() {
            public void onChange(String type, Map<String, Object> record, Map<String, Object> oldRecord) {
                Log.p("New message " + record.get("text"));
            }
        })
        .subscribe();
  • Method Details

    • isSupported

      public static boolean isSupported()

      True when this port has a WebSocket client.

      Returns

      whether realtime works here

    • channel

      public SupabaseRealtime.Channel channel(String name)

      Creates a channel. Add listeners, then call subscribe().

      Parameters
      • name: the channel name
      Returns

      the channel

    • disconnect

      public void disconnect()
      Closes the socket and drops every channel.