Hi, we are using graphql-ws in an app using react-native-webview. It actually work quite well untill we switch to another app or put the app in background mode.
Expected Behaviour
The socket should keep reconnect or at least try to re-connect/re-init if needed.
In case re-connect/re-init, we would like to run a specific function to resync data after connect successfully.
Actual Behaviour
All subscription stop working and could not work even when we tried to resubscibe.
We got this after reopen the app.
WebSocket connection to 'wss://my-domain.com/subscription' failed: The operation couldn’t be completed. (kNWErrorDomainPOSIX error 53 - Software caused connection abort)
TCL: -> Socket closed -> code: – 1006
Further Information
Seem like IOS will kill socket connection when app is in background state.
I have read about the issue with safari and tried using ping/pong with client.terminate() and it is not working because the socket connection is completely shutdown, not in pending state.
We managed to re-init socket when reopen app by detect close_code === 1006 then re-register all previous subscription like bellow but feel like it should be a cleaner, better and easier way to do this.
I think we should have a method allow re-init all socket connection and subscriptions when needed. Any ideas?
this.client = createClientWithOnReconnected({
...options,
keepAlive: 5000, // send ping message every 5s
retryWait: () => 2000,
retryAttempts: 30,
on: {
connecting: () => console.log("Connecting to WebSocket"),
connected: (socket) => {
console.log("Connected to WebSocket server", socket);
},
error: (code, reason) => {
console.log(`Socket error:`, { code, reason });
},
closed: ({ code, reason }) => {
console.log(`Connection closed:`, { code, reason });
if (code === 1006) {
// this unsubscribe all existing subscription and resubscribe them
// when asking new subscription and no subscriptions existed, it will try to create new socket connection
reRegisterAllSubsciption()
}
},
},
});
this.client.onReconnected(() => {
console.log("Socket: onReconnected");
refreshData()
});
Hi, we are using graphql-ws in an app using react-native-webview. It actually work quite well untill we switch to another app or put the app in background mode.
Expected Behaviour
Actual Behaviour All subscription stop working and could not work even when we tried to resubscibe. We got this after reopen the app.
Further Information
client.terminate()
and it is not working because the socket connection is completely shutdown, not in pending state.close_code === 1006
then re-register all previous subscription like bellow but feel like it should be a cleaner, better and easier way to do this. I think we should have a method allow re-init all socket connection and subscriptions when needed. Any ideas?