Skip to content
This repository has been archived by the owner on May 10, 2023. It is now read-only.

Closing Subscriptions to Websocket #30

Closed
RPloutarchou opened this issue Jul 29, 2021 · 4 comments
Closed

Closing Subscriptions to Websocket #30

RPloutarchou opened this issue Jul 29, 2021 · 4 comments

Comments

@RPloutarchou
Copy link

I have multiple subscription open within a mobile game I am developing. I was wandering If there is any way to unsubscribe from all active subscriptions and unregister all their listeners in order to safely reload my game.

@NavidK0
Copy link
Owner

NavidK0 commented Jul 29, 2021

I have multiple subscription open within a mobile game I am developing. I was wandering If there is any way to unsubscribe from all active subscriptions and unregister all their listeners in order to safely reload my game.

You can use GraphQLClient.Unsubscribe(id) to unsubscribe a listener. Unfortunately, there is no way to unsubscribe from all listeners at once because GraphQLClient does not keep track of subscription ids.

That being said, if you want to dispose of the WebSocket and have it make a new one, you can use HttpUtils.Dispose() which will dispose of the current underlying WebSocket (and force it to make a new one the next time a subscription is created). I am unsure if this will unsubscribe all the listeners associated with that WebSocket, however, but it's worth a shot to try and find out.

@RPloutarchou
Copy link
Author

I have multiple subscription open within a mobile game I am developing. I was wandering If there is any way to unsubscribe from all active subscriptions and unregister all their listeners in order to safely reload my game.

You can use GraphQLClient.Unsubscribe(id) to unsubscribe a listener. Unfortunately, there is no way to unsubscribe from all listeners at once because GraphQLClient does not keep track of subscription ids.

That being said, if you want to dispose of the WebSocket and have it make a new one, you can use HttpUtils.Dispose() which will dispose of the current underlying WebSocket (and force it to make a new one the next time a subscription is created). I am unsure if this will unsubscribe all the listeners associated with that WebSocket, however, but it's worth a shot to try and find out.

Thanks for the reply, I will try using the Dispose() method as suggested. Thanks again for your help.

@NavidK0
Copy link
Owner

NavidK0 commented Jul 29, 2021

I have multiple subscription open within a mobile game I am developing. I was wandering If there is any way to unsubscribe from all active subscriptions and unregister all their listeners in order to safely reload my game.

You can use GraphQLClient.Unsubscribe(id) to unsubscribe a listener. Unfortunately, there is no way to unsubscribe from all listeners at once because GraphQLClient does not keep track of subscription ids.
That being said, if you want to dispose of the WebSocket and have it make a new one, you can use HttpUtils.Dispose() which will dispose of the current underlying WebSocket (and force it to make a new one the next time a subscription is created). I am unsure if this will unsubscribe all the listeners associated with that WebSocket, however, but it's worth a shot to try and find out.

Thanks for the reply, I will try using the Dispose() method as suggested. Thanks again for your help.

Do let me know how it goes! There are some easy solutions here that can be added to make this easier for developers.

@RPloutarchou
Copy link
Author

RPloutarchou commented Jul 30, 2021

It works great! Everything else I have tried worked fine in the editor but not on an actual phone. This solution is perfect! Thank you so much for your help!!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants