UNPKG

@mescius/dspdfviewer

Version:
260 lines (259 loc) 10.4 kB
import { UserAccess, SharedDocumentInfo, SharedAccessMode, ModificationType, ModificationsState } from "../SharedDocuments/types"; import { ISupportApi } from "./ISupportApi"; import { GcPdfViewer } from "../GcPdfViewer"; import { AnnotationBase } from "../Annotations/AnnotationTypes"; import { ClientMessageType, ClientMessage, ClientRequestType } from "./Connection/ClientMessage"; import { ServerMessage, StartSharedModeResponse } from "./Connection/ServerMessage"; import { ProgressDialogSink } from "../Dialogs/Types"; import { SaveSettings, StampCategory, ViewerFeatureName } from "../Models/ViewerTypes"; import { DocumentModification, TableDefClientModel, OpenDocumentInfo } from "./types"; import { SupportApiType, TaskStatusAnswer } from "./ISupportApiBase"; import { ClientTableExtractOptions } from "../TableDataExtraction/types"; /** * SupportApi client. * * Usage example: * let supportApi = new SupportApi({supportApiUrl: "http://localhost/supportapiservice"}); * await supportApi.open("somedomain.com/mypdf.pdf"); * await supportApi.close(); **/ export declare class SupportApiImpl implements ISupportApi { private _host; private _supportApiUrl; private _openPromise?; private _openedDocumentInfo?; private _options; private _clientId; private _persistentConnection?; private _documentSharedFlag; private _webSocketUrl; private _requestInit; private _token; private _status; userAccessList: UserAccess[]; sharedAccessMode: SharedAccessMode; private _connected?; private _lastConnectAttemptPromise; private _serverVersion; /** * Constructor. * @param options */ constructor(_host: GcPdfViewer, options?: any); dispose(): void; /** * Unique client identifier. * */ get clientId(): string; /** * Opened document information with meta-data. * */ get docInfo(): OpenDocumentInfo; get status(): 'opening' | 'opening-shared' | 'opened-shared' | 'opened' | 'closed'; set status(val: 'opening' | 'opening-shared' | 'opened-shared' | 'opened' | 'closed'); /** * Returns the type of the SupportApi implementation. */ get supportApiType(): SupportApiType | undefined; /** * Call this method in order to apply pdf viewer options when options are changed. * @param options */ applyOptions(options?: any): void; /** * Sets the viewer instance for the SupportApi client. This method is called during the initialization of the viewer. * It passes a reference to the viewer that utilizes an instance of the SupportApi client of this class. * * @param viewer The viewer instance that uses the SupportApi client instance of this class. */ setViewer(viewer: any): void; /** * Gets a value indicating whether the viewer has a persistent connection to the server. **/ get hasPersistentConnection(): boolean; /** * Indicates whether the viewer can edit the specified annotation. * @param annotation */ canEditAnnotation(annotation?: AnnotationBase | null): boolean; /** * Closes previously opened document and free client and server resources. **/ close(): Promise<string>; /** * Returns an array of features that are disabled or unsupported by the SupportApi instance. * * @returns {ViewerFeatureName[] | null} - An array of feature names that are disabled/unsupported, * or null if the information is unavailable. */ getDisabledFeatures(): ViewerFeatureName[] | null; /** * Returns list of all users who have access to the active document. */ listUsersWithAccess(): Promise<UserAccess[]>; /** * Returns list of all available users. */ listAllUsers(): Promise<string[]>; /** * Returns list of all documents shared for current user. */ listSharedDocuments(): Promise<SharedDocumentInfo[]>; /** * Open a shared document on the server. * @param documentId */ openSharedDocument(documentId: string): Promise<OpenDocumentInfo>; /** * Start sharing document. This method should be called after the openSharedDocument method and after the document is open by the viewer. * */ startSharedMode(): Promise<StartSharedModeResponse>; stopSharedMode(): Promise<void>; /** * Allow access to an active document for the user specified by the userName argument. * @param userName * @param accessMode */ shareDocument(userName: string, accessMode: SharedAccessMode, modificationsState: ModificationsState, startSharedMode?: boolean): Promise<OpenDocumentInfo | null>; /** * Disallow access to an active document for the user specified by the userName argument. * @param userName */ unshareDocument(userName: string): Promise<void>; /** * Send a message to the server over a persistent connection without waiting for an answer. * @param type * @param messageData */ sendMessage(type: ClientMessageType, messageData: Partial<ClientMessage>): Promise<void>; /** * Send a request message to the server over a persistent connection and return a promise that is resolved by the server's response. * @param type * @param messageData */ sendRequest<T>(type: ClientRequestType, messageData?: Partial<ClientMessage>): Promise<T>; get documentId(): string; get isDocumentShared(): boolean; /** * Gets a value indicating whether the SupportApi client currently connected to the server. **/ get isConnected(): boolean; /** * Sets a value indicating whether the SupportApi client currently connected to the server. **/ set isConnected(val: boolean); /** * Attempt to connect SupportApi client to server. * @param lazy Optional. Pass true if you don't want to check the connection again if the server is already checked. Default is false. */ connect(lazy?: boolean): Promise<boolean>; /** * Modify shared document. * @param type Modification type. * @param data Modification data. */ modifySharedDocument(type: ModificationType, data?: { pageIndex: number; annotation: AnnotationBase; } | { pageIndex: number; annotationId: string; } | { resultStructure: number[]; structureChanges: { pageIndex: number; add: boolean; checkNumPages: number; }[]; pdfInfo: { numPages: number; fingerprint: string; }; }): Promise<void>; /** * This method is called when a new server message is received, * except for request response messages, these messages are processed by the caller. * @param message */ onPushMessage(message: ServerMessage): void; /** * Gets the URL which can be used to download modified document from SupportApi service. * @param filename Default value for filename property in HTTP header. */ getDownloadUrl(filename: string, format: "PDF" | "PNG" | "SVG" | undefined, correlationId: string): Promise<string>; /** * Gets the URL which can be used to download modified document from SupportApi service. * @param filename Default value for filename property in HTTP header. */ getDownloadUnmodifiedUrl(filename: string): string; /** * Open document from given URL. * @param url */ /** * Set viewer options. Method should be called before start using Support API. * Returns "ok" or Error message. **/ setOptions(saveSettings: SaveSettings | undefined, correlationId: string, fileName?: string): Promise<string>; extractTableData(extractSettings?: ClientTableExtractOptions): Promise<TableDefClientModel[] | null>; /** * Open document using binary data. * @param data */ openBinary(data: any): Promise<void>; /** * Closes the document loader and releases resources on the server. * @returns A promise that resolves to a boolean indicating the success of the operation. */ closeDocumentLoader(): Promise<boolean>; /** * Make sure the document loader is exists on the server. * Document Loader may not be present after server restart. **/ checkDocumentLoader(): Promise<boolean>; /** * Checks the status of a long asynchronous task by its correlation ID. * * @param {string} [correlationId] - Optional correlation ID to identify the task. * @returns {Promise<{ done?: boolean; code?: number; message?: string; current?: number; total?: number; } | null>} A promise that resolves to an object containing the task status, or null if an error occurs. */ checkTaskStatus?(correlationId?: string): Promise<TaskStatusAnswer | null>; cancelTask?(correlationId?: string): Promise<void>; /** * Get predefined stamp images info. **/ getStampCategories(): Promise<StampCategory[]>; getStampImageUrl(categoryId: string, imageName: string, enableCache: boolean): string; /** * Download modified files from shared storage. * @param fileIds * @param sink */ downloadFiles(fileIds: string[], sink?: ProgressDialogSink): Promise<boolean>; /** * Upload files. * @param fileIds * @param sink */ uploadFiles(fileIds: string[], sink?: ProgressDialogSink): Promise<boolean>; /** * Modify opened document. Returns "ok" or Error message. * @param documentModification */ modify(documentModification: DocumentModification, correlationId: string): Promise<string>; /** * Verify signature field. * @param fieldName */ verifySignature(fieldName: string): Promise<boolean>; /** * Contact server and get Support API version. * */ serverVersion(): Promise<any>; /** * Contact server and pop last error if any. * Returned promise is always resolved even when server is not available. * */ getLastError(): Promise<string>; private _reset; }