Options
All
  • Public
  • Public/Protected
  • All
Menu

Provides higher-level abstractions on top of the Livepeer VOD API focused on the NFT-minting process.

remarks

This class requires an API key to be used for calling the Livepeer API. As such, it is most appropriately used in a secure context like a backend server (even if only acting as a proxy). It can still be used from the browser with a CORS-enabled API key, but beware that the API key will be exposed for anyone that grabs it from your web page.

Hierarchy

  • Api

Index

Constructors

  • Creates a new Api instance with the given API configuration.

    remarks

    If you're running a backend proxy like Livepeer Web API Proxy you can pass an empty configuration to the API here. The client will use the same endpoint as the current page by default and won't include any credentials in the requests. All API paths are prefixed with /api.

    Parameters

    • api: ApiOptions

      The options to pass to the Livepeer API client.

    Returns Api

Properties

vod: VodApi

Methods

  • checkNftNormalize(asset: Asset, sizeLimit?: number): { desiredProfile: null | FfmpegProfile; possible: boolean }
  • Checks if the specified asset requires any special processing before being minted as an NFT.

    remarks

    This is an optional function call, you can also just call nftNormalize directly to have the video asset processed in the best way possible for being minted as an NFT. This function is useful only if you want to show some feedback to the user, like asking if they want to mint the asset as is or process it first.

    Parameters

    • asset: Asset

      The asset to check. It must have been fully populated with the video metadata, meaning that the Task that created it must have already completed.

    • Optional sizeLimit: number

      The size limit to shrink the asset to. Defaults to 100MB.

    Returns { desiredProfile: null | FfmpegProfile; possible: boolean }

    An object with 2 fields possible and desiredProfile. The possible field is a boolean indicating if the asset can actually be normalized or not, i.e. if there is any acceptable bitrate to reduce its size below the sizeLimit. The desiredProfile field is the video profile that should be used to transcode the asset, if possible.

  • createAsset(name: string, content: File | ReadableStream, reportProgress?: (progress: number) => void): Promise<Asset>
  • Utility for performing the full file upload process for creating an asset in the Livepeer API.

    remarks

    This assumes you are calling both requestUploadUrl and uploadFile from the same place. In the most efficient scenario, you would only create an upload URL from your backend, forward it to your frontend and make the upload directly from the frontend.

    This one can be used to get started, it will only be either: more inefficient in case you pipe the whole file contents through your backend, or; insecure if you call the Livepeer API from the frontend.

    Parameters

    • name: string

      The name of the asset that will be created.

    • content: File | ReadableStream

      The content of the file to be uploaded.

    • reportProgress: (progress: number) => void = ...

      A function that will be called periodically with the progress of the upload. Parts of it only work in the browser.

        • (progress: number): void
        • Parameters

          • progress: number

          Returns void

    Returns Promise<Asset>

    The newly created and already processed/populated Asset.

  • exportToIPFS(assetId: string, nftMetadata?: string | Record<string, any>, reportProgress?: (progress: number) => void): Promise<ExportToIPFSOutput>
  • Exports an asset to decentralized storage (IPFS).

    remarks

    This actually exports 2 files to IPFS:

    • One with the raw contents of the video asset
    • Another one with the NFT metadata in IPFS pointing to the above file. So you can mint the NFT directly with the URL of this file as the tokenUri of the ERC-721 contract.
    remarks

    You can also customize the NFT metadata created by passing the nftMetadata argument to this function. This will be deep merged with the default metadata created for the NFT.

    Parameters

    • assetId: string

      The ID of the asset to export.

    • Optional nftMetadata: string | Record<string, any>

      The custom overrides for fields in the NFT metadata. You can change the value of any field by specifying it here, or delete any default field by specifying null.

    • Optional reportProgress: (progress: number) => void

      A function that will be called periodically with the progress of the export task.

        • (progress: number): void
        • Parameters

          • progress: number

          Returns void

    Returns Promise<ExportToIPFSOutput>

    The information about the files exported to IPFS. Use the nftMetadataUrl field as the tokenUri for minting the NFT of the asset.

  • nftNormalize(asset: Asset, reportProgress?: (progress: number) => void, sizeLimit?: number): Promise<Asset>
  • Normalizes the specified asset fot the best possible NFT.

    remarks

    Normalization means transcoding the asset to a better suitable format, codec and quality. Currently, this means ensuring that the asset fits within the limit of some NFT marketplaces like OpenSea, which has a strict file size limit of 100 MB. Check the getDesiredBitrate and makeProfile for more information on how that calculation is made.

    Parameters

    • asset: Asset

      The asset to normalize. It must have been fully populated with the video metadata, meaning that the Task that created it must have already completed.

    • Optional reportProgress: (progress: number) => void

      A function that will be called periodically with the progress of the transcode task.

        • (progress: number): void
        • Parameters

          • progress: number

          Returns void

    • Optional sizeLimit: number

      The size limit to shrink the asset to. Defaults to 100MB.

    Returns Promise<Asset>

    The new asset created with the normalized video spec.

  • requestUploadUrl(name: string): Promise<{ asset: Asset; task: Task; url: string }>
  • Request a direct upload URL for a file to be uploaded to the API.

    remarks

    This is simply a proxy to VodApi.requestUploadUrl, exposed here as a helper so you don't need to interact with the VodApi class directly as well.

    Parameters

    • name: string

      The name of the asset that will be created.

    Returns Promise<{ asset: Asset; task: Task; url: string }>

    An object with the url and created asset and task. The asset and task can be used to track the progress of the upload (see waitTask).

  • waitTask(task: Task, reportProgress?: (progress: number) => void): Promise<Task>
  • Wait until a specified task is completed.

    remarks

    This will simply call the getTask API repeatedly until the task is either successful or failed. For a promise-like API this will also throw an exception in case the task is failed.

    Parameters

    • task: Task

      The task object that should be waited for.

    • Optional reportProgress: (progress: number) => void

      An optional callback to be called with the progress of the running task, which is a number for 0 to 1. Useful for showing some UI feedback to users.

        • (progress: number): void
        • Parameters

          • progress: number

          Returns void

    Returns Promise<Task>

    The finished Task object also containing the task output. Check the output field for the respective output depending on the task type.

Generated using TypeDoc