Send ephemeral messages with Broadcast, track and synchronize state with Presence, and listen to database changes with Postgres Change Data Capture (CDC).
This client enables you to use the following Supabase Realtime's features:
Broadcast: send ephemeral messages from client to clients with minimal latency. Use cases include sharing cursor positions between users.
Presence: track and synchronize shared state across clients with the help of CRDTs. Use cases include tracking which users are currently viewing a specific webpage.
Postgres Change Data Capture (CDC): listen for changes in your PostgreSQL database and send them to clients.
Usage
Installing the Package
1npm install @supabase/realtime-js
Creating a Channel
1import { RealtimeClient } from '@supabase/realtime-js'
23const client = new RealtimeClient(REALTIME_URL, {
4 params: {
5 apikey: API_KEY
6 },
7})
89const channel = client.channel('test-channel', {})
1011channel.subscribe((status, err) => {
12 if (status === 'SUBSCRIBED') {
13 console.log('Connected!')
14 }
1516 if (status === 'CHANNEL_ERROR') {
17 console.log(`There was an error subscribing to channel: ${err.message}`)
18 }
1920 if (status === 'TIMED_OUT') {
21 console.log('Realtime server did not respond in time.')
22 }
2324 if (status === 'CLOSED') {
25 console.log('Realtime channel was unexpectedly closed.')
26 }
27})
Notes:
REALTIME_URL is 'ws://localhost:4000/socket' when developing locally and 'wss://<project_ref>.supabase.co/realtime/v1' when connecting to your Supabase project.
API_KEY is a JWT whose claims must contain exp and role (existing database role).
Channel name can be any string.
Broadcast
Your client can send and receive messages based on the event.
Setting ack to true means that the channel.send promise will resolve once server replies with acknowledgement that it received the broadcast message request.
Setting self to true means that the client will receive the broadcast message it sent out.
Setting private to true means that the client will use RLS to determine if the user can connect or not to a given channel.
Presence
Your client can track and sync state that's stored in the channel.
12 commit(s) and 4 issue activity found in the last 90 days -- score normalized to 10
Reason
license file detected
Details
Info: project has a license file: LICENSE.md:0
Info: FSF or OSI recognized license: MIT License: LICENSE.md:0
Reason
packaging workflow detected
Details
Info: Project packages its releases by way of GitHub Actions.: .github/workflows/release.yml:11
Reason
dependency not pinned by hash detected -- score normalized to 3
Details
Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:27: update your workflow using https://app.stepsecurity.io/secureworkflow/supabase/realtime-js/ci.yml/master?enable=pin
Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:29: update your workflow using https://app.stepsecurity.io/secureworkflow/supabase/realtime-js/ci.yml/master?enable=pin
Warn: third-party GitHubAction not pinned by hash: .github/workflows/ci.yml:33: update your workflow using https://app.stepsecurity.io/secureworkflow/supabase/realtime-js/ci.yml/master?enable=pin
Warn: third-party GitHubAction not pinned by hash: .github/workflows/ci.yml:41: update your workflow using https://app.stepsecurity.io/secureworkflow/supabase/realtime-js/ci.yml/master?enable=pin
Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/docs.yml:20: update your workflow using https://app.stepsecurity.io/secureworkflow/supabase/realtime-js/docs.yml/master?enable=pin
Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/docs.yml:23: update your workflow using https://app.stepsecurity.io/secureworkflow/supabase/realtime-js/docs.yml/master?enable=pin
Warn: third-party GitHubAction not pinned by hash: .github/workflows/docs.yml:33: update your workflow using https://app.stepsecurity.io/secureworkflow/supabase/realtime-js/docs.yml/master?enable=pin
Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/release.yml:20: update your workflow using https://app.stepsecurity.io/secureworkflow/supabase/realtime-js/release.yml/master?enable=pin
Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/release.yml:23: update your workflow using https://app.stepsecurity.io/secureworkflow/supabase/realtime-js/release.yml/master?enable=pin
Info: 0 out of 6 GitHub-owned GitHubAction dependencies pinned
Info: 0 out of 3 third-party GitHubAction dependencies pinned
Info: 2 out of 2 npmCommand dependencies pinned
Reason
7 existing vulnerabilities detected
Details
Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv
Warn: Project is vulnerable to: GHSA-7m27-7ghc-44w9
Warn: Project is vulnerable to: GHSA-67mh-4wv8-2f99
Warn: Project is vulnerable to: GHSA-mwcw-c2x4-8c55
Warn: Project is vulnerable to: GHSA-vg6x-rcgg-rjx6
Warn: Project is vulnerable to: GHSA-9crc-q9x8-hgqq
Reason
detected GitHub workflow tokens with excessive permissions
Details
Warn: no topLevel permission defined: .github/workflows/ci.yml:1
Warn: no topLevel permission defined: .github/workflows/docs.yml:1
Warn: no topLevel permission defined: .github/workflows/release.yml:1
Info: no jobLevel write permissions found
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Warn: no fuzzer integrations found
Reason
security policy file not detected
Details
Warn: no security policy file detected
Warn: no security file to analyze
Warn: no security file to analyze
Warn: no security file to analyze
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Warn: 0 commits out of 30 are checked with a SAST tool
Score
5.6
/10
Last Scanned on 2025-02-10
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.