SDKsWeb SDK

Features

Every built-in feature — inactivity timeout, loading indicator, controls, picture-in-picture, screen sharing, background removal, and disclaimer

Features are built-in behaviors controlled through the features config object. Each feature has an enabled flag and, in some cases, tuning options. Several are on by default, so the table below is also the list of what to turn off. You can also change features at runtime. See feature control methods. A runtime change to pictureInPicture, or to whether the screen-share button shows, takes effect from the next session.

Feature keyDefaultPurpose
inactiveTimeouton: 60 s idle, 30 s countdownEnd the session after a period of inactivity, after a warning.
loadingIndicatoronThe agent's photo and spinner shown while the session starts.
controlsonBuilt-in controls (mute, volume, screen share, end).
pictureInPictureoffPop the avatar out when the user switches tabs.
screenShareoffLet the user share their screen with the avatar.
backgroundRemovalfollows style.viewCut the avatar out of a green-screen stream.
disclaimeronSmall disclaimer text shown under the controls.

Inactivity timeout

End the session after a period with no conversation. Before it ends, the SDK shows a Still there? card with an I'm here button and a countdown.

await NapsterCompanionApiSdk.init(getToken, {
  features: {
    inactiveTimeout: {
      enabled: true,
      duration: 60000, // idle time before the warning, in ms
      countdown: 30,   // countdown length before the session ends, in seconds
    },
  },
});
OptionTypeDefaultDescription
enabledbooleantrueTurn the timeout on.
durationnumber60000Idle time before the warning appears, in milliseconds. Max 180000 (3 minutes). A larger value is ignored and the current value (60000 by default) stays.
countdownnumber30How long the warning stays up before the session ends, in seconds. Between 20 and 60; values outside that range are clamped.

The timer starts when the avatar appears. It restarts each time a message completes, from the user or the agent. A click or key press in the picture-in-picture window restarts it too.

While the warning is up:

  • The microphone is held silent, so the agent hears nothing until the visitor clicks I'm here. The visitor's own mute setting is kept.
  • The built-in controls are hidden.
  • Every command sent over the data channel is dropped without an error. This includes sendCommand, stopAvatarTalking(), and puppeteer talk lines.
  • Messages that complete don't restart the timer. Only I'm here dismisses the warning.

When the visitor clicks I'm here, the SDK sends the message "I'm here" as the user, without asking the agent to reply. This restarts the server's own idle timer too. The message appears in the session transcript and in onData.

onInactivityStatusChange fires with true when the warning appears. It fires with false each time the timer restarts, including when the visitor clicks I'm here, so expect repeated false calls. When the countdown runs out, the session ends and onDestroy fires instead.

In puppeteer mode, the lines you send with talk don't restart this timer. Turn the timeout off with inactiveTimeout: { enabled: false }. Otherwise, with the default settings, the SDK ends the session about 90 seconds after the avatar appears, even while the avatar is talking.

Server idle timeout

The server has its own idle timeout. By default, it closes a session after 3 minutes without audio or messages. A minute before that, the SDK shows the same Still there? card with a 60-second countdown, even when inactiveTimeout is off. This card doesn't fire onInactivityStatusChange and doesn't drop commands. To keep sessions open, set disableIdleTimeout on the agent.

Loading indicator

While the session starts, the SDK shows the agent's photo with a spinner, then plays a short zoom-in when the avatar appears. It's on by default. Turn it off when you show your own loading screen:

await NapsterCompanionApiSdk.init(getToken, {
  features: {
    loadingIndicator: { enabled: false },
  },
});

The microphone card still appears either way, because the visitor needs it to allow microphone access. The photo comes from agent.photoUrl.

Built-in controls

The controls are the mute, volume, screen-share, and end buttons over the avatar. They're on by default. They fade out about 5 seconds after the avatar appears or the pointer leaves the widget, and come back when the pointer returns. They stay visible while one of them has keyboard focus.

The volume button turns the sound on and off. Turning it back on sets the volume to 70. To set a specific volume level, use setAudioVolume from your own UI. Turn the controls off entirely when your application provides its own, using the instance methods (muteMic, setAudioVolume, stopAvatarTalking, destroy, and so on). The disclaimer sits in the same bar, so turning the controls off also removes the disclaimer.

