Installations
npm install @kanli8_supabase/realtime-js
Developer Guide
Typescript
Yes
Module System
CommonJS
Node Version
16.17.1
NPM Version
8.15.0
Score
67.1
Supply Chain
97.9
Quality
74.7
Maintenance
100
Vulnerability
100
License
Releases
Contributors
Languages
TypeScript (96.52%)
JavaScript (2.94%)
CSS (0.53%)
Love this project? Help keep it running — sponsor us today! 🚀
Developer
Download Statistics
Total Downloads
816
Last Day
2
Last Week
5
Last Month
28
Last Year
157
GitHub Statistics
MIT License
333 Stars
338 Commits
61 Forks
28 Watchers
9 Branches
101 Contributors
Updated on Feb 19, 2025
Package Meta Information
Latest Version
2.4.0-6
Package Id
@kanli8_supabase/realtime-js@2.4.0-6
Unpacked Size
351.56 kB
Size
51.22 kB
File Count
93
NPM Version
8.15.0
Node Version
16.17.1
Published on
Apr 26, 2023
Total Downloads
Cumulative downloads
Total Downloads
816
Last Day
100%
2
Compared to previous day
Last Week
-16.7%
5
Compared to previous week
Last Month
180%
28
Compared to previous month
Last Year
-76.2%
157
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Supabase Realtime Client
Send ephemeral messages with Broadcast, track and synchronize state with Presence, and listen to database changes with Postgres Change Data Capture (CDC).
Guides · Reference Docs · Multiplayer Demo
Overview
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' 2 3const client = new RealtimeClient(REALTIME_URL, { 4 params: { 5 apikey: API_KEY, 6 eventsPerSecond: 10, 7 }, 8}) 9 10const channel = client.channel('test-channel', {}) 11 12channel.subscribe((status, err) => { 13 if (status === 'SUBSCRIBED') { 14 console.log('Connected!') 15 } 16 17 if (status === 'CHANNEL_ERROR') { 18 console.log(`There was an error subscribing to channel: ${err.message}`) 19 } 20 21 if (status === 'TIMED_OUT') { 22 console.log('Realtime server did not respond in time.') 23 } 24 25 if (status === 'CLOSED') { 26 console.log('Realtime channel was unexpectedly closed.') 27 } 28})
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 containexp
androle
(existing database role).- Channel name can be any
string
. eventsPerSecond
, or client-side rate limiting, enforces the number of events sent to the Realtime server uniformly spread across a second. The default is 10, which means that the client can send one event, whether that's Broadcast/Presence/Postgres CDC, every 100 milliseconds. You may change this as you see fit, and choose to disable by passing in a negative number, but note that the server's rate limiting will need to be updated accordingly. You can learn more about Realtime's rate limits here: https://supabase.com/docs/guides/realtime/rate-limits.
Broadcast
Your client can send and receive messages based on the event
.
1// Setup... 2 3const channel = client.channel('broadcast-test', { broadcast: { ack: false, self: false } }) 4 5channel.on('broadcast', { event: 'some-event' }, (payload) => 6 console.log(payload) 7) 8 9channel.subscribe(async (status) => { 10 if (status === 'SUBSCRIBED') { 11 // Send message to other clients listening to 'broadcast-test' channel 12 await channel.send({ 13 type: 'broadcast', 14 event: 'some-event', 15 payload: { hello: 'world' }, 16 }) 17 } 18})
Notes:
- Setting
ack
totrue
means that thechannel.send
promise will resolve once server replies with acknowledgement that it received the broadcast message request. - Setting
self
totrue
means that the client will receive the broadcast message it sent out.
Presence
Your client can track and sync state that's stored in the channel.
1// Setup... 2 3const channel = client.channel( 4 'presence-test', 5 { 6 config: { 7 presence: { 8 key: '' 9 } 10 } 11 } 12) 13 14channel.on('presence', { event: 'sync' }, () => { 15 console.log('Online users: ', channel.presenceState()) 16}) 17 18channel.on('presence', { event: 'join' }, ({ newPresences }) => { 19 console.log('New users have joined: ', newPresences) 20}) 21 22channel.on('presence', { event: 'leave' }, ({ leftPresences }) => { 23 console.log('Users have left: ', leftPresences) 24}) 25 26channel.subscribe(async (status) => { 27 if (status === 'SUBSCRIBED') { 28 const status = await channel.track({ 'user_id': 1 }) 29 console.log(status) 30 } 31})
Postgres CDC
Receive database changes on the client.
1// Setup... 2 3const channel = client.channel('db-changes') 4 5channel.on('postgres_changes', { event: '*', schema: 'public' }, (payload) => { 6 console.log('All changes in public schema: ', payload) 7}) 8 9channel.on('postgres_changes', { event: 'INSERT', schema: 'public', table: 'messages' }, (payload) => { 10 console.log('All inserts in messages table: ', payload) 11}) 12 13channel.on('postgres_changes', { event: 'UPDATE', schema: 'public', table: 'users', filter: 'username=eq.Realtime' }, (payload) => { 14 console.log('All updates on users table when username is Realtime: ', payload) 15}) 16 17channel.subscribe(async (status) => { 18 if (status === 'SUBSCRIBED') { 19 console.log('Ready to receive database changes!') 20 } 21})
Get All Channels
You can see all the channels that your client has instantiatied.
1// Setup... 2 3client.getChannels()
Cleanup
It is highly recommended that you clean up your channels after you're done with them.
- Remove a single channel
1// Setup... 2 3const channel = client.channel('some-channel-to-remove') 4 5channel.subscribe() 6 7client.removeChannel(channel)
- Remove all channels
1// Setup... 2 3const channel1 = client.channel('a-channel-to-remove') 4const channel2 = client.channel('another-channel-to-remove') 5 6channel1.subscribe() 7channel2.subscribe() 8 9client.removeAllChannels()
Credits
This repo draws heavily from phoenix-js.
License
MIT.

No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
all changesets reviewed
Reason
no binaries found in the repo
Reason
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.
Learn More