DOIP Client Library - JavaScript Version
    Preparing search index...

    Class StandardDoipClient

    This class provides an implementation of the DOIP client that can use either HTTPS or native TCP for DOIP communication, depending on the available interfaces and configuration. It automatically selects the appropriate protocol (HTTPS or TCP) based on the service information and client capabilities.

    // Create a client with service info and authentication
    const authentication =
    new PasswordAuthenticationInfo('admin', 'password');
    const serviceInfo = {
    ipAddress: 'localhost',
    port: 9000
    };
    const client = new StandardDoipClient({ serviceInfo, authentication });

    // Create a client with a base URI
    const client = new StandardDoipClient('https://localhost:8443/doip');

    // Create a client with multiple interfaces and a preferred protocol
    const serviceInfo = {
    interfaces: [
    { ipAddress: '127.0.0.1', port: 9000 },
    { baseUri: 'https://localhost:8443/doip/' }
    ]
    };
    const client = new StandardDoipClient({ serviceInfo, preferredProtocol: 'TCP' });

    Hierarchy (View Summary)

    Index

    Constructors

    • Constructs a StandardDoipClient.

      Parameters

      • options: Options & { baseUri?: string; preferredProtocol?: string }

        Optional default request options. The serviceInfo and authentication property can be used to provide a default serviceInfo and authentication for all requests. The options may optionally specify a "preferredProtocol", either "TCP" for native DOIP or "HTTPS" for the DOIP API for HTTP Clients. For convenience the options may specify a "baseUri", the base HTTP endpoint of a DOIP API for HTTP Clients service.

      Returns StandardDoipClient

    • Convenience constructor for a StandardDoipClient which uses the DOIP API for HTTP Clients.

      Parameters

      • baseUri: string

        The base HTTP endpoint of the DOIP API for HTTP Clients service

      • Optionaloptions: Options & { preferredProtocol?: string }

        Optional default request options. The authentication property can be used to provide a default authentication for all requests.

      Returns StandardDoipClient

    Properties

    defaultOptions?: Options

    Default options for all operations performed by this client. These options can be overridden by providing options to individual method calls.

    Methods

    • Performs a DOIP operation using a DoipRequest object.

      Parameters

      • doipRequest: DoipRequest

        The DOIP request to perform

      • Optionaloptions: Options

        Optional request options for this operation

      Returns Promise<DoipResponse>

      A promise that resolves to a DoipResponse. The caller is responsible for closing the DoipResponse.

      const request = {
      targetId: 'service',
      operationId: '0.DOIP/Op.Hello'
      };
      const response = await client.performOperation(request);
      console.log(await response.asJson()); // asJson closes the response
    • Performs a DOIP operation by specifying the target ID, operation ID, and optional input.

      Parameters

      • targetId: string

        The ID of the target digital object or service

      • operationId: string

        The ID of the operation to perform

      • Optionalinput:
            | ArrayBuffer
            | ArrayBufferView<ArrayBufferLike>
            | Blob
            | Json
            | InDoipMessage
            | ReadableStream<Uint8Array<ArrayBufferLike>>

        Optional input for the operation

      • Optionaloptions: Options

        Optional request options for this operation

      Returns Promise<DoipResponse>

      A promise that resolves to a DoipResponse. The caller is responsible for closing the DoipResponse.

      const response = await client.performOperation('service', '0.DOIP/Op.Hello');
      console.log(await response.asJson()); // asJson closes the response
    • Determines the ID for a service, based on the options given. If options does not specify a service ID, there may be a client default. Defaults to service if no other info is specified.

      Parameters

      • Optionaloptions: Options

        Optional request options

      Returns string

      The ID for the service

    • This method creates a copy of the request and adds authentication information and attributes from the options or default options if not already present.

      Parameters

      • doipRequest: DoipRequest

        The DOIP request to augment

      • Optionaloptions: Options

        Optional request options

      Returns DoipRequest

      The augmented DOIP request

    • Sends a hello request to the service to get information about the service and verify connectivity.

      Parameters

      • Optionaloptions: Options

        Optional request options

      Returns Promise<DigitalObject>

      A promise that resolves to a DigitalObject containing information about the service

      DoipError for error responses

      const serviceInfo = await client.hello();
      console.log(serviceInfo);
    • Retrieves a digital object by ID.

      Parameters

      • targetId: string

        The ID of the digital object to retrieve

      • Optionaloptions: Options

        Optional request options

      Returns Promise<null | DigitalObject>

      A promise that resolves to the retrieved DigitalObject, or null if not found

      DoipError for error responses

      const object = await client.retrieve('20.500.123/1');
      if (object) {
      console.log(object.attributes.content);
      }
    • Retrieves a list of operations that can be performed on the specified target.

      Parameters

      • targetId: string

        The ID of the target digital object or service

      • Optionaloptions: Options

        Optional request options

      Returns Promise<string[]>

      A promise that resolves to an array of operation IDs

      DoipError for error responses

      // List operations for a specific object
      const operations = await client.listOperations('20.500.123/1');
      console.log(operations);

      // List operations for the service using the default service ID
      const serviceOps = await client.listOperations('service');
      console.log(serviceOps);
    • Searches for digital objects matching the specified query and returns only their IDs.

      Parameters

      • query: string

        The search query

      • Optionalparams: QueryParams

        Optional query parameters

      • Optionaloptions: Options

        Optional request options

      Returns Promise<SearchResults<string>>

      A promise that resolves to SearchResults which among other properties is an async iterable iterator of digital object IDs The caller is responsible for closing the SearchResults.

      DoipError for error responses

      const results = await client.searchIds('type:Document');
      try {
      for await (const id of results) {
      console.log(id);
      }
      } finally {
      await results.close();
      }
    • Searches for digital objects matching the specified query and returns the complete digital objects.

      Parameters

      • query: string

        The search query

      • Optionalparams: QueryParams

        Optional query parameters

      • Optionaloptions: Options

        Optional request options

      Returns Promise<SearchResults<DigitalObject>>

      A promise that resolves to SearchResults which among other properties is an async iterable iterator of digital objects. The caller is responsible for closing the SearchResults.

      DoipError for error responses

      const results = await client.search('type:Document');
      console.log(`Number of results: ${results.size}`);
      try {
      for await (const object of results) {
      console.log(`${object.id}: ${object.attributes.content.name}`);
      }
      } finally {
      await results.close();
      }
    • Deletes a digital object by ID.

      Parameters

      • targetId: string

        The ID of the digital object to delete

      • Optionaloptions: Options

        Optional request options

      Returns Promise<void>

      A promise that resolves when the deletion is complete

      DoipError for error responses

      await client.delete('20.500.123/1');
      
    • Retrieves the body of a specific element of a digital object by its ID.

      Parameters

      • targetId: string

        The ID of the digital object

      • elementId: string

        The ID of the element to retrieve

      • Optionaloptions: Options

        Optional request options

      Returns Promise<null | Body>

      A promise that resolves to the element body, or null if not found

      DoipError for error responses

      // Get the bytes of a binary element payload
      const elementBody = await client.retrieveElementBytes('20.500.123/1', 'attachment-binary');
      if (elementBody) {
      const buffer = await elementBody.arrayBuffer();
      const bytes = new Uint8Array(buffer);
      console.log(`length: ${bytes.length}`);
      // process bytes
      }

      // Get text from a text element body
      const elementBody = await client.retrieveElementBytes('20.500.123/1', 'attachment-text');
      if (elementBody) {
      const text = await elementBody.text();
      console.log(text);
      }
    • Retrieves a specific byte range of an element of a digital object.

      Parameters

      • targetId: string

        The ID of the digital object

      • elementId: string

        The ID of the element to retrieve

      • start: undefined | null | number

        The starting byte position (inclusive)

      • end: undefined | null | number

        The ending byte position (inclusive)

      • Optionaloptions: Options

        Optional request options

      Returns Promise<null | Body>

      A promise that resolves to the partial element body, or null if not found

      DoipError for error responses

      // Retrieve the first 1000 bytes of a binary element body
      const elementBody = await client.retrievePartialElementBytes('20.500.123/1', 'attachment-binary', 0, 999);
      if (elementBody) {
      const buffer = await elementBody.arrayBuffer();
      const bytes = new Uint8Array(buffer);
      console.log(`length: ${bytes.length}`);
      }

      // Retrieve bytes from the middle of a text element body
      const elementBody = await client.retrievePartialElementBytes('20.500.123/1', 'text', 2, 5);
      if (elementBody) {
      console.log(await elementBody.text());
      }
    • Creates a new digital object.

      Parameters

      • digitalObject: DigitalObject

        The digital object to create

      • Optionaloptions: Options

        Optional request options

      Returns Promise<DigitalObject>

      A promise that resolves to the created digital object

      DoipError for error responses

      const object = {
      type: 'Document',
      attributes: {
      content: {
      name: 'Example Document'
      }
      }
      };
      const createdObject = await client.create(object);
      console.log(createdObject.id);
    • Updates an existing digital object.

      Parameters

      • digitalObject: DigitalObject

        The digital object to update

      • Optionaloptions: Options

        Optional request options

      Returns Promise<DigitalObject>

      A promise that resolves to the updated digital object

      DoipError for error responses

      const object = await client.retrieve('20.500.123/1');
      if (object) {
      object.attributes.content.name = 'Updated Example Document';
      const updatedObject = await client.update(object);
      console.log(updatedObject.attributes.content.name);
      }
    • Parameters

      Returns boolean

    • Performs a DOIP operation.

      This method must be implemented by concrete subclasses to handle the actual communication with DOIP services.

      Parameters

      • doipRequest: DoipRequest

        The DOIP request to perform

      • Optionaloptions: Options

        Optional request options for this operation

      Returns Promise<DoipResponse>

      A promise that resolves to a DoipResponse

    • Closes the client and releases any resources.

      Returns Promise<void>