@touchcastllc/napster-companion-api-dev 1.6.0-alpha.0 → 1.6.0-alpha.3
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.
- package/README.md +74 -2
- package/lib/button/element.d.ts +2 -0
- package/lib/button/navigationHold.d.ts +7 -0
- package/lib/button/session.d.ts +45 -0
- package/lib/button/trigger.d.ts +21 -0
- package/lib/index.css +1 -1
- package/lib/index.d.ts +104 -33
- package/lib/index.esm.js +1 -1
- package/lib/index.js +1 -1
- package/lib/index.standalone.js +1 -1
- package/lib/services/micGate.d.ts +37 -0
- package/lib/services/webrtc.d.ts +0 -5
- package/lib/types/index.d.ts +89 -42
- package/package.json +1 -1
- package/lib/button/index.d.ts +0 -46
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Handle returned by {@link gateOnMicrophone}. Lets the caller tear down an
|
|
3
|
+
* active recovery card (e.g. on session destroy) independent of whether the
|
|
4
|
+
* user ever retries.
|
|
5
|
+
*/
|
|
6
|
+
export interface MicGateController {
|
|
7
|
+
/** Force-hide the recovery card, if one is mounted. Safe to call unconditionally. */
|
|
8
|
+
dismiss(): void;
|
|
9
|
+
}
|
|
10
|
+
export interface MicGateOptions {
|
|
11
|
+
/** Element the recovery card mounts into on denial. */
|
|
12
|
+
root: HTMLElement;
|
|
13
|
+
/**
|
|
14
|
+
* The microphone is available. Fires once for an immediate grant, and
|
|
15
|
+
* again after each successful "Check again" retry. May return a promise —
|
|
16
|
+
* {@link gateOnMicrophone}'s own promise waits for it, so a caller that
|
|
17
|
+
* awaits the gate call also waits for whatever `onGranted` kicks off.
|
|
18
|
+
*/
|
|
19
|
+
onGranted: () => void | Promise<void>;
|
|
20
|
+
/** Reported once, on the FIRST failure only — never on a refused retry. */
|
|
21
|
+
onError?: (error: Error) => void;
|
|
22
|
+
/** Fires immediately before the recovery card mounts. */
|
|
23
|
+
onBeforeRecovery?: () => void;
|
|
24
|
+
/**
|
|
25
|
+
* Staleness probe, checked after every await before the gate touches the DOM
|
|
26
|
+
* or calls back. A session destroyed — or superseded by a new init() — while
|
|
27
|
+
* the browser prompt was open must not mount a recovery card into its own
|
|
28
|
+
* detached root, and must not drive the session that replaced it.
|
|
29
|
+
*/
|
|
30
|
+
isStale?: () => boolean;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Gate a session on microphone access (CA-622): try once, and on denial keep
|
|
34
|
+
* the widget mounted with a recovery card ("Check again", CA-774) instead of
|
|
35
|
+
* tearing it down.
|
|
36
|
+
*/
|
|
37
|
+
export declare function gateOnMicrophone(opts: MicGateOptions): Promise<MicGateController>;
|
package/lib/services/webrtc.d.ts
CHANGED
|
@@ -3,9 +3,7 @@ import type { MediaCapture } from "../utils/MediaCapture";
|
|
|
3
3
|
export interface WebRTCController {
|
|
4
4
|
startWithToken: (token: string) => Promise<void>;
|
|
5
5
|
close: () => void;
|
|
6
|
-
forceReconnect: () => Promise<void>;
|
|
7
6
|
getConnectionStatus: () => string;
|
|
8
|
-
getReconnectAttempts: () => number;
|
|
9
7
|
getError: () => Error | null;
|
|
10
8
|
updateAudioDevice: (deviceId: string) => Promise<void>;
|
|
11
9
|
}
|
|
@@ -19,9 +17,6 @@ interface WebRTCParams {
|
|
|
19
17
|
videoStream?: MediaStream | null;
|
|
20
18
|
audioStream?: MediaStream | null;
|
|
21
19
|
}) => void;
|
|
22
|
-
onDataChannel?: (dc: RTCDataChannel) => void;
|
|
23
|
-
maxReconnectAttempts?: number;
|
|
24
|
-
reconnectInterval?: number;
|
|
25
20
|
/**
|
|
26
21
|
* ICE servers for the peer connection. When omitted, servers from the
|
|
27
22
|
* connection token are used, else {@link DEFAULT_ICE_SERVERS}. Provide this to
|
package/lib/types/index.d.ts
CHANGED
|
@@ -303,8 +303,7 @@ export interface NavigationProgressOptions {
|
|
|
303
303
|
height?: string;
|
|
304
304
|
}
|
|
305
305
|
/**
|
|
306
|
-
* Cross-page persistence options.
|
|
307
|
-
* `initWithButton` share the same persistence engine.
|
|
306
|
+
* Cross-page persistence options.
|
|
308
307
|
*/
|
|
309
308
|
export interface PersistenceOptions {
|
|
310
309
|
/** Turn persistence on. Required — there is no boolean shorthand. */
|
|
@@ -401,10 +400,75 @@ export interface PersistenceOptions {
|
|
|
401
400
|
trapBackNavigation?: boolean;
|
|
402
401
|
}
|
|
403
402
|
/**
|
|
404
|
-
*
|
|
403
|
+
* Click-to-start configuration. Opt in with `enabled: true`; without it `init()`
|
|
404
|
+
* connects immediately, exactly as it does with no `button` block at all.
|
|
405
|
+
*/
|
|
406
|
+
export interface ButtonConfig {
|
|
407
|
+
/** Opt in to click-to-start. Default `false`. */
|
|
408
|
+
enabled?: boolean;
|
|
409
|
+
/**
|
|
410
|
+
* Host-owned trigger — an element, or a selector resolved once at `init()`.
|
|
411
|
+
* When set the SDK renders no card of its own and `label`, `avatarUrl` and
|
|
412
|
+
* `description` are ignored. The SDK never moves or reparents the node; it
|
|
413
|
+
* sets `data-np-state`, toggles `disabled`, and hides it while a session is
|
|
414
|
+
* live, restoring it on end.
|
|
415
|
+
*/
|
|
416
|
+
element?: HTMLElement | string;
|
|
417
|
+
/** Card text. Default: `"Talk to an agent"`. Ignored when `element` is set. */
|
|
418
|
+
label?: string;
|
|
419
|
+
/** Optional companion picture on the card. Ignored when `element` is set. */
|
|
420
|
+
avatarUrl?: string;
|
|
421
|
+
/** Supporting line under the label (Figma entry-point card). Ignored when `element` is set. */
|
|
422
|
+
description?: string;
|
|
423
|
+
}
|
|
424
|
+
/**
|
|
425
|
+
* Returned by `init()` in button mode. Nothing is connected when you receive it:
|
|
426
|
+
* the session starts on a click, or on `start()`.
|
|
427
|
+
*/
|
|
428
|
+
export interface NapsterCompanionApiController {
|
|
429
|
+
/**
|
|
430
|
+
* The current session's instance: `null` before the first `start()` and after
|
|
431
|
+
* `end()`/`destroy()`, non-null from the moment an attempt gets past the
|
|
432
|
+
* microphone gate. Non-null does **not** mean the avatar is live — a denied
|
|
433
|
+
* microphone leaves the attempt parked behind the recovery card with an
|
|
434
|
+
* instance already handed back. Use `onAvatarReady` for "the session is up".
|
|
435
|
+
*/
|
|
436
|
+
getInstance(): NapsterCompanionApiInstance | null;
|
|
437
|
+
/**
|
|
438
|
+
* Start a session, as if the trigger was clicked. Resolves with the instance once
|
|
439
|
+
* connected, or `null` if the attempt failed — the failure is reported through
|
|
440
|
+
* `onError` — or if the controller has already been destroyed. It never rejects:
|
|
441
|
+
* the click path has no caller to catch one.
|
|
442
|
+
*/
|
|
443
|
+
start(): Promise<NapsterCompanionApiInstance | null>;
|
|
444
|
+
/** End the session. The trigger returns to idle and can start another. */
|
|
445
|
+
end(): void;
|
|
446
|
+
/** Remove the SDK card (or release the host's node) and tear down any session. */
|
|
447
|
+
destroy(): void;
|
|
448
|
+
}
|
|
449
|
+
/**
|
|
450
|
+
* Main configuration object passed to `init(getToken, config)`.
|
|
405
451
|
* All fields are optional; sensible defaults are used by the SDK.
|
|
406
452
|
*/
|
|
407
453
|
export interface NapsterCompanionApiConfig {
|
|
454
|
+
/**
|
|
455
|
+
* Connection transport. Optional — the SDK defaults to `"webrtc"`, which is
|
|
456
|
+
* the only transport that exists today, so there is no reason to set this
|
|
457
|
+
* yet. Any other value is a compile-time error, and an unsupported
|
|
458
|
+
* transport/modality combination is rejected at init() with a clear error.
|
|
459
|
+
*
|
|
460
|
+
* Reserved for future transports (e.g. WebSocket).
|
|
461
|
+
*/
|
|
462
|
+
transport?: "webrtc";
|
|
463
|
+
/**
|
|
464
|
+
* Connection modality. Optional — the SDK defaults to `"video"`, the only
|
|
465
|
+
* modality that exists today. Paired with {@link transport}: see that field
|
|
466
|
+
* for how invalid combinations are handled.
|
|
467
|
+
*
|
|
468
|
+
* Note this is the *connection* modality, not the UI being shown — how the
|
|
469
|
+
* session presents is a separate, runtime-changeable axis.
|
|
470
|
+
*/
|
|
471
|
+
modality?: "video";
|
|
408
472
|
/** Position of the avatar on screen. See `Position` enum. */
|
|
409
473
|
position?: Position;
|
|
410
474
|
/** CSS class name(s) to add to the SDK root container. Useful for theming. */
|
|
@@ -461,20 +525,12 @@ export interface NapsterCompanionApiConfig {
|
|
|
461
525
|
/**
|
|
462
526
|
* Keep the session alive across page navigation. When enabled, the page is wrapped in
|
|
463
527
|
* a same-origin iframe so navigation happens inside it while the avatar stays in the
|
|
464
|
-
* top document, which never reloads.
|
|
528
|
+
* top document, which never reloads.
|
|
465
529
|
* When on, `mountContainer` is ignored — the avatar must live in the top document.
|
|
466
530
|
*/
|
|
467
531
|
persistence?: PersistenceOptions;
|
|
468
|
-
/**
|
|
469
|
-
|
|
470
|
-
* passing it to `init()` (which connects immediately, with no button) throws.
|
|
471
|
-
*/
|
|
472
|
-
button?: {
|
|
473
|
-
/** Button text. Default: `"Talk to an agent"`. */
|
|
474
|
-
label?: string;
|
|
475
|
-
/** Optional companion picture shown on the button. */
|
|
476
|
-
avatarUrl?: string;
|
|
477
|
-
};
|
|
532
|
+
/** Click-to-start configuration. Omit for the default connect-immediately behaviour. */
|
|
533
|
+
button?: ButtonConfig;
|
|
478
534
|
/** Lifecycle callbacks. All are optional. */
|
|
479
535
|
/** Called when the SDK has finished initialization and is ready to render. */
|
|
480
536
|
onReady?: () => void;
|
|
@@ -585,42 +641,33 @@ export interface NapsterCompanionApiInstance {
|
|
|
585
641
|
readonly isUserTalking: boolean;
|
|
586
642
|
}
|
|
587
643
|
/**
|
|
588
|
-
* Top-level SDK object exposed by the package. Call `init(
|
|
644
|
+
* Top-level SDK object exposed by the package. Call `init(getToken, config)` to
|
|
589
645
|
* bootstrap the SDK and receive a `NapsterCompanionApiInstance` for runtime control.
|
|
590
646
|
*/
|
|
591
647
|
export interface NapsterCompanionApiSDK {
|
|
592
648
|
/**
|
|
593
|
-
* Initialize the SDK
|
|
594
|
-
*
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
*
|
|
599
|
-
*
|
|
600
|
-
*
|
|
601
|
-
* when run inside the persistence site frame.
|
|
649
|
+
* Initialize the SDK in click-to-start mode: resolves with a controller, and
|
|
650
|
+
* nothing connects until `start()` or a click on the entry point.
|
|
651
|
+
*
|
|
652
|
+
* `getToken` is called by the SDK itself once the microphone permission has
|
|
653
|
+
* settled — on every attempt, including a "Check again" retry — so the
|
|
654
|
+
* connection token is always fresh when signaling starts. A pre-minted token
|
|
655
|
+
* string is not accepted: minting it before the mic prompt lets it go stale
|
|
656
|
+
* while the user is deciding.
|
|
602
657
|
*/
|
|
603
|
-
|
|
658
|
+
init(getToken: () => Promise<string>, config: Partial<NapsterCompanionApiConfig> & {
|
|
659
|
+
button: ButtonConfig & {
|
|
660
|
+
enabled: true;
|
|
661
|
+
};
|
|
662
|
+
}): Promise<NapsterCompanionApiController>;
|
|
604
663
|
/**
|
|
605
|
-
*
|
|
606
|
-
* before a connection token exists. A connection's lifetime starts the moment the
|
|
607
|
-
* backend creates it, and a prompt the user leaves open for seconds spends that
|
|
608
|
-
* budget before signaling runs — the session then fails to come up.
|
|
609
|
-
*
|
|
610
|
-
* `initWithButton` does this internally. Use it on the `init` path, where the host
|
|
611
|
-
* app owns when the token is minted:
|
|
612
|
-
*
|
|
613
|
-
* ```js
|
|
614
|
-
* await SDK.requestMicrophoneAccess();
|
|
615
|
-
* const token = await mintConnectionToken();
|
|
616
|
-
* await SDK.init(token, config);
|
|
617
|
-
* ```
|
|
664
|
+
* Initialize the SDK and connect immediately: resolves once the session is up.
|
|
618
665
|
*
|
|
619
|
-
*
|
|
620
|
-
*
|
|
621
|
-
*
|
|
666
|
+
* `getToken` is called by the SDK itself once the microphone permission has
|
|
667
|
+
* settled, so the connection token is always fresh when signaling starts. A
|
|
668
|
+
* pre-minted token string is not accepted.
|
|
622
669
|
*/
|
|
623
|
-
|
|
670
|
+
init(getToken: () => Promise<string>, config?: Partial<NapsterCompanionApiConfig>): Promise<NapsterCompanionApiInstance>;
|
|
624
671
|
/** The SDK version string (useful for diagnostics). */
|
|
625
672
|
version: string;
|
|
626
673
|
}
|
package/package.json
CHANGED
package/lib/button/index.d.ts
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import "./Button.css";
|
|
2
|
-
import type { NapsterCompanionApiConfig, NapsterCompanionApiInstance } from "../types";
|
|
3
|
-
/**
|
|
4
|
-
* Returned by {@link initWithButton}. A session controller: start/end the agent session,
|
|
5
|
-
* reach the live instance, or tear the button down. Created synchronously — nothing
|
|
6
|
-
* connects until `start()` (or a button click).
|
|
7
|
-
*
|
|
8
|
-
* Inside the SDK's own persistence frame (and during SSR) the call no-ops and every
|
|
9
|
-
* method here is a harmless no-op — `getInstance()` stays `null`. With
|
|
10
|
-
* `debug: true` the skip is logged.
|
|
11
|
-
*/
|
|
12
|
-
export interface NapsterCompanionApiController {
|
|
13
|
-
/** The live avatar instance once connected, else `null`. */
|
|
14
|
-
getInstance(): NapsterCompanionApiInstance | null;
|
|
15
|
-
/** Start the session (as if the button was clicked). */
|
|
16
|
-
start(): Promise<void>;
|
|
17
|
-
/** End the session (and, if persisted, unwrap back to the plain site). The button reappears. */
|
|
18
|
-
end(): void;
|
|
19
|
-
/** Remove the button and any active session/iframe. */
|
|
20
|
-
destroy(): void;
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* What the button entry point needs from the SDK. Wired by the SDK's `initWithButton`
|
|
24
|
-
* method so this module never reaches into the singleton's internals.
|
|
25
|
-
*/
|
|
26
|
-
export interface ButtonDeps {
|
|
27
|
-
/** Connect a session; mounts the avatar into the button-owned root. */
|
|
28
|
-
init: (token: string, config?: Partial<NapsterCompanionApiConfig>) => Promise<NapsterCompanionApiInstance>;
|
|
29
|
-
/** Create + position the persistent, button-owned `#np_companion-sdk-root` and return it. */
|
|
30
|
-
mountRoot: (config: Partial<NapsterCompanionApiConfig>) => HTMLElement;
|
|
31
|
-
/** Remove the button-owned root and release SDK ownership (on destroy). */
|
|
32
|
-
unmountRoot: () => void;
|
|
33
|
-
/**
|
|
34
|
-
* Tear down any live session AND its persisted iframe WITHOUT navigating — reveal the
|
|
35
|
-
* page in place. Called when the whole widget is being removed (`destroy()`), where a
|
|
36
|
-
* page reload would be the wrong response. Private to the SDK↔button seam.
|
|
37
|
-
*/
|
|
38
|
-
disposeSession: () => void;
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Build the button entry point. Returns a {@link NapsterCompanionApiController}.
|
|
42
|
-
*
|
|
43
|
-
* A no-op (returns an inert controller) when run inside the persistence site frame,
|
|
44
|
-
* so the same snippet is safe on every page.
|
|
45
|
-
*/
|
|
46
|
-
export declare function createButton(deps: ButtonDeps, getToken: () => Promise<string>, config?: Partial<NapsterCompanionApiConfig>): NapsterCompanionApiController;
|