Gathering detailed insights and metrics for @supabase/realtime-js
Gathering detailed insights and metrics for @supabase/realtime-js
Gathering detailed insights and metrics for @supabase/realtime-js
Gathering detailed insights and metrics for @supabase/realtime-js
@supabase/supabase-js
Isomorphic Javascript client for Supabase
@supabase-cache-helpers/postgrest-react-query
A collection of React Query utilities for working with Supabase.
@supabase/postgrest-js
Isomorphic PostgREST client
@supabase/functions-js
JS Client library to interact with Supabase Functions.
An isomorphic Javascript client for Supabase Realtime server.
npm install @supabase/realtime-js
60.6
Supply Chain
99.1
Quality
98.3
Maintenance
100
Vulnerability
100
License
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
324 Stars
325 Commits
58 Forks
27 Watching
7 Branches
96 Contributors
Updated on 27 Nov 2024
Minified
Minified + Gzipped
TypeScript (96.5%)
JavaScript (2.97%)
CSS (0.54%)
Cumulative downloads
Total Downloads
Last day
0.9%
85,763
Compared to previous day
Last week
4.7%
520,298
Compared to previous week
Last month
13.1%
2,138,953
Compared to previous month
Last year
157%
17,530,815
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 }, 7}) 8 9const channel = client.channel('test-channel', {}) 10 11channel.subscribe((status, err) => { 12 if (status === 'SUBSCRIBED') { 13 console.log('Connected!') 14 } 15 16 if (status === 'CHANNEL_ERROR') { 17 console.log(`There was an error subscribing to channel: ${err.message}`) 18 } 19 20 if (status === 'TIMED_OUT') { 21 console.log('Realtime server did not respond in time.') 22 } 23 24 if (status === 'CLOSED') { 25 console.log('Realtime channel was unexpectedly closed.') 26 } 27})
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
.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.private
to true
means that the client will use RLS to determine if the user can connect or not to a given channel.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 binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
Reason
packaging workflow detected
Details
Reason
Found 23/24 approved changesets -- score normalized to 9
Reason
dependency not pinned by hash detected -- score normalized to 6
Details
Reason
4 existing vulnerabilities detected
Details
Reason
7 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 5
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 2024-11-18
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