修复潜在同步问题

pull/1583/head
lyswhut 2023-08-21 13:57:36 +08:00
parent 53bc50d05c
commit 72fe8f3af1
4 changed files with 28 additions and 11 deletions

View File

@ -3,7 +3,7 @@
### 不兼容性变更
该版本修改了同步协议逻辑,至少需要PC端v2.4.0或移动端v1.0.7版本才能连接使用。
该版本修改了同步协议逻辑,同步功能至少需要PC端v2.4.0或移动端v1.1.0版本或同步服务v2.0.0才能连接使用。
### 新增

View File

@ -219,9 +219,14 @@ export const connect = (urlInfo: LX.Sync.Client.UrlInfo, keyInfo: LX.Sync.Client
})
client.addEventListener('close', ({ code }) => {
const err = new Error('closed')
try {
for (const handler of closeEvents) void handler(err)
handleDisconnection()
} catch (err: any) {
log.error(err?.message)
}
closeEvents = []
handleDisconnection()
message2read.onDestroy()
switch (code) {
case SYNC_CLOSE_CODE.normal:
// case SYNC_CLOSE_CODE.failed:

View File

@ -62,6 +62,8 @@ const overwriteRemoteListData = async(socket: LX.Sync.Server.Socket, listData: L
if (excludeIds.includes(client.keyInfo.clientId) || !client.isReady) return
tasks.push(client.remoteSyncList.onListSyncAction(action).then(() => {
updateDeviceSnapshotKey(socket.keyInfo, key)
}).catch(err => {
console.log(err.message)
}))
})
if (!tasks.length) return

View File

@ -41,8 +41,13 @@ const codeTools: {
}
const syncData = async(socket: LX.Sync.Server.Socket) => {
let disconnected = false
socket.onClose(() => {
disconnected = true
})
for (const module of Object.values(modules)) {
await module.sync(socket)
if (disconnected) throw new Error('disconnected')
}
}
@ -215,17 +220,22 @@ const handleStartServer = async(port = 9527, ip = '0.0.0.0') => await new Promis
})
})
socket.addEventListener('close', () => {
if (!socket.isReady) {
const err = new Error('closed')
try {
for (const handler of closeEvents) void handler(err)
} catch (err: any) {
log.error(err?.message)
}
closeEvents = []
msg2call.onDestroy()
if (socket.isReady) {
log.info('deconnection', socket.keyInfo.deviceName)
// events = {}
if (!status.devices.length) handleUnconnection()
} else {
const queryData = url.parse(request.url as string, true).query as Record<string, string>
log.info('deconnection', queryData.i)
return
}
const err = new Error('closed')
for (const handler of closeEvents) void handler(err)
// events = {}
closeEvents = []
if (!status.devices.length) handleUnconnection()
log.info('deconnection', socket.keyInfo.deviceName)
})
socket.onClose = function(handler: typeof closeEvents[number]) {
closeEvents.push(handler)