diff --git a/lib/Service/ApiService.php b/lib/Service/ApiService.php index 1fbbeed1842..46c0890eb4d 100644 --- a/lib/Service/ApiService.php +++ b/lib/Service/ApiService.php @@ -200,8 +200,11 @@ public function push(Session $session, Document $document, int $version, array $ return new DataResponse([]); } try { + // could we just send out all incoming steps directly? without filtering out step1/2 + $this->addToPushQueue($session, $document, [$awareness, ...$steps]); + // either keep sync request to fetch all steps to catch up missed ones + // or generate a sync1 message during save and send it to all clients $result = $this->documentService->addStep($document, $session, $steps, $version, $token); - $this->addToPushQueue($session, $document, $version); } catch (InvalidArgumentException $e) { return new DataResponse($e->getMessage(), 422); } catch (DoesNotExistException|NotPermittedException) { @@ -211,10 +214,9 @@ public function push(Session $session, Document $document, int $version, array $ return new DataResponse($result); } - private function addToPushQueue(Session $session, Document $document, int $version): void { + private function addToPushQueue(Session $session, Document $document, array $steps): void { try { $queue = Server::get(IQueue::class); - $syncResponse = $this->sync($session, $document, $version); $sessions = $this->sessionService->getActiveSessions($document->getId()); $sessions = array_values(array_unique(array_map(fn ($session): ?string => $session['userId'], $sessions))); foreach ($sessions as $userId) { @@ -224,7 +226,7 @@ private function addToPushQueue(Session $session, Document $document, int $versi 'message' => 'text_steps', 'body' => [ 'documentId' => $document->getId(), - 'response' => $syncResponse->getData(), + 'steps' => $steps, ], ]); } diff --git a/src/services/PollingBackend.js b/src/services/PollingBackend.js index 0bca39ee20c..47cc60fceb3 100644 --- a/src/services/PollingBackend.js +++ b/src/services/PollingBackend.js @@ -95,7 +95,7 @@ class PollingBackend { this.fetcher = setInterval(this._fetchSteps.bind(this), 50) document.addEventListener('visibilitychange', this.visibilitychange.bind(this)) this.#notifyPushBus = getNotifyBus() - this.#notifyPushBus?.on('notify_push', this.handleNotifyPush.bind(this)) + // this.#notifyPushBus?.on('notify_push', this.handleNotifyPush.bind(this)) } /** @@ -202,7 +202,7 @@ class PollingBackend { } disconnect() { - this.#notifyPushBus?.off('notify_push', this.handleNotifyPush) + // this.#notifyPushBus?.off('notify_push', this.handleNotifyPush) clearInterval(this.fetcher) this.fetcher = 0 document.removeEventListener('visibilitychange', this.visibilitychange.bind(this)) diff --git a/src/services/WebSocketPolyfill.js b/src/services/WebSocketPolyfill.js index 7ec1ad53bba..fdc5fad4b44 100644 --- a/src/services/WebSocketPolyfill.js +++ b/src/services/WebSocketPolyfill.js @@ -51,11 +51,9 @@ export default function initWebSocketPolyfill(syncService, fileId, initialSessio if (messageBody.documentId !== fileId) { return } - messageBody.response.steps.forEach(steps => { - steps.data.forEach((s) => { - const data = decodeArrayBuffer(s?.step ?? s) - this.onmessage({ data }) - }) + messageBody.steps.forEach(step => { + const data = decodeArrayBuffer(step) + this.onmessage({ data }) }) }) this.url = url