I find that Theia Frontend keeps reconnecting to the Backend after the Backend has shut down, as a result, once the Backend restart, the Frontend can connect to it.
But i want to make the reconnection manually. For example, only if the user move the mouse over the offline page, its Frontend sends a reconnection message to the Backend.
Can i do that? Please help.
We currently use ReconnectingWebSocket
. See https://github.com/eclipse-theia/theia/blob/e95311d16baa865e50a356dc108e1bd800952a33/packages/core/src/browser/messaging/ws-connection-provider.ts#L91
You might be able to rebind this through Inversify to use your own mechanism instead?
Note that you need to provide an instance mimicking a real WebSocket but that never closes. The current connection status depends on traffic going in/out, not on actual disconnections. See https://github.com/eclipse-theia/theia/blob/1ca3ec37c079a6b316278cf292609653e57b8151/packages/core/src/browser/connection-status-service.ts#L152
Yes i see. Once i call ReconnectingWebsockets.close()
, the Frontend will not automatically reconnect to the Backend any more. And if i want to reconnect, calling ReconnectingWebsockets.reconnect()
is well.
But it really confuses me that by doing the following steps, the Frontend can reconnect to the Backend:
- call
ReconnectingWebsockets.close()
in Frontend.
- shut down the Backend manually.
- restart the Backend. (the Frontend will not reconnect to the Backend)
- call
ReconnectingWebsockets.reconnect()
manually in the Frontend.
However, if i shut down the Backend first,
- shut down the Backend manually.
- call
ReconnectingWebsockets.close()
in Frontend.
- restart the Backend. (the Frontend will not reconnect to the Backend)
- call
ReconnectingWebsockets.reconnect()
manually in the Frontend.
the Frontend can never reconnect to the Backend, unless i refresh the page.
I really do not known why.
I find it is because calling ReconnectingWebsockets.close()
sets _closeCalled
to be true, then _connectLock
can not be set to false, which reaults in ReconnectingWebsockets.reconnect()
returns immediately.