Skip to content

Commit 9a4009a

Browse files
authored
Merge pull request #473 from supabase/fix/realtime-broadcast
fix: only enrich payload for database changes
2 parents 53decab + ddb6676 commit 9a4009a

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

src/lib/SupabaseRealtimeClient.ts

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -34,27 +34,27 @@ export class SupabaseRealtimeClient {
3434
* @param filter An object that specifies what you want to listen to from the event.
3535
* @param callback A callback function that is called whenever the event occurs.
3636
*/
37-
on(
38-
event: string,
39-
filter?: Record<string, string>,
40-
callback?: (payload: SupabaseRealtimePayload<any>) => void
41-
) {
42-
this.channel.on(event, filter ?? {}, (payload: any) => {
43-
const { schema, table, commit_timestamp, type, errors } = payload.payload
44-
let enrichedPayload: SupabaseRealtimePayload<any> = {
45-
schema: schema,
46-
table: table,
47-
commit_timestamp: commit_timestamp,
48-
eventType: type,
49-
new: {},
50-
old: {},
51-
errors: errors,
52-
}
37+
on(event: string, filter?: Record<string, string>, callback?: (payload: any) => void) {
38+
this.channel.on(event, filter ?? {}, ({ payload }: { payload: any }) => {
39+
let enrichedPayload = payload
5340

54-
enrichedPayload = { ...enrichedPayload, ...this.getPayloadRecords(payload.payload) }
41+
if (event === 'realtime') {
42+
const { schema, table, commit_timestamp, type, errors } = enrichedPayload
43+
enrichedPayload = {
44+
schema: schema,
45+
table: table,
46+
commit_timestamp: commit_timestamp,
47+
eventType: type,
48+
new: {},
49+
old: {},
50+
errors: errors,
51+
}
52+
enrichedPayload = { ...enrichedPayload, ...this.getPayloadRecords(payload) }
53+
}
5554

5655
callback && callback(enrichedPayload)
5756
})
57+
5858
return this
5959
}
6060

0 commit comments

Comments
 (0)