feat: implement useClient from client controller

This commit is contained in:
Paul Makles
2022-06-28 19:59:58 +01:00
parent ce88fab714
commit 5f2311b09c
72 changed files with 330 additions and 457 deletions

View File

@@ -20,6 +20,7 @@ type Transition =
export default class Session {
state: State = window.navigator.onLine ? "Ready" : "Offline";
user_id: string | null = null;
client: Client | null = null;
constructor() {
@@ -83,6 +84,7 @@ export default class Session {
private destroyClient() {
this.client!.removeAllListeners();
this.user_id = null;
this.client = null;
}
@@ -101,7 +103,7 @@ export default class Session {
}
@action async emit(data: Transition) {
console.info("Handle event:", data);
console.info(`[FSM ${this.user_id ?? "Anonymous"}]`, data);
switch (data.action) {
// Login with session
@@ -112,6 +114,7 @@ export default class Session {
try {
await this.client!.useExistingSession(data.session);
this.user_id = this.client!.user!._id;
} catch (err) {
this.state = "Ready";
throw err;