diff --git a/lib/realtime/realtime.ts b/lib/realtime/realtime.ts index 112035f7d9..9f8948c42e 100644 --- a/lib/realtime/realtime.ts +++ b/lib/realtime/realtime.ts @@ -72,7 +72,7 @@ export interface RealtimeNoteData { updatetime: number // type: ot.EditorSocketIOServer - server: any + server: ot.EditorSocketIOServer authors: Record authorship: Authorship[] @@ -714,7 +714,7 @@ export function ifMayEdit(socket: SocketIO.Socket, callback: (canEdit: boolean) } // TODO: test it -function operationCallback(socket: SocketIO.Socket, operation: any) { +function operationCallback(socket: SocketIO.Socket, operation: ot.Operation[]) { const noteId = socket.noteId if (!noteId || !notes[noteId]) return const note = notes[noteId] diff --git a/tsconfig.json b/tsconfig.json index bbc91998dc..85772bade4 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -17,7 +17,8 @@ "typeRoots": ["./typings", "./node_modules/@types"], "paths": { - "@hackmd/diff-match-patch": ["./typings/diff-match-patch/"] + "@hackmd/diff-match-patch": ["./typings/diff-match-patch/"], + "ot": ["./typings/ot/"] } }, "include": [ diff --git a/typings/ot/index.d.ts b/typings/ot/index.d.ts new file mode 100644 index 0000000000..e86de954d3 --- /dev/null +++ b/typings/ot/index.d.ts @@ -0,0 +1,62 @@ +import SocketIO from "socket.io"; +import EventEmitter from "events"; + +declare module 'ot' { + + export const version: number + + export type Operation = number | string + + export class TextOperation { + static isRetain(op: Operation): boolean + + static isInsert(op: Operation): boolean + + static isDelete(op: Operation): boolean + } + + export class EditorSocketIOServer extends EventEmitter { + + public isDirty: boolean + public document: string + public debug: boolean + public operations: Operation[] + + constructor( + document: string, + operations: Operation[], + docId: string, + mayWrite: ( + socket: SocketIO.Socket, + callback: (canEdit: boolean) => void) => void, + operationCallback: ( + socket: SocketIO.Socket, + operation: Operation[]) => void, + operationEventCallback?: any) + + setLogger(logger): void + + debugLog(mes: string): void + + setDocumentMaxLength(number): void + + addClient(socket: SocketIO.Socket): void + + onOperation(socket: SocketIO.Server, revision, operation, selection) + + onGetOperations(socket, base, head) + + updateSelection(socket, selection) + + setName(socket, name) + + setColor(socket, color) + + getClient(clientId) + + onDisconnect(socket) + } + +} + +