Skip to content

Commit

Permalink
major (#279): Implemented new optimised algorithm for merging OT upda…
Browse files Browse the repository at this point in the history
…tes and waiting for updates to be received before sending more
  • Loading branch information
Luna-Klatzer committed Mar 2, 2025
1 parent 85bb763 commit 19de3b3
Show file tree
Hide file tree
Showing 23 changed files with 720 additions and 206 deletions.
146 changes: 146 additions & 0 deletions images/Optimised-Sync-Algorithm.drawio
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
<mxfile host="app.diagrams.net" agent="Mozilla/5.0 (X11; Linux x86_64; rv:135.0) Gecko/20100101 Firefox/135.0" version="26.0.16">
<diagram name="Page-1" id="XjZ5yrti3hqe7NaUJyNq">
<mxGraphModel dx="768" dy="452" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="850" pageHeight="1100" math="0" shadow="0">
<root>
<mxCell id="0" />
<mxCell id="1" parent="0" />
<mxCell id="qi1Hokcf2H9-zP8ce8hU-1" value="Optimised Sync Algorithm" style="swimlane;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="20" y="160" width="740" height="320" as="geometry" />
</mxCell>
<mxCell id="qi1Hokcf2H9-zP8ce8hU-47" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=1;exitY=0.5;exitDx=0;exitDy=0;entryX=0;entryY=0.5;entryDx=0;entryDy=0;" edge="1" parent="qi1Hokcf2H9-zP8ce8hU-1" source="qi1Hokcf2H9-zP8ce8hU-2" target="qi1Hokcf2H9-zP8ce8hU-43">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="qi1Hokcf2H9-zP8ce8hU-2" value="" style="ellipse;whiteSpace=wrap;html=1;aspect=fixed;fillColor=#000000;" vertex="1" parent="qi1Hokcf2H9-zP8ce8hU-1">
<mxGeometry x="20" y="149.5" width="20" height="20" as="geometry" />
</mxCell>
<mxCell id="qi1Hokcf2H9-zP8ce8hU-9" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=1;exitY=0.5;exitDx=0;exitDy=0;entryX=0;entryY=0.5;entryDx=0;entryDy=0;" edge="1" parent="qi1Hokcf2H9-zP8ce8hU-1" source="qi1Hokcf2H9-zP8ce8hU-3" target="qi1Hokcf2H9-zP8ce8hU-7">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="qi1Hokcf2H9-zP8ce8hU-3" value="&lt;div&gt;merge any compatible OTs&lt;/div&gt;" style="rounded=1;whiteSpace=wrap;html=1;" vertex="1" parent="qi1Hokcf2H9-zP8ce8hU-1">
<mxGeometry x="189" y="136" width="70" height="46" as="geometry" />
</mxCell>
<mxCell id="qi1Hokcf2H9-zP8ce8hU-15" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=1;exitY=0.5;exitDx=0;exitDy=0;entryX=0;entryY=0.5;entryDx=0;entryDy=0;" edge="1" parent="qi1Hokcf2H9-zP8ce8hU-1" source="qi1Hokcf2H9-zP8ce8hU-7" target="qi1Hokcf2H9-zP8ce8hU-13">
<mxGeometry relative="1" as="geometry">
<Array as="points">
<mxPoint x="319" y="159" />
<mxPoint x="319" y="121" />
</Array>
</mxGeometry>
</mxCell>
<mxCell id="qi1Hokcf2H9-zP8ce8hU-18" value="no" style="edgeLabel;html=1;align=center;verticalAlign=middle;resizable=0;points=[];" vertex="1" connectable="0" parent="qi1Hokcf2H9-zP8ce8hU-15">
<mxGeometry x="-0.1752" y="-2" relative="1" as="geometry">
<mxPoint x="-2" y="-1" as="offset" />
</mxGeometry>
</mxCell>
<mxCell id="qi1Hokcf2H9-zP8ce8hU-16" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=1;exitY=0.5;exitDx=0;exitDy=0;entryX=0;entryY=0.5;entryDx=0;entryDy=0;" edge="1" parent="qi1Hokcf2H9-zP8ce8hU-1" source="qi1Hokcf2H9-zP8ce8hU-7" target="qi1Hokcf2H9-zP8ce8hU-50">
<mxGeometry relative="1" as="geometry">
<Array as="points">
<mxPoint x="319" y="159" />
<mxPoint x="319" y="197" />
</Array>
</mxGeometry>
</mxCell>
<mxCell id="qi1Hokcf2H9-zP8ce8hU-17" value="yes" style="edgeLabel;html=1;align=center;verticalAlign=middle;resizable=0;points=[];" vertex="1" connectable="0" parent="qi1Hokcf2H9-zP8ce8hU-16">
<mxGeometry x="-0.1137" y="-3" relative="1" as="geometry">
<mxPoint x="3" as="offset" />
</mxGeometry>
</mxCell>
<mxCell id="qi1Hokcf2H9-zP8ce8hU-7" value="" style="triangle;whiteSpace=wrap;html=1;" vertex="1" parent="qi1Hokcf2H9-zP8ce8hU-1">
<mxGeometry x="279" y="149" width="20" height="20" as="geometry" />
</mxCell>
<mxCell id="qi1Hokcf2H9-zP8ce8hU-10" value="queue empty?" style="text;html=1;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;" vertex="1" parent="qi1Hokcf2H9-zP8ce8hU-1">
<mxGeometry x="259" y="114" width="60" height="30" as="geometry" />
</mxCell>
<mxCell id="qi1Hokcf2H9-zP8ce8hU-29" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=1;exitY=0.5;exitDx=0;exitDy=0;entryX=0;entryY=0.5;entryDx=0;entryDy=0;" edge="1" parent="qi1Hokcf2H9-zP8ce8hU-1" source="qi1Hokcf2H9-zP8ce8hU-13" target="qi1Hokcf2H9-zP8ce8hU-22">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="qi1Hokcf2H9-zP8ce8hU-13" value="&lt;div&gt;register OTs in&lt;/div&gt;&lt;div&gt;waiting pool&lt;/div&gt;" style="rounded=1;whiteSpace=wrap;html=1;" vertex="1" parent="qi1Hokcf2H9-zP8ce8hU-1">
<mxGeometry x="349" y="105" width="110" height="32.5" as="geometry" />
</mxCell>
<mxCell id="qi1Hokcf2H9-zP8ce8hU-24" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=1;exitY=0.5;exitDx=0;exitDy=0;entryX=0;entryY=0.5;entryDx=0;entryDy=0;" edge="1" parent="qi1Hokcf2H9-zP8ce8hU-1" source="qi1Hokcf2H9-zP8ce8hU-12" target="qi1Hokcf2H9-zP8ce8hU-23">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="qi1Hokcf2H9-zP8ce8hU-12" value="&lt;div&gt;send oldest OT to&lt;/div&gt;&lt;div&gt;server&lt;/div&gt;" style="rounded=1;whiteSpace=wrap;html=1;" vertex="1" parent="qi1Hokcf2H9-zP8ce8hU-1">
<mxGeometry x="349" y="228.5" width="110" height="30" as="geometry" />
</mxCell>
<mxCell id="qi1Hokcf2H9-zP8ce8hU-49" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=0.5;exitY=0;exitDx=0;exitDy=0;entryX=0.5;entryY=1;entryDx=0;entryDy=0;" edge="1" parent="qi1Hokcf2H9-zP8ce8hU-1" source="qi1Hokcf2H9-zP8ce8hU-22" target="qi1Hokcf2H9-zP8ce8hU-48">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="qi1Hokcf2H9-zP8ce8hU-22" value="&lt;div&gt;merge any compatible OTs&lt;/div&gt;" style="rounded=1;whiteSpace=wrap;html=1;" vertex="1" parent="qi1Hokcf2H9-zP8ce8hU-1">
<mxGeometry x="489" y="103.13" width="110" height="36.25" as="geometry" />
</mxCell>
<mxCell id="qi1Hokcf2H9-zP8ce8hU-36" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=1;exitY=0.5;exitDx=0;exitDy=0;entryX=0;entryY=0.5;entryDx=0;entryDy=0;" edge="1" parent="qi1Hokcf2H9-zP8ce8hU-1" source="qi1Hokcf2H9-zP8ce8hU-23" target="qi1Hokcf2H9-zP8ce8hU-35">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="qi1Hokcf2H9-zP8ce8hU-23" value="&lt;div&gt;wait for ack for the sent OT&lt;/div&gt;" style="rounded=1;whiteSpace=wrap;html=1;" vertex="1" parent="qi1Hokcf2H9-zP8ce8hU-1">
<mxGeometry x="489" y="221" width="110" height="45" as="geometry" />
</mxCell>
<mxCell id="qi1Hokcf2H9-zP8ce8hU-25" value="" style="ellipse;whiteSpace=wrap;html=1;aspect=fixed;fillColor=#000000;" vertex="1" parent="qi1Hokcf2H9-zP8ce8hU-1">
<mxGeometry x="699" y="149.5" width="20" height="20" as="geometry" />
</mxCell>
<mxCell id="qi1Hokcf2H9-zP8ce8hU-38" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=1;exitY=0.5;exitDx=0;exitDy=0;entryX=0;entryY=0.5;entryDx=0;entryDy=0;" edge="1" parent="qi1Hokcf2H9-zP8ce8hU-1" source="qi1Hokcf2H9-zP8ce8hU-35" target="qi1Hokcf2H9-zP8ce8hU-25">
<mxGeometry relative="1" as="geometry">
<Array as="points">
<mxPoint x="669" y="244" />
<mxPoint x="669" y="160" />
</Array>
</mxGeometry>
</mxCell>
<mxCell id="qi1Hokcf2H9-zP8ce8hU-39" value="no" style="edgeLabel;html=1;align=center;verticalAlign=middle;resizable=0;points=[];" vertex="1" connectable="0" parent="qi1Hokcf2H9-zP8ce8hU-38">
<mxGeometry x="-0.4402" y="1" relative="1" as="geometry">
<mxPoint x="1" y="-4" as="offset" />
</mxGeometry>
</mxCell>
<mxCell id="qi1Hokcf2H9-zP8ce8hU-40" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=1;exitY=0.5;exitDx=0;exitDy=0;entryX=0;entryY=0.5;entryDx=0;entryDy=0;" edge="1" parent="qi1Hokcf2H9-zP8ce8hU-1" source="qi1Hokcf2H9-zP8ce8hU-35" target="qi1Hokcf2H9-zP8ce8hU-50">
<mxGeometry relative="1" as="geometry">
<Array as="points">
<mxPoint x="669" y="244" />
<mxPoint x="669" y="292" />
<mxPoint x="299" y="292" />
<mxPoint x="299" y="197" />
</Array>
</mxGeometry>
</mxCell>
<mxCell id="qi1Hokcf2H9-zP8ce8hU-41" value="yes" style="edgeLabel;html=1;align=center;verticalAlign=middle;resizable=0;points=[];" vertex="1" connectable="0" parent="qi1Hokcf2H9-zP8ce8hU-40">
<mxGeometry x="-0.7296" y="-1" relative="1" as="geometry">
<mxPoint y="-33" as="offset" />
</mxGeometry>
</mxCell>
<mxCell id="qi1Hokcf2H9-zP8ce8hU-35" value="" style="triangle;whiteSpace=wrap;html=1;" vertex="1" parent="qi1Hokcf2H9-zP8ce8hU-1">
<mxGeometry x="619" y="233.5" width="20" height="20" as="geometry" />
</mxCell>
<mxCell id="qi1Hokcf2H9-zP8ce8hU-37" value="OTs to send?" style="text;html=1;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;" vertex="1" parent="qi1Hokcf2H9-zP8ce8hU-1">
<mxGeometry x="599" y="190" width="60" height="43.5" as="geometry" />
</mxCell>
<mxCell id="qi1Hokcf2H9-zP8ce8hU-46" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=1;exitY=0.5;exitDx=0;exitDy=0;entryX=0;entryY=0.5;entryDx=0;entryDy=0;" edge="1" parent="qi1Hokcf2H9-zP8ce8hU-1" source="qi1Hokcf2H9-zP8ce8hU-43" target="qi1Hokcf2H9-zP8ce8hU-3">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="qi1Hokcf2H9-zP8ce8hU-43" value="&lt;div&gt;acquire update lock&lt;/div&gt;&lt;div&gt;to preserve&lt;/div&gt;&lt;div&gt;change&lt;/div&gt;&lt;div&gt;history&lt;/div&gt;" style="rounded=1;whiteSpace=wrap;html=1;" vertex="1" parent="qi1Hokcf2H9-zP8ce8hU-1">
<mxGeometry x="61" y="127" width="108" height="64" as="geometry" />
</mxCell>
<mxCell id="qi1Hokcf2H9-zP8ce8hU-52" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=1;exitY=0.5;exitDx=0;exitDy=0;entryX=0;entryY=0.5;entryDx=0;entryDy=0;" edge="1" parent="qi1Hokcf2H9-zP8ce8hU-1" source="qi1Hokcf2H9-zP8ce8hU-48" target="qi1Hokcf2H9-zP8ce8hU-25">
<mxGeometry relative="1" as="geometry">
<Array as="points">
<mxPoint x="669" y="65" />
<mxPoint x="669" y="160" />
</Array>
</mxGeometry>
</mxCell>
<mxCell id="qi1Hokcf2H9-zP8ce8hU-53" value="&lt;div&gt;receive process&lt;/div&gt;&lt;div&gt;will take care of it&lt;/div&gt;" style="edgeLabel;html=1;align=center;verticalAlign=middle;resizable=0;points=[];" vertex="1" connectable="0" parent="qi1Hokcf2H9-zP8ce8hU-52">
<mxGeometry x="0.2113" y="3" relative="1" as="geometry">
<mxPoint as="offset" />
</mxGeometry>
</mxCell>
<mxCell id="qi1Hokcf2H9-zP8ce8hU-48" value="release update lock" style="rounded=1;whiteSpace=wrap;html=1;" vertex="1" parent="qi1Hokcf2H9-zP8ce8hU-1">
<mxGeometry x="489" y="50" width="110" height="30" as="geometry" />
</mxCell>
<mxCell id="qi1Hokcf2H9-zP8ce8hU-51" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=0.5;exitY=1;exitDx=0;exitDy=0;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" edge="1" parent="qi1Hokcf2H9-zP8ce8hU-1" source="qi1Hokcf2H9-zP8ce8hU-50" target="qi1Hokcf2H9-zP8ce8hU-12">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="qi1Hokcf2H9-zP8ce8hU-50" value="&lt;div&gt;release update lock &lt;br&gt;&lt;/div&gt;" style="rounded=1;whiteSpace=wrap;html=1;" vertex="1" parent="qi1Hokcf2H9-zP8ce8hU-1">
<mxGeometry x="345" y="182" width="120" height="30" as="geometry" />
</mxCell>
</root>
</mxGraphModel>
</diagram>
</mxfile>
Binary file added images/Optimised-Sync-Algorithm.drawio.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Reveal {
}
// @ts-ignore
if (!(typeof Reveal.availableFragments === 'function')) {
console.log("Reveal JS plugin isn't compatible with reveal.js version < 2.4.0")
console.log("[Reveal] Reveal JS plugin isn't compatible with reveal.js version < 2.4.0")
return false
}
return true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ export class AsyncLock {
private isLocked = false
private callbackQueue: Array<() => Promise<void>> = []

/**
* Acquires the lock and executes the callback.
*
* If the lock is already acquired, the callback will be queued.
* @param callback The callback
*/
public async acquire(callback: () => Promise<void>): Promise<void> {
if (this.isLocked) {
await new Promise<void>(resolve => {
Expand All @@ -20,6 +26,10 @@ export class AsyncLock {
}
}

/**
* Releases the lock and executes the next callback in the queue.
* @private
*/
private release(): void {
if (this.callbackQueue.length > 0) {
const nextCallback = this.callbackQueue.shift()! // Will logically always have at least one item
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/**
* Gets the human-readable time info of a Date object or a Unix timestamp in milliseconds.
* @param date The date to format, can be a Date object or a number (timestamp)
*/
export function getHumanReadableTimeInfo(date: Date | number): string {
// If the date is a number, convert it to a Date object
if (typeof date === 'number') {
Expand Down Expand Up @@ -28,7 +32,7 @@ export function getHumanReadableTimeInfo(date: Date | number): string {
}

/**
* Get the human-readable date of a Date object. (use the timezone of the client)
* Get the human-readable date of a Date object or a Unix timestamp in milliseconds.
* @param date The date to format, can be a Date object or a number (timestamp)
*/
export function getHumanReadablePreciseDate(date: Date | number): string {
Expand Down
3 changes: 3 additions & 0 deletions solardoc/frontend/src/common/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from './async-lock'
export * from './format-date'
export * from './wait-for'
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @param interval The interval in milliseconds to check the condition.
* @param timeout The timeout in milliseconds to wait for the condition to be met.
*/
export async function waitForConditionAndExecute(
export async function waitForCondAndExec(
cond: () => boolean,
callback: () => Promise<void>,
interval: number,
Expand Down
2 changes: 1 addition & 1 deletion solardoc/frontend/src/components/common/TimeRef.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script setup lang="ts">
import { getHumanReadablePreciseDate, getHumanReadableTimeInfo } from '@/scripts/format-date'
import { getHumanReadablePreciseDate, getHumanReadableTimeInfo } from '@/common/format-date'
import PaddedInfoBox from '@/components/common/PaddedInfoBox.vue'
import { ref } from 'vue'
Expand Down
4 changes: 2 additions & 2 deletions solardoc/frontend/src/components/editor/ContributorsCount.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { useDarkModeStore } from '@/stores/dark-mode'
import { useCurrentFileStore } from '@/stores/current-file'
import { useCurrentUserStore } from '@/stores/current-user'
import { useContributorsStore } from '@/stores/contributors'
import { waitForConditionAndExecute } from '@/scripts/wait-for'
import { waitForCondAndExec } from '@/common/wait-for'
import { interceptErrors } from '@/errors/handler/error-handler'
import { useFileOwnerStore } from '@/stores/file-owner'
import { storeToRefs } from 'pinia'
Expand All @@ -23,7 +23,7 @@ const { owner } = storeToRefs(fileOwnerStore)
interceptErrors(
(async () => {
if (currentUserStore.loggedIn && !!currentUserStore.bearer) {
await waitForConditionAndExecute(
await waitForCondAndExec(
() => currentFileStore.remoteFile && !!currentFileStore.ownerId,
async () =>
await contributorsStore.fetchAndUpdateContributors(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script lang="ts" setup>
import { getHumanReadableTimeInfo } from '@/scripts/format-date'
import { getHumanReadableTimeInfo } from '@/common/format-date'
import type { EditorChannel } from '@/services/phoenix/editor-channel'
import { useEditorUpdateWSClient } from '@/stores/editor-update-ws-client'
import { storeToRefs } from 'pinia'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { useOverlayStateStore } from '@/stores/overlay-state'
import CloseButtonSVG from '@/components/icons/CloseButtonSVG.vue'
import { useCurrentFileStore } from '@/stores/current-file'
import { getHumanReadableTimeInfo } from '@/scripts/format-date'
import { getHumanReadableTimeInfo } from '@/common/format-date'
import { ref } from 'vue'
import { useCurrentUserStore } from '@/stores/current-user'
import CollaboratorList from '@/components/editor/dropdown/editor-settings/CollaboratorList.vue'
Expand All @@ -13,7 +13,7 @@ import { ensureLoggedIn } from '@/scripts/ensure-logged-in'
import { showInfoNotifFromObj } from '@/scripts/show-notif'
import constants from '@/plugins/constants'
import { useRouter } from 'vue-router'
import { waitForConditionAndExecute } from '@/scripts/wait-for'
import { waitForCondAndExec } from '@/common/wait-for'
import { useFileOwnerStore } from '@/stores/file-owner'
const $router = useRouter()
Expand All @@ -27,7 +27,7 @@ const owner = ref<UserPublic>({ username: 'Local User', id: 'local-user-id' })
interceptErrors(
(async () => {
if (currentUserStore.loggedIn && !!currentUserStore.bearer) {
await waitForConditionAndExecute(
await waitForCondAndExec(
() => currentFileStore.remoteFile && !!currentFileStore.ownerId,
async () => {
await fileOwnerStore.fetchAndUpdateFileOwner(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script setup lang="ts">
import { usePreviewLoadingStore } from '@/stores/preview-loading'
import { getHumanReadableTimeInfo } from '@/scripts/format-date'
import { getHumanReadableTimeInfo } from '@/common/format-date'
import { useCurrentFileStore } from '@/stores/current-file'
import { ref } from 'vue'
Expand Down
13 changes: 10 additions & 3 deletions solardoc/frontend/src/scripts/channel/join-channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { EditorChannel, JoinChannelOptions } from '@/services/phoenix/edito
import { PhoenixSDSError } from '@/services/phoenix/errors'
import { useEditorUpdateWSClient } from '@/stores/editor-update-ws-client'
import { useCurrentFileStore } from '@/stores/current-file'
import { handleOTUpdates, type OTransRespDto } from '@/services/phoenix/ot-trans'
import { OTManager, type OTransRespDto } from '@/services/phoenix/ot-trans'
import type { File } from '@/services/phoenix/gen/phoenix-rest-service'
import { useCurrentUserStore } from '@/stores/current-user'

Expand Down Expand Up @@ -35,8 +35,15 @@ export function joinChannel(channel: EditorChannel, password?: string): Promise<
editorUpdateWSClient.setCurrentChannel(channel)
await currentFileStore.initOTransStackFromServerTrans(initTrans)

// Start the ot update handler
handleOTUpdates()
// Start the OT update handler
const listenPromise = OTManager.listenForUpdates()
if (!listenPromise) {
throw new PhoenixSDSError(
'Failed to start OT update handler',
'Please reload the page and try again later. If the problem persists, contact the developers.',
)
}
await listenPromise
resolve()
},
errorResp => {
Expand Down
Loading

0 comments on commit 19de3b3

Please sign in to comment.