NavidK0 / SimpleGraphQL-For-Unity

A simple graphQL client that allows one to use .graphql files (or code) for queries, mutations, and subscriptions with Unity.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Closing Subscriptions to Websocket

RPloutarchou opened this issue · comments

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.

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.

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.

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.

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!!