SDKsWeb SDK

Configuration

The full config object passed to init — layout, style, agent, launcher, features, callbacks, and persistence

The second argument to init is a NapsterCompanionApiConfig object. Every field is optional, and the SDK applies defaults for anything you leave out. This page is the full reference, grouped by concern.

All options

Every top-level field on NapsterCompanionApiConfig. All are optional. Jump to a section for the details.

OptionTypeDefaultDescription
layoutLayoutConfig{ type: "fixed", position: "bottom-right" }Float as a corner widget, or render inside your own element. See Layout.
styleStyleConfig{ view: "round" }Avatar shape, accent color, and a CSS class. See Style.
agentAgentConfig—The agent's photo. See Agent.
buttonButtonConfig—A launcher button that connects on click. See Start on click.
featuresFeatureConfig—Turn built-in features on or off and tune them. See Features.
persistencePersistenceOptions—Keep one session alive across page navigation. See Persistence.
debugbooleanfalseVerbose SDK logging to the console. See Debug.
Callbacksfunctions—onReady, onError, onData, onAvatarReady, onSessionStatusChange, onInactivityStatusChange, onDestroy, onFeaturesUpdate, onScreenShareStateChange. See Callbacks.

The config also accepts transport ("webrtc") and modality ("video"). They're reserved for future connection types, and those are the only values today, so leave them out.

Layout

FieldTypeDefaultDescription
type"fixed" | "inline""fixed""fixed" floats the avatar over the page as a corner widget. "inline" renders it inside mountContainer and fills it.
positionPosition"bottom-right"Where the floating widget sits in the viewport. Only applies to "fixed".
mountContainerHTMLElement | stringdocument.bodyThe element to render into, as an element or a CSS selector. Only applies to "inline".

The floating widget always mounts on document.body, so mountContainer is ignored unless type is "inline". If a selector matches no element, the SDK falls back to document.body. It logs a warning about this only with debug: true. A selector that isn't valid CSS, such as "#1box", throws, and init() rejects.

With persistence.enabled, the SDK ignores type: "inline" and mountContainer and always floats the widget. If you pass mountContainer as well, it writes a warning to the console.

Position values

position accepts any value from the Position enum:

Enum memberValue
Position.BOTTOM_RIGHT"bottom-right" (default)
Position.BOTTOM_CENTER"bottom-center"
Position.BOTTOM_LEFT"bottom-left"
Position.TOP_RIGHT"top-right"
Position.TOP_CENTER"top-center"
Position.TOP_LEFT"top-left"
Position.CENTER"center"
import { NapsterCompanionApiSdk, Position } from "@touchcastllc/napster-companion-api";

await NapsterCompanionApiSdk.init(getToken, {
  layout: { position: Position.BOTTOM_LEFT },
});

In plain JavaScript you can pass the string value, for example position: "bottom-left".

Inline layout

Set type: "inline" to render the avatar inside your own element and fill it. You control placement, size, and shape by styling that element.

// <div id="avatar-box" style="width: 320px; height: 480px"></div>
await NapsterCompanionApiSdk.init(getToken, {
  layout: { type: "inline", mountContainer: "#avatar-box" },
  style: { view: "rectangle" },
});

Sizing rules in inline mode:

  • rectangle and silhouette fill your container's width and height.
  • view: "round" renders a circle sized to the container's width. Give it a container at least as tall as it is wide, or the circle extends below the container.
  • If your container has no explicit height, the SDK sizes it at 4:5 (rectangle, silhouette) or 1:1 (round) so the avatar is never invisible.
  • Video is cropped to cover, never stretched or distorted.

The controls need a minimum amount of room. Give the container's content area (its size without its own border and padding) at least:

What has to fitMinimum
Controls with screen sharing (4 buttons)176 px wide
Controls without screen sharing (3 buttons)132 px wide
Controls, rectangle and silhouette views, disclaimer off80 px tall
Controls, round view, disclaimer off64 px tall
Launcher card with the default label150 px wide

