@touchcastllc/napster-companion-api-dev 2.0.0-alpha.2 → 2.0.0-alpha.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/README.md +29 -0
  2. package/lib/button/session.d.ts +7 -0
  3. package/lib/button/trigger.d.ts +2 -0
  4. package/lib/components/Avatar/controlsAutoHide.d.ts +30 -0
  5. package/lib/components/Avatar/readyGrow.d.ts +37 -0
  6. package/lib/components/InactiveOverlay/index.d.ts +2 -0
  7. package/lib/components/MicPermission/index.d.ts +5 -3
  8. package/lib/components/StyledTooltip/index.d.ts +3 -0
  9. package/lib/components/controls/createControlButton.d.ts +9 -0
  10. package/lib/constants/accessibleNames.d.ts +7 -0
  11. package/lib/constants/inactivity.d.ts +6 -0
  12. package/lib/constants/index.d.ts +1 -0
  13. package/lib/index.css +1 -1
  14. package/lib/index.d.ts +6 -0
  15. package/lib/index.esm.js +1 -1
  16. package/lib/index.js +1 -1
  17. package/lib/index.standalone.js +1 -1
  18. package/lib/services/micRecovery.d.ts +33 -0
  19. package/lib/services/microphoneManager.d.ts +13 -0
  20. package/lib/services/sessionAnnouncements.d.ts +32 -0
  21. package/lib/stores/index.d.ts +1 -1
  22. package/lib/stores/selectors.d.ts +3 -0
  23. package/lib/stores/slices/avatarSlice.d.ts +4 -1
  24. package/lib/types/index.d.ts +5 -1
  25. package/lib/utils/InactiveOverlayManager.d.ts +10 -0
  26. package/lib/utils/announcer.d.ts +26 -0
  27. package/lib/utils/canHover.d.ts +7 -0
  28. package/lib/utils/classnames.d.ts +2 -0
  29. package/lib/utils/containerSizeWatcher.d.ts +53 -0
  30. package/lib/utils/focus.d.ts +8 -0
  31. package/lib/utils/glassFrame.d.ts +2 -2
  32. package/lib/utils/hostLanguage.d.ts +15 -0
  33. package/lib/utils/inertSiblings.d.ts +12 -0
  34. package/lib/utils/widgetRoot.d.ts +5 -0
  35. package/package.json +1 -1
@@ -0,0 +1,33 @@
1
+ export interface MicRecoveryController {
2
+ destroy(): void;
3
+ }
4
+ export interface MicRecoveryOptions {
5
+ /** Element the card mounts into — `#np_companion-sdk-root`. */
6
+ root: HTMLElement;
7
+ /**
8
+ * The avatar shape to render the card as, read when the card opens rather
9
+ * than once at creation: this controller lives as long as the widget, and
10
+ * the view can change under it (`updateStyle()`).
11
+ */
12
+ getView: () => string | undefined;
13
+ }
14
+ /**
15
+ * A click on the badged mute button: ask for the microphone back.
16
+ *
17
+ * Where the browser can still ask (Firefox reports "prompt" after a
18
+ * mid-session revoke) the retry puts the browser's own Allow/Block prompt on
19
+ * screen, and that prompt is the whole interaction — no card on top of it,
20
+ * and none after the user answers it. Only "blocked" opens the card: the
21
+ * browser will not ask (Chrome, "denied"), so the user has to be told how to
22
+ * unblock it themselves.
23
+ */
24
+ export declare function requestMicRecovery(): Promise<void>;
25
+ /**
26
+ * The recovery card for a microphone lost MID-session (CA-1076) — the same
27
+ * `MicPermission` card micGate.ts mounts at session start, but driven purely
28
+ * by `avatar.micRecoveryOpen` instead of by a session attempt: the session is
29
+ * live here and `session.status` stays ready. The card has no close control
30
+ * (removed in CA-1114): requestMicRecovery() above sets the flag, and it drops
31
+ * by itself once the microphone is available again (avatarSlice).
32
+ */
33
+ export declare function createMicRecovery(options: MicRecoveryOptions): MicRecoveryController;
@@ -1,8 +1,12 @@
1
+ export type MicAvailability = "available" | "unavailable";
2
+ export type MicRetryResult = "granted" | "refused" | "blocked";
1
3
  export type MicManagerEventMap = {
2
4
  stream: MediaStream | null;
3
5
  muted: boolean;
4
6
  device: string | undefined;
5
7
  error: Error;
8
+ availability: MicAvailability;
9
+ sourceMuted: boolean;
6
10
  };
