SDKsWeb SDK

Methods

Every method on the instance returned by init, plus the top-level SDK object

This page lists everything you can call. Most of it is the NapsterCompanionApiInstance, the object init resolves to, grouped by area. The top-level SDK object is at the end.

Lifecycle

MethodSignatureDescription
showAvatar() => voidShow the avatar video if it's hidden.
hideAvatar() => voidHide the avatar video.
avatarIsVisible() => booleanWhether the avatar video is visible.
destroy() => voidTear down the SDK, remove DOM nodes, close the connection, and release media.

hideAvatar hides only the avatar video. The control bar stays on screen, and the session and its audio keep running. avatarIsVisible() returns false after hideAvatar, and also before the avatar has rendered. In that state, showAvatar() does nothing.

if (!instance.avatarIsVisible()) instance.showAvatar();
// ...
instance.destroy();

Always call destroy() when the widget leaves the page. See teardown. With the launcher, instance.destroy() only ends the session, and the launcher comes back. To remove the launcher, call the controller's destroy().

Styling and position

MethodSignatureDescription
updateStyle(style: Partial<StyleConfig>) => voidChange the avatar shape, accent color, or CSS class. Only the keys you pass change. See Style.
setPosition(position: Position) => voidMove the floating widget to one of the position values. No effect in inline layout. To move it back, call setPosition again with the original value.
import { Position } from "@touchcastllc/napster-companion-api";

instance.setPosition(Position.TOP_LEFT);
instance.updateStyle({ view: "rectangle", accentColor: "#0091ff" });

Feature control

Toggle and reconfigure features after init. feature is one of the keys of the features config object.

MethodSignatureDescription
enableFeature(feature: keyof FeatureConfig) => voidEnable a feature by name.
disableFeature(feature: keyof FeatureConfig) => voidDisable a feature by name.
updateFeatureConfig(feature: keyof FeatureConfig, config) => voidUpdate a single feature's config. Keys you leave out keep their current values.

TypeScript requires enabled in the config object, so include it even when you only change another key.

instance.disableFeature("controls");
instance.updateFeatureConfig("disclaimer", { enabled: true, text: "New disclaimer text" });
instance.enableFeature("controls");

backgroundRemoval follows style.view and ignores these calls. See Background removal.

Feature names are typed as keyof FeatureConfig, so your editor autocompletes them and rejects typos. The valid keys are listed on the Features page.

Screen sharing

features.screenShare.enabled: true shows the built-in screen-share button and makes isScreenShareSupported return true. See the screen sharing feature.

MemberSignatureDescription
startScreenShare() => Promise<void>Start sharing. Opens the browser's screen picker.
stopScreenShare() => voidStop sharing.
toggleScreenShare() => Promise<void>Toggle sharing on or off.
isScreenSharingboolean (getter)Whether sharing is currently active.
isScreenShareSupportedboolean (getter)Whether the browser supports sharing and the feature is enabled.

If the user cancels the screen picker, startScreenShare resolves without sharing. Other errors go to onError, and the promise rejects. toggleScreenShare never rejects: its errors go only to onError.

if (instance.isScreenShareSupported) {
  await instance.toggleScreenShare();
}

Audio control

MemberSignatureDescription
muteAudio() => voidMute the avatar's audio output.
unmuteAudio() => voidUnmute the avatar's audio output.
isAudioMutedboolean (getter)Whether the avatar's audio is muted.
setAudioVolume(volume: number) => voidSet output volume. Range 0–1; values outside are clamped.
getAudioVolume() => numberCurrent output volume, 0–1. Defaults to 1.

Microphone control

MemberSignatureDescription
muteMic() => voidMute the user's microphone.
unmuteMic() => voidUnmute the user's microphone.
isMicMutedboolean (getter)Whether the microphone is muted.

Speech control

MemberSignatureDescription
stopAvatarTalking() => voidInterrupt the avatar's current response so it stops talking.
isAvatarSpeakingboolean (getter)Whether the avatar is currently speaking.
isUserTalkingboolean (getter)Whether the user is currently talking, detected from the microphone. Needs the built-in controls.

isUserTalking is detected by the built-in control bar. If you set features.controls.enabled: false in init, it's always false. It's also false while the microphone is muted.

// Interrupt the avatar from your own button
if (instance.isAvatarSpeaking) instance.stopAvatarTalking();

Session and advanced

MemberSignatureDescription
sessionIdstring | undefined (getter)The current session identifier. Set as soon as the SDK starts connecting. undefined before that and after the connection closes.
sendCommand(command: DataChannelCommand) => voidSend a typed command over the data channel. Commands sent while the session isn't live are dropped with a console warning. See Messaging.

sessionId

Read sessionId to correlate the live session with your backend records — for example to fetch the transcript later via Monitor sessions.

const id = instance.sessionId;

sendCommand

sendCommand takes a DataChannelCommand, the typed union documented on the Messaging page. The package doesn't export this type by name. If you need it, derive it with Parameters<NapsterCompanionApiInstance["sendCommand"]>[0].

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

instance.sendCommand({
  type: DataChannelMessageType.SEND_MESSAGE,
  data: { text: "Hi", role: "user", trigger_response: true },
});

SDK object

The top-level NapsterCompanionApiSdk object exposes:

MemberSignatureDescription
init(getToken, config?) => Promise<NapsterCompanionApiInstance>Mount the widget and start connecting. Resolves once the widget is on the page, before the session is live. With button.enabled, resolves to a launcher controller instead. See Initialization.
versionstringThe SDK version string, useful for diagnostics.

The launcher controller (start, end, getInstance, destroy) is documented under Start on click.

Next steps

On this page