@odoo/o-spreadsheet
Version:
A spreadsheet component
108 lines (107 loc) • 4.19 kB
TypeScript
import { EventBus } from "../helpers/event_bus";
import { SelectiveHistory as RevisionLog } from "../history/selective_history";
import { Client, ClientId, ClientPosition, CollaborativeEvent } from "../types/collaborative/session";
import { CollaborationMessage, StateUpdateMessage, TransportService } from "../types/collaborative/transport_service";
import { Command, CoreCommand } from "../types/commands";
import { HistoryChange } from "../types/history";
import { Lazy, UID } from "../types/misc";
import { WorkbookData } from "../types/workbook_data";
import { ICommandSquisher } from "./command_squisher";
import { Revision } from "./revisions";
export declare class ClientDisconnectedError extends Error {
}
export declare class Session extends EventBus<CollaborativeEvent> {
private revisions;
private transportService;
private serverRevisionId;
private commandSquisher;
/**
* Positions of the others client.
*/
private clients;
private clientId;
private pendingMessages;
/**
* Stored position of the client, if session.move is called while the client is not in a session.
* Will be used to send the position to the server when the client joins.
*/
private awaitingClientPosition;
private waitingAck;
/**
* Flag used to block all commands when an undo or redo is triggered, until
* it is accepted on the server
*/
private waitingUndoRedoAck;
private isReplayingInitialRevisions;
private processedRevisions;
private lastRevisionMessage;
private uuidGenerator;
private lastLocalOperation;
/**
* Manages the collaboration between multiple users on the same spreadsheet.
* It can forward local state changes to other users to ensure they all eventually
* reach the same state.
* It also manages the positions of each client in the spreadsheet to provide
* a visual indication of what other users are doing in the spreadsheet.
*
* @param revisions
* @param transportService communication channel used to send and receive messages
* between all connected clients
* @param serverRevisionId
* @param commandSquisher used to squish and unsquish commands to reduce the size of messages sent to the server
*/
constructor(revisions: RevisionLog<Revision>, transportService: TransportService<CollaborationMessage>, serverRevisionId: UID | undefined, commandSquisher: ICommandSquisher);
canApplyOptimisticUpdate(): boolean;
/**
* Add a new revision to the collaborative session.
* It will be transmitted to all other connected clients.
*/
save(rootCommand: Command, commands: CoreCommand[], changes: HistoryChange[]): void;
undo(revisionId: UID): void;
redo(revisionId: UID): void;
join(client?: Client): void;
loadInitialMessages(messages: StateUpdateMessage[]): void;
/**
* Notify the server that the user client left the collaborative session
*/
leave(data?: Lazy<WorkbookData>): Promise<void>;
/**
* Send a snapshot of the spreadsheet to the collaboration server
*/
snapshot(data: WorkbookData): Promise<void>;
getCurrentClient(): Client;
getClient(clientId: ClientId): Client;
getConnectedClients(): Set<Client>;
getRevisionId(): UID;
isFullySynchronized(): boolean;
/**
* Get the last local revision
* */
getLastLocalNonEmptyRevision(): Revision | undefined;
/**
* Notify that the position of the client has changed
*/
move(position: ClientPosition): void;
/**
* Handles messages received from other clients in the collaborative
* session.
*/
private onMessageReceived;
private onClientMoved;
/**
* Register the new client and send your
* own position back.
*/
private onClientJoined;
private onClientLeft;
private sendUpdateMessage;
private sendToTransport;
/**
* Send the next pending message
*/
private sendPendingMessage;
private acknowledge;
private isAlreadyProcessed;
isWrongServerRevisionId(message: CollaborationMessage): boolean;
private dropPendingHistoryMessages;
}