7
11
  export type MicManagerEvent = keyof MicManagerEventMap;
8
12
  type Handler<E extends MicManagerEvent> = (payload: MicManagerEventMap[E]) => void;
@@ -19,6 +23,15 @@ export interface MicrophoneManager {
19
23
  getTrack(): MediaStreamTrack | null;
20
24
  getAnalyser(): AnalyserNode | null;
21
25
  getCurrentDeviceId(): string | undefined;
26
+ /** False while the microphone is lost and cannot be re-acquired unprompted. */
27
+ isAvailable(): boolean;
28
+ /** True while the browser itself is holding the capture muted. */
29
+ isSourceMuted(): boolean;
30
+ /**
31
+ * Ask for a lost microphone again, on the user's initiative. The only path
32
+ * that may put a browser permission prompt on screen mid-session.
33
+ */
34
+ retry(): Promise<MicRetryResult>;
22
35
  on<E extends MicManagerEvent>(event: E, handler: Handler<E>): () => void;
23
36
  }
24
37
  export declare const DEFAULT_AUDIO_CONSTRAINTS: MediaTrackConstraints;
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Turns session, microphone, sound and screen-share changes into short
3
+ * screen-reader announcements (CA-1145, WCAG 4.1.3). Texts proposed by the
4
+ * developer, approved by the manager in review.
5
+ *
6
+ * "Session ended" is not here: teardown resets the avatar and the session
7
+ * before anything could tell an end from a reset, so `destroyInstance()`
8
+ * stops this watcher first and announces the end itself.
9
+ *
10
+ * Everything is spoken through the widget's announcer (utils/announcer.ts).
11
+ */
12
+ export declare const ANNOUNCEMENTS: {
13
+ readonly connecting: "Connecting";
14
+ readonly ready: "Avatar is ready";
15
+ readonly muted: "Microphone muted";
16
+ readonly unmuted: "Microphone unmuted";
17
+ readonly micUnavailable: "Microphone unavailable";
18
+ readonly micAvailable: "Microphone available again";
19
+ readonly soundMuted: "Sound muted";
20
+ readonly soundUnmuted: "Sound unmuted";
21
+ readonly screenShareStarted: "Screen sharing started";
22
+ readonly screenShareStopped: "Screen sharing stopped";
23
+ readonly sessionEnded: "Session ended";
24
+ };
25
+ export declare function watchSessionAnnouncements(announce: (text: string) => void): () => void;
26
+ /**
27
+ * Speaks `text` from a short-lived region on the page body, `delayMs` from
28
+ * now. Only for the end of a session whose root is removed (no click-to-start
29
+ * button): the widget's announcer lives in that root and goes with it.
30
+ * Returns a function that removes the region early.
31
+ */
32
+ export declare function announceOutsideWidget(text: string, delayMs?: number): () => void;
@@ -2,7 +2,7 @@ export { store } from "./store";
2
2
  export type { RootState } from "./store";
3
3
  export { setOnFeaturesUpdateCallback } from "./middleware/featuresUpdateMiddleware";
4
4
  export * from "./selectors";
