Class LensRepository

The LensRepository is used to query for lenses from specific lens groups, or for a lens with a specific ID.

Lens groups are configured in the CameraKit Portal -- that's where you'll find lens group IDs and lens IDs.

Lenses must be loaded by the LensRepository before they can be applied to a CameraKitSession.

Example

const cameraKit = await bootstrapCameraKit(options)
const session = await cameraKit.createSession()
const lens = await cameraKit.lensRepository.loadLens(lensId, groupId)
session.applyLens(lens)

Hierarchy

  • LensRepository

Methods

  • Retrieve a single Lens.

    Parameters

    • lensId: string

      Desired Lens's unique ID. Can be found in the CameraKit Portal.

    • groupId: string

      The ID of a group containing the desired Lens. Can be found in the CameraKit Portal.

    Returns Promise<Lens>

    Resolves with the desired Lens, or rejects if an error occurred (including a missing Lens).

  • Retrieve the Lenses contained in a list of Lens Groups.

    This may result in multiple requests to retrieve Lens data (e.g. one per desired group). If any constituent requests fail, those errors will be reported in the response – but the returned Promise will not be rejected. Any Lenses which could be successfully retrieved will be available in the response.

    Parameters

    • groupIds: string[]

      A list of Lens Group IDs. Can be found in the CameraKit Portal.

    Returns Promise<{
        errors: Error[];
        lenses: Lens[];
    }>

    Resolves with a flattened list of all lenses in the desired groups. If any errors occurred during the query operation, these will be included in a separate list. If errors are present, the list of Lenses may not contain all the Lenses from the desired groups.

  • Loads and caches lens content and dependencies to reduce latency when applyLens is later called to apply the lens. This is an in-memory cache, it will not be persisted across page loads.

    This may useful if the application A) knows which lenses will be applied and B) has some opportunity to call this method before a lens is applied. For example, if the user must perform some other actions before lenses become active, this might be a good opportunity to cache lenses to improve applyLens latency.

    Parameters

    • lenses: Lens[]

      Array of lenses to cache in memory.

    • assetTimingsToCache: ("required" | "onDemand")[] = ...

      Lenses specify certain required assets that are necessary for the lens to render, and other assets which may be needed by the lens. By default this method will cache all of those assets, but this behavior can be modified to only load the required assets, only the "onDemand" assets, or neither (by passing an empty array).

    Returns Promise<void>

    Example

    const lens = await cameraKit.lensRepository.loadLens(lensId, groupId)
    await cameraKit.lensRepository.cacheLensContent([lens])

    // sometime later -- this call will use the cached lens content, making lens application faster.
    await cameraKitSession.applyLens(lens)
  • Returns loaded Lens metadata if available.

    Parameters

    • lensId: string

    Returns undefined | LensProtoWithGroupId

  • Removes Lens content from the in-memory cache.

    Parameters

    Returns void

Generated using TypeDoc