feat: access myUserProfile through Client
This commit is contained in:
@@ -1,10 +1,12 @@
|
|||||||
import { io, Socket } from 'socket.io-client'
|
import { io, Socket } from 'socket.io-client'
|
||||||
import { CallMethod, ClientEvent } from './ApiDeclare.ts'
|
import { CallMethod, ClientEvent } from './ApiDeclare.ts'
|
||||||
import ApiCallbackMessage from './ApiCallbackMessage.ts'
|
import ApiCallbackMessage from './ApiCallbackMessage.ts'
|
||||||
|
import User from "./client_data/User.ts"
|
||||||
|
|
||||||
type UnknownObject = { [key: string]: unknown }
|
type UnknownObject = { [key: string]: unknown }
|
||||||
|
|
||||||
class Client {
|
class Client {
|
||||||
|
static myUserProfile?: User
|
||||||
static socket?: Socket
|
static socket?: Socket
|
||||||
static events: { [key: string]: (data: UnknownObject) => UnknownObject } = {}
|
static events: { [key: string]: (data: UnknownObject) => UnknownObject } = {}
|
||||||
static connect() {
|
static connect() {
|
||||||
@@ -32,6 +34,16 @@ class Client {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
static async auth(token: string, timeout: number = 5000) {
|
||||||
|
const re = await this.invoke("User.auth", {
|
||||||
|
access_token: token
|
||||||
|
}, timeout)
|
||||||
|
if (re.code == 200)
|
||||||
|
this.myUserProfile = (await Client.invoke("User.getMyInfo", {
|
||||||
|
token: token
|
||||||
|
})).data as unknown as User
|
||||||
|
return re
|
||||||
|
}
|
||||||
static on(eventName: ClientEvent, func: (data: UnknownObject) => UnknownObject) {
|
static on(eventName: ClientEvent, func: (data: UnknownObject) => UnknownObject) {
|
||||||
this.events[eventName] = func
|
this.events[eventName] = func
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user