5
- export { setSessionId, setTransport, setStopInteraction, setMuted, setAutoMicActive, setVolume, setAvatarSpeaking, setScreenSharing, setUserTalking, setConnectionToken, setCloseConnectionHandler, setSessionTerminatedByServer, resetAvatar, } from "./slices/avatarSlice";
5
+ export { setSessionId, setTransport, setStopInteraction, setMuted, setMicUnavailable, setMicRecoveryOpen, setMicSourceMuted, setAutoMicActive, setVolume, setAvatarSpeaking, setScreenSharing, setUserTalking, setConnectionToken, setCloseConnectionHandler, setSessionTerminatedByServer, resetAvatar, } from "./slices/avatarSlice";
6
6
  export { setSessionStatus, resetSession } from "./slices/sessionSlice";
7
7
  export type { SessionStatus } from "./slices/sessionSlice";
8
8
  export { setFeatures, resetFeatures, setDebugMode } from "./slices/appSlice";
@@ -8,6 +8,9 @@ import type { SessionStatus } from "./slices/sessionSlice";
8
8
  export declare const selectSessionId: (state: RootState) => string | undefined;
9
9
  export declare const selectTransport: (state: RootState) => Transport | null;
10
10
  export declare const selectMuted: (state: RootState) => boolean;
11
+ export declare const selectMicUnavailable: (state: RootState) => boolean;
12
+ export declare const selectMicRecoveryOpen: (state: RootState) => boolean;
13
+ export declare const selectMicSourceMuted: (state: RootState) => boolean;
11
14
  export declare const selectAutoMicActive: (state: RootState) => boolean;
12
15
  export declare const selectAvatarSpeaking: (state: RootState) => boolean;
13
16
  export declare const selectUserTalking: (state: RootState) => boolean;
