Fix websocket restoration

This commit is contained in:
SrGooglo 2025-05-15 14:09:31 +00:00
parent 8163056179
commit d589168e73
2 changed files with 9 additions and 9 deletions

View File

@ -40,11 +40,15 @@ class ComtyApp extends React.Component {
await this.auth.flush()
await this.initialization()
app.cores.api.reset()
app.navigation.goMain()
},
onLogout: async () => {
await this.auth.flush()
app.cores.api.reset()
app.navigation.goAuth()
},
onInvalidSession: async (error) => {

View File

@ -24,6 +24,7 @@ export default class APICore extends Core {
listenEvent: this.listenEvent.bind(this),
unlistenEvent: this.unlistenEvent.bind(this),
emitEvent: this.emitEvent.bind(this),
reset: this.reset.bind(this),
measurePing: measurePing,
useRequest: useRequest,
}
@ -84,6 +85,10 @@ export default class APICore extends Core {
return this.client.ws.sockets.get(instance).off(key, handler)
}
async reset() {
this.client.ws.connectAll()
}
async onInitialize() {
this.client = await createClient({
eventBus: app.eventBus,
@ -93,15 +98,6 @@ export default class APICore extends Core {
},
})
// handle auth events
this.client.eventBus.on("auth:login_success", () => {
this.client.ws.connectAll()
})
this.client.eventBus.on("auth:logout_success", () => {
this.client.ws.connectAll()
})
// make a basic request to check if the API is available
await this.client
.baseRequest({