Compare commits
3 Commits
f097a491ae
...
37281232c0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
37281232c0 | ||
|
|
8b3022bed0 | ||
|
|
8acf72c7bf |
@@ -7,6 +7,7 @@ import User from "./User.ts"
|
|||||||
import UserMySelf from "./UserMySelf.ts"
|
import UserMySelf from "./UserMySelf.ts"
|
||||||
import CallbackError from "./CallbackError.ts"
|
import CallbackError from "./CallbackError.ts"
|
||||||
import Chat from "./Chat.ts"
|
import Chat from "./Chat.ts"
|
||||||
|
import { CallableMethodBeforeAuth } from "lingchair-internal-shared"
|
||||||
|
|
||||||
export {
|
export {
|
||||||
User,
|
User,
|
||||||
@@ -18,11 +19,20 @@ export default class LingChairClient {
|
|||||||
declare client: Socket
|
declare client: Socket
|
||||||
declare access_token: string
|
declare access_token: string
|
||||||
declare refresh_token?: string
|
declare refresh_token?: string
|
||||||
|
declare auto_fresh_token: boolean
|
||||||
|
declare auth_cache: {
|
||||||
|
refresh_token?: string,
|
||||||
|
access_token?: string,
|
||||||
|
account?: string,
|
||||||
|
password?: string,
|
||||||
|
}
|
||||||
constructor(args: {
|
constructor(args: {
|
||||||
server_url: string
|
server_url: string
|
||||||
device_id: string,
|
device_id: string,
|
||||||
io?: Partial<ManagerOptions & SocketOptions>
|
io?: Partial<ManagerOptions & SocketOptions>
|
||||||
|
auto_fresh_token: boolean
|
||||||
}) {
|
}) {
|
||||||
|
this.auto_fresh_token = args.auto_fresh_token || false
|
||||||
this.client = io(args.server_url, {
|
this.client = io(args.server_url, {
|
||||||
transports: ["polling", "websocket", "webtransport"],
|
transports: ["polling", "websocket", "webtransport"],
|
||||||
...args.io,
|
...args.io,
|
||||||
@@ -59,6 +69,15 @@ export default class LingChairClient {
|
|||||||
code: -1,
|
code: -1,
|
||||||
msg: err.message,
|
msg: err.message,
|
||||||
})
|
})
|
||||||
|
if (CallableMethodBeforeAuth.indexOf(method) == -1 && res.code == 401 && this.auto_fresh_token) {
|
||||||
|
if (this.auth_cache)
|
||||||
|
this.auth(this.auth_cache).then((re) => {
|
||||||
|
if (!re) resolve(res)
|
||||||
|
this.invoke(method, args, timeout).then((re) => resolve(re))
|
||||||
|
})
|
||||||
|
else
|
||||||
|
resolve(res)
|
||||||
|
} else
|
||||||
resolve(res)
|
resolve(res)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@@ -99,6 +118,8 @@ export default class LingChairClient {
|
|||||||
if ((!args.access_token && !args.refresh_token) && (!args.account && !args.password))
|
if ((!args.access_token && !args.refresh_token) && (!args.account && !args.password))
|
||||||
throw new Error('Access/Refresh token or account & password required')
|
throw new Error('Access/Refresh token or account & password required')
|
||||||
|
|
||||||
|
this.auth_cache = args
|
||||||
|
|
||||||
this.refresh_token = args.refresh_token
|
this.refresh_token = args.refresh_token
|
||||||
|
|
||||||
let access_token = args.access_token
|
let access_token = args.access_token
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ class Client {
|
|||||||
this.socket?.disconnect()
|
this.socket?.disconnect()
|
||||||
this.socket && delete this.socket
|
this.socket && delete this.socket
|
||||||
this.socket = io({
|
this.socket = io({
|
||||||
transports: ['websocket'],
|
transports: ['websocket', 'polling', 'webtransport'],
|
||||||
auth: {
|
auth: {
|
||||||
device_id: data.device_id,
|
device_id: data.device_id,
|
||||||
session_id: this.sessionId,
|
session_id: this.sessionId,
|
||||||
|
|||||||
@@ -34,6 +34,8 @@ export default function GroupMembersListItem({ user, chat }: Args) {
|
|||||||
dialog({
|
dialog({
|
||||||
headline: "移除群组成员",
|
headline: "移除群组成员",
|
||||||
description: `确定要移除 ${nickname} 吗?`,
|
description: `确定要移除 ${nickname} 吗?`,
|
||||||
|
closeOnEsc: true,
|
||||||
|
closeOnOverlayClick: true,
|
||||||
actions: [
|
actions: [
|
||||||
{
|
{
|
||||||
text: "取消",
|
text: "取消",
|
||||||
|
|||||||
Reference in New Issue
Block a user