@@ -4,6 +4,9 @@ export interface AvatarState {
4
4
  transport: Transport | null;
5
5
  stopInteraction: boolean;
6
6
  muted: boolean;
7
+ micUnavailable: boolean;
8
+ micRecoveryOpen: boolean;
9
+ micSourceMuted: boolean;
7
10
  autoMicActive: boolean;
8
11
  volume: number;
9
12
  avatarSpeaking: boolean;
@@ -13,5 +16,5 @@ export interface AvatarState {
13
16
  closeConnectionHandler?: () => void;
14
17
  sessionTerminatedByServer: boolean;
15
18
  }
16
- export declare const setSessionId: import("@reduxjs/toolkit").ActionCreatorWithOptionalPayload<string | undefined, "avatar/setSessionId">, setTransport: import("@reduxjs/toolkit").ActionCreatorWithPayload<Transport | null, "avatar/setTransport">, setStopInteraction: import("@reduxjs/toolkit").ActionCreatorWithPayload<boolean, "avatar/setStopInteraction">, setMuted: import("@reduxjs/toolkit").ActionCreatorWithPayload<boolean, "avatar/setMuted">, setAutoMicActive: import("@reduxjs/toolkit").ActionCreatorWithPayload<boolean, "avatar/setAutoMicActive">, setVolume: import("@reduxjs/toolkit").ActionCreatorWithPayload<number, "avatar/setVolume">, setAvatarSpeaking: import("@reduxjs/toolkit").ActionCreatorWithPayload<boolean, "avatar/setAvatarSpeaking">, setScreenSharing: import("@reduxjs/toolkit").ActionCreatorWithPayload<boolean, "avatar/setScreenSharing">, setUserTalking: import("@reduxjs/toolkit").ActionCreatorWithPayload<boolean, "avatar/setUserTalking">, setConnectionToken: import("@reduxjs/toolkit").ActionCreatorWithOptionalPayload<string | undefined, "avatar/setConnectionToken">, setCloseConnectionHandler: import("@reduxjs/toolkit").ActionCreatorWithOptionalPayload<(() => void) | undefined, "avatar/setCloseConnectionHandler">, setSessionTerminatedByServer: import("@reduxjs/toolkit").ActionCreatorWithPayload<boolean, "avatar/setSessionTerminatedByServer">, resetAvatar: import("@reduxjs/toolkit").ActionCreatorWithoutPayload<"avatar/resetAvatar">;
19
+ export declare const setSessionId: import("@reduxjs/toolkit").ActionCreatorWithOptionalPayload<string | undefined, "avatar/setSessionId">, setTransport: import("@reduxjs/toolkit").ActionCreatorWithPayload<Transport | null, "avatar/setTransport">, setStopInteraction: import("@reduxjs/toolkit").ActionCreatorWithPayload<boolean, "avatar/setStopInteraction">, setMuted: import("@reduxjs/toolkit").ActionCreatorWithPayload<boolean, "avatar/setMuted">, setMicUnavailable: import("@reduxjs/toolkit").ActionCreatorWithPayload<boolean, "avatar/setMicUnavailable">, setMicRecoveryOpen: import("@reduxjs/toolkit").ActionCreatorWithPayload<boolean, "avatar/setMicRecoveryOpen">, setMicSourceMuted: import("@reduxjs/toolkit").ActionCreatorWithPayload<boolean, "avatar/setMicSourceMuted">, setAutoMicActive: import("@reduxjs/toolkit").ActionCreatorWithPayload<boolean, "avatar/setAutoMicActive">, setVolume: import("@reduxjs/toolkit").ActionCreatorWithPayload<number, "avatar/setVolume">, setAvatarSpeaking: import("@reduxjs/toolkit").ActionCreatorWithPayload<boolean, "avatar/setAvatarSpeaking">, setScreenSharing: import("@reduxjs/toolkit").ActionCreatorWithPayload<boolean, "avatar/setScreenSharing">, setUserTalking: import("@reduxjs/toolkit").ActionCreatorWithPayload<boolean, "avatar/setUserTalking">, setConnectionToken: import("@reduxjs/toolkit").ActionCreatorWithOptionalPayload<string | undefined, "avatar/setConnectionToken">, setCloseConnectionHandler: import("@reduxjs/toolkit").ActionCreatorWithOptionalPayload<(() => void) | undefined, "avatar/setCloseConnectionHandler">, setSessionTerminatedByServer: import("@reduxjs/toolkit").ActionCreatorWithPayload<boolean, "avatar/setSessionTerminatedByServer">, resetAvatar: import("@reduxjs/toolkit").ActionCreatorWithoutPayload<"avatar/resetAvatar">;
17
20
  export declare const avatarReducer: import("redux").Reducer<AvatarState>;
@@ -335,7 +335,11 @@ export interface LayoutConfig {
335
335
  * - `"inline"`: the avatar renders inside `mountContainer` and fills it. Size
336
336
  * and shape come from how you style that container; `position` is ignored.
337
337
  * When the container has no explicit height, an internal 4:5 ratio is used
338
- * so the avatar is never invisible.
338
+ * so the avatar is never invisible. The container's content area must be at
339
+ * least 176px wide (132px without screen share) and 80px tall (64px for
340
+ * `round`) or the controls clip — the SDK warns in the console when there
341
+ * is too little room. See the README, "Inline layout: minimum container
342
+ * size".
339
343
  */
340
344
  type?: "fixed" | "inline";
341
345
  /** Position of the avatar on screen. Meaningful only when `type` is
@@ -43,6 +43,10 @@ export declare class InactiveOverlayManager {
43
43
  private isVisible;
44
44
  private readonly mountElement;
45
45
  private pipTarget;
46
+ /** Where keyboard focus was when the overlay took it (CA-1139). */
47
+ private returnFocusTo;
48
+ /** Switches back on what the overlay covers (CA-1139 review). */
49
+ private restoreCovered;
46
50
  private readonly callbacks;
47
51
  constructor(mountElement: HTMLElement, callbacks?: InactiveOverlayCallbacks);
48
52
  /**
@@ -55,6 +59,12 @@ export declare class InactiveOverlayManager {
55
59
  * This is the single entry point for hiding the overlay
56
60
  */
57
61
  hide(): void;
62
+ /**
63
+ * restoreFocus is false when the session is ending (countdown run out,
64
+ * teardown): destroyInstance() moves focus once, to the entry point or
65
+ * mount — restoring here first would move it twice (Serhii's review).
66
+ */
67
+ private hideOverlay;
58
68
  /**
59
69
  * Check if overlay is currently visible
60
70
  */
@@ -0,0 +1,26 @@
1
+ /**
2
+ * The widget's one screen-reader announcer (CA-1139).
3
+ *
4
+ * A single visually hidden `aria-live="polite"` region per root, shared by
5
+ * everything that needs to speak — several regions would talk over each
6
+ * other. The PiP document gets its own, since a live region only speaks for
7
+ * the document it lives in. Styled in App.css.
8
+ */
9
+ /**
10
+ * Text is written this long after the region is cleared. Screen readers
11
+ * announce a *change* to a region that already exists; clearing and writing
12
+ * in the same tick is no change at all, and a region created in the same tick
13
+ * as its text is often not read.
14
+ */
15
+ export declare const ANNOUNCE_DELAY_MS = 100;
16
+ /**
17
+ * Adds the announcer to a root, or returns the one it has. Call this when the
18
+ * root is created, so the region already exists by the time anything speaks.
19
+ */
20
+ export declare function createAnnouncer(root: HTMLElement): HTMLElement;
21
+ /**
22
+ * Reads `text` out through the announcer of the root `from` belongs to.
23
+ * `from` may be inside the root (main page) or contain it (the PiP body,
24
+ * which holds the PiP stage).
25
+ */
26
+ export declare function announce(from: HTMLElement, text: string): void;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Whether the primary input can hover — false on phones and tablets. This is
3
+ * the SDK's one "is this a touch device" signal, the same query as
4
+ * ControlBar.css's hover rule. No matchMedia (older engines) counts as able
5
+ * to hover.
6
+ */
7
+ export declare function canHover(win?: Window): boolean;
@@ -35,6 +35,8 @@ export declare const ControlClasses: {
35
35
  readonly stop: "np_companion-action-btn-container-stop";
36
36
  readonly questionBar: "np_companion-chat-question-bar-container";
37
37
  readonly muted: "np_companion-muted";
38
+ /** Mic lost mid-session — ControlBar.css draws the warning badge off this. */
39
+ readonly micUnavailable: "np_companion-mic-unavailable";
38
40
  readonly hidden: "np_companion-hidden";
39
41
  readonly expanded: "np_companion-action-btn-container-expanded";
40
42
  readonly collapse: "np_companion-action-btn-container-collapse";
@@ -0,0 +1,53 @@
1
+ /**
2
+ * CA-845 — in inline layout the host sizes the container, so it can be given
3
+ * less room than the control row needs, and the buttons then clip silently
4
+ * (WCAG 1.4.10 Reflow needs a stated, testable floor). This watches the
5
+ * container and warns once when something stops fitting.
6
+ *
7
+ * It detects the problem from geometry instead of comparing against a stored
8
+ * width: the numbers can't drift out of step with the CSS (button size, gaps,
9
+ * pill padding), and the warning can say exactly how much room is missing.
10
+ */
11
+ export type FitProblem = {
12
+ kind: "controls-width";
13
+ availablePx: number;
14
+ requiredPx: number;
15
+ } | {
16
+ kind: "controls-height";
17
+ availablePx: number;
18
+ requiredPx: number;
19
+ } | {
20
+ kind: "entry-text";
21
+ availablePx: number;
22
+ };
23
+ export interface ContainerSizeWatcher {
24
+ /** Schedule a measurement now (e.g. controls were just mounted). */
25
+ check(): void;
26
+ destroy(): void;
27
+ }
28
+ /**
29
+ * Measures how the SDK's content sits inside the room the host gave it.
30
+ *
31
+ * "Room" is the root's own box, not the container's outer box: the root fills
32
+ * the container's content area, so the host's border and padding are already
33
+ * subtracted — which is what the integrator has to account for.
34
+ *
35
+ * - `controls-width`: the control row sticks out of its pill. `requiredPx` is
36
+ * the available width plus the overflow, i.e. the smallest room the row fits
37
+ * in.
38
+ * - `controls-height`: the pill is cut off by the top or bottom of the room.
39
+ * - `entry-text`: the entry-point card's text is clipped.
40
+ *
41
+ * Returns `[]` before the controls exist.
42
+ */
43
+ export declare function measureFit(root: HTMLElement): FitProblem[];
44
+ /**
45
+ * Watches the host container of an inline-layout widget and warns (always —
46
+ * `critical_warn` ignores debug mode, like other genuine integrator
47
+ * misconfiguration) when the controls or the start card stop fitting.
48
+ *
49
+ * One warning per kind of problem, each time it appears: it re-arms once the
50
+ * container fits again. Does nothing in fixed layout, where the SDK sizes
51
+ * itself (240px, wider than any threshold).
52
+ */
53
+ export declare function createContainerSizeWatcher(root: HTMLElement): ContainerSizeWatcher;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Focuses an element that may not be focusable on its own — a container the
3
+ * widget was in, or the widget root — so focus has somewhere sensible to land
4
+ * instead of <body> (CA-1139). A plain <div> gets a temporary tabindex="-1",
5
+ * dropped again once focus moves on; a tabindex the host set is left as is.
6
+ * <body> is skipped: focus is already there, and it must not gain a tabindex.
7
+ */
8
+ export declare function focusWithTemporaryTabindex(el: HTMLElement): void;
@@ -24,8 +24,8 @@ export interface WrapWithGlassFrameOptions {
24
24
  *
25
25
  * Used to carry the translucent glass-frame ring every card in this SDK
26
26
  * once rendered (avatar shape, control-bar pill, Entry Point card,
27
- * MicPermission card) — removed per manager feedback ("треба прибрати всі
28
- * скляні бордери, не тільки навколо шейпів"), so this now just wraps;
27
+ * MicPermission card) — removed per manager feedback ("remove all the glass
28
+ * borders, not only around the shapes"), so this now just wraps;
29
29
  * kept as the one place every caller's page-position class lands, since
30
30
  * that part of the contract is unrelated to the frame that used to live
31
31
  * here.
@@ -0,0 +1,15 @@
1
+ /**
2
+ * The widget's own texts are English and the SDK root says so (`lang="en"`,
3
+ * CA-1148). Texts the integrator supplies through the config (button label
4
+ * and description, disclaimer) are written in the host page's language
5
+ * instead, so they carry the page's `lang` — otherwise a screen reader would
6
+ * read, say, a German label with the English voice.
7
+ */
8
+ /** The host page's declared language, or "" when it declares none. */
9
+ export declare function hostLanguage(): string;
10
+ /**
11
+ * Marks an element holding integrator text with the host page's language.
12
+ * With no page language there is nothing to mark it with: the attribute is
13
+ * removed and the element inherits the root's English.
14
+ */
15
+ export declare function applyHostLanguage(el: HTMLElement): void;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Makes everything next to `el` inert — not focusable, not read by screen
3
+ * readers — and returns a function that undoes it. Used while an overlay
4
+ * covers its siblings, so Tab cannot reach a control hidden under it
5
+ * (CA-1139). Not `aria-modal`: that would claim the whole host page.
6
+ *
7
+ * A sibling holding the widget's announcer is not made inert itself — inert
8
+ * content is not read out, so the warning would go silent (the PiP stage
9
+ * holds both the announcer and the controls). Its other children are, instead.
10
+ * Elements that were already inert are left out, so the undo keeps them so.
11
+ */
12
+ export declare function makeSiblingsInert(el: HTMLElement): () => void;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * The widget root `from` belongs to: the root around it on the main page, or
3
+ * the stage inside it when `from` is the PiP body. Falls back to `from`.
4
+ */
5
+ export declare function findWidgetRoot(from: HTMLElement): HTMLElement;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@touchcastllc/napster-companion-api-dev",
3
- "version": "2.0.0-alpha.2",
3
+ "version": "2.0.0-alpha.20",
4
4
  "keywords": [
5
5
  "napster",
6
6
  "companion-api",