Skip to content

Methods

The @stripchatdev/ext-helper SDK exposes three instance methods — makeRequest, subscribe, and unsubscribe — and a factory function createExtHelper that initializes the SDK.

createExtHelper

Creates and initializes an ExtHelper instance. Call this once at the entry point of each HTML page.

ts
import { createExtHelper } from '@stripchatdev/ext-helper';

const ext = createExtHelper();

The function automatically:

  • Connects to the host platform.
  • Reads the current theme (dark or light) and sets data-theme on the <html> element.

Returns an ExtHelper instance with makeRequest, subscribe, and unsubscribe methods.

makeRequest

Sends a typed request to the platform and returns a promise with the result.

ts
ext.makeRequest(request, params): Promise<Result>
ArgumentTypeDescription
requeststringRequest name. See Requests.
paramsvariesParameters specific to each request. Described per request in Requests.

Returns: Promise resolving to a result specific to the request. See Requests for return types.

Example

ts
const ctx = await ext.makeRequest('v1.ext.context.get', null);

subscribe

Subscribes to a platform event. The handler is called each time the event is emitted.

ts
ext.subscribe(eventName, handler): void
ArgumentTypeDescription
eventNamestringEvent name to subscribe to. See Events for the full list.
handler(data) => voidCallback invoked with the event payload.

Example

ts
ext.subscribe('v1.ext.context.updated', ({ context }) => {
  console.log(context);
});

unsubscribe

Removes an event subscription.

ts
ext.unsubscribe(eventName, handler?): void
ArgumentTypeDescription
eventNamestringEvent name to subscribe to. See Events for the full list.
handler(data) => voidOptional. The specific handler to remove. If omitted, all handlers for this event are removed.

Example

ts
const onUpdate = ({ context }) => {
  console.log(context);
};

ext.subscribe('v1.ext.context.updated', onUpdate);

// later
ext.unsubscribe('v1.ext.context.updated', onUpdate);