接通 Windows 与 Web 设备间加密文字聊天
This commit is contained in:
1 parent
b04034ee89
commit
d1efdedc57
27 files changed
+880
-22
No files matched your search
+8
-3
@@ -25,6 +25,7 @@ export const useSession = defineStore('session', () => {
|
||||
const identity = shallowRef<Identity>()
|
||||
const connection = ref('离线')
|
||||
const contactChanges = ref(0)
|
||||
const inboxChanges = ref(0)
|
||||
let token = ''
|
||||
let socket: WebSocket | undefined
|
||||
let retry: ReturnType<typeof setTimeout> | undefined
|
||||
@@ -56,6 +57,7 @@ export const useSession = defineStore('session', () => {
|
||||
attempts = 0
|
||||
}
|
||||
if (type === 'contacts_changed') contactChanges.value++
|
||||
if (type === 'inbox_changed') inboxChanges.value++
|
||||
}
|
||||
active.onclose = (event) => {
|
||||
if (socket !== active) return
|
||||
@@ -90,10 +92,13 @@ export const useSession = defineStore('session', () => {
|
||||
}
|
||||
|
||||
async function authorized<T>(path: string, method = 'GET', body?: object) {
|
||||
const current = token
|
||||
try {
|
||||
return await request<T>(path, method, token, body)
|
||||
const response = await request<T>(path, method, current, body)
|
||||
if (token !== current) throw new Error('登录会话已变更')
|
||||
return response
|
||||
} catch (error) {
|
||||
if (error instanceof APIError && error.status === 401) clear()
|
||||
if (token === current && error instanceof APIError && error.status === 401) clear()
|
||||
throw error
|
||||
}
|
||||
}
|
||||
@@ -104,7 +109,7 @@ export const useSession = defineStore('session', () => {
|
||||
}
|
||||
|
||||
return {
|
||||
identity, connection, contactChanges, authenticate, logout,
|
||||
identity, connection, contactChanges, inboxChanges, authenticate, logout, authorized,
|
||||
devices: () => authorized<Device[]>('/devices'),
|
||||
revoke: (id: string) => authorized<void>('/devices/' + encodeURIComponent(id), 'DELETE'),
|
||||
contacts: () => authorized<Contact[]>('/contacts'),
|
||||
|
||||
Reference in new issue
Block a user