Runtime API

The Raydiant SDK's runtime API allows you to hook into the app lifecycle to:

  • Start animations and videos when your app becomes visible
  • Loop a video if it's the only presentation in the playlist
  • Move to the next presentation in the playlist when an error occurs
  • Add support for dynamic duration

Usage

// If installed with NPM:
import { runtime } from '@raydiant/sdk';
// Or if installed using the global script:
const { runtime } = window.Raydiant;

// Subscribe to the runtime's 'play' event. This event will be
// sent when your app becomes visible and whenever it loops.  
const unsubscribe = runtime.subscribe('play', () => {
  // ...
});

// Send the 'complete' event to move to the next presentation in
// the playlist. If your app is the only presentation in the 
// playlist, the 'play' event triggered again.
runtime.complete();

// Send the 'complete' event with an error. Pass an error to
// complete when your app has encountered an error, instructing
// the runtime to move on to the next presentation in the playlist.
runtime.complete(new Error());

Interrupt Locks
Beta

The runtime API provides a way to lock the app from being interrupted by a publish or a scheduled event.

Using interrupt locks is useful when building an interactive kiosk app where you want to avoid interruptions while a user is interacting with it.

Automatic Locking

Use the addIdleListener method to automatically lock the app when a user interacts with your app.

import { runtime } from '@raydiant/sdk';
// Or if installed using the global script:
const { runtime } = window.Raydiant;

// Defaults (add listener to document with 30s idle time).
runtime.addIdleListener();

// With custom idle timeout (in seconds)
runtime.addIdleListener(5);

// With callback (receives idle=true when inactive and idle=false when active).
runtime.addIdleListener(5, (idle) => { ... });

// With custom container
runtime.addIdleListener(containerEl, 5, (idle) => { ... });

Manual Locking

For more control you can manually request a lock with the acquireInterruptLock method. The lock will automatically release after 1 minute unless renewed.

import { runtime } from '@raydiant/sdk';

// Request a lock. The lock will release after 1 minute unless renewed.
const lock = await runtime.acquireInterruptLock();

// Renew lock. Increase the expiry time to another minute.
await lock.renew();

// Release the lock. Allow content to interrupt again.
await lock.release();

Next Steps


Was this article helpful to you?
GitHubProvide feedback

Last edited on July 02, 2024.
GitHubEdit this page