Gathering detailed insights and metrics for @kanli8_supabase/realtime-js
Gathering detailed insights and metrics for @kanli8_supabase/realtime-js
npm install @kanli8_supabase/realtime-js
Typescript
Module System
Node Version
NPM Version
67.1
Supply Chain
97.9
Quality
74.7
Maintenance
100
Vulnerability
100
License
TypeScript (96.52%)
JavaScript (2.94%)
CSS (0.53%)
Love this project? Help keep it running — sponsor us today! 🚀
Total Downloads
816
Last Day
2
Last Week
5
Last Month
28
Last Year
157
MIT License
333 Stars
338 Commits
61 Forks
28 Watchers
9 Branches
101 Contributors
Updated on Feb 19, 2025
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
Cumulative downloads
Total Downloads
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
Guides · Reference Docs · Multiplayer Demo
This client enables you to use the following Supabase Realtime's features:
1npm install @supabase/realtime-js
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})
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).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.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})
ack
to true
means that the channel.send
promise will resolve once server replies with acknowledgement that it received the broadcast message request.self
to true
means that the client will receive the broadcast message it sent out.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})
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})
You can see all the channels that your client has instantiatied.
1// Setup... 2 3client.getChannels()
It is highly recommended that you clean up your channels after you're done with them.
1// Setup... 2 3const channel = client.channel('some-channel-to-remove') 4 5channel.subscribe() 6 7client.removeChannel(channel)
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()
This repo draws heavily from phoenix-js.
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
Reason
packaging workflow detected
Details
Reason
dependency not pinned by hash detected -- score normalized to 3
Details
Reason
7 existing vulnerabilities detected
Details
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
security policy file not detected
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
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