Expose cursor management
This commit is contained in:
parent
02f32e894a
commit
7e3f972531
3 changed files with 34 additions and 6 deletions
|
|
@ -19,7 +19,8 @@ export type {
|
|||
Cursor
|
||||
} from "./file-operations/filesystem-operations";
|
||||
export type { PersistenceProvider } from "./persistence/persistence";
|
||||
|
||||
export type { CursorSpan } from "./services/types/CursorSpan";
|
||||
export type { ClientCursors } from "./services/types/ClientCursors";
|
||||
export type { NetworkConnectionStatus } from "./types/network-connection-status";
|
||||
export { DocumentUpdateStatus } from "./types/document-update-status";
|
||||
export { SyncClient } from "./sync-client";
|
||||
|
|
|
|||
|
|
@ -5,10 +5,13 @@ import { WebSocketServerMessage } from "./types/WebSocketServerMessage";
|
|||
import { Syncer } from "../sync-operations/syncer";
|
||||
import { WebSocketClientMessage } from "./types/WebSocketClientMessage";
|
||||
import { CursorPositionFromClient } from "./types/CursorPositionFromClient";
|
||||
import { ClientCursors } from "./types/ClientCursors";
|
||||
|
||||
export class WebSocketManager {
|
||||
private readonly webSocketStatusChangeListeners: (() => unknown)[] = [];
|
||||
// private readonly cur: (() => unknown)[] = [];
|
||||
private readonly remoteCursorsUpdateListeners: ((
|
||||
cursors: ClientCursors[]
|
||||
) => unknown)[] = [];
|
||||
|
||||
private refreshWebSocketInterval: NodeJS.Timeout | undefined;
|
||||
|
||||
|
|
@ -66,6 +69,12 @@ export class WebSocketManager {
|
|||
this.webSocketStatusChangeListeners.push(listener);
|
||||
}
|
||||
|
||||
public addRemoteCursorsUpdateListener(
|
||||
listener: (cursors: ClientCursors[]) => void
|
||||
): void {
|
||||
this.remoteCursorsUpdateListeners.push(listener);
|
||||
}
|
||||
|
||||
public async reset(): Promise<void> {
|
||||
this.setWebSocketRefreshInterval();
|
||||
this.updateWebSocket(this.settings.getSettings());
|
||||
|
|
@ -129,7 +138,13 @@ export class WebSocketManager {
|
|||
this.logger.info(
|
||||
`Received cursor positions for ${JSON.stringify(message.clients)}`
|
||||
);
|
||||
// Handle cursor positions if needed
|
||||
this.remoteCursorsUpdateListeners.forEach((listener) => {
|
||||
listener(
|
||||
message.clients.filter(
|
||||
(client) => client.deviceId !== this.deviceId
|
||||
)
|
||||
);
|
||||
});
|
||||
} else {
|
||||
this.logger.warn(
|
||||
`Received unknown message type: ${JSON.stringify(message)}`
|
||||
|
|
@ -163,9 +178,7 @@ export class WebSocketManager {
|
|||
};
|
||||
}
|
||||
|
||||
public sendCursorPositions(
|
||||
cursorPositions: CursorPositionFromClient
|
||||
): void {
|
||||
public updateLocalCursors(cursorPositions: CursorPositionFromClient): void {
|
||||
if (!this.isWebSocketConnected) {
|
||||
this.logger.warn(
|
||||
"WebSocket is not connected, cannot send cursor positions"
|
||||
|
|
|
|||
|
|
@ -19,6 +19,8 @@ import type { NetworkConnectionStatus } from "./types/network-connection-status"
|
|||
import { DocumentUpdateStatus } from "./types/document-update-status";
|
||||
import { WebSocketManager } from "./services/websocket-manager";
|
||||
import { createClientId } from "./utils/create-client-id";
|
||||
import { CursorSpan } from "./services/types/CursorSpan";
|
||||
import { ClientCursors } from "./services/types/ClientCursors";
|
||||
|
||||
export class SyncClient {
|
||||
private static readonly MINIMUM_SAVE_INTERVAL_MS = 1000;
|
||||
|
|
@ -273,6 +275,18 @@ export class SyncClient {
|
|||
});
|
||||
}
|
||||
|
||||
public async updateLocalCursors(documentToCursors: {
|
||||
[path: RelativePath]: CursorSpan[];
|
||||
}): Promise<void> {
|
||||
return this.webSocketManager.updateLocalCursors({ documentToCursors });
|
||||
}
|
||||
|
||||
public addRemoteCursorsUpdateListener(
|
||||
listener: (cursors: ClientCursors[]) => void
|
||||
): void {
|
||||
this.webSocketManager.addRemoteCursorsUpdateListener(listener);
|
||||
}
|
||||
|
||||
public getDocumentSyncingStatus(
|
||||
relativePath: RelativePath
|
||||
): DocumentUpdateStatus {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue