@burdenoff/website-sdk 2026.1102.3 → 2026.1104.2

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 (42) hide show
  1. package/README.md +46 -6
  2. package/dist/avatar-live/index.d.mts +2 -2
  3. package/dist/avatar-live/index.d.ts +2 -2
  4. package/dist/avatar-live/index.js +29 -4
  5. package/dist/avatar-live/index.js.map +1 -1
  6. package/dist/avatar-live/index.mjs +29 -4
  7. package/dist/avatar-live/index.mjs.map +1 -1
  8. package/dist/avatar-live-view/index.d.mts +19 -4
  9. package/dist/avatar-live-view/index.d.ts +19 -4
  10. package/dist/avatar-live-view/index.js +135 -28
  11. package/dist/avatar-live-view/index.js.map +1 -1
  12. package/dist/avatar-live-view/index.mjs +130 -23
  13. package/dist/avatar-live-view/index.mjs.map +1 -1
  14. package/dist/{chunk-DZLUZKOX.js → chunk-22OT6E26.js} +44 -12
  15. package/dist/chunk-22OT6E26.js.map +1 -0
  16. package/dist/{chunk-ZWEEBHXJ.mjs → chunk-5JQGE3XI.mjs} +44 -12
  17. package/dist/chunk-5JQGE3XI.mjs.map +1 -0
  18. package/dist/{chunk-K3QZGJEH.mjs → chunk-7MSB3EUI.mjs} +4 -3
  19. package/dist/chunk-7MSB3EUI.mjs.map +1 -0
  20. package/dist/{chunk-7O2I32ZN.js → chunk-WSEQ2I6I.js} +4 -3
  21. package/dist/chunk-WSEQ2I6I.js.map +1 -0
  22. package/dist/components/explore.d.mts +1 -1
  23. package/dist/components/explore.d.ts +1 -1
  24. package/dist/components/explore.js +13 -13
  25. package/dist/components/explore.mjs +1 -1
  26. package/dist/{explore-DtSPdlEy.d.ts → explore-BV4dRwoC.d.ts} +7 -0
  27. package/dist/{explore-DaSNdm4O.d.mts → explore-BgEeGPvY.d.mts} +7 -0
  28. package/dist/{explore-avatar-live-config-N4WhJzgS.d.mts → explore-avatar-live-config-B6_p0q1c.d.mts} +14 -1
  29. package/dist/{explore-avatar-live-config-CAfN5eAX.d.ts → explore-avatar-live-config-DRpS-mqQ.d.ts} +14 -1
  30. package/dist/index.d.mts +13 -7
  31. package/dist/index.d.ts +13 -7
  32. package/dist/index.js +59 -48
  33. package/dist/index.js.map +1 -1
  34. package/dist/index.mjs +16 -5
  35. package/dist/index.mjs.map +1 -1
  36. package/dist/{types-CndbmBK-.d.mts → types-CXqaLlNB.d.mts} +14 -1
  37. package/dist/{types-CndbmBK-.d.ts → types-CXqaLlNB.d.ts} +14 -1
  38. package/package.json +1 -1
  39. package/dist/chunk-7O2I32ZN.js.map +0 -1
  40. package/dist/chunk-DZLUZKOX.js.map +0 -1
  41. package/dist/chunk-K3QZGJEH.mjs.map +0 -1
  42. package/dist/chunk-ZWEEBHXJ.mjs.map +0 -1
package/README.md CHANGED
@@ -301,6 +301,8 @@ publishes audio, video or data, and it sends the avatar nothing to say.
301
301
  manifestVersion: 'hb-en-1', // the version of `suggestedQuestions`
302
302
  // Optional: used only where the server checks for bots (see "The bot check is the server's setting").
303
303
  turnstileSiteKey: TURNSTILE_SITE_KEY,
304
+ // Optional, default false: end a session nobody attends to (see "A session nobody attends to").
305
+ endUnattended: true,
304
306
  },
305
307
  }}
306
308
  />
@@ -420,14 +422,50 @@ publishes audio, video or data, and it sends the avatar nothing to say.
420
422
  limits, region, language, paused, a question the avatar cannot read) is one
421
423
  short sentence and "Continue in Chat". A network or CORS failure, or a route
422
424
  that is not there, shows the view as it was before.
