@archboard/codex-realtime-voice 0.0.0-stage → 0.1.0
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/LICENSE +21 -0
- package/README.md +621 -2
- package/dist/app-server-contract-D4E5bibD.mjs +177 -0
- package/dist/browser.d.mts +10 -0
- package/dist/browser.mjs +475 -0
- package/dist/contract-CZDUvuVt.d.mts +19587 -0
- package/dist/contract-Cupd2jDS.d.mts +131 -0
- package/dist/contract-DTEwX7x-.d.mts +164 -0
- package/dist/contract-qg6q9-vH.d.mts +6905 -0
- package/dist/contract.d.mts +2 -0
- package/dist/contract.mjs +1 -0
- package/dist/controllers.d.mts +588 -0
- package/dist/controllers.mjs +4754 -0
- package/dist/gateway-envelope-CODkg5rz.mjs +43 -0
- package/dist/gateway-envelope-Ch4BsYcK.d.mts +36 -0
- package/dist/instructions-CmBJHqpa.mjs +8980 -0
- package/dist/media-state-CakgDCk4.d.mts +215 -0
- package/dist/model-YHUwnXnC.mjs +2808 -0
- package/dist/react.d.mts +34 -0
- package/dist/react.mjs +49 -0
- package/dist/realtime-contract-DwkCluo2.mjs +1167 -0
- package/dist/realtime-contract-wHmSyUIe.d.mts +150 -0
- package/dist/realtime-state-CTBmCjt1.mjs +182 -0
- package/dist/realtime-state-DT4uvrIV.d.mts +16 -0
- package/dist/realtime.d.mts +3 -0
- package/dist/realtime.mjs +3 -0
- package/dist/runtime.d.mts +93 -0
- package/dist/runtime.mjs +289 -0
- package/dist/schemas.d.mts +7075 -0
- package/dist/schemas.mjs +1 -0
- package/dist/server.d.mts +1374 -0
- package/dist/server.mjs +38224 -0
- package/dist/snapshot-BCrCORmt.d.mts +8597 -0
- package/dist/transport-CqOvXrAE.mjs +5168 -0
- package/package.json +71 -5
package/dist/react.d.mts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { a as VoiceClientSnapshot, r as VoiceClient } from "./contract-Cupd2jDS.mjs";
|
|
2
|
+
import { JSX, ReactNode } from "react";
|
|
3
|
+
/** Inputs for the provider. */
|
|
4
|
+
interface VoiceClientProviderProps {
|
|
5
|
+
/** The client from `createVoiceClient`. The host connects and disposes it. */
|
|
6
|
+
readonly client: VoiceClient;
|
|
7
|
+
readonly children: ReactNode;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* The client, for `useVoiceClient` and `useVoiceState` below.
|
|
11
|
+
* @param props The client and what is drawn.
|
|
12
|
+
* @returns What is drawn, with the client offered to it.
|
|
13
|
+
*/
|
|
14
|
+
declare function VoiceClientProvider(props: VoiceClientProviderProps): JSX.Element;
|
|
15
|
+
/**
|
|
16
|
+
* The voice client of the nearest `VoiceClientProvider`, for its actions.
|
|
17
|
+
* @returns The client.
|
|
18
|
+
* @throws {Error} When no provider is above the component.
|
|
19
|
+
*/
|
|
20
|
+
declare function useVoiceClient(): VoiceClient;
|
|
21
|
+
/**
|
|
22
|
+
* The client's whole state, re-rendering on each publication.
|
|
23
|
+
* @returns The state.
|
|
24
|
+
*/
|
|
25
|
+
declare function useVoiceState(): VoiceClientSnapshot;
|
|
26
|
+
/**
|
|
27
|
+
* Part of the client's state, re-rendering only when that part changes.
|
|
28
|
+
* @param select Picks part of the state. It runs once per publication. Return
|
|
29
|
+
* a part of the state or a primitive: a new object is a change, so the
|
|
30
|
+
* component then re-renders on every publication.
|
|
31
|
+
* @returns The selected part.
|
|
32
|
+
*/
|
|
33
|
+
declare function useVoiceState<Selected>(select: (state: VoiceClientSnapshot) => Selected): Selected;
|
|
34
|
+
export { VoiceClientProvider, useVoiceClient, useVoiceState };
|
package/dist/react.mjs
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { createContext, useContext, useMemo, useSyncExternalStore } from "react";
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
// src/ui/voice-client/hooks/use-voice-client.ts
|
|
4
|
+
/** The client a `VoiceClientProvider` offers, or null outside one. */
|
|
5
|
+
const VoiceClientContext = createContext(null);
|
|
6
|
+
/**
|
|
7
|
+
* The voice client of the nearest `VoiceClientProvider`, for its actions.
|
|
8
|
+
* @returns The client.
|
|
9
|
+
* @throws {Error} When no provider is above the component.
|
|
10
|
+
*/
|
|
11
|
+
function useVoiceClient() {
|
|
12
|
+
const client = useContext(VoiceClientContext);
|
|
13
|
+
if (client === null) throw new Error("useVoiceClient needs a VoiceClientProvider above it.");
|
|
14
|
+
return client;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* The client's state, whole or by a selector.
|
|
18
|
+
* @param select Picks part of the state, when given.
|
|
19
|
+
* @returns The selected part, or the whole state.
|
|
20
|
+
*/
|
|
21
|
+
function useVoiceState(select) {
|
|
22
|
+
const client = useVoiceClient();
|
|
23
|
+
const read = useMemo(() => {
|
|
24
|
+
if (select === void 0) return client.snapshot;
|
|
25
|
+
let last = null;
|
|
26
|
+
return () => {
|
|
27
|
+
const state = client.snapshot();
|
|
28
|
+
if (last?.state !== state) last = {
|
|
29
|
+
state,
|
|
30
|
+
selected: select(state)
|
|
31
|
+
};
|
|
32
|
+
return last.selected;
|
|
33
|
+
};
|
|
34
|
+
}, [client, select]);
|
|
35
|
+
return useSyncExternalStore(client.subscribe, read, read);
|
|
36
|
+
}
|
|
37
|
+
// src/ui/voice-client/components/VoiceClientProvider.tsx
|
|
38
|
+
/**
|
|
39
|
+
* The client, for `useVoiceClient` and `useVoiceState` below.
|
|
40
|
+
* @param props The client and what is drawn.
|
|
41
|
+
* @returns What is drawn, with the client offered to it.
|
|
42
|
+
*/
|
|
43
|
+
function VoiceClientProvider(props) {
|
|
44
|
+
return /* @__PURE__ */ jsx(VoiceClientContext.Provider, {
|
|
45
|
+
value: props.client,
|
|
46
|
+
children: props.children
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
export { VoiceClientProvider, useVoiceClient, useVoiceState };
|