@theoremjs/react 0.3.5-next.1037.g9282f21 → 0.3.5-next.1039.gdc39c80

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 CHANGED
@@ -501,7 +501,7 @@ This code opens `wss://<your host>/api/live/relay?profile=<id>`. To send your ow
501
501
 
502
502
  To get the messages your relay sends with `liveHostEnvelope`, give `useLiveCall` an `onHostMessage`. See [Send the page your own messages](https://github.com/masudl-hub/theoremai/blob/main/web/README.md#send-the-page-your-own-messages).
503
503
 
504
- `startCall`, and the start buttons of `LiveRunner`, open the call's audio inside the press, before `connection` is called. When your own press waits before it calls `startCall`, call `call.prepareAudio()` first in that press: the call then uses that audio and does not open another. See [Open the audio in the press](https://github.com/masudl-hub/theoremai/blob/main/web/README.md#open-the-audio-in-the-press).
504
+ `startCall`, and the start buttons of `LiveRunner`, open the call's audio inside the press, before `connection` is called. When your own press waits before it calls `startCall`, call `call.prepareAudio()` first in that press: the call then uses that audio and does not open another. When the press comes before the call exists, for example while the page still loads, call `prepareLiveAudio()` from `@theoremjs/react/live` in the press, and give what it returns to `startCall({ video, audio })` when the call starts. The call plays through that output, opens no other, keeps it across reconnects, and closes it once when the call ends, also when it ends before it connects. See [Open the audio in the press](https://github.com/masudl-hub/theoremai/blob/main/web/README.md#open-the-audio-in-the-press).
505
505
 
506
506
  To know when a call ends, and why, give `useLiveCall` an `onCallEnded`. It is called once for each call the person starts, with a `LiveCallEnd`: `cancelled` when the person ends the call before it connects, `user` after it connects, `agent` when the other side closes it, and `failed` with the error. A call whose component unmounts ends as `user`, or `cancelled` before it connects. See [Know when the call ended](https://github.com/masudl-hub/theoremai/blob/main/web/README.md#know-when-the-call-ended).
507
507
 
@@ -2,6 +2,17 @@ import type { LiveProfileInterface } from '@theoremjs/agents/interface';
2
2
  import type { LiveCallOptions, LiveConnection } from '@theoremjs/web/client';
3
3
  import { type LiveCaptionState, type LiveCaptionTurn } from '../../client/live/live-captions.js';
4
4
  import { type LiveVideoFrame, type LiveVideoOptions } from '../../client/live/live-video.js';
5
+ /** How `startCall` starts a call. */
6
+ export interface LiveStartOptions {
7
+ /** Turn the camera on once the call connects, when the profile takes video. */
8
+ video: boolean;
9
+ /**
10
+ * The audio output the host opened with `prepareLiveAudio` in the person's press, such as one
11
+ * made before this call existed. The call plays through it, opens no other, keeps it across
12
+ * reconnects, and closes it once when the call ends. Default: the call opens its own.
13
+ */
14
+ audio?: AudioContext;
15
+ }
5
16
  /** What `useLiveCall` takes: the profile, what the call opens, and the host's part in the call. */
6
17
  export type LiveCallInput = {
7
18
  iface: LiveProfileInterface;
@@ -61,9 +72,7 @@ export declare function useLiveCall({ iface, connection, video, ...options }: Li
61
72
  setTextDraft: import("react").Dispatch<import("react").SetStateAction<string>>;
62
73
  handleEnd: () => void;
63
74
  prepareAudio: () => void;
64
- startCall: (options: {
65
- video: boolean;
66
- }) => void;
75
+ startCall: (options: LiveStartOptions) => void;
67
76
  handleRestart: () => Promise<void>;
68
77
  handleSendText: (text?: string) => void;
69
78
  handleToggleMic: () => void;
@@ -22,7 +22,7 @@ function useLiveCallLifecycle(controls, captionsRef, sessionActive, videoAvailab
22
22
  videoOnConnectRef.current = options.video && videoAvailable;
23
23
  setCallStarted(true);
24
24
  setEnded(false);
25
- void controls.startSession();
25
+ void controls.startSession(options.audio);
26
26
  }, [controls, videoAvailable]);
27
27
  useEffect(() => {
28
28
  if (sessionActive)
@@ -42,7 +42,7 @@ export declare function useLiveRunnerControls(args: {
42
42
  }): {
43
43
  prepareAudio: () => void;
44
44
  teardownSession: () => void;
45
- startSession: () => Promise<void>;
45
+ startSession: (given?: AudioContext) => Promise<void>;
46
46
  handleSendText: (text?: string) => void;
47
47
  handleToggleVideo: () => Promise<void>;
48
48
  handleFlipCamera: () => Promise<void>;
@@ -40,10 +40,14 @@ export function useLiveRunnerControls(args) {
40
40
  args.setInputLevel(0);
41
41
  args.setOutputLevel(0);
42
42
  }, [args]);
43
- const startSession = useCallback(async () => {
43
+ /** `given` is an audio output the host opened in the press, before the call existed. */
44
+ const startSession = useCallback(async (given) => {
44
45
  // invariant: The audio opens before the first await, inside the press that started the call.
45
- const held = preparedAudioRef.current;
46
+ const prepared = preparedAudioRef.current;
46
47
  preparedAudioRef.current = null;
48
+ if (given && prepared !== given)
49
+ releaseAudio(prepared);
50
+ const held = given ?? prepared;
47
51
  args.clearFailure();
48
52
  args.resetCaptions();
49
53
  const failStart = (err) => {
package/live.d.ts CHANGED
@@ -4,9 +4,10 @@
4
4
  * @module
5
5
  */
6
6
  export type { LiveAudioOptions, LiveCallEnd, LiveCallOptions, LiveClientTuning, LiveConnection, PageTool, PageToolAnswer, PageTools, } from '@theoremjs/web/client';
7
+ export { prepareLiveAudio } from '@theoremjs/web/client';
7
8
  export type { LiveFacingMode, LiveVideoFrame, LiveVideoOptions, } from './client/live/live-video.js';
8
9
  export { type LiveVideoFit, type LiveVideoOverlay, type LiveVideoView, liveFramePointInPreview, } from './client/live/live-video-view.js';
9
- export { type LiveCall, type LiveCallInput, useLiveCall, } from './components/live/use-live-call.js';
10
+ export { type LiveCall, type LiveCallInput, type LiveStartOptions, useLiveCall, } from './components/live/use-live-call.js';
10
11
  export { LiveCallTile, type LiveCallTileProps, type LiveCallTileSlots, } from './ui/LiveCallTile.js';
11
12
  export type { LiveRunnerProps, LiveRunnerSlots } from './ui/LiveRunner.js';
12
13
  export { LiveRunner } from './ui/LiveRunner.js';
package/live.js CHANGED
@@ -7,6 +7,7 @@
7
7
  import '@astryxdesign/core/reset.css';
8
8
  import '@astryxdesign/core/astryx.css';
9
9
  import './ui/built/theme.css';
10
+ export { prepareLiveAudio } from '@theoremjs/web/client';
10
11
  export { liveFramePointInPreview, } from "./client/live/live-video-view.js";
11
12
  export { useLiveCall, } from "./components/live/use-live-call.js";
12
13
  export { LiveCallTile, } from "./ui/LiveCallTile.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@theoremjs/react",
3
- "version": "0.3.5-next.1037.g9282f21",
3
+ "version": "0.3.5-next.1039.gdc39c80",
4
4
  "description": "React bindings for Theorem: headless hooks + transport, an Astryx chat UI, and a Web-standard server handler.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -60,8 +60,8 @@
60
60
  "@stylexjs/stylex": "0.19.0",
61
61
  "react": "^19.0.0",
62
62
  "react-dom": "^19.0.0",
63
- "@theoremjs/agents": "^0.3.5-next.1037.g9282f21",
64
- "@theoremjs/web": "^0.3.5-next.1037.g9282f21"
63
+ "@theoremjs/agents": "^0.3.5-next.1039.gdc39c80",
64
+ "@theoremjs/web": "^0.3.5-next.1039.gdc39c80"
65
65
  },
66
66
  "peerDependenciesMeta": {
67
67
  "@astryxdesign/core": {