Client is a normal client that can communicate with the server. It has documents and sends changes of the documents in local to the server to synchronize with other replicas in remote.

Constructors

Properties

apiKey: string
attachmentMap: Map<string, Attachment<unknown, any>>
authTokenInjector?: ((reason?) => Promise<string>)

Type declaration

    • (reason?): Promise<string>
    • Parameters

      • Optional reason: string

      Returns Promise<string>

conditions: Record<ClientCondition, boolean>
id?: string
keepalive: boolean = false
key: string
processing: boolean = false
reconnectStreamDelay: number
retrySyncLoopDelay: number
rpcClient: PromiseClient<{
    methods: {
        activateClient: {
            I: typeof ActivateClientRequest;
            O: typeof ActivateClientResponse;
            kind: Unary;
            name: "ActivateClient";
        };
        attachDocument: {
            I: typeof AttachDocumentRequest;
            O: typeof AttachDocumentResponse;
            kind: Unary;
            name: "AttachDocument";
        };
        broadcast: {
            I: typeof BroadcastRequest;
            O: typeof BroadcastResponse;
            kind: Unary;
            name: "Broadcast";
        };
        deactivateClient: {
            I: typeof DeactivateClientRequest;
            O: typeof DeactivateClientResponse;
            kind: Unary;
            name: "DeactivateClient";
        };
        detachDocument: {
            I: typeof DetachDocumentRequest;
            O: typeof DetachDocumentResponse;
            kind: Unary;
            name: "DetachDocument";
        };
        pushPullChanges: {
            I: typeof PushPullChangesRequest;
            O: typeof PushPullChangesResponse;
            kind: Unary;
            name: "PushPullChanges";
        };
        removeDocument: {
            I: typeof RemoveDocumentRequest;
            O: typeof RemoveDocumentResponse;
            kind: Unary;
            name: "RemoveDocument";
        };
        watchDocument: {
            I: typeof WatchDocumentRequest;
            O: typeof WatchDocumentResponse;
            kind: ServerStreaming;
            name: "WatchDocument";
        };
    };
    typeName: "yorkie.v1.YorkieService";
}>

Type declaration

  • Readonly methods: {
        activateClient: {
            I: typeof ActivateClientRequest;
            O: typeof ActivateClientResponse;
            kind: Unary;
            name: "ActivateClient";
        };
        attachDocument: {
            I: typeof AttachDocumentRequest;
            O: typeof AttachDocumentResponse;
            kind: Unary;
            name: "AttachDocument";
        };
        broadcast: {
            I: typeof BroadcastRequest;
            O: typeof BroadcastResponse;
            kind: Unary;
            name: "Broadcast";
        };
        deactivateClient: {
            I: typeof DeactivateClientRequest;
            O: typeof DeactivateClientResponse;
            kind: Unary;
            name: "DeactivateClient";
        };
        detachDocument: {
            I: typeof DetachDocumentRequest;
            O: typeof DetachDocumentResponse;
            kind: Unary;
            name: "DetachDocument";
        };
        pushPullChanges: {
            I: typeof PushPullChangesRequest;
            O: typeof PushPullChangesResponse;
            kind: Unary;
            name: "PushPullChanges";
        };
        removeDocument: {
            I: typeof RemoveDocumentRequest;
            O: typeof RemoveDocumentResponse;
            kind: Unary;
            name: "RemoveDocument";
        };
        watchDocument: {
            I: typeof WatchDocumentRequest;
            O: typeof WatchDocumentResponse;
            kind: ServerStreaming;
            name: "WatchDocument";
        };
    }
    • Readonly activateClient: {
          I: typeof ActivateClientRequest;
          O: typeof ActivateClientResponse;
          kind: Unary;
          name: "ActivateClient";
      }

      Generated

      from rpc yorkie.v1.YorkieService.ActivateClient

      • Readonly I: typeof ActivateClientRequest
      • Readonly O: typeof ActivateClientResponse
      • Readonly kind: Unary
      • Readonly name: "ActivateClient"
    • Readonly attachDocument: {
          I: typeof AttachDocumentRequest;
          O: typeof AttachDocumentResponse;
          kind: Unary;
          name: "AttachDocument";
      }

      Generated

      from rpc yorkie.v1.YorkieService.AttachDocument

      • Readonly I: typeof AttachDocumentRequest
      • Readonly O: typeof AttachDocumentResponse
      • Readonly kind: Unary
      • Readonly name: "AttachDocument"
    • Readonly broadcast: {
          I: typeof BroadcastRequest;
          O: typeof BroadcastResponse;
          kind: Unary;
          name: "Broadcast";
      }

      Generated

      from rpc yorkie.v1.YorkieService.Broadcast

      • Readonly I: typeof BroadcastRequest
      • Readonly O: typeof BroadcastResponse
      • Readonly kind: Unary
      • Readonly name: "Broadcast"
    • Readonly deactivateClient: {
          I: typeof DeactivateClientRequest;
          O: typeof DeactivateClientResponse;
          kind: Unary;
          name: "DeactivateClient";
      }

      Generated

      from rpc yorkie.v1.YorkieService.DeactivateClient

      • Readonly I: typeof DeactivateClientRequest
      • Readonly O: typeof DeactivateClientResponse
      • Readonly kind: Unary
      • Readonly name: "DeactivateClient"
    • Readonly detachDocument: {
          I: typeof DetachDocumentRequest;
          O: typeof DetachDocumentResponse;
          kind: Unary;
          name: "DetachDocument";
      }

      Generated

      from rpc yorkie.v1.YorkieService.DetachDocument

      • Readonly I: typeof DetachDocumentRequest
      • Readonly O: typeof DetachDocumentResponse
      • Readonly kind: Unary
      • Readonly name: "DetachDocument"
    • Readonly pushPullChanges: {
          I: typeof PushPullChangesRequest;
          O: typeof PushPullChangesResponse;
          kind: Unary;
          name: "PushPullChanges";
      }

      Generated

      from rpc yorkie.v1.YorkieService.PushPullChanges

      • Readonly I: typeof PushPullChangesRequest
      • Readonly O: typeof PushPullChangesResponse
      • Readonly kind: Unary
      • Readonly name: "PushPullChanges"
    • Readonly removeDocument: {
          I: typeof RemoveDocumentRequest;
          O: typeof RemoveDocumentResponse;
          kind: Unary;
          name: "RemoveDocument";
      }

      Generated

      from rpc yorkie.v1.YorkieService.RemoveDocument

      • Readonly I: typeof RemoveDocumentRequest
      • Readonly O: typeof RemoveDocumentResponse
      • Readonly kind: Unary
      • Readonly name: "RemoveDocument"
    • Readonly watchDocument: {
          I: typeof WatchDocumentRequest;
          O: typeof WatchDocumentResponse;
          kind: ServerStreaming;
          name: "WatchDocument";
      }

      Generated

      from rpc yorkie.v1.YorkieService.WatchDocument

      • Readonly I: typeof WatchDocumentRequest
      • Readonly O: typeof WatchDocumentResponse
      • Readonly kind: ServerStreaming
      • Readonly name: "WatchDocument"
  • Readonly typeName: "yorkie.v1.YorkieService"
