|
3 | 3 | * SPDX-License-Identifier: AGPL-3.0-or-later |
4 | 4 | */ |
5 | 5 |
|
| 6 | +import { decodeArrayBuffer, encodeArrayBuffer } from '../helpers/base64' |
6 | 7 | import { logger } from '../helpers/logger.js' |
7 | | -import { decodeArrayBuffer } from '../helpers/base64' |
8 | 8 | import getNotifyBus from './NotifyService.js' |
9 | 9 | import type { Step, Session, SyncService } from './SyncService' |
10 | 10 |
|
@@ -76,16 +76,24 @@ export default function initWebSocketPolyfill(syncService: SyncService, fileId: |
76 | 76 | send(step: Uint8Array<ArrayBufferLike>) { |
77 | 77 | // Useful for debugging what steps are sent and how they were initiated |
78 | 78 | // logStep(step) |
79 | | - if (this.#processingVersion) { |
80 | | - // this is a direct response while processing the step |
81 | | - console.error(`Failed to process step ${this.#processingVersion}.`, { |
82 | | - lastSuccessfullyProcessed: syncService.version, |
83 | | - sendingSyncStep1: step, |
84 | | - }) |
85 | | - // Do not increase the syncService.version for the current steps |
86 | | - // as we failed to process them. |
87 | | - this.#processingVersion = 0 |
| 79 | + |
| 80 | + const encoded = encodeArrayBuffer(step) |
| 81 | + const isSyncStep1 = encoded < 'AAE' |
| 82 | + if (!this.#processingVersion || !isSyncStep1) { |
| 83 | + syncService.sendStep(step) |
| 84 | + return |
88 | 85 | } |
| 86 | + |
| 87 | + // If `this.#processingVersion` is set, we're in the middle of applying steps of one version. |
| 88 | + // If `isSyncStep1`, Yjs failed to integrate a message due to pending structs. |
| 89 | + // Log and ask for recovery due to a not applied/missing step. |
| 90 | + console.error(`Failed to process step ${this.#processingVersion}.`, { |
| 91 | + lastSuccessfullyProcessed: syncService.version, |
| 92 | + sendingSyncStep1: step, |
| 93 | + }) |
| 94 | + // Do not increase the syncService.version for the current steps |
| 95 | + // as we failed to process them. |
| 96 | + this.#processingVersion = 0 |
89 | 97 | syncService.sendRecoveryStep(step) |
90 | 98 | } |
91 | 99 |
|
|
0 commit comments