Merge branch 'develop' into staging-new

Signed-off-by: Andrey Sobolev <haiodo@gmail.com>
This commit is contained in:
Andrey Sobolev 2025-02-11 16:26:24 +07:00
commit 80f38389f1
No known key found for this signature in database
GPG Key ID: BD80F68D68D8F7F2

View File

@ -35,7 +35,6 @@ import core, {
FindResult, FindResult,
LoadModelResponse, LoadModelResponse,
MeasureMetricsContext, MeasureMetricsContext,
type PersonUuid,
Ref, Ref,
SearchOptions, SearchOptions,
SearchQuery, SearchQuery,
@ -45,11 +44,12 @@ import core, {
TxApplyIf, TxApplyIf,
TxHandler, TxHandler,
TxResult, TxResult,
type WorkspaceUuid,
clone, clone,
generateId, generateId,
toFindResult, toFindResult,
type MeasureContext type MeasureContext,
type PersonUuid,
type WorkspaceUuid
} from '@hcengineering/core' } from '@hcengineering/core'
import platform, { import platform, {
PlatformError, PlatformError,
@ -467,6 +467,23 @@ class Connection implements ClientConnection {
} }
} }
checkArrayBufferPing (data: ArrayBuffer): boolean {
if (data.byteLength === pingConst.length || data.byteLength === pongConst.length) {
const text = new TextDecoder().decode(data)
if (text === pingConst) {
void this.sendRequest({ method: pingConst, params: [] }).catch((err) => {
this.ctx.error('failed to send ping', { err })
})
return true
}
if (text === pongConst) {
this.pingResponse = Date.now()
return true
}
}
return false
}
private openConnection (ctx: MeasureContext, socketId: number): void { private openConnection (ctx: MeasureContext, socketId: number): void {
this.binaryMode = false this.binaryMode = false
this.helloReceived = false this.helloReceived = false
@ -523,25 +540,17 @@ class Connection implements ClientConnection {
}) })
return return
} }
if ( if (event.data instanceof ArrayBuffer && this.checkArrayBufferPing(event.data)) {
event.data instanceof ArrayBuffer &&
(event.data.byteLength === pingConst.length || event.data.byteLength === pongConst.length)
) {
const text = new TextDecoder().decode(event.data)
if (text === pingConst) {
void this.sendRequest({ method: pingConst, params: [] }).catch((err) => {
this.ctx.error('failed to send ping', { err })
})
}
if (text === pongConst) {
this.pingResponse = Date.now()
}
return return
} }
if (event.data instanceof Blob) { if (event.data instanceof Blob) {
void event.data void event.data
.arrayBuffer() .arrayBuffer()
.then((data) => { .then((data) => {
if (this.checkArrayBufferPing(data)) {
// Support ping/pong
return
}
if (this.compressionMode && this.helloReceived) { if (this.compressionMode && this.helloReceived) {
try { try {
data = uncompress(data) data = uncompress(data)