Fix love connection (#6275)

Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com>
This commit is contained in:
Denis Bykhov 2024-08-07 11:40:50 +05:00 committed by GitHub
parent ce9a30a3ff
commit 954a3bb9e7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
11 changed files with 38 additions and 15 deletions

View File

@ -87,6 +87,8 @@ export class TParticipantInfo extends TDoc implements ParticipantInfo {
x!: number
y!: number
sessionId!: string | null
}
@Model(love.class.JoinRequest, core.class.Doc, DOMAIN_TRANSIENT)

View File

@ -337,13 +337,18 @@ export class ModelDb extends MemDb {
}
protected async txUpdateDoc (tx: TxUpdateDoc<Doc>): Promise<TxResult> {
const doc = this.getObject(tx.objectId) as any
TxProcessor.updateDoc2Doc(doc, tx)
return tx.retrieve === true ? { object: doc } : {}
try {
const doc = this.getObject(tx.objectId) as any
TxProcessor.updateDoc2Doc(doc, tx)
return tx.retrieve === true ? { object: doc } : {}
} catch (err: any) {}
return {}
}
protected async txRemoveDoc (tx: TxRemoveDoc<Doc>): Promise<TxResult> {
this.delDoc(tx.objectId)
try {
this.delDoc(tx.objectId)
} catch (err: any) {}
return {}
}

View File

@ -136,7 +136,8 @@ export default plugin(presentationId, {
Endpoint: '' as Metadata<string>,
FrontUrl: '' as Asset,
PreviewConfig: '' as Metadata<PreviewConfig | undefined>,
ClientHook: '' as Metadata<ClientHook>
ClientHook: '' as Metadata<ClientHook>,
SessionId: '' as Metadata<string>
},
status: {
FileTooLarge: '' as StatusCode

View File

@ -261,7 +261,7 @@ class Connection implements ClientConnection {
void this.opt?.onConnect?.(
(resp as HelloResponse).reconnect === true ? ClientConnectEvent.Reconnected : ClientConnectEvent.Connected,
null
this.sessionId
)
this.schedulePing(socketId)
return

View File

@ -72,9 +72,12 @@ export async function connect (title: string): Promise<Client | undefined> {
})
},
// We need to refresh all active live queries and clear old queries.
onConnect: (event: ClientConnectEvent) => {
onConnect: (event: ClientConnectEvent, data: any) => {
console.log('WorkbenchClient: onConnect', event)
try {
if (event === ClientConnectEvent.Connected) {
setMetadata(presentation.metadata.SessionId, data)
}
if ((_clientSet && event === ClientConnectEvent.Connected) || event === ClientConnectEvent.Refresh) {
void refreshClient(true)
}

View File

@ -57,7 +57,6 @@
rooms
} from '../stores'
import {
connectRoom,
disconnect,
getRoomName,
isCameraEnabled,

View File

@ -43,6 +43,7 @@
} from '../utils'
import ControlBar from './ControlBar.svelte'
import ParticipantView from './ParticipantView.svelte'
import presentation from '@hcengineering/presentation'
export let withVideo: boolean
export let room: TypeRoom
@ -223,7 +224,11 @@
await $storePromise
if (!$isConnected && !$isCurrentInstanceConnected) {
if (
!$isConnected &&
!$isCurrentInstanceConnected &&
$myInfo?.sessionId === getMetadata(presentation.metadata.SessionId)
) {
const info = $infos.filter((p) => p.room === room._id)
await tryConnect($personByIdStore, $myInfo, room, info, $myRequests, $invites)
}

View File

@ -485,14 +485,16 @@ async function moveToRoom (
y: number,
currentInfo: ParticipantInfo | undefined,
currentPerson: Person,
room: Room
room: Room,
sessionId: string | null
): Promise<void> {
const client = getClient()
if (currentInfo !== undefined) {
await client.diffUpdate(currentInfo, {
x,
y,
room: room._id
room: room._id,
sessionId
})
} else {
await client.createDoc(love.class.ParticipantInfo, core.space.Workspace, {
@ -500,7 +502,8 @@ async function moveToRoom (
y,
room: room._id,
person: currentPerson._id,
name: currentPerson.name
name: currentPerson.name,
sessionId
})
}
const loc = getCurrentLocation()
@ -529,7 +532,7 @@ export async function connectRoom (
room: Room
): Promise<void> {
await disconnect()
await moveToRoom(x, y, currentInfo, currentPerson, room)
await moveToRoom(x, y, currentInfo, currentPerson, room, getMetadata(presentation.metadata.SessionId) ?? null)
await connectLK(currentPerson, room)
}

View File

@ -51,6 +51,7 @@ export interface ParticipantInfo extends Doc {
room: Ref<Room>
x: number
y: number
sessionId: string | null
}
export interface RoomInfo extends Doc {

View File

@ -168,6 +168,9 @@ export async function connect (title: string): Promise<Client | undefined> {
return
}
try {
if (event === ClientConnectEvent.Connected) {
setMetadata(presentation.metadata.SessionId, data)
}
if ((_clientSet && event === ClientConnectEvent.Connected) || event === ClientConnectEvent.Refresh) {
void ctx.with('refresh client', {}, async () => {
await refreshClient(tokenChanged)

View File

@ -84,7 +84,8 @@ async function createUserInfo (acc: Ref<Account>, control: TriggerControl): Prom
name: person !== undefined ? getName(control.hierarchy, person, control.branding?.lastNameFirst) : account.email,
room: room?._id ?? love.ids.Reception,
x: 0,
y: 0
y: 0,
sessionId: null
})
const ptx = control.txFactory.createTxApplyIf(
core.space.Workspace,
@ -93,7 +94,7 @@ async function createUserInfo (acc: Ref<Account>, control: TriggerControl): Prom
[
{
_class: love.class.ParticipantInfo,
query: { person }
query: { person: personId }
}
],
[tx],