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
show, hide, destroy
Styling & position
Update look and placement
Feature control
Toggle features at runtime
Screen sharing
Start, stop, and query
Audio, mic & speech
Control the media
Session & advanced
sessionId, sendCommand
SDK object
init, version, and the launcher controller
Lifecycle
| Method | Signature | Description |
|---|---|---|
showAvatar | () => void | Show the avatar video if it's hidden. |
hideAvatar | () => void | Hide the avatar video. |
avatarIsVisible | () => boolean | Whether the avatar video is visible. |
destroy | () => void | Tear 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
| Method | Signature | Description |
|---|---|---|
updateStyle | (style: Partial<StyleConfig>) => void | Change the avatar shape, accent color, or CSS class. Only the keys you pass change. See Style. |
setPosition | (position: Position) => void | Move 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.
| Method | Signature | Description |
|---|---|---|
enableFeature | (feature: keyof FeatureConfig) => void | Enable a feature by name. |
disableFeature | (feature: keyof FeatureConfig) => void | Disable a feature by name. |
updateFeatureConfig | (feature: keyof FeatureConfig, config) => void | Update 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.
| Member | Signature | Description |
|---|---|---|
startScreenShare | () => Promise<void> | Start sharing. Opens the browser's screen picker. |
stopScreenShare | () => void | Stop sharing. |
toggleScreenShare | () => Promise<void> | Toggle sharing on or off. |
isScreenSharing | boolean (getter) | Whether sharing is currently active. |
isScreenShareSupported | boolean (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
| Member | Signature | Description |
|---|---|---|
muteAudio | () => void | Mute the avatar's audio output. |
unmuteAudio | () => void | Unmute the avatar's audio output. |
isAudioMuted | boolean (getter) | Whether the avatar's audio is muted. |
setAudioVolume | (volume: number) => void | Set output volume. Range 0–1; values outside are clamped. |
getAudioVolume | () => number | Current output volume, 0–1. Defaults to 1. |
Microphone control
| Member | Signature | Description |
|---|---|---|
muteMic | () => void | Mute the user's microphone. |
unmuteMic | () => void | Unmute the user's microphone. |
isMicMuted | boolean (getter) | Whether the microphone is muted. |
Speech control
| Member | Signature | Description |
|---|---|---|
stopAvatarTalking | () => void | Interrupt the avatar's current response so it stops talking. |
isAvatarSpeaking | boolean (getter) | Whether the avatar is currently speaking. |
isUserTalking | boolean (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
| Member | Signature | Description |
|---|---|---|
sessionId | string | 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) => void | Send 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:
| Member | Signature | Description |
|---|---|---|
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. |
version | string | The SDK version string, useful for diagnostics. |
The launcher controller (start, end, getInstance, destroy) is documented under Start on click.