setAuthToken: ((token) => void)

Type declaration

    • (token): void
    • Parameters

      • token: string

      Returns void

status: ClientStatus
syncLoopDuration: number
taskQueue: (() => Promise<any>)[]

Type declaration

    • (): Promise<any>
    • Returns Promise<any>

Methods

  • activate activates this client. That is, it registers itself to the server and receives a unique ID from the server. The given ID is used to distinguish different clients.

    Returns Promise<void>

  • attach attaches the given document to this client. It tells the server that this client will synchronize the given document.

    Type Parameters

    Parameters

    • doc: Document<T, P>
    • options: {
          initialPresence?: P;
          initialRoot?: T;
          syncMode?: SyncMode;
      } = {}
      • Optional initialPresence?: P
      • Optional initialRoot?: T
      • Optional syncMode?: SyncMode

    Returns Promise<Document<T, P>>

  • broadcast broadcasts the given payload to the given topic.

    Parameters

    • docKey: string
    • topic: string
    • payload: Json
    • Optional options: BroadcastOptions

    Returns Promise<void>

  • deactivate deactivates this client.

    Parameters

    • options: {
          keepalive: boolean;
      } = ...

      If keepalive is true, the client will request deactivation immediately using fetch with the keepalive option enabled. This is useful for ensuring the deactivation request completes even if the page is being unloaded, such as in beforeunload or unload event listeners.

      • keepalive: boolean

    Returns Promise<void>

  • detach detaches the given document from this client. It tells the server that this client will no longer synchronize the given document.

    To collect garbage things like CRDT tombstones left on the document, all the changes should be applied to other replicas before GC time. For this, if the document is no longer used by this client, it should be detached.

    Type Parameters

    Parameters

    • doc: Document<T, P>
    • options: {
          removeIfNotAttached?: boolean;
      } = {}
      • Optional removeIfNotAttached?: boolean

    Returns Promise<Document<T, P>>

  • enqueueTask enqueues the given task to the task queue.

    Parameters

    • task: (() => Promise<any>)
        • (): Promise<any>
        • Returns Promise<any>

    Returns Promise<any>

  • getID returns a ActorID of client.

    Returns undefined | string

  • handleConnectError handles the given error. If the given error can be retried after handling, it returns true.

    Parameters

    • err: any

    Returns Promise<boolean>

  • Type Parameters

    Parameters

    • attachment: Attachment<T, P>
    • resp: WatchDocumentResponse

    Returns void

  • isActive checks if the client is active.

    Returns boolean

  • processNext processes the next task in the task queue. This method is part of enqueueTask.

    Returns Promise<void>

  • runSyncLoop runs the sync loop. The sync loop pushes local changes to the server and pulls remote changes from the server.

    Returns void

  • runWatchLoop runs the watch loop for the given document. The watch loop listens to the events of the given document from the server.

    Parameters

    • docKey: string

    Returns Promise<void>

  • sync pushes local changes of the attached documents to the server and receives changes of the remote replica from the server then apply them to local documents.

    Type Parameters

    Parameters

    Returns Promise<Document<T, P>[]>