The disclaimer is on by default. The default one-line disclaimer needs about 24 px more height than the table shows.

If the widget has less room than that, the controls get clipped and the SDK writes a warning to the console, even without debug: true. The floating widget sizes itself (240 px wide) and needs nothing from you.

Style

FieldTypeDefaultDescription
view"round" | "rectangle" | "silhouette""round"Avatar shape. Use "rectangle" when your own styling needs a rectangular container. Use "silhouette" to cut the avatar out of a green-screen stream. See Green screen.
accentColorstring"#be369d"Your brand color, as any CSS color. See Accent color.
classNamestring—CSS class names added to the SDK's root element, for your own theming.

In init, view is required whenever you pass style. Without it, the avatar has no shape. Change any of these at runtime with updateStyle, which takes only the fields you change.

Accent color

accentColor replaces the SDK's default pink with your brand color:

await NapsterCompanionApiSdk.init(getToken, {
  style: { view: "round", accentColor: "#0091ff" },
});

It colors the live microphone button, the button on the microphone card, the ring around the agent's photo while the session loads, and the I'm here button on the inactivity card. If you don't set agent.photoUrl, it also fills the circle behind the placeholder icon. The muted microphone button keeps its fixed warning color. The persistence progress bar has its own color option.

Pick a color with enough contrast against white text and the page behind the widget. A very light accent color can make the buttons hard to read.

Green screen

view: "silhouette" cuts the avatar out of its background so it floats over your page. It removes green from the video, so it only works when the session sends a green-screen stream. Turn that on with useGreenVideo on the agent's WebRTC channel. If the stream isn't green-screen, you see the normal video background with no error.

Agent

FieldTypeDefaultDescription
photoUrlstring—The agent's photo. The SDK shows it on the launcher card and while the session loads. Without it, those show a generic placeholder.

Features

The features object turns built-in behaviors on and off. Each feature is a small object with its own enabled flag plus optional tuning values.

Every feature, with its defaults and options, is documented on the Features page.

Callbacks

All callbacks are optional. They're covered in full on the Events page.

CallbackSignatureFires when
onReady() => voidThe SDK has mounted the widget. This happens before the microphone prompt and before any connection. Use onAvatarReady to know when the session is live.
onError(error: Error) => voidA runtime or network error occurs.
onData(data: EventMessage) => voidA server event arrives over the data channel.
onAvatarReady(isReady?: boolean) => voidThe session goes live (true), or ends (false).
onSessionStatusChange(status: SessionStatus) => voidThe session moves to a new stage, such as waiting for the microphone or video arriving.
onInactivityStatusChange(isInactive: boolean) => voidThe inactivity warning appears or goes away.
onDestroy() => voidThe session is torn down.
onFeaturesUpdate(features: FeatureConfig) => voidFeature configuration changes at runtime.
onScreenShareStateChange(isSharing: boolean) => voidScreen sharing starts or stops.

The package doesn't export EventMessage or SessionStatus. In TypeScript, derive them from NapsterCompanionApiConfig, which is exported:

import type { NapsterCompanionApiConfig } from "@touchcastllc/napster-companion-api";

type EventMessage = Parameters<NonNullable<NapsterCompanionApiConfig["onData"]>>[0];
type SessionStatus = Parameters<NonNullable<NapsterCompanionApiConfig["onSessionStatusChange"]>>[0];

Persistence

The persistence object keeps one session alive across page navigation on a multi-page site:

NapsterCompanionApiSdk.init(getToken, {
  persistence: { enabled: true },
});

It has its own page. The behavior (iframe wrap, break-out rules, deferred wrap, programmatic navigation) and the full option table are covered in Persistence.

Debug

OptionTypeDefaultDescription
debugbooleanfalseTurn on verbose SDK logging in the console. Without it, the console shows only warnings about misconfiguration, such as a container too small for the controls. All other warnings, errors and channel logs appear only with debug: true. onError fires either way. See Troubleshooting → Debug mode.

Next steps

On this page