await NapsterCompanionApiSdk.init(getToken, {
  features: {
    controls: {
      enabled: false, // hide the built-in buttons and render your own
    },
  },
});

You can toggle them at runtime:

instance.updateFeatureConfig("controls", { enabled: false });
// later
instance.enableFeature("controls");

Picture-in-picture

Pop the avatar into a Document Picture-in-Picture window when the user switches browser tabs, so the conversation stays visible while they work elsewhere. The PiP window mirrors the live avatar video and shows the built-in controls, even when controls is off. Closing the PiP window or returning to the original tab brings the avatar back to the page.

await NapsterCompanionApiSdk.init(getToken, {
  features: {
    pictureInPicture: {
      enabled: true,
      width: 400,  // optional, default 400
      height: 300, // optional, default 300
    },
  },
});
OptionTypeDefaultDescription
enabledbooleanfalseTurn on automatic picture-in-picture.
widthnumber400PiP window width in pixels.
heightnumber300PiP window height in pixels.

Automatic PiP requires Chrome or Edge 116+ and:

  • A secure context (HTTPS).
  • Active media playback with audio.
  • The site has met the browser's Media Engagement Index threshold.

If these aren't met, the avatar stays on the page when the tab loses focus, and no error is thrown. To check support from code, use the exported checkPiPSupport helper.

PiP support helpers

The SDK exports two helpers for detecting automatic picture-in-picture support:

import { checkPiPSupport, resetPiPSupportCache } from "@touchcastllc/napster-companion-api";

if (checkPiPSupport()) {
  // the browser supports automatic Document Picture-in-Picture
}

checkPiPSupport() returns whether the browser supports automatic Document Picture-in-Picture (Chrome or Edge 116+), and caches the result. It doesn't check the HTTPS or Media Engagement requirements, so the window can still fail to open when it returns true. resetPiPSupportCache() clears that cache, which is mainly useful in tests.

Screen sharing

Share the user's screen with the avatar. The SDK captures the display about once per second, at up to 1280×720 and without audio. It draws each capture to an internal canvas and streams it over WebRTC so the avatar can see what the user sees. It runs entirely in the browser, with no plugins or extensions.

await NapsterCompanionApiSdk.init(getToken, {
  features: {
    screenShare: {
      enabled: true,
    },
  },
});

features.screenShare.enabled must be true for the screen-share button to appear and for isScreenShareSupported to return true.

Start and stop sharing from your own UI with the screen-sharing methods:

await instance.startScreenShare(); // opens the browser's screen picker
instance.stopScreenShare();
await instance.toggleScreenShare();

The SDK sends the start_video and stop_video commands to the avatar for you. Screen sharing stops when you call destroy(), when the WebRTC connection closes, or when the user clicks the browser's own Stop sharing button. Listen for onScreenShareStateChange to keep your UI in sync.

Background removal

Background removal cuts the avatar out of a green-screen stream. You don't set it directly: it's on when style.view is "silhouette", and off for every other view. Calls to enableFeature, disableFeature, or updateFeatureConfig for this feature are accepted but don't change it.

To use it, set view: "silhouette" and turn on useGreenVideo on the agent's WebRTC channel.

Disclaimer

A small disclaimer shown under the control buttons, for legal text or usage hints. It's on by default with the default text. Set enabled: false to remove it, or provide your own text.

await NapsterCompanionApiSdk.init(getToken, {
  features: {
    disclaimer: {
      enabled: true,
      text: "AI-generated responses. May contain errors.",
      color: "#666666", // optional
    },
  },
});
OptionTypeDefaultDescription
enabledbooleantrueShow the disclaimer.
textstring"This is an AI avatar. Check important info."The disclaimer text.
colorstring—CSS color for the text.

The disclaimer appears once the session is live, and fades out and back in with the controls. It sits in the controls bar, so it doesn't show when controls is off. Long text is cut to two lines. Hovering the disclaimer shows its full text in a tooltip. You can change it at runtime:

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

Next steps

On this page