The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
realtime protocol messages
abc3c7504ee6d5f2
diff --git a/apps/docs/docs/guides/realtime/protocol.mdx b/apps/docs/docs/guides/realtime/protocol.mdxnew file mode 100644index 00000000000..7818171a8d1--- /dev/null+++ b/apps/docs/docs/guides/realtime/protocol.mdx@@ -0,0 +1,107 @@+---+id: protocol+title: Realtime Protocol+description: Understanding Realtime Protocol+sidebar_label: Protocol+---+++## Connection++In the initial message, the client sends the server a configuration of features that wants to use.++```json+{+ "topic":$TOPIC,+ "event":"phx_join",+ "payload":{+ "config":{+ "broadcast":{+ "self":true+ },+ "presence":{+ "key":""+ },+ "postgres_changes":[+ {+ "event":$EVENT,+ "schema":$SCHEMA,+ "table":$TABLE,+ "filter":$FILTER+ }+ ]+ }+ },+ "ref":$REF_NUMBER+}+```++In response, the server sends the Postgres CDC configuration with a unique id. By this id, the client should route incoming changes to the appropriate callback.++```json+{+ "event":"phx_reply",+ "payload":{+ "response":{+ "postgres_changes":[+ {+ "id":13399220,+ "event":"*",+ "filter":$FILTER,+ "schema":$SCHEMA,+ "table":$TABLE+ }+ ]+ },+ "status":"ok"+ },+ "ref":$REF_NUMBER,+ "topic":$TOPIC+}+```++## System message++Currently, a system message uses only to inform about the status of the Postgres CDC subscription. The `payload.status` indicates if the subscription success or not. The body of the `payload.message` can be "Subscribed to PostgreSQL" or "Subscribing to PostgreSQL failed" with subscription params.++```json+{+ "event":"system",+ "payload":{+ "channel":"any",+ "extension":"postgres_changes",+ "message":$MESSAGE,+ "status":"ok" | "error"+ },+ "ref":null,+ "topic":$TOPIC+}+```++## Heartbeat++The heartbeat message should be sent every 60 seconds to avoid a connection timeout.++```json+{+ "topic":"phoenix",+ "event":"heartbeat",+ "payload":{},+ "ref":$REF_NUMBER+}+```++## Access Token++To update the access token need to send to the server the following message and specify a new token in the `payload.access_token` value.++```json+{+ "topic":$TOPIC,+ "event":"access_token",+ "payload":{+ "access_token":$NEW_JWT_TOKEN+ },+ "ref":$REF_NUMBER+}+```