1.0.0 • Published 6 months ago

dnm-sdk v1.0.0

Weekly downloads
-
License
ISC
Repository
-
Last release
6 months ago

SDK for Video Creation IFrame Integration

Overview

This SDK provides a straightforward way to integrate Danim video creation iframe into your web applications.

Installation

Include the SDK in your project:

// Using npm
npm install [your-sdk-name]

// Or, using Yarn
yarn add [your-sdk-name]

Usage

To use the SDK, follow these steps:

1. Import the SDK

import { launchCreateVideoIFrame } from "dnm-iframe-sdk";

2. Initialize the IFrame

Call launchCreateVideoIFrame with the required parameters.

launchCreateVideoIFrame(
  domId,
  templateShortId,
  token,
  onLoadCallback,
  width,
  height
);
- domId: The DOM ID of the container where the iframe will be appended.
- templateShortId: Identifier for the template used in video creation.
- token: Authentication token.
- onLoadCallback: (Optional) Callback function ##### - executed after the iframe loads.
- width: (Optional) Width of the iframe (default: "100%").
- height: (Optional) Height of the iframe (default: "900px").

3. Handling Events

The iframe will communicate with the parent window using window.parent.postMessage. Listen to these messages to handle events:

Video Creation Success:
window.addEventListener("message", (event) => {
  if (event.data.generationLaunchSuccess) {
    // Handle successful video generation
    const videoId = event.data.videoId;
    // Your code here
  }
});
Video Creation Error:
window.addEventListener("message", (event) => {
  if (event.data.generationLaunchError) {
    // Handle video generation error
    // Your code here
  }
});
Error Handling

The SDK throws an error if the iframe container is not found. Ensure that the domId provided matches an existing element in the DOM.

try {
  launchCreateVideoIFrame(
    domId,
    templateShortId,
    token,
    onLoadCallback,
    width,
    height
  );
} catch (error) {
  console.error(error);
}
1.0.0

6 months ago