Methods
Every method on the instance returned by init, plus the top-level SDK object
This page is the full reference for everything you can call. Most of it covers the NapsterCompanionApiInstance — the object that drives a live session, which init resolves to — grouped by area. At the end you'll find the top-level SDK object.
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
Lifecycle
| Method | Signature | Description |
|---|---|---|
showAvatar | () => void | Show the avatar if it's hidden. |
hideAvatar | () => void | Hide the avatar from the screen. |
avatarIsVisible | () => boolean | Whether the avatar is currently visible. |
destroy | () => void | Tear down the SDK, remove DOM nodes, close the connection, and release media. |
if (!instance.avatarIsVisible()) instance.showAvatar();
// ...
instance.destroy();Always call destroy() when the widget leaves the page. See teardown.
Styling and position
| Method | Signature | Description |
|---|---|---|
updateStyles | (styles: StyleObject) => void | Merge new inline styles into the SDK root container. |
setPosition | (position: Position) => void | Move the widget to one of the position values. |
clearPosition | () => void | Clear a programmatic position and revert to the configured/default one. |
updateAvatarStyle | (style: Partial<avatarStyleConfig>) => void | Update the avatar shape and border. Only the keys you pass change. |
instance.setPosition("top-left");
instance.updateAvatarStyle({ view: "rectangle" });
instance.updateStyles({ zIndex: "2000" });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. Partial — only the keys you pass change. |
instance.disableFeature("controls");
instance.updateFeatureConfig("disclaimer", { text: "New disclaimer text" });
instance.enableFeature("controls");Feature names are typed as keyof FeatureConfig, so your editor autocompletes them and rejects typos. The valid keys are listed in the features config.
Screen sharing
Requires features.screenShare.enabled: 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 (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. |
// Build your own push-to-talk control
if (instance.isAvatarSpeaking) instance.stopAvatarTalking();Session and advanced
| Member | Signature | Description |
|---|---|---|
sessionId | string | undefined (getter) | The current session identifier. Set once the connection is established, undefined after it closes. |
sendCommand | (command: DataChannelCommand) => void | Send a typed command over the data channel. 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.
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 | (token, config?) => Promise<NapsterCompanionApiInstance> | Connect and mount the widget. See Initialization. |
version | string | The SDK version string, useful for diagnostics. |