423
- - **Ending.** Stop, switching to Chat, closing the panel, hiding the page, and
424
- the live avatar going off under a session (the panel's locale changing to one
425
+ - **Ending.** Stop, closing the panel, leaving the page (`pagehide`), and the
426
+ live avatar going off under a session (the panel's locale changing to one
425
427
  whose strings have not been reviewed) all end the session with a `keepalive`
426
- request and leave the room. The end is a simple CORS request: its body is a
428
+ request and leave the room. Once the create has been sent (connecting,
429
+ joining, speaking), switching to the Chat tab (or pressing Continue in Chat)
430
+ and hiding the page (another browser tab, another app) do **not** end it: the
431
+ Avatar pane is only hidden, the room's video and audio stay attached, and the
432
+ avatar speaks to the end the server planned for it, which a hidden page
433
+ cannot extend. Coming back to the Avatar tab shows the session as it is, with
434
+ the countdown to the server's end, and asks nothing again. Before the create,
435
+ nothing paid exists, so the Chat tab still calls off an availability check, a
436
+ "Start when ready" and a bot check, and a hidden page still calls off a
437
+ "Start when ready" and returns a bot check to the consent card, all with
438
+ nothing created. While a session is created, joined or played, Chat's own
439
+ read-aloud and dictation are held (`ExplorePage`'s `voiceHold`): a reading
440
+ under way stops, and both controls stay where they are, `aria-disabled`, with
441
+ the avatar's status line as their title, until the session ends; nothing in
442
+ Chat ends the session. The end is a simple CORS request: its body is a
427
443
  string and the SDK sets no `content-type`, so the browser sends it as
428
444
  `text/plain;charset=UTF-8` (which the gateway accepts for this route), and on
429
445
  production nothing else is added, so no preflight has to complete while the
430
446
  page unloads. The server ends sessions on its own deadlines as well.
447
+ - **A session nobody attends to (opt-in: `live.endUnattended: true`, or
448
+ `websiteAvatarLive({ …, endUnattended: true })`).** Out of sight (the Chat
449
+ tab, a hidden page) the answer under way still plays to its end, and then
450
+ the session ends, with reason `user`, once:
451
+ - **its answer has played out**: at once. This is the lifecycle rule for
452
+ every later stage: an idle tail after an answer runs only while the Avatar
453
+ view is in sight, and going out of sight during one ends the session then.
454
+ The answer counts as played out 5 s after its speech ends at the source
455
+ (the room's other voice, the server's speaker, leaves or unpublishes): the
456
+ server's 3 s tail allowance for the worker's lag, plus 2 s. Today the
457
+ server ends a session about 3 s after its answer, so its own end comes
458
+ first and the browser sends nothing.
459
+ - **the browser holds its sound back** (autoplay refused, or the audio
460
+ context suspended) once the avatar's voice has arrived: after a 5 s grace,
461
+ since "Tap to turn on sound" is out of sight. The view then says "The live avatar stopped early." and "The
462
+ full answer is in Chat.". Back in sight within the grace, the button shows
463
+ and nothing ends; in sight, a held-back sound never ends a session.
464
+
465
+ Unset (the default) or `false`: a session out of sight plays on to the
466
+ server's planned end. A browser that silences a background page without
467
+ telling the room (iOS Safari may) cannot be seen; the server's planned end
468
+ bounds that session either way.
431
469
  - **Consent copy is versioned.** The panel shows a consent card only when it
432
470
  holds reviewed copy for exactly the version the server names; otherwise the
433
471
  view stays as it was. `web-consent-2026-11-02` is product-neutral: its card
@@ -510,9 +548,11 @@ publishes audio, video or data, and it sends the avatar nothing to say.
510
548
  of the same host for the validation check.
511
549
  - **Not verified in this package.** Every test here uses fakes: nothing reaches
512
550
  Turnstile, the gateway, the avatar service or the media room. Left to the
513
- alpha test: real playback on iPhone Safari and Android Chrome; that
514
- `page_hide` ends actually arrive from those browsers; and that the receive-only
515
- token has `canPublish=false` and `canPublishData=false`, and a worker RPC
551
+ alpha test: real playback on iPhone Safari and Android Chrome; that the voice
552
+ keeps playing behind the Chat tab and in a background browser tab there (a
553
+ browser may suspend it; the server still ends the session at its planned
554
+ end); that `page_hide` ends actually arrive from those browsers; and that the
555
+ receive-only token has `canPublish=false` and `canPublishData=false`, and a worker RPC
516
556
  addressed to the viewer is dropped without disconnecting it (the media client
517
557
  answers incoming RPC requests on its own, so "never publishes" holds only as
518
558
  far as the token's permissions do).
@@ -1,5 +1,5 @@
1
- import { R as ReceiveOnlyJoinOptions, a as ReceiveOnlySession } from '../types-CndbmBK-.mjs';
2
- export { A as AvatarLiveModule, b as ReceiveOnlyEvent } from '../types-CndbmBK-.mjs';
1
+ import { R as ReceiveOnlyJoinOptions, a as ReceiveOnlySession } from '../types-CXqaLlNB.mjs';
2
+ export { A as AvatarLiveModule, b as ReceiveOnlyEvent } from '../types-CXqaLlNB.mjs';
3
3
 
4
4
  /**
5
5
  * Join the room in `options.url` with the receive-only `options.token`, and play the avatar worker's video and voice
@@ -1,5 +1,5 @@
1
- import { R as ReceiveOnlyJoinOptions, a as ReceiveOnlySession } from '../types-CndbmBK-.js';
2
- export { A as AvatarLiveModule, b as ReceiveOnlyEvent } from '../types-CndbmBK-.js';
1
+ import { R as ReceiveOnlyJoinOptions, a as ReceiveOnlySession } from '../types-CXqaLlNB.js';
2
+ export { A as AvatarLiveModule, b as ReceiveOnlyEvent } from '../types-CXqaLlNB.js';
3
3
 
4
4
  /**
5
5
  * Join the room in `options.url` with the receive-only `options.token`, and play the avatar worker's video and voice
@@ -35,15 +35,30 @@ async function joinReceiveOnly(options) {
35
35
  });
36
36
  let leaving = false;
37
37
  const isSpeaker = (participant) => participant.identity === workerIdentity;
38
+ const voiced = /* @__PURE__ */ new Set();
39
+ let speechEnded = false;
38
40
  const consider = (publication, participant) => {
39
- if (leaving || !isSpeaker(participant) || !isMedia(publication)) return;
41
+ if (leaving) return;
42
+ if (!isSpeaker(participant)) {
43
+ if (publication.kind === livekitClient.Track.Kind.Audio) {
44
+ voiced.add(participant.identity);
45
+ }
46
+ return;
47
+ }
48
+ if (!isMedia(publication)) return;
40
49
  if (!publication.isSubscribed) publication.setSubscribed(true);
41
50
  };
51
+ const voiceGone = (participant) => {
52
+ if (leaving || speechEnded || !voiced.has(participant.identity)) return;
53
+ speechEnded = true;
54
+ onEvent({ type: "speech-ended" });
55
+ };
42
56
  const reportPlayback = () => {
43
57
  if (leaving) return;
44
58
  onEvent({
45
59
  type: "playback-blocked",
46
- blocked: !room.canPlaybackAudio || !room.canPlaybackVideo
60
+ blocked: !room.canPlaybackAudio || !room.canPlaybackVideo,
61
+ sound: !room.canPlaybackAudio
47
62
  });
48
63
  };
49
64
  room.on(livekitClient.RoomEvent.TrackPublished, consider).on(
@@ -64,9 +79,19 @@ async function joinReceiveOnly(options) {
64
79
  }
65
80
  ).on(livekitClient.RoomEvent.TrackUnsubscribed, (track) => {
66
81
  track.detach();
67
- }).on(livekitClient.RoomEvent.ParticipantDisconnected, (participant) => {
68
- if (!leaving && isSpeaker(participant)) {
82
+ }).on(
83
+ livekitClient.RoomEvent.TrackUnpublished,
84
+ (publication, participant) => {
85
+ if (!isSpeaker(participant) && publication.kind === livekitClient.Track.Kind.Audio) {
86
+ voiceGone(participant);
87
+ }
88
+ }
89
+ ).on(livekitClient.RoomEvent.ParticipantDisconnected, (participant) => {
90
+ if (leaving) return;
91
+ if (isSpeaker(participant)) {
69
92
  onEvent({ type: "speaker-left" });
93
+ } else {
94
+ voiceGone(participant);
70
95
  }
71
96
  }).on(livekitClient.RoomEvent.AudioPlaybackStatusChanged, reportPlayback).on(livekitClient.RoomEvent.VideoPlaybackStatusChanged, reportPlayback).on(livekitClient.RoomEvent.Disconnected, (reason) => {
72
97
  if (leaving) return;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/avatar-live/receive-only.ts"],"names":["DisconnectReason","Track","Room","RoomEvent"],"mappings":";;;;;AA6BA,IAAM,gBAAA,uBAAsD,GAAA,CAAI;AAAA,EAC9DA,8BAAA,CAAiB,YAAA;AAAA,EACjBA,8BAAA,CAAiB,WAAA;AAAA,EACjBA,8BAAA,CAAiB;AACnB,CAAC,CAAA;AAED,SAAS,QAAQ,WAAA,EAA8C;AAC7D,EAAA,OACE,WAAA,CAAY,SAASC,mBAAA,CAAM,IAAA,CAAK,SAChC,WAAA,CAAY,IAAA,KAASA,oBAAM,IAAA,CAAK,KAAA;AAEpC;AAOA,eAAsB,gBACpB,OAAA,EAC6B;AAC7B,EAAA,MAAM,EAAE,GAAA,EAAK,KAAA,EAAO,gBAAgB,KAAA,EAAO,KAAA,EAAO,SAAQ,GAAI,OAAA;AAC9D,EAAA,IAAI,MAAA;AACJ,EAAA,IAAI;AACF,IAAA,MAAA,GAAS,IAAI,IAAI,GAAG,CAAA;AAAA,EACtB,CAAA,CAAA,MAAQ;AACN,IAAA,MAAM,IAAI,MAAM,4CAA4C,CAAA;AAAA,EAC9D;AACA,EAAA,IAAI,MAAA,CAAO,aAAa,MAAA,EAAQ;AAC9B,IAAA,MAAM,IAAI,MAAM,4CAA4C,CAAA;AAAA,EAC9D;AACA,EAAA,IAAI,CAAC,KAAA,IAAS,CAAC,cAAA,EAAgB;AAC7B,IAAA,MAAM,IAAI,MAAM,mDAAmD,CAAA;AAAA,EACrE;AAEA,EAAA,MAAM,IAAA,GAAO,IAAIC,kBAAA,CAAK;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GAAY,IAAA;AAClB,IAAA,KAAA,CAAM,SAAA,GAAY,IAAA;AAAA,EACpB,CAAA;AAEA,EAAA,IAAI;AACF,IAAA,MAAM,KAAK,OAAA,CAAQ,GAAA,EAAK,OAAO,EAAE,aAAA,EAAe,OAAO,CAAA;AAAA,EACzD,SAAS,KAAA,EAAO;AACd,IAAA,OAAA,GAAU,IAAA;AACV,IAAA,IAAA,CAAK,kBAAA,EAAmB;AACxB,IAAA,SAAA,EAAU;AACV,IAAA,MAAM,KAAA;AAAA,EACR;AAGA,EAAA,KAAA,MAAW,WAAA,IAAe,IAAA,CAAK,kBAAA,CAAmB,MAAA,EAAO,EAAG;AAC1D,IAAA,KAAA,MAAW,WAAA,IAAe,WAAA,CAAY,iBAAA,CAAkB,MAAA,EAAO,EAAG;AAChE,MAAA,QAAA,CAAS,aAAa,WAAW,CAAA;AAAA,IACnC;AAAA,EACF;AACA,EAAA,cAAA,EAAe;AAEf,EAAA,OAAO;AAAA,IACL,gBAAgB,YAAY;AAG1B,MAAA,MAAM,OAAA,CAAQ,WAAW,CAAC,IAAA,CAAK,YAAW,EAAG,IAAA,CAAK,UAAA,EAAY,CAAC,CAAA;AAC/D,MAAA,cAAA,EAAe;AAAA,IACjB,CAAA;AAAA,IACA,OAAO,YAAY;AACjB,MAAA,IAAI,OAAA,EAAS;AACb,MAAA,OAAA,GAAU,IAAA;AACV,MAAA,SAAA,EAAU;AACV,MAAA,IAAI;AACF,QAAA,MAAM,KAAK,UAAA,EAAW;AAAA,MACxB,CAAA,SAAE;AACA,QAAA,IAAA,CAAK,kBAAA,EAAmB;AAAA,MAC1B;AAAA,IACF;AAAA,GACF;AACF","file":"index.js","sourcesContent":["/**\n * BOFF-9797. The live avatar's room, joined to watch and listen only.\n *\n * A visitor's browser on a product website holds a subscribe-only room token: it can receive the avatar worker's\n * video and voice and do nothing else. This adapter keeps to that from its side too:\n *\n * - **Nothing is subscribed automatically** (`autoSubscribe: false`). Only the tracks of `workerIdentity`, the avatar\n * worker the create answer named, are subscribed, and only their video and audio. Any other participant's track\n * (the server's own speaker included) is never asked for, and is dropped again should the server send it anyway.\n * - **Nothing is published.** No microphone, no camera, no data, no RPC method: this file never calls a publishing\n * API, and the token would refuse one.\n * - **Safari and iOS** hold sound back until a gesture. The room reports it (`playback-blocked`) and the panel offers\n * \"Tap to turn on sound\", whose tap calls `enablePlayback`.\n *\n * Written for the website from the media library's public API: nothing here is copied from the product apps.\n */\nimport {\n DisconnectReason,\n Room,\n RoomEvent,\n Track,\n type RemoteParticipant,\n type RemoteTrack,\n type RemoteTrackPublication,\n} from \"livekit-client\";\n\nimport type { ReceiveOnlyJoinOptions, ReceiveOnlySession } from \"./types\";\n\n/** The reasons a room closes because the server closed it, rather than because the connection was lost. */\nconst CLOSED_BY_SERVER: ReadonlySet<DisconnectReason> = new Set([\n DisconnectReason.ROOM_DELETED,\n DisconnectReason.ROOM_CLOSED,\n DisconnectReason.PARTICIPANT_REMOVED,\n]);\n\nfunction isMedia(publication: RemoteTrackPublication): boolean {\n return (\n publication.kind === Track.Kind.Video ||\n publication.kind === Track.Kind.Audio\n );\n}\n\n/**\n * Join the room in `options.url` with the receive-only `options.token`, and play the avatar worker's video and voice\n * in `options.video` and `options.audio`. Resolves once connected; rejects when the room cannot be joined (the panel\n * then ends the session).\n */\nexport async function joinReceiveOnly(\n options: ReceiveOnlyJoinOptions,\n): Promise<ReceiveOnlySession> {\n const { url, token, workerIdentity, video, audio, onEvent } = options;\n let parsed: URL;\n try {\n parsed = new URL(url);\n } catch {\n throw new Error(\"live avatar: the room address is not a URL\");\n }\n if (parsed.protocol !== \"wss:\") {\n throw new Error(\"live avatar: the room address must be wss:\");\n }\n if (!token || !workerIdentity) {\n throw new Error(\"live avatar: the room token or speaker is missing\");\n }\n\n const room = new Room({\n // One small video, always shown while the session lasts: no quality switching, no layer pausing.\n adaptiveStream: false,\n dynacast: false,\n // Closing the tab or leaving the page leaves the room at once. Belt and braces with the panel's own page-hide\n // handler, which also asks the server to end the session: either may run first, and both are safe to repeat.\n disconnectOnPageLeave: true,\n });\n let leaving = false;\n\n const isSpeaker = (participant: RemoteParticipant) =>\n participant.identity === workerIdentity;\n\n /** Subscribe to `publication` when it is the speaker's video or audio; leave everything else alone. */\n const consider = (\n publication: RemoteTrackPublication,\n participant: RemoteParticipant,\n ) => {\n if (leaving || !isSpeaker(participant) || !isMedia(publication)) return;\n if (!publication.isSubscribed) publication.setSubscribed(true);\n };\n\n const reportPlayback = () => {\n if (leaving) return;\n onEvent({\n type: \"playback-blocked\",\n blocked: !room.canPlaybackAudio || !room.canPlaybackVideo,\n });\n };\n\n room\n .on(RoomEvent.TrackPublished, consider)\n .on(\n RoomEvent.TrackSubscribed,\n (\n track: RemoteTrack,\n publication: RemoteTrackPublication,\n participant: RemoteParticipant,\n ) => {\n if (leaving) return;\n if (!isSpeaker(participant) || !isMedia(publication)) {\n // Never asked for: drop it rather than play it.\n publication.setSubscribed(false);\n return;\n }\n if (track.kind === Track.Kind.Video) {\n track.attach(video);\n onEvent({ type: \"speaker-track\", kind: \"video\" });\n } else {\n track.attach(audio);\n onEvent({ type: \"speaker-track\", kind: \"audio\" });\n }\n },\n )\n .on(RoomEvent.TrackUnsubscribed, (track: RemoteTrack) => {\n track.detach();\n })\n .on(RoomEvent.ParticipantDisconnected, (participant: RemoteParticipant) => {\n if (!leaving && isSpeaker(participant)) {\n onEvent({ type: \"speaker-left\" });\n }\n })\n .on(RoomEvent.AudioPlaybackStatusChanged, reportPlayback)\n .on(RoomEvent.VideoPlaybackStatusChanged, reportPlayback)\n .on(RoomEvent.Disconnected, (reason?: DisconnectReason) => {\n if (leaving) return;\n onEvent({\n type: \"disconnected\",\n byServer: reason !== undefined && CLOSED_BY_SERVER.has(reason),\n });\n });\n\n const detachAll = () => {\n for (const participant of room.remoteParticipants.values()) {\n for (const publication of participant.trackPublications.values()) {\n publication.track?.detach();\n }\n }\n video.srcObject = null;\n audio.srcObject = null;\n };\n\n try {\n await room.connect(url, token, { autoSubscribe: false });\n } catch (error) {\n leaving = true;\n room.removeAllListeners();\n detachAll();\n throw error;\n }\n\n // Whoever was in the room before this viewer joined: their tracks were published before the listener above.\n for (const participant of room.remoteParticipants.values()) {\n for (const publication of participant.trackPublications.values()) {\n consider(publication, participant);\n }\n }\n reportPlayback();\n\n return {\n enablePlayback: async () => {\n // Both started inside the visitor's gesture, before anything is awaited: Safari allows playback only there.\n // A refusal leaves the room as it was, and the report below keeps the button offered.\n await Promise.allSettled([room.startAudio(), room.startVideo()]);\n reportPlayback();\n },\n leave: async () => {\n if (leaving) return;\n leaving = true;\n detachAll();\n try {\n await room.disconnect();\n } finally {\n room.removeAllListeners();\n }\n },\n };\n}\n"]}
1
+ {"version":3,"sources":["../../src/avatar-live/receive-only.ts"],"names":["DisconnectReason","Track","Room","RoomEvent"],"mappings":";;;;;AAgCA,IAAM,gBAAA,uBAAsD,GAAA,CAAI;AAAA,EAC9DA,8BAAA,CAAiB,YAAA;AAAA,EACjBA,8BAAA,CAAiB,WAAA;AAAA,EACjBA,8BAAA,CAAiB;AACnB,CAAC,CAAA;AAED,SAAS,QAAQ,WAAA,EAA8C;AAC7D,EAAA,OACE,WAAA,CAAY,SAASC,mBAAA,CAAM,IAAA,CAAK,SAChC,WAAA,CAAY,IAAA,KAASA,oBAAM,IAAA,CAAK,KAAA;AAEpC;AAOA,eAAsB,gBACpB,OAAA,EAC6B;AAC7B,EAAA,MAAM,EAAE,GAAA,EAAK,KAAA,EAAO,gBAAgB,KAAA,EAAO,KAAA,EAAO,SAAQ,GAAI,OAAA;AAC9D,EAAA,IAAI,MAAA;AACJ,EAAA,IAAI;AACF,IAAA,MAAA,GAAS,IAAI,IAAI,GAAG,CAAA;AAAA,EACtB,CAAA,CAAA,MAAQ;AACN,IAAA,MAAM,IAAI,MAAM,4CAA4C,CAAA;AAAA,EAC9D;AACA,EAAA,IAAI,MAAA,CAAO,aAAa,MAAA,EAAQ;AAC9B,IAAA,MAAM,IAAI,MAAM,4CAA4C,CAA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AAE,aAAA,EAAe,OAAO,CAAA;AAAA,EACzD,SAAS,KAAA,EAAO;AACd,IAAA,OAAA,GAAU,IAAA;AACV,IAAA,IAAA,CAAK,kBAAA,EAAmB;AACxB,IAAA,SAAA,EAAU;AACV,IAAA,MAAM,KAAA;AAAA,EACR;AAGA,EAAA,KAAA,MAAW,WAAA,IAAe,IAAA,CAAK,kBAAA,CAAmB,MAAA,EAAO,EAAG;AAC1D,IAAA,KAAA,MAAW,WAAA,IAAe,WAAA,CAAY,iBAAA,CAAkB,MAAA,EAAO,EAAG;AAChE,MAAA,QAAA,CAAS,aAAa,WAAW,CAAA;AAAA,IACnC;AAAA,EACF;AACA,EAAA,cAAA,EAAe;AAEf,EAAA,OAAO;AAAA,IACL,gBAAgB,YAAY;AAG1B,MAAA,MAAM,OAAA,CAAQ,WAAW,CAAC,IAAA,CAAK,YAAW,EAAG,IAAA,CAAK,UAAA,EAAY,CAAC,CAAA;AAC/D,MAAA,cAAA,EAAe;AAAA,IACjB,CAAA;AAAA,IACA,OAAO,YAAY;AACjB,MAAA,IAAI,OAAA,EAAS;AACb,MAAA,OAAA,GAAU,IAAA;AACV,MAAA,SAAA,EAAU;AACV,MAAA,IAAI;AACF,QAAA,MAAM,KAAK,UAAA,EAAW;AAAA,MACxB,CAAA,SAAE;AACA,QAAA,IAAA,CAAK,kBAAA,EAAmB;AAAA,MAC1B;AAAA,IACF;AAAA,GACF;AACF","file":"index.js","sourcesContent":["/**\n * BOFF-9797. The live avatar's room, joined to watch and listen only.\n *\n * A visitor's browser on a product website holds a subscribe-only room token: it can receive the avatar worker's\n * video and voice and do nothing else. This adapter keeps to that from its side too:\n *\n * - **Nothing is subscribed automatically** (`autoSubscribe: false`). Only the tracks of `workerIdentity`, the avatar\n * worker the create answer named, are subscribed, and only their video and audio. Any other participant's track\n * (the server's own speaker included) is never asked for, and is dropped again should the server send it anyway.\n * - **Nothing is published.** No microphone, no camera, no data, no RPC method: this file never calls a publishing\n * API, and the token would refuse one.\n * - **Safari and iOS** hold sound back until a gesture. The room reports it (`playback-blocked`, with `sound` when the\n * sound is held back and not only the video) and the panel offers \"Tap to turn on sound\", whose tap calls\n * `enablePlayback`.\n * - **The end of the speech** is told (`speech-ended`) from what any viewer of the room sees: the other voice in it, the\n * server's speaker that the worker follows, leaving the room or unpublishing its voice. Its track is never subscribed.\n *\n * Written for the website from the media library's public API: nothing here is copied from the product apps.\n */\nimport {\n DisconnectReason,\n Room,\n RoomEvent,\n Track,\n type RemoteParticipant,\n type RemoteTrack,\n type RemoteTrackPublication,\n} from \"livekit-client\";\n\nimport type { ReceiveOnlyJoinOptions, ReceiveOnlySession } from \"./types\";\n\n/** The reasons a room closes because the server closed it, rather than because the connection was lost. */\nconst CLOSED_BY_SERVER: ReadonlySet<DisconnectReason> = new Set([\n DisconnectReason.ROOM_DELETED,\n DisconnectReason.ROOM_CLOSED,\n DisconnectReason.PARTICIPANT_REMOVED,\n]);\n\nfunction isMedia(publication: RemoteTrackPublication): boolean {\n return (\n publication.kind === Track.Kind.Video ||\n publication.kind === Track.Kind.Audio\n );\n}\n\n/**\n * Join the room in `options.url` with the receive-only `options.token`, and play the avatar worker's video and voice\n * in `options.video` and `options.audio`. Resolves once connected; rejects when the room cannot be joined (the panel\n * then ends the session).\n */\nexport async function joinReceiveOnly(\n options: ReceiveOnlyJoinOptions,\n): Promise<ReceiveOnlySession> {\n const { url, token, workerIdentity, video, audio, onEvent } = options;\n let parsed: URL;\n try {\n parsed = new URL(url);\n } catch {\n throw new Error(\"live avatar: the room address is not a URL\");\n }\n if (parsed.protocol !== \"wss:\") {\n throw new Error(\"live avatar: the room address must be wss:\");\n }\n if (!token || !workerIdentity) {\n throw new Error(\"live avatar: the room token or speaker is missing\");\n }\n\n const room = new Room({\n // One small video, always shown while the session lasts: no quality switching, no layer pausing.\n adaptiveStream: false,\n dynacast: false,\n // Closing the tab or leaving the page leaves the room at once. Belt and braces with the panel's own page-hide\n // handler, which also asks the server to end the session: either may run first, and both are safe to repeat.\n disconnectOnPageLeave: true,\n });\n let leaving = false;\n\n const isSpeaker = (participant: RemoteParticipant) =>\n participant.identity === workerIdentity;\n\n /**\n * Everyone else in the room seen publishing a voice: the server's speaker, whose speech the worker voices. Noted\n * only, never subscribed to, so that the end of that speech can be told (`speech-ended`).\n */\n const voiced = new Set<string>();\n let speechEnded = false;\n\n /** Subscribe to `publication` when it is the speaker's video or audio; leave everything else alone. */\n const consider = (\n publication: RemoteTrackPublication,\n participant: RemoteParticipant,\n ) => {\n if (leaving) return;\n if (!isSpeaker(participant)) {\n if (publication.kind === Track.Kind.Audio) {\n voiced.add(participant.identity);\n }\n return;\n }\n if (!isMedia(publication)) return;\n if (!publication.isSubscribed) publication.setSubscribed(true);\n };\n\n /** A voice seen published has gone (its track, or its participant): the speech has ended at its source. Once. */\n const voiceGone = (participant: RemoteParticipant) => {\n if (leaving || speechEnded || !voiced.has(participant.identity)) return;\n speechEnded = true;\n onEvent({ type: \"speech-ended\" });\n };\n\n const reportPlayback = () => {\n if (leaving) return;\n onEvent({\n type: \"playback-blocked\",\n blocked: !room.canPlaybackAudio || !room.canPlaybackVideo,\n sound: !room.canPlaybackAudio,\n });\n };\n\n room\n .on(RoomEvent.TrackPublished, consider)\n .on(\n RoomEvent.TrackSubscribed,\n (\n track: RemoteTrack,\n publication: RemoteTrackPublication,\n participant: RemoteParticipant,\n ) => {\n if (leaving) return;\n if (!isSpeaker(participant) || !isMedia(publication)) {\n // Never asked for: drop it rather than play it.\n publication.setSubscribed(false);\n return;\n }\n if (track.kind === Track.Kind.Video) {\n track.attach(video);\n onEvent({ type: \"speaker-track\", kind: \"video\" });\n } else {\n track.attach(audio);\n onEvent({ type: \"speaker-track\", kind: \"audio\" });\n }\n },\n )\n .on(RoomEvent.TrackUnsubscribed, (track: RemoteTrack) => {\n track.detach();\n })\n .on(\n RoomEvent.TrackUnpublished,\n (publication: RemoteTrackPublication, participant: RemoteParticipant) => {\n if (!isSpeaker(participant) && publication.kind === Track.Kind.Audio) {\n voiceGone(participant);\n }\n },\n )\n .on(RoomEvent.ParticipantDisconnected, (participant: RemoteParticipant) => {\n if (leaving) return;\n if (isSpeaker(participant)) {\n onEvent({ type: \"speaker-left\" });\n } else {\n voiceGone(participant);\n }\n })\n .on(RoomEvent.AudioPlaybackStatusChanged, reportPlayback)\n .on(RoomEvent.VideoPlaybackStatusChanged, reportPlayback)\n .on(RoomEvent.Disconnected, (reason?: DisconnectReason) => {\n if (leaving) return;\n onEvent({\n type: \"disconnected\",\n byServer: reason !== undefined && CLOSED_BY_SERVER.has(reason),\n });\n });\n\n const detachAll = () => {\n for (const participant of room.remoteParticipants.values()) {\n for (const publication of participant.trackPublications.values()) {\n publication.track?.detach();\n }\n }\n video.srcObject = null;\n audio.srcObject = null;\n };\n\n try {\n await room.connect(url, token, { autoSubscribe: false });\n } catch (error) {\n leaving = true;\n room.removeAllListeners();\n detachAll();\n throw error;\n }\n\n // Whoever was in the room before this viewer joined: their tracks were published before the listener above.\n for (const participant of room.remoteParticipants.values()) {\n for (const publication of participant.trackPublications.values()) {\n consider(publication, participant);\n }\n }\n reportPlayback();\n\n return {\n enablePlayback: async () => {\n // Both started inside the visitor's gesture, before anything is awaited: Safari allows playback only there.\n // A refusal leaves the room as it was, and the report below keeps the button offered.\n await Promise.allSettled([room.startAudio(), room.startVideo()]);\n reportPlayback();\n },\n leave: async () => {\n if (leaving) return;\n leaving = true;\n detachAll();\n try {\n await room.disconnect();\n } finally {\n room.removeAllListeners();\n }\n },\n };\n}\n"]}
@@ -33,15 +33,30 @@ async function joinReceiveOnly(options) {
33
33
  });
34
34
  let leaving = false;
35
35
  const isSpeaker = (participant) => participant.identity === workerIdentity;
36
+ const voiced = /* @__PURE__ */ new Set();
37
+ let speechEnded = false;
36
38
  const consider = (publication, participant) => {
37
- if (leaving || !isSpeaker(participant) || !isMedia(publication)) return;
39
+ if (leaving) return;
40
+ if (!isSpeaker(participant)) {
41
+ if (publication.kind === Track.Kind.Audio) {
42
+ voiced.add(participant.identity);
43
+ }
44
+ return;
45
+ }
46
+ if (!isMedia(publication)) return;
38
47
  if (!publication.isSubscribed) publication.setSubscribed(true);
39
48
  };
49
+ const voiceGone = (participant) => {
50
+ if (leaving || speechEnded || !voiced.has(participant.identity)) return;
51
+ speechEnded = true;
52
+ onEvent({ type: "speech-ended" });
53
+ };
40
54
  const reportPlayback = () => {
41
55
  if (leaving) return;
42
56
  onEvent({
43
57
  type: "playback-blocked",
44
- blocked: !room.canPlaybackAudio || !room.canPlaybackVideo
58
+ blocked: !room.canPlaybackAudio || !room.canPlaybackVideo,
59
+ sound: !room.canPlaybackAudio
45
60
  });
46
61
  };
47
62
  room.on(RoomEvent.TrackPublished, consider).on(
@@ -62,9 +77,19 @@ async function joinReceiveOnly(options) {
62
77
  }
63
78
  ).on(RoomEvent.TrackUnsubscribed, (track) => {
64
79
  track.detach();
65
- }).on(RoomEvent.ParticipantDisconnected, (participant) => {
66
- if (!leaving && isSpeaker(participant)) {
80
+ }).on(
81
+ RoomEvent.TrackUnpublished,
82
+ (publication, participant) => {
83
+ if (!isSpeaker(participant) && publication.kind === Track.Kind.Audio) {
84
+ voiceGone(participant);
85
+ }
86
+ }
87
+ ).on(RoomEvent.ParticipantDisconnected, (participant) => {
88
+ if (leaving) return;
89
+ if (isSpeaker(participant)) {
67
90
  onEvent({ type: "speaker-left" });
91
+ } else {
92
+ voiceGone(participant);
68
93
  }
69
94
  }).on(RoomEvent.AudioPlaybackStatusChanged, reportPlayback).on(RoomEvent.VideoPlaybackStatusChanged, reportPlayback).on(RoomEvent.Disconnected, (reason) => {
70
95
  if (leaving) return;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/avatar-live/receive-only.ts"],"names":[],"mappings":";;;AA6BA,IAAM,gBAAA,uBAAsD,GAAA,CAAI;AAAA,EAC9D,gBAAA,CAAiB,YAAA;AAAA,EACjB,gBAAA,CAAiB,WAAA;AAAA,EACjB,gBAAA,CAAiB;AACnB,CAAC,CAAA;AAED,SAAS,QAAQ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AAAA,IACnC;AAAA,EACF;AACA,EAAA,cAAA,EAAe;AAEf,EAAA,OAAO;AAAA,IACL,gBAAgB,YAAY;AAG1B,MAAA,MAAM,OAAA,CAAQ,WAAW,CAAC,IAAA,CAAK,YAAW,EAAG,IAAA,CAAK,UAAA,EAAY,CAAC,CAAA;AAC/D,MAAA,cAAA,EAAe;AAAA,IACjB,CAAA;AAAA,IACA,OAAO,YAAY;AACjB,MAAA,IAAI,OAAA,EAAS;AACb,MAAA,OAAA,GAAU,IAAA;AACV,MAAA,SAAA,EAAU;AACV,MAAA,IAAI;AACF,QAAA,MAAM,KAAK,UAAA,EAAW;AAAA,MACxB,CAAA,SAAE;AACA,QAAA,IAAA,CAAK,kBAAA,EAAmB;AAAA,MAC1B;AAAA,IACF;AAAA,GACF;AACF","file":"index.mjs","sourcesContent":["/**\n * BOFF-9797. The live avatar's room, joined to watch and listen only.\n *\n * A visitor's browser on a product website holds a subscribe-only room token: it can receive the avatar worker's\n * video and voice and do nothing else. This adapter keeps to that from its side too:\n *\n * - **Nothing is subscribed automatically** (`autoSubscribe: false`). Only the tracks of `workerIdentity`, the avatar\n * worker the create answer named, are subscribed, and only their video and audio. Any other participant's track\n * (the server's own speaker included) is never asked for, and is dropped again should the server send it anyway.\n * - **Nothing is published.** No microphone, no camera, no data, no RPC method: this file never calls a publishing\n * API, and the token would refuse one.\n * - **Safari and iOS** hold sound back until a gesture. The room reports it (`playback-blocked`) and the panel offers\n * \"Tap to turn on sound\", whose tap calls `enablePlayback`.\n *\n * Written for the website from the media library's public API: nothing here is copied from the product apps.\n */\nimport {\n DisconnectReason,\n Room,\n RoomEvent,\n Track,\n type RemoteParticipant,\n type RemoteTrack,\n type RemoteTrackPublication,\n} from \"livekit-client\";\n\nimport type { ReceiveOnlyJoinOptions, ReceiveOnlySession } from \"./types\";\n\n/** The reasons a room closes because the server closed it, rather than because the connection was lost. */\nconst CLOSED_BY_SERVER: ReadonlySet<DisconnectReason> = new Set([\n DisconnectReason.ROOM_DELETED,\n DisconnectReason.ROOM_CLOSED,\n DisconnectReason.PARTICIPANT_REMOVED,\n]);\n\nfunction isMedia(publication: RemoteTrackPublication): boolean {\n return (\n publication.kind === Track.Kind.Video ||\n publication.kind === Track.Kind.Audio\n );\n}\n\n/**\n * Join the room in `options.url` with the receive-only `options.token`, and play the avatar worker's video and voice\n * in `options.video` and `options.audio`. Resolves once connected; rejects when the room cannot be joined (the panel\n * then ends the session).\n */\nexport async function joinReceiveOnly(\n options: ReceiveOnlyJoinOptions,\n): Promise<ReceiveOnlySession> {\n const { url, token, workerIdentity, video, audio, onEvent } = options;\n let parsed: URL;\n try {\n parsed = new URL(url);\n } catch {\n throw new Error(\"live avatar: the room address is not a URL\");\n }\n if (parsed.protocol !== \"wss:\") {\n throw new Error(\"live avatar: the room address must be wss:\");\n }\n if (!token || !workerIdentity) {\n throw new Error(\"live avatar: the room token or speaker is missing\");\n }\n\n const room = new Room({\n // One small video, always shown while the session lasts: no quality switching, no layer pausing.\n adaptiveStream: false,\n dynacast: false,\n // Closing the tab or leaving the page leaves the room at once. Belt and braces with the panel's own page-hide\n // handler, which also asks the server to end the session: either may run first, and both are safe to repeat.\n disconnectOnPageLeave: true,\n });\n let leaving = false;\n\n const isSpeaker = (participant: RemoteParticipant) =>\n participant.identity === workerIdentity;\n\n /** Subscribe to `publication` when it is the speaker's video or audio; leave everything else alone. */\n const consider = (\n publication: RemoteTrackPublication,\n participant: RemoteParticipant,\n ) => {\n if (leaving || !isSpeaker(participant) || !isMedia(publication)) return;\n if (!publication.isSubscribed) publication.setSubscribed(true);\n };\n\n const reportPlayback = () => {\n if (leaving) return;\n onEvent({\n type: \"playback-blocked\",\n blocked: !room.canPlaybackAudio || !room.canPlaybackVideo,\n });\n };\n\n room\n .on(RoomEvent.TrackPublished, consider)\n .on(\n RoomEvent.TrackSubscribed,\n (\n track: RemoteTrack,\n publication: RemoteTrackPublication,\n participant: RemoteParticipant,\n ) => {\n if (leaving) return;\n if (!isSpeaker(participant) || !isMedia(publication)) {\n // Never asked for: drop it rather than play it.\n publication.setSubscribed(false);\n return;\n }\n if (track.kind === Track.Kind.Video) {\n track.attach(video);\n onEvent({ type: \"speaker-track\", kind: \"video\" });\n } else {\n track.attach(audio);\n onEvent({ type: \"speaker-track\", kind: \"audio\" });\n }\n },\n )\n .on(RoomEvent.TrackUnsubscribed, (track: RemoteTrack) => {\n track.detach();\n })\n .on(RoomEvent.ParticipantDisconnected, (participant: RemoteParticipant) => {\n if (!leaving && isSpeaker(participant)) {\n onEvent({ type: \"speaker-left\" });\n }\n })\n .on(RoomEvent.AudioPlaybackStatusChanged, reportPlayback)\n .on(RoomEvent.VideoPlaybackStatusChanged, reportPlayback)\n .on(RoomEvent.Disconnected, (reason?: DisconnectReason) => {\n if (leaving) return;\n onEvent({\n type: \"disconnected\",\n byServer: reason !== undefined && CLOSED_BY_SERVER.has(reason),\n });\n });\n\n const detachAll = () => {\n for (const participant of room.remoteParticipants.values()) {\n for (const publication of participant.trackPublications.values()) {\n publication.track?.detach();\n }\n }\n video.srcObject = null;\n audio.srcObject = null;\n };\n\n try {\n await room.connect(url, token, { autoSubscribe: false });\n } catch (error) {\n leaving = true;\n room.removeAllListeners();\n detachAll();\n throw error;\n }\n\n // Whoever was in the room before this viewer joined: their tracks were published before the listener above.\n for (const participant of room.remoteParticipants.values()) {\n for (const publication of participant.trackPublications.values()) {\n consider(publication, participant);\n }\n }\n reportPlayback();\n\n return {\n enablePlayback: async () => {\n // Both started inside the visitor's gesture, before anything is awaited: Safari allows playback only there.\n // A refusal leaves the room as it was, and the report below keeps the button offered.\n await Promise.allSettled([room.startAudio(), room.startVideo()]);\n reportPlayback();\n },\n leave: async () => {\n if (leaving) return;\n leaving = true;\n detachAll();\n try {\n await room.disconnect();\n } finally {\n room.removeAllListeners();\n }\n },\n };\n}\n"]}
1
+ {"version":3,"sources":["../../src/avatar-live/receive-only.ts"],"names":[],"mappings":";;;AAgCA,IAAM,gBAAA,uBAAsD,GAAA,CAAI;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AAA,cAAA,EAAe;AAAA,IACjB,CAAA;AAAA,IACA,OAAO,YAAY;AACjB,MAAA,IAAI,OAAA,EAAS;AACb,MAAA,OAAA,GAAU,IAAA;AACV,MAAA,SAAA,EAAU;AACV,MAAA,IAAI;AACF,QAAA,MAAM,KAAK,UAAA,EAAW;AAAA,MACxB,CAAA,SAAE;AACA,QAAA,IAAA,CAAK,kBAAA,EAAmB;AAAA,MAC1B;AAAA,IACF;AAAA,GACF;AACF","file":"index.mjs","sourcesContent":["/**\n * BOFF-9797. The live avatar's room, joined to watch and listen only.\n *\n * A visitor's browser on a product website holds a subscribe-only room token: it can receive the avatar worker's\n * video and voice and do nothing else. This adapter keeps to that from its side too:\n *\n * - **Nothing is subscribed automatically** (`autoSubscribe: false`). Only the tracks of `workerIdentity`, the avatar\n * worker the create answer named, are subscribed, and only their video and audio. Any other participant's track\n * (the server's own speaker included) is never asked for, and is dropped again should the server send it anyway.\n * - **Nothing is published.** No microphone, no camera, no data, no RPC method: this file never calls a publishing\n * API, and the token would refuse one.\n * - **Safari and iOS** hold sound back until a gesture. The room reports it (`playback-blocked`, with `sound` when the\n * sound is held back and not only the video) and the panel offers \"Tap to turn on sound\", whose tap calls\n * `enablePlayback`.\n * - **The end of the speech** is told (`speech-ended`) from what any viewer of the room sees: the other voice in it, the\n * server's speaker that the worker follows, leaving the room or unpublishing its voice. Its track is never subscribed.\n *\n * Written for the website from the media library's public API: nothing here is copied from the product apps.\n */\nimport {\n DisconnectReason,\n Room,\n RoomEvent,\n Track,\n type RemoteParticipant,\n type RemoteTrack,\n type RemoteTrackPublication,\n} from \"livekit-client\";\n\nimport type { ReceiveOnlyJoinOptions, ReceiveOnlySession } from \"./types\";\n\n/** The reasons a room closes because the server closed it, rather than because the connection was lost. */\nconst CLOSED_BY_SERVER: ReadonlySet<DisconnectReason> = new Set([\n DisconnectReason.ROOM_DELETED,\n DisconnectReason.ROOM_CLOSED,\n DisconnectReason.PARTICIPANT_REMOVED,\n]);\n\nfunction isMedia(publication: RemoteTrackPublication): boolean {\n return (\n publication.kind === Track.Kind.Video ||\n publication.kind === Track.Kind.Audio\n );\n}\n\n/**\n * Join the room in `options.url` with the receive-only `options.token`, and play the avatar worker's video and voice\n * in `options.video` and `options.audio`. Resolves once connected; rejects when the room cannot be joined (the panel\n * then ends the session).\n */\nexport async function joinReceiveOnly(\n options: ReceiveOnlyJoinOptions,\n): Promise<ReceiveOnlySession> {\n const { url, token, workerIdentity, video, audio, onEvent } = options;\n let parsed: URL;\n try {\n parsed = new URL(url);\n } catch {\n throw new Error(\"live avatar: the room address is not a URL\");\n }\n if (parsed.protocol !== \"wss:\") {\n throw new Error(\"live avatar: the room address must be wss:\");\n }\n if (!token || !workerIdentity) {\n throw new Error(\"live avatar: the room token or speaker is missing\");\n }\n\n const room = new Room({\n // One small video, always shown while the session lasts: no quality switching, no layer pausing.\n adaptiveStream: false,\n dynacast: false,\n // Closing the tab or leaving the page leaves the room at once. Belt and braces with the panel's own page-hide\n // handler, which also asks the server to end the session: either may run first, and both are safe to repeat.\n disconnectOnPageLeave: true,\n });\n let leaving = false;\n\n const isSpeaker = (participant: RemoteParticipant) =>\n participant.identity === workerIdentity;\n\n /**\n * Everyone else in the room seen publishing a voice: the server's speaker, whose speech the worker voices. Noted\n * only, never subscribed to, so that the end of that speech can be told (`speech-ended`).\n */\n const voiced = new Set<string>();\n let speechEnded = false;\n\n /** Subscribe to `publication` when it is the speaker's video or audio; leave everything else alone. */\n const consider = (\n publication: RemoteTrackPublication,\n participant: RemoteParticipant,\n ) => {\n if (leaving) return;\n if (!isSpeaker(participant)) {\n if (publication.kind === Track.Kind.Audio) {\n voiced.add(participant.identity);\n }\n return;\n }\n if (!isMedia(publication)) return;\n if (!publication.isSubscribed) publication.setSubscribed(true);\n };\n\n /** A voice seen published has gone (its track, or its participant): the speech has ended at its source. Once. */\n const voiceGone = (participant: RemoteParticipant) => {\n if (leaving || speechEnded || !voiced.has(participant.identity)) return;\n speechEnded = true;\n onEvent({ type: \"speech-ended\" });\n };\n\n const reportPlayback = () => {\n if (leaving) return;\n onEvent({\n type: \"playback-blocked\",\n blocked: !room.canPlaybackAudio || !room.canPlaybackVideo,\n sound: !room.canPlaybackAudio,\n });\n };\n\n room\n .on(RoomEvent.TrackPublished, consider)\n .on(\n RoomEvent.TrackSubscribed,\n (\n track: RemoteTrack,\n publication: RemoteTrackPublication,\n participant: RemoteParticipant,\n ) => {\n if (leaving) return;\n if (!isSpeaker(participant) || !isMedia(publication)) {\n // Never asked for: drop it rather than play it.\n publication.setSubscribed(false);\n return;\n }\n if (track.kind === Track.Kind.Video) {\n track.attach(video);\n onEvent({ type: \"speaker-track\", kind: \"video\" });\n } else {\n track.attach(audio);\n onEvent({ type: \"speaker-track\", kind: \"audio\" });\n }\n },\n )\n .on(RoomEvent.TrackUnsubscribed, (track: RemoteTrack) => {\n track.detach();\n })\n .on(\n RoomEvent.TrackUnpublished,\n (publication: RemoteTrackPublication, participant: RemoteParticipant) => {\n if (!isSpeaker(participant) && publication.kind === Track.Kind.Audio) {\n voiceGone(participant);\n }\n },\n )\n .on(RoomEvent.ParticipantDisconnected, (participant: RemoteParticipant) => {\n if (leaving) return;\n if (isSpeaker(participant)) {\n onEvent({ type: \"speaker-left\" });\n } else {\n voiceGone(participant);\n }\n })\n .on(RoomEvent.AudioPlaybackStatusChanged, reportPlayback)\n .on(RoomEvent.VideoPlaybackStatusChanged, reportPlayback)\n .on(RoomEvent.Disconnected, (reason?: DisconnectReason) => {\n if (leaving) return;\n onEvent({\n type: \"disconnected\",\n byServer: reason !== undefined && CLOSED_BY_SERVER.has(reason),\n });\n });\n\n const detachAll = () => {\n for (const participant of room.remoteParticipants.values()) {\n for (const publication of participant.trackPublications.values()) {\n publication.track?.detach();\n }\n }\n video.srcObject = null;\n audio.srcObject = null;\n };\n\n try {\n await room.connect(url, token, { autoSubscribe: false });\n } catch (error) {\n leaving = true;\n room.removeAllListeners();\n detachAll();\n throw error;\n }\n\n // Whoever was in the room before this viewer joined: their tracks were published before the listener above.\n for (const participant of room.remoteParticipants.values()) {\n for (const publication of participant.trackPublications.values()) {\n consider(publication, participant);\n }\n }\n reportPlayback();\n\n return {\n enablePlayback: async () => {\n // Both started inside the visitor's gesture, before anything is awaited: Safari allows playback only there.\n // A refusal leaves the room as it was, and the report below keeps the button offered.\n await Promise.allSettled([room.startAudio(), room.startVideo()]);\n reportPlayback();\n },\n leave: async () => {\n if (leaving) return;\n leaving = true;\n detachAll();\n try {\n await room.disconnect();\n } finally {\n room.removeAllListeners();\n }\n },\n };\n}\n"]}
@@ -1,7 +1,7 @@
1
1
  import * as react from 'react';
2
2
  import { ReactNode } from 'react';
3
- import { E as ExplorePanelAvatarLive, a as ExploreLocale, A as AvatarConversation } from '../explore-avatar-live-config-N4WhJzgS.mjs';
4
- import '../types-CndbmBK-.mjs';
3
+ import { E as ExplorePanelAvatarLive, a as ExploreLocale, A as AvatarConversation } from '../explore-avatar-live-config-B6_p0q1c.mjs';
4
+ import '../types-CXqaLlNB.mjs';
5
5
  import '../use-explore-chat-CbfohA9O.mjs';
6
6
  import '../explore-types-Ol1Mm3dW.mjs';
7
7
 
@@ -9,6 +9,11 @@ interface AvatarLiveViewProps {
9
9
  live: ExplorePanelAvatarLive;
10
10
  /** The Avatar view is showing: the panel is open and its Avatar tab is selected. */
11
11
  active: boolean;
12
+ /**
13
+ * The panel is open, whichever tab it shows. With `active` it tells the Chat tab (open, not active: the pane is only
14
+ * hidden, and a session under way keeps playing) from the panel closing (not open: what is under way ends).
15
+ */
16
+ open: boolean;
12
17
  locale: ExploreLocale;
13
18
  /** The product the panel speaks for, when it is one product's own; null on the portfolio's. */
14
19
  productName: string | null;
@@ -19,8 +24,18 @@ interface AvatarLiveViewProps {
19
24
  };
20
25
  /** The Avatar tab as it was before the live avatar: shown whenever the live avatar is not offered or not reachable. */
21
26
  fallback: ReactNode;
22
- /** Back to the Chat tab. Leaving the Avatar tab ends a session, like any other way out of it. */
27
+ /**
28
+ * Back to the Chat tab. Like the Chat tab itself, it calls off a start that has not been sent yet, and leaves a
29
+ * session under way speaking.
30
+ */
23
31
  onContinueInChat: () => void;
32
+ /**
33
+ * Told whenever the avatar's voice starts or stops being the page's: its status line while a session is being
34
+ * created, joined or played ("Connecting to the live avatar…", "The avatar is speaking."), and null otherwise (and
35
+ * when the view goes). The panel holds Chat's own read-aloud and dictation meanwhile, so the page never speaks in two
36
+ * voices and the microphone never takes down the avatar's.
37
+ */
38
+ onVoiceHold?: (line: string | null) => void;
24
39
  /** "Continue in Chat" in the panel's language: the panel's own word for it, so this chunk carries none of the panel's. */
25
40
  continueInChat: string;
26
41
  /**
@@ -51,6 +66,6 @@ interface AvatarLiveViewProps {
51
66
  /** The panel's conversation, null when there is no provider. */
52
67
  conversation: AvatarConversation | null;
53
68
  }
54
- declare function AvatarLiveView({ live, active, locale, productName, still, fallback, onContinueInChat, continueInChat, newChat, send, tryAsking, prompts, touchFirst, currentPath, off, base, headers, conversation, }: AvatarLiveViewProps): react.JSX.Element;
69
+ declare function AvatarLiveView({ live, active, open, locale, productName, still, fallback, onContinueInChat, onVoiceHold, continueInChat, newChat, send, tryAsking, prompts, touchFirst, currentPath, off, base, headers, conversation, }: AvatarLiveViewProps): react.JSX.Element;
55
70
 
56
71
  export { AvatarLiveView, type AvatarLiveViewProps };
@@ -1,7 +1,7 @@
1
1
  import * as react from 'react';
2
2
  import { ReactNode } from 'react';
3
- import { E as ExplorePanelAvatarLive, a as ExploreLocale, A as AvatarConversation } from '../explore-avatar-live-config-CAfN5eAX.js';
4
- import '../types-CndbmBK-.js';
3
+ import { E as ExplorePanelAvatarLive, a as ExploreLocale, A as AvatarConversation } from '../explore-avatar-live-config-DRpS-mqQ.js';
4
+ import '../types-CXqaLlNB.js';
5
5
  import '../use-explore-chat-B3dOOvJN.js';
6
6
  import '../explore-types-Ol1Mm3dW.js';
7
7
 
@@ -9,6 +9,11 @@ interface AvatarLiveViewProps {
9
9
  live: ExplorePanelAvatarLive;
10
10
  /** The Avatar view is showing: the panel is open and its Avatar tab is selected. */
11
11
  active: boolean;
12
+ /**
13
+ * The panel is open, whichever tab it shows. With `active` it tells the Chat tab (open, not active: the pane is only
14
+ * hidden, and a session under way keeps playing) from the panel closing (not open: what is under way ends).
15
+ */
16
+ open: boolean;
12
17
  locale: ExploreLocale;
13
18
  /** The product the panel speaks for, when it is one product's own; null on the portfolio's. */
14
19
  productName: string | null;
@@ -19,8 +24,18 @@ interface AvatarLiveViewProps {
19
24
  };
20
25
  /** The Avatar tab as it was before the live avatar: shown whenever the live avatar is not offered or not reachable. */
21
26
  fallback: ReactNode;
22
- /** Back to the Chat tab. Leaving the Avatar tab ends a session, like any other way out of it. */
27
+ /**
28
+ * Back to the Chat tab. Like the Chat tab itself, it calls off a start that has not been sent yet, and leaves a
29
+ * session under way speaking.
30
+ */
23
31
  onContinueInChat: () => void;
32
+ /**
33
+ * Told whenever the avatar's voice starts or stops being the page's: its status line while a session is being
34
+ * created, joined or played ("Connecting to the live avatar…", "The avatar is speaking."), and null otherwise (and
35
+ * when the view goes). The panel holds Chat's own read-aloud and dictation meanwhile, so the page never speaks in two
36
+ * voices and the microphone never takes down the avatar's.
37
+ */
38
+ onVoiceHold?: (line: string | null) => void;
24
39
  /** "Continue in Chat" in the panel's language: the panel's own word for it, so this chunk carries none of the panel's. */
25
40
  continueInChat: string;
26
41
  /**
@@ -51,6 +66,6 @@ interface AvatarLiveViewProps {
51
66
  /** The panel's conversation, null when there is no provider. */
52
67
  conversation: AvatarConversation | null;
53
68
  }
54
- declare function AvatarLiveView({ live, active, locale, productName, still, fallback, onContinueInChat, continueInChat, newChat, send, tryAsking, prompts, touchFirst, currentPath, off, base, headers, conversation, }: AvatarLiveViewProps): react.JSX.Element;
69
+ declare function AvatarLiveView({ live, active, open, locale, productName, still, fallback, onContinueInChat, onVoiceHold, continueInChat, newChat, send, tryAsking, prompts, touchFirst, currentPath, off, base, headers, conversation, }: AvatarLiveViewProps): react.JSX.Element;
55
70
 
56
71
  export { AvatarLiveView, type AvatarLiveViewProps };