# Realtime subscriptions

`wss://<ref>.<zone>/realtime/v1?apikey=<publishable key>`

## Order

1. On connect you receive `ready`
2. `{"type":"subscribe","channel":"table:notes"}`
3. When that table changes you receive `change`

## What you must do first

**Realtime has to be turned on for each table.** A table you haven't turned on stays silent.

Turn it on with `set_realtime { ref, table: "notes", enabled: true }`, and check which tables are on with `list_realtime_tables`.
In SQL, the statement you used on Supabase works as it is (SQL editor, `run_sql`, migrations):

```sql
alter publication supabase_realtime add table notes;
```

Realtime is turned on for that table once the SQL has run. `drop table notes` turns it off.

`alter publication supabase_realtime add table notes`, as you wrote it for Supabase, runs too. The SQL editor, `run_sql` and migrations take that statement out and turn realtime on for the table once the rest has run (`drop table` turns it off). Tables in the public schema only.

## Only what you can see arrives

Change notifications also have to pass the access rules to be delivered.
A row the publishable key cannot read never arrives over realtime either. That is the point of the feature.

## Other messages

`{"type":"broadcast","channel":"room:1","payload":{...}}`: messages between people
`{"type":"presence","channel":"room:1","state":{...}}`: who is connected

For both broadcast and presence you receive messages **only after you subscribe to the channel**.
If you don't, you get an `error` telling you to subscribe first.

## Settings and private channel rules

```
get_realtime_settings            on or off, public channels allowed, limits
set_realtime_settings            change them (only what is given, owners and admins)
list_realtime_policies           the realtime_messages table's rules
create_realtime_messages_table   make the table rules are written on
add_realtime_policy              add a rule template (signed-in-read | signed-in-write | own-channel)
```

With `allow_public` off only private channels work, and the realtime_messages table's rules decide who joins. Developers and above can add rules.

---

https://end.blackall.ai/docs/realtime?lang=en
