Engine

The Engine serves as the entry point for the SDK, providing access to all its functionalities. It's a singleton instance, ensuring that there can only be one instance of the engine available at any given time.

Initialization

1. Obtain a License

To use the Rendley SDK, you need to acquire a license. Visit Rendley (opens in a new tab) to obtain your license details.

import { Engine } from "@rendley/sdk";
 
const engine = Engine.getInstance({
  license: {
    licenseName: "YOUR_LICENSE_NAME",
    licenseKey: "YOUR_LICENSE_KEY",
  },
  display: {
    width: 1920,
    height: 1080,
    backgroundColor: "#000000",
  },
});

Replace YOUR_LICENSE_NAME and YOUR_LICENSE_KEY with your actual license.

This code sets up the singleton instance with your desired settings.

Once the singleton is initialized, you can use the engine to instantiate its functionalities. To do this, call the init method and pass in the canvas element where Rendley SDK will render its content:

await engine.init(canvasElement);

Note that the canvasElement should be an existing DOM element that you want to render the SDK's content into.

Serialize

The serialize method allows you to capture the current state of the Engine and convert it into a JSON format. This can be useful for saving the state of your application or transferring it between different environments.

To serialize the Engine's state, execute the following command:

const serializedData = Engine.getInstance().serialize();

This method returns a JSON object representing the current state of the Engine, which you can then store or manipulate as needed.

Deserialize

To restore the Engine from a previously serialized JSON state, utilize the deserialize method. This method takes the JSON data as input and reinitializes the Engine with that state.

To deserialize the Engine's state, use the following syntax:

await Engine.deserialize(serializedData);

Make sure that the serializedData is a valid JSON object generated by the serialize method. This will allow the Engine to accurately restore its previous state and all associated functionalities.