const subscribe = () => {
const channel = supabase.realtime
.channel(`sync-activities-${uuidv4()}`)
.on("postgres_changes", { event: "*", schema: "public", table: "activities" },
async (payload) => { /* process */ }
)
.subscribe(async (status, err) => {
if (status === "SUBSCRIBED") return;
if (["CLOSED", "CHANNEL_ERROR", "TIMED_OUT"].includes(status)) {
await supabase.removeChannel(channel);
subscribe();
}
});
};
subscribe();
const subscribe = () => {
const channel = supabase.realtime
.channel(`sync-activities-${uuidv4()}`)
.on("postgres_changes", { event: "*", schema: "public", table: "activities" },
async (payload) => { /* process */ }
)
.subscribe(async (status, err) => {
if (status === "SUBSCRIBED") return;
if (["CLOSED", "CHANNEL_ERROR", "TIMED_OUT"].includes(status)) {
await supabase.removeChannel(channel);
subscribe();
}
});
};
subscribe();