Best practice to subscribe multiple times to the same channel?
I have an angular app with realtime.
My idea was to create a service that holds a realtime channel.
Then I have a page component that subscribe to that channel once the user visits the page, and unsubscribes the channel when the user leaves the page.
However, if the user user visits the page twice, I receive the following error.
What is the best practice here? Do I have to always instantiate a new channel if the user visits the page?
Channel:
const response = await this.notificationsChannel.unsubscribe()
}`
My idea was to create a service that holds a realtime channel.
Then I have a page component that subscribe to that channel once the user visits the page, and unsubscribes the channel when the user leaves the page.
However, if the user user visits the page twice, I receive the following error.
ERROR tried to subscribe multiple times. 'subscribe' can only be called a single time per channel instanceWhat is the best practice here? Do I have to always instantiate a new channel if the user visits the page?
Channel:
private notificationsChannel: RealtimeChannel = supabaseClient
.channel('notificationsChannel')
.on('postgres_changes', {
...
})``
Component
public subscribeToRealtimeNotifications(): void {
this.notificationsChannel.subscribe()
}
public async unsubscribeToRealtimeNotifications(): Promise<void> {const response = await this.notificationsChannel.unsubscribe()
}`