Closed plopezlpz closed 1 month ago
@plopezlpz hello,
newSubscription
adds the subscription to channel to the SDK's internal registry. Duplicate call of newSubscription
with the same channel results into error you've shown.
To solve this you should not only call unsubscribe
, but also removeSubscription
method. See common description all Centrifugo SDKs try to follow: https://centrifugal.dev/docs/transports/client_api#subscription-management
Alternatively, you may keep newSubscription
outside of the component, calling it only once, then when component opens – call subscribe, on navigating out - just call unsubscribe. In this case though subscription will stay in the internal registry after component finished.
Internal registry's goal is to automatically manage resubscribes to channels on reconnect.
thanks a lot @FZambia, working now just calling unsubscribe
and subscribe
withouth the call to newSubscription
I'd like to subscribe or unsubscribe to channels, but I can see that this is not really possible.
I have a svelte component when navigating to a page I want to subscribe to the updates on that ID, when I navigate out I want to unsubscribe, since I no longer need those:
So on loading the page I get subscribed correctly to say channel
a-123
then I get this when calling unsubscribe():unsubscribed: 0, unsubscribe called
If I navigate back to the page I want to resubscribe, I get this error:
I'm not sure if this is somehow possible or desirable.
versions:
JS client: centrifuge: 5.2.2 node: 5.4.5