@talqing/react 0.4.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 +170 -0
- package/dist/cjs/images.d.ts +17 -0
- package/dist/cjs/images.d.ts.map +1 -0
- package/dist/cjs/images.js +68 -0
- package/dist/cjs/images.js.map +1 -0
- package/dist/cjs/index.d.ts +10 -0
- package/dist/cjs/index.d.ts.map +1 -0
- package/dist/cjs/index.js +64 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/media.d.ts +20 -0
- package/dist/cjs/media.d.ts.map +1 -0
- package/dist/cjs/media.js +46 -0
- package/dist/cjs/media.js.map +1 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/rpc.d.ts +17 -0
- package/dist/cjs/rpc.d.ts.map +1 -0
- package/dist/cjs/rpc.js +48 -0
- package/dist/cjs/rpc.js.map +1 -0
- package/dist/cjs/session.d.ts +77 -0
- package/dist/cjs/session.d.ts.map +1 -0
- package/dist/cjs/session.js +55 -0
- package/dist/cjs/session.js.map +1 -0
- package/dist/cjs/userdata.d.ts +10 -0
- package/dist/cjs/userdata.d.ts.map +1 -0
- package/dist/cjs/userdata.js +24 -0
- package/dist/cjs/userdata.js.map +1 -0
- package/dist/esm/images.d.ts +17 -0
- package/dist/esm/images.d.ts.map +1 -0
- package/dist/esm/images.js +65 -0
- package/dist/esm/images.js.map +1 -0
- package/dist/esm/index.d.ts +10 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +35 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/media.d.ts +20 -0
- package/dist/esm/media.d.ts.map +1 -0
- package/dist/esm/media.js +42 -0
- package/dist/esm/media.js.map +1 -0
- package/dist/esm/package.json +3 -0
- package/dist/esm/rpc.d.ts +17 -0
- package/dist/esm/rpc.d.ts.map +1 -0
- package/dist/esm/rpc.js +44 -0
- package/dist/esm/rpc.js.map +1 -0
- package/dist/esm/session.d.ts +77 -0
- package/dist/esm/session.d.ts.map +1 -0
- package/dist/esm/session.js +50 -0
- package/dist/esm/session.js.map +1 -0
- package/dist/esm/userdata.d.ts +10 -0
- package/dist/esm/userdata.d.ts.map +1 -0
- package/dist/esm/userdata.js +21 -0
- package/dist/esm/userdata.js.map +1 -0
- package/package.json +73 -0
- package/src/images.ts +97 -0
- package/src/index.ts +58 -0
- package/src/media.ts +77 -0
- package/src/rpc.ts +61 -0
- package/src/session.tsx +148 -0
- package/src/userdata.ts +27 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Talqing
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
# @talqing/react
|
|
2
|
+
|
|
3
|
+
React bindings for Talqing web calls: join a voice or video agent from a browser,
|
|
4
|
+
attach a photo mid-call, share a screen, read and write the session's userdata,
|
|
5
|
+
and answer the agent when a tool calls back into your page.
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @talqing/react
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
npm 7+ and pnpm install the peers for you — `@talqing/client`, `@talqing/sdk`,
|
|
12
|
+
`livekit-client`, `@livekit/components-react`, `react` and `react-dom`. Yarn only
|
|
13
|
+
warns, so on Yarn:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
yarn add @talqing/react @talqing/client @talqing/sdk livekit-client @livekit/components-react
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Mint the token on your server
|
|
20
|
+
|
|
21
|
+
`POST /v1/calls/token` needs the **editor** role, and a Talqing credential that
|
|
22
|
+
can mint a call token can also create and delete agents, read every transcript
|
|
23
|
+
and spend the workspace's credits. **Never ship one to a browser.**
|
|
24
|
+
|
|
25
|
+
`contact_key` and `userdata` are the second reason. `contact_key` decides whose
|
|
26
|
+
history the call resumes and `userdata` is merged onto that person's record — so
|
|
27
|
+
on a server-minted call, the browser cannot choose either. They never leave your
|
|
28
|
+
backend.
|
|
29
|
+
|
|
30
|
+
```ts
|
|
31
|
+
// app/api/talqing-token/route.ts — your server, with @talqing/sdk
|
|
32
|
+
import { TalqingClient } from "@talqing/sdk";
|
|
33
|
+
|
|
34
|
+
const talqing = new TalqingClient({
|
|
35
|
+
baseUrl: "https://api.in.talqing.com",
|
|
36
|
+
token: process.env.TALQING_API_TOKEN,
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
export async function POST(request: Request) {
|
|
40
|
+
const user = await authenticate(request); // your sign-in, not ours
|
|
41
|
+
if (!user) return new Response("unauthorized", { status: 401 });
|
|
42
|
+
|
|
43
|
+
const call = await talqing.calls.token({
|
|
44
|
+
tokenRequest: {
|
|
45
|
+
agent_id: process.env.TALQING_AGENT_ID,
|
|
46
|
+
contact_key: user.id,
|
|
47
|
+
userdata: { name: user.name, plan: user.plan },
|
|
48
|
+
},
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
if (call.warnings.length) console.warn(call.warnings); // stored nowhere else
|
|
52
|
+
return Response.json({
|
|
53
|
+
server_url: call.server_url,
|
|
54
|
+
participant_token: call.participant_token,
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Join from the browser
|
|
60
|
+
|
|
61
|
+
```tsx
|
|
62
|
+
"use client";
|
|
63
|
+
import { useEffect } from "react";
|
|
64
|
+
import {
|
|
65
|
+
TalqingSessionProvider,
|
|
66
|
+
useAgent,
|
|
67
|
+
useSessionMessages,
|
|
68
|
+
useTalqingConnection,
|
|
69
|
+
useTalqingSession,
|
|
70
|
+
} from "@talqing/react";
|
|
71
|
+
|
|
72
|
+
export function CallSession({ onLeave }: { onLeave: () => void }) {
|
|
73
|
+
const session = useTalqingSession({
|
|
74
|
+
fetchToken: async () => {
|
|
75
|
+
const response = await fetch("/api/talqing-token", { method: "POST" });
|
|
76
|
+
return await response.json();
|
|
77
|
+
},
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
useEffect(() => {
|
|
81
|
+
// The token is minted inside start(), so an API refusal — an unpublished
|
|
82
|
+
// agent, a workspace out of credits — arrives here.
|
|
83
|
+
session.start().catch(onLeave);
|
|
84
|
+
return () => void session.end();
|
|
85
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps -- mount and unmount only
|
|
86
|
+
}, []);
|
|
87
|
+
|
|
88
|
+
return (
|
|
89
|
+
<TalqingSessionProvider session={session}>
|
|
90
|
+
<CallUI onLeave={onLeave} />
|
|
91
|
+
</TalqingSessionProvider>
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function CallUI({ onLeave }: { onLeave: () => void }) {
|
|
96
|
+
const { isConnected, end } = useTalqingConnection();
|
|
97
|
+
const agent = useAgent();
|
|
98
|
+
const { messages } = useSessionMessages();
|
|
99
|
+
|
|
100
|
+
return (
|
|
101
|
+
<div>
|
|
102
|
+
<p>{isConnected ? `agent: ${agent.state}` : "connecting…"}</p>
|
|
103
|
+
{messages.map((message) => (
|
|
104
|
+
<p key={message.id}>
|
|
105
|
+
<b>{message.from?.isLocal ? "You" : "Agent"}</b> {message.message}
|
|
106
|
+
</p>
|
|
107
|
+
))}
|
|
108
|
+
<button onClick={() => { void end(); onLeave(); }}>End call</button>
|
|
109
|
+
</div>
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
**One session is one call.** Start it when the component mounts and end it on the
|
|
115
|
+
way out. Place a second call by mounting a second session — give the component a
|
|
116
|
+
`key` that changes per call. A finished session's token names the room that call
|
|
117
|
+
used, and the API will not let a second call rejoin it.
|
|
118
|
+
|
|
119
|
+
**The room's state is not the agent's state.** `isConnected` goes true partway
|
|
120
|
+
through the join, while the agent is still starting up. Wait for
|
|
121
|
+
`useAgent().state === "listening"` before telling the caller to speak.
|
|
122
|
+
|
|
123
|
+
## The three ways to authorize a call
|
|
124
|
+
|
|
125
|
+
Exactly one per call, and passing two is a type error rather than a precedence
|
|
126
|
+
rule.
|
|
127
|
+
|
|
128
|
+
| | When |
|
|
129
|
+
| --- | --- |
|
|
130
|
+
| `{ token }` | Your server already minted, and you forwarded `server_url` and `participant_token`. |
|
|
131
|
+
| `{ fetchToken }` | Your endpoint mints. Called once, when the call starts. |
|
|
132
|
+
| `{ client, agentId, callOptions }` | **Trusted first-party surfaces only.** Mints from the browser with a `TalqingClient` you already hold — an app same-origin with the API, signed in as a real editor. Not for a widget you embed for your customers. |
|
|
133
|
+
|
|
134
|
+
`callOptions` is on the third branch alone, because it carries `contact_key` and
|
|
135
|
+
`userdata`. `roomOptions` rides on all three.
|
|
136
|
+
|
|
137
|
+
The third branch is the only one where this browser is what minted, so it is the
|
|
138
|
+
only one where `session.warnings` fills in. On the other two your own server
|
|
139
|
+
received them.
|
|
140
|
+
|
|
141
|
+
## What else is here
|
|
142
|
+
|
|
143
|
+
| | |
|
|
144
|
+
| --- | --- |
|
|
145
|
+
| `useTalqingImages(room)` | Send a photo to the agent mid-call and follow what became of it — four states, because the agent can go away mid-upload. |
|
|
146
|
+
| `useTalqingScreenShare()` | Share a screen on the settings that keep it legible. `start()` must run inside a click. |
|
|
147
|
+
| `useTalqingUserdata()` | Read and write the live session's userdata over RPC. |
|
|
148
|
+
| `useTalqingRpcHandlers(handlers)` | Answer a tool's `frontend_rpc` calls into your page. `useTalqingFrontendRpcs()` is the declarative version. |
|
|
149
|
+
| `useTalqingAvatarTrack()` | The track to render for a video agent. |
|
|
150
|
+
| `TALQING_SCREEN_SHARE_CAPTURE` / `_PUBLISH` | The measured capture settings, exported so you can read them. |
|
|
151
|
+
|
|
152
|
+
## The escape hatch
|
|
153
|
+
|
|
154
|
+
**This layer only ever adds.** Anything LiveKit can do, you can do — take
|
|
155
|
+
`useTalqingConnection().room` and use `livekit-client` directly. We never remove
|
|
156
|
+
a capability to make our own surface look tidier, and we do not re-wrap LiveKit
|
|
157
|
+
to rename it: `useAgent`, `useSessionMessages` and `VideoTrack` are re-exported
|
|
158
|
+
here under their own names, and they are the same modules
|
|
159
|
+
`@livekit/components-react` exports.
|
|
160
|
+
|
|
161
|
+
That guarantee is why `livekit-client` and `@livekit/components-react` are peer
|
|
162
|
+
dependencies rather than dependencies: the `Room` we hand you must be the same
|
|
163
|
+
class your own imports and `instanceof` resolve to.
|
|
164
|
+
|
|
165
|
+
## Without React
|
|
166
|
+
|
|
167
|
+
[`@talqing/client`](https://www.npmjs.com/package/@talqing/client) is the same
|
|
168
|
+
call protocol as plain functions over a `Room` you manage yourself.
|
|
169
|
+
[`@talqing/sdk`](https://www.npmjs.com/package/@talqing/sdk) is the rest of the
|
|
170
|
+
API. Full reference: <https://docs.talqing.com/sdks/react>.
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Room } from "livekit-client";
|
|
2
|
+
import { type TalqingSentImage } from "@talqing/client";
|
|
3
|
+
/** Send images to the agent on this call, and follow what became of each.
|
|
4
|
+
*
|
|
5
|
+
* `send` resolves once the bytes are on their way; the outcome arrives on the
|
|
6
|
+
* returned list, which is what a thumbnail should render.
|
|
7
|
+
*
|
|
8
|
+
* Takes the `Room` rather than reading it from the session context: a byte
|
|
9
|
+
* stream and an RPC handler are room-level things, and passing the room keeps
|
|
10
|
+
* this usable from a surface that manages its own connection —
|
|
11
|
+
* `useTalqingConnection().room` inside a provider, or the Room you built. */
|
|
12
|
+
export declare function useTalqingImages(room: Room | null | undefined): {
|
|
13
|
+
send: (file: File) => Promise<TalqingSentImage>;
|
|
14
|
+
sent: TalqingSentImage[];
|
|
15
|
+
clear: () => void;
|
|
16
|
+
};
|
|
17
|
+
//# sourceMappingURL=images.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"images.d.ts","sourceRoot":"","sources":["../../src/images.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAIL,KAAK,gBAAgB,EACtB,MAAM,iBAAiB,CAAC;AAEzB;;;;;;;;8EAQ8E;AAC9E,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,GAAG,SAAS;iBA4C7C,IAAI,KAAG,OAAO,CAAC,gBAAgB,CAAC;;;EAgChD"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
"use client";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.useTalqingImages = useTalqingImages;
|
|
5
|
+
const react_1 = require("react");
|
|
6
|
+
const client_1 = require("@talqing/client");
|
|
7
|
+
/** Send images to the agent on this call, and follow what became of each.
|
|
8
|
+
*
|
|
9
|
+
* `send` resolves once the bytes are on their way; the outcome arrives on the
|
|
10
|
+
* returned list, which is what a thumbnail should render.
|
|
11
|
+
*
|
|
12
|
+
* Takes the `Room` rather than reading it from the session context: a byte
|
|
13
|
+
* stream and an RPC handler are room-level things, and passing the room keeps
|
|
14
|
+
* this usable from a surface that manages its own connection —
|
|
15
|
+
* `useTalqingConnection().room` inside a provider, or the Room you built. */
|
|
16
|
+
function useTalqingImages(room) {
|
|
17
|
+
const [sent, setSent] = (0, react_1.useState)([]);
|
|
18
|
+
const timers = (0, react_1.useRef)(new Map());
|
|
19
|
+
const settle = (0, react_1.useCallback)((streamId, patch) => {
|
|
20
|
+
const timer = timers.current.get(streamId);
|
|
21
|
+
if (timer) {
|
|
22
|
+
clearTimeout(timer);
|
|
23
|
+
timers.current.delete(streamId);
|
|
24
|
+
}
|
|
25
|
+
setSent((images) => images.map((image) => (image.streamId === streamId ? { ...image, ...patch } : image)));
|
|
26
|
+
}, []);
|
|
27
|
+
(0, react_1.useEffect)(() => {
|
|
28
|
+
if (!room)
|
|
29
|
+
return;
|
|
30
|
+
return (0, client_1.onTalqingImageResult)(room, ({ streamId, ok, error }) => settle(streamId, { status: ok ? "sent" : "failed", error }));
|
|
31
|
+
}, [room, settle]);
|
|
32
|
+
const pending = timers.current;
|
|
33
|
+
(0, react_1.useEffect)(() => () => {
|
|
34
|
+
pending.forEach(clearTimeout);
|
|
35
|
+
pending.clear();
|
|
36
|
+
}, [pending]);
|
|
37
|
+
/* Each thumbnail is an object URL over the downscaled blob, and each pins that
|
|
38
|
+
blob in memory until it is revoked. This hook is mounted per call, so
|
|
39
|
+
without this every call's images would be held for the life of the tab. */
|
|
40
|
+
const previews = (0, react_1.useRef)([]);
|
|
41
|
+
(0, react_1.useEffect)(() => () => {
|
|
42
|
+
previews.current.forEach(URL.revokeObjectURL);
|
|
43
|
+
previews.current = [];
|
|
44
|
+
}, []);
|
|
45
|
+
const send = (0, react_1.useCallback)(async (file) => {
|
|
46
|
+
if (!room)
|
|
47
|
+
throw new Error("the call is not connected");
|
|
48
|
+
const image = await (0, client_1.sendTalqingImage)(room, file);
|
|
49
|
+
previews.current.push(image.previewUrl);
|
|
50
|
+
setSent((images) => [...images, image]);
|
|
51
|
+
timers.current.set(image.streamId, setTimeout(() => settle(image.streamId, {
|
|
52
|
+
status: "unknown",
|
|
53
|
+
// Four states, not two: the one people forget is the agent going
|
|
54
|
+
// away mid-upload, where no ack is ever coming.
|
|
55
|
+
error: "we did not hear back — the agent may not have received it",
|
|
56
|
+
}), client_1.TALQING_IMAGE_ACK_TIMEOUT_MS));
|
|
57
|
+
return image;
|
|
58
|
+
}, [room, settle]);
|
|
59
|
+
const clear = (0, react_1.useCallback)(() => {
|
|
60
|
+
setSent((images) => {
|
|
61
|
+
images.forEach((image) => URL.revokeObjectURL(image.previewUrl));
|
|
62
|
+
previews.current = [];
|
|
63
|
+
return [];
|
|
64
|
+
});
|
|
65
|
+
}, []);
|
|
66
|
+
return { send, sent, clear };
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=images.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"images.js","sourceRoot":"","sources":["../../src/images.ts"],"names":[],"mappings":";AAAA,YAAY,CAAC;;AAoBb,4CA4EC;AA9FD,iCAAiE;AAEjE,4CAKyB;AAEzB;;;;;;;;8EAQ8E;AAC9E,SAAgB,gBAAgB,CAAC,IAA6B;IAC5D,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,IAAA,gBAAQ,EAAqB,EAAE,CAAC,CAAC;IACzD,MAAM,MAAM,GAAG,IAAA,cAAM,EAAC,IAAI,GAAG,EAAyC,CAAC,CAAC;IAExE,MAAM,MAAM,GAAG,IAAA,mBAAW,EAAC,CAAC,QAAgB,EAAE,KAAgC,EAAE,EAAE;QAChF,MAAM,KAAK,GAAG,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QAC3C,IAAI,KAAK,EAAE,CAAC;YAC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 @@
|
|
|
1
|
+
export { TalqingSessionProvider, useTalqingConnection, useTalqingSession, } from "./session.js";
|
|
2
|
+
export type { TalqingCallOptions, TalqingSession, TalqingSessionOptions, } from "./session.js";
|
|
3
|
+
export { useTalqingUserdata } from "./userdata.js";
|
|
4
|
+
export { useTalqingImages } from "./images.js";
|
|
5
|
+
export { useTalqingFrontendRpcs, useTalqingRpcHandlers } from "./rpc.js";
|
|
6
|
+
export { useTalqingAvatarTrack, useTalqingScreenShare } from "./media.js";
|
|
7
|
+
export * from "@talqing/client";
|
|
8
|
+
export { useAgent, useSessionMessages, VideoTrack, } from "@livekit/components-react";
|
|
9
|
+
export type { AgentState, ReceivedMessage, TrackReference, UseAgentReturn, UseSessionReturn, } from "@livekit/components-react";
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAYA,OAAO,EACL,sBAAsB,EACtB,oBAAoB,EACpB,iBAAiB,GAClB,MAAM,cAAc,CAAC;AACtB,YAAY,EACV,kBAAkB,EAClB,cAAc,EACd,qBAAqB,GACtB,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,sBAAsB,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AACzE,OAAO,EAAE,qBAAqB,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAQ1E,cAAc,iBAAiB,CAAC;AAYhC,OAAO,EACL,QAAQ,EACR,kBAAkB,EAClB,UAAU,GACX,MAAM,2BAA2B,CAAC;AACnC,YAAY,EACV,UAAU,EACV,eAAe,EACf,cAAc,EACd,cAAc,EACd,gBAAgB,GACjB,MAAM,2BAA2B,CAAC"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* React bindings for the Talqing call protocol.
|
|
3
|
+
*
|
|
4
|
+
* Thin by design. Everything here is either the call lifecycle (`useTalqingSession`
|
|
5
|
+
* and the auth union it takes) or a hook over something `@talqing/client` does to
|
|
6
|
+
* a `Room`. Nothing here wraps LiveKit to rename it: the layer only ever ADDS, so
|
|
7
|
+
* anything LiveKit can do you can do — take `useTalqingConnection().room` and use
|
|
8
|
+
* `livekit-client` directly. We never remove a capability to make our own surface
|
|
9
|
+
* look tidier, which is also why `livekit-client` and `@livekit/components-react`
|
|
10
|
+
* are peer dependencies: the `Room` we hand you is the same class your own
|
|
11
|
+
* imports and `instanceof` resolve to.
|
|
12
|
+
*/
|
|
13
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
14
|
+
if (k2 === undefined) k2 = k;
|
|
15
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
16
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
17
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
18
|
+
}
|
|
19
|
+
Object.defineProperty(o, k2, desc);
|
|
20
|
+
}) : (function(o, m, k, k2) {
|
|
21
|
+
if (k2 === undefined) k2 = k;
|
|
22
|
+
o[k2] = m[k];
|
|
23
|
+
}));
|
|
24
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
25
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
26
|
+
};
|
|
27
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
28
|
+
exports.VideoTrack = exports.useSessionMessages = exports.useAgent = exports.useTalqingScreenShare = exports.useTalqingAvatarTrack = exports.useTalqingRpcHandlers = exports.useTalqingFrontendRpcs = exports.useTalqingImages = exports.useTalqingUserdata = exports.useTalqingSession = exports.useTalqingConnection = exports.TalqingSessionProvider = void 0;
|
|
29
|
+
var session_js_1 = require("./session.js");
|
|
30
|
+
Object.defineProperty(exports, "TalqingSessionProvider", { enumerable: true, get: function () { return session_js_1.TalqingSessionProvider; } });
|
|
31
|
+
Object.defineProperty(exports, "useTalqingConnection", { enumerable: true, get: function () { return session_js_1.useTalqingConnection; } });
|
|
32
|
+
Object.defineProperty(exports, "useTalqingSession", { enumerable: true, get: function () { return session_js_1.useTalqingSession; } });
|
|
33
|
+
var userdata_js_1 = require("./userdata.js");
|
|
34
|
+
Object.defineProperty(exports, "useTalqingUserdata", { enumerable: true, get: function () { return userdata_js_1.useTalqingUserdata; } });
|
|
35
|
+
var images_js_1 = require("./images.js");
|
|
36
|
+
Object.defineProperty(exports, "useTalqingImages", { enumerable: true, get: function () { return images_js_1.useTalqingImages; } });
|
|
37
|
+
var rpc_js_1 = require("./rpc.js");
|
|
38
|
+
Object.defineProperty(exports, "useTalqingFrontendRpcs", { enumerable: true, get: function () { return rpc_js_1.useTalqingFrontendRpcs; } });
|
|
39
|
+
Object.defineProperty(exports, "useTalqingRpcHandlers", { enumerable: true, get: function () { return rpc_js_1.useTalqingRpcHandlers; } });
|
|
40
|
+
var media_js_1 = require("./media.js");
|
|
41
|
+
Object.defineProperty(exports, "useTalqingAvatarTrack", { enumerable: true, get: function () { return media_js_1.useTalqingAvatarTrack; } });
|
|
42
|
+
Object.defineProperty(exports, "useTalqingScreenShare", { enumerable: true, get: function () { return media_js_1.useTalqingScreenShare; } });
|
|
43
|
+
/* All of `@talqing/client`, so one install and one import cover a web call.
|
|
44
|
+
* Everything there works against any `Room`, with or without React — the token
|
|
45
|
+
* source, the userdata and image and frontend-RPC calls, and the measured
|
|
46
|
+
* capture constants. Re-exported wholesale rather than as a curated list
|
|
47
|
+
* because the whole package is meant to be reachable from here, and a list
|
|
48
|
+
* would quietly fall behind it. */
|
|
49
|
+
__exportStar(require("@talqing/client"), exports);
|
|
50
|
+
/* LiveKit's own, re-exported UNDER THEIR OWN NAMES so a tenant installs one
|
|
51
|
+
* package and imports one name.
|
|
52
|
+
*
|
|
53
|
+
* Re-exporting is not wrapping: there is no surface of ours here to drift, and
|
|
54
|
+
* nothing is subtracted — `useAgent` is the ten-state discriminated union
|
|
55
|
+
* LiveKit ships, with every derived boolean, every action and
|
|
56
|
+
* `failureReasons` intact. Keeping LiveKit's names is the point: a
|
|
57
|
+
* `useTalqing`-prefixed alias would claim these as ours and hide where to read
|
|
58
|
+
* their documentation. Import them from `@livekit/components-react` instead if
|
|
59
|
+
* you prefer — it is the same module. */
|
|
60
|
+
var components_react_1 = require("@livekit/components-react");
|
|
61
|
+
Object.defineProperty(exports, "useAgent", { enumerable: true, get: function () { return components_react_1.useAgent; } });
|
|
62
|
+
Object.defineProperty(exports, "useSessionMessages", { enumerable: true, get: function () { return components_react_1.useSessionMessages; } });
|
|
63
|
+
Object.defineProperty(exports, "VideoTrack", { enumerable: true, get: function () { return components_react_1.VideoTrack; } });
|
|
64
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;GAUG;;;;;;;;;;;;;;;;;AAEH,2CAIsB;AAHpB,oHAAA,sBAAsB,OAAA;AACtB,kHAAA,oBAAoB,OAAA;AACpB,+GAAA,iBAAiB,OAAA;AAQnB,6CAAmD;AAA1C,iHAAA,kBAAkB,OAAA;AAC3B,yCAA+C;AAAtC,6GAAA,gBAAgB,OAAA;AACzB,mCAAyE;AAAhE,gHAAA,sBAAsB,OAAA;AAAE,+GAAA,qBAAqB,OAAA;AACtD,uCAA0E;AAAjE,iHAAA,qBAAqB,OAAA;AAAE,iHAAA,qBAAqB,OAAA;AAErD;;;;;mCAKmC;AACnC,kDAAgC;AAEhC;;;;;;;;;yCASyC;AACzC,8DAImC;AAHjC,4GAAA,QAAQ,OAAA;AACR,sHAAA,kBAAkB,OAAA;AAClB,8GAAA,UAAU,OAAA"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type TrackReference } from "@livekit/components-react";
|
|
2
|
+
/** Share the caller's screen with the agent, on the settings that keep it
|
|
3
|
+
* legible — see `TALQING_SCREEN_SHARE_CAPTURE` for why each one is what it is. */
|
|
4
|
+
export declare function useTalqingScreenShare(): {
|
|
5
|
+
/** Whether a screen is being shared right now. */
|
|
6
|
+
enabled: boolean;
|
|
7
|
+
/** True while the browser picker is open or the track is publishing. */
|
|
8
|
+
pending: boolean;
|
|
9
|
+
/** Opens the browser's share picker. Must be called from a user gesture. */
|
|
10
|
+
start: () => Promise<boolean | undefined> | Promise<void>;
|
|
11
|
+
/** Stops sharing. The agent is told it can no longer see on the next turn. */
|
|
12
|
+
stop: () => Promise<boolean | undefined> | Promise<void>;
|
|
13
|
+
};
|
|
14
|
+
/** The video track to render for a video agent.
|
|
15
|
+
*
|
|
16
|
+
* Prefers the avatar worker's camera — the worker publishes on the agent's
|
|
17
|
+
* behalf, which is how it is identified — and falls back through the worker's
|
|
18
|
+
* screen share and then the agent's own tracks. */
|
|
19
|
+
export declare function useTalqingAvatarTrack(): TrackReference | undefined;
|
|
20
|
+
//# sourceMappingURL=media.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"media.d.ts","sourceRoot":"","sources":["../../src/media.ts"],"names":[],"mappings":"AAIA,OAAO,EAKL,KAAK,cAAc,EACpB,MAAM,2BAA2B,CAAC;AAMnC;mFACmF;AACnF,wBAAgB,qBAAqB;IAQ/B,kDAAkD;;IAElD,wEAAwE;;IAExE,4EAA4E;;IAE5E,8EAA8E;;EAKnF;AAED;;;;oDAIoD;AACpD,wBAAgB,qBAAqB,IAAI,cAAc,GAAG,SAAS,CAgClE"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
"use client";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.useTalqingScreenShare = useTalqingScreenShare;
|
|
5
|
+
exports.useTalqingAvatarTrack = useTalqingAvatarTrack;
|
|
6
|
+
const react_1 = require("react");
|
|
7
|
+
const livekit_client_1 = require("livekit-client");
|
|
8
|
+
const components_react_1 = require("@livekit/components-react");
|
|
9
|
+
const client_1 = require("@talqing/client");
|
|
10
|
+
/** Share the caller's screen with the agent, on the settings that keep it
|
|
11
|
+
* legible — see `TALQING_SCREEN_SHARE_CAPTURE` for why each one is what it is. */
|
|
12
|
+
function useTalqingScreenShare() {
|
|
13
|
+
const { toggle, enabled, pending } = (0, components_react_1.useTrackToggle)({
|
|
14
|
+
source: livekit_client_1.Track.Source.ScreenShare,
|
|
15
|
+
captureOptions: client_1.TALQING_SCREEN_SHARE_CAPTURE,
|
|
16
|
+
publishOptions: client_1.TALQING_SCREEN_SHARE_PUBLISH,
|
|
17
|
+
});
|
|
18
|
+
return (0, react_1.useMemo)(() => ({
|
|
19
|
+
/** Whether a screen is being shared right now. */
|
|
20
|
+
enabled,
|
|
21
|
+
/** True while the browser picker is open or the track is publishing. */
|
|
22
|
+
pending,
|
|
23
|
+
/** Opens the browser's share picker. Must be called from a user gesture. */
|
|
24
|
+
start: () => toggle(true),
|
|
25
|
+
/** Stops sharing. The agent is told it can no longer see on the next turn. */
|
|
26
|
+
stop: () => toggle(false),
|
|
27
|
+
}), [enabled, pending, toggle]);
|
|
28
|
+
}
|
|
29
|
+
/** The video track to render for a video agent.
|
|
30
|
+
*
|
|
31
|
+
* Prefers the avatar worker's camera — the worker publishes on the agent's
|
|
32
|
+
* behalf, which is how it is identified — and falls back through the worker's
|
|
33
|
+
* screen share and then the agent's own tracks. */
|
|
34
|
+
function useTalqingAvatarTrack() {
|
|
35
|
+
const { agent } = (0, components_react_1.useVoiceAssistant)();
|
|
36
|
+
const remoteParticipants = (0, components_react_1.useRemoteParticipants)();
|
|
37
|
+
const worker = remoteParticipants.find((participant) => participant.kind === livekit_client_1.ParticipantKind.AGENT &&
|
|
38
|
+
participant.attributes["lk.publish_on_behalf"] === agent?.identity);
|
|
39
|
+
const agentTracks = (0, components_react_1.useParticipantTracks)([livekit_client_1.Track.Source.Camera, livekit_client_1.Track.Source.ScreenShare], agent?.identity);
|
|
40
|
+
const workerTracks = (0, components_react_1.useParticipantTracks)([livekit_client_1.Track.Source.Camera, livekit_client_1.Track.Source.ScreenShare], worker?.identity);
|
|
41
|
+
return (workerTracks.find((track) => track.source === livekit_client_1.Track.Source.Camera) ??
|
|
42
|
+
workerTracks.find((track) => track.source === livekit_client_1.Track.Source.ScreenShare) ??
|
|
43
|
+
agentTracks.find((track) => track.source === livekit_client_1.Track.Source.Camera) ??
|
|
44
|
+
agentTracks.find((track) => track.source === livekit_client_1.Track.Source.ScreenShare));
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=media.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"media.js","sourceRoot":"","sources":["../../src/media.ts"],"names":[],"mappings":";AAAA,YAAY,CAAC;;AAkBb,sDAmBC;AAOD,sDAgCC;AA1ED,iCAAgC;AAChC,mDAAgF;AAChF,gEAMmC;AACnC,4CAGyB;AAEzB;mFACmF;AACnF,SAAgB,qBAAqB;IACnC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,IAAA,iCAAc,EAAC;QAClD,MAAM,EAAE,sBAAK,CAAC,MAAM,CAAC,WAAW;QAChC,cAAc,EAAE,qCAA4B;QAC5C,cAAc,EAAE,qCAA4B;KAC7C,CAAC,CAAC;IACH,OAAO,IAAA,eAAO,EACZ,GAAG,EAAE,CAAC,CAAC;QACL,kDAAkD;QAClD,OAAO;QACP,wEAAwE;QACxE,OAAO;QACP,4EAA4E;QAC5E,KAAK,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC;QACzB,8EAA8E;QAC9E,IAAI,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC;KAC1B,CAAC,EACF,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,CAAC,CAC3B,CAAC;AACJ,CAAC;AA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
|
1
|
+
import { type JsonValue, type TalqingRpcHandlers } from "@talqing/client";
|
|
2
|
+
/** Handle the agent's `frontend_rpc` calls into this page.
|
|
3
|
+
*
|
|
4
|
+
* Registration waits for the room to connect and is undone on unmount. Pass
|
|
5
|
+
* `enabled: false` to hold off. */
|
|
6
|
+
export declare function useTalqingRpcHandlers(handlers: TalqingRpcHandlers, enabled?: boolean): void;
|
|
7
|
+
/** The declarative alternative: register nothing, render what arrived.
|
|
8
|
+
*
|
|
9
|
+
* Keeps the latest payload per method name and always answers the agent "ok". */
|
|
10
|
+
export declare function useTalqingFrontendRpcs(enabled?: boolean): {
|
|
11
|
+
actions: Record<string, {
|
|
12
|
+
payload?: JsonValue;
|
|
13
|
+
at: number;
|
|
14
|
+
}>;
|
|
15
|
+
clear: () => void;
|
|
16
|
+
};
|
|
17
|
+
//# sourceMappingURL=rpc.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rpc.d.ts","sourceRoot":"","sources":["../../src/rpc.ts"],"names":[],"mappings":"AAGA,OAAO,EAEL,KAAK,SAAS,EACd,KAAK,kBAAkB,EAExB,MAAM,iBAAiB,CAAC;AAGzB;;;oCAGoC;AACpC,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,kBAAkB,EAAE,OAAO,UAAO,QAOjF;AAED;;kFAEkF;AAClF,wBAAgB,sBAAsB,CAAC,OAAO,UAAO;;kBAEtB,SAAS;YAAM,MAAM;;;EA+BnD"}
|
package/dist/cjs/rpc.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
"use client";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.useTalqingRpcHandlers = useTalqingRpcHandlers;
|
|
5
|
+
exports.useTalqingFrontendRpcs = useTalqingFrontendRpcs;
|
|
6
|
+
const react_1 = require("react");
|
|
7
|
+
const client_1 = require("@talqing/client");
|
|
8
|
+
const session_js_1 = require("./session.js");
|
|
9
|
+
/** Handle the agent's `frontend_rpc` calls into this page.
|
|
10
|
+
*
|
|
11
|
+
* Registration waits for the room to connect and is undone on unmount. Pass
|
|
12
|
+
* `enabled: false` to hold off. */
|
|
13
|
+
function useTalqingRpcHandlers(handlers, enabled = true) {
|
|
14
|
+
const { room, isConnected } = (0, session_js_1.useTalqingConnection)();
|
|
15
|
+
(0, react_1.useEffect)(() => {
|
|
16
|
+
if (!enabled || !room || !isConnected)
|
|
17
|
+
return;
|
|
18
|
+
return (0, client_1.registerTalqingRpcHandlers)(room, handlers);
|
|
19
|
+
}, [enabled, handlers, isConnected, room]);
|
|
20
|
+
}
|
|
21
|
+
/** The declarative alternative: register nothing, render what arrived.
|
|
22
|
+
*
|
|
23
|
+
* Keeps the latest payload per method name and always answers the agent "ok". */
|
|
24
|
+
function useTalqingFrontendRpcs(enabled = true) {
|
|
25
|
+
const [actions, setActions] = (0, react_1.useState)({});
|
|
26
|
+
const handlers = (0, react_1.useMemo)(() => ({
|
|
27
|
+
"*": async (data) => {
|
|
28
|
+
const payload = JSON.parse(data.payload || "{}");
|
|
29
|
+
const method = String(payload.method || "");
|
|
30
|
+
if (method) {
|
|
31
|
+
setActions((current) => ({
|
|
32
|
+
...current,
|
|
33
|
+
[method]: {
|
|
34
|
+
payload: payload.payload,
|
|
35
|
+
at: Date.now(),
|
|
36
|
+
},
|
|
37
|
+
}));
|
|
38
|
+
}
|
|
39
|
+
return "ok";
|
|
40
|
+
},
|
|
41
|
+
}), []);
|
|
42
|
+
useTalqingRpcHandlers(handlers, enabled);
|
|
43
|
+
return {
|
|
44
|
+
actions,
|
|
45
|
+
clear: () => setActions({}),
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=rpc.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rpc.js","sourceRoot":"","sources":["../../src/rpc.ts"],"names":[],"mappings":";AAAA,YAAY,CAAC;;AAeb,sDAOC;AAKD,wDAiCC;A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AqB,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IAEzC,OAAO;QACL,OAAO;QACP,KAAK,EAAE,GAAG,EAAE,CAAC,UAAU,CAAC,EAAE,CAAC;KAC5B,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { Room, type RoomOptions } from "livekit-client";
|
|
3
|
+
import { type UseSessionReturn } from "@livekit/components-react";
|
|
4
|
+
import { type TalqingCallCredentials } from "@talqing/client";
|
|
5
|
+
import type { TalqingClient, TokenRequest } from "@talqing/sdk";
|
|
6
|
+
/** Everything about one web call except which agent runs it. Wire-shaped, like
|
|
7
|
+
* every other request type in this SDK. */
|
|
8
|
+
export type TalqingCallOptions = Omit<TokenRequest, "agent_id">;
|
|
9
|
+
type TalqingCallAuth =
|
|
10
|
+
/** Your server called `POST /v1/calls/token` and forwarded these two fields. */
|
|
11
|
+
{
|
|
12
|
+
token: TalqingCallCredentials;
|
|
13
|
+
fetchToken?: never;
|
|
14
|
+
client?: never;
|
|
15
|
+
agentId?: never;
|
|
16
|
+
callOptions?: never;
|
|
17
|
+
}
|
|
18
|
+
/** Your endpoint mints one. Called once, when the call starts. */
|
|
19
|
+
| {
|
|
20
|
+
fetchToken: () => Promise<TalqingCallCredentials>;
|
|
21
|
+
token?: never;
|
|
22
|
+
client?: never;
|
|
23
|
+
agentId?: never;
|
|
24
|
+
callOptions?: never;
|
|
25
|
+
}
|
|
26
|
+
/** Mint from the browser with a `TalqingClient` that already holds a
|
|
27
|
+
* credential. **Trusted first-party surfaces only** — an app that is
|
|
28
|
+
* same-origin with the API and signed in as a real editor, which is what our
|
|
29
|
+
* own dashboard is. If you are embedding a call widget for your customers,
|
|
30
|
+
* this is not your branch. */
|
|
31
|
+
| {
|
|
32
|
+
client: TalqingClient;
|
|
33
|
+
agentId: string | null;
|
|
34
|
+
/** `contact_key`, `userdata`, `vars` and the per-call agent selection.
|
|
35
|
+
* Only on this branch: on the other two the server passes them when it
|
|
36
|
+
* mints, which is what keeps a browser from choosing whose history to
|
|
37
|
+
* resume. */
|
|
38
|
+
callOptions?: TalqingCallOptions;
|
|
39
|
+
token?: never;
|
|
40
|
+
fetchToken?: never;
|
|
41
|
+
};
|
|
42
|
+
export type TalqingSessionOptions = TalqingCallAuth & {
|
|
43
|
+
roomOptions?: RoomOptions;
|
|
44
|
+
};
|
|
45
|
+
/** LiveKit's session, plus what resolving this call's plan complained about. */
|
|
46
|
+
export type TalqingSession = UseSessionReturn & {
|
|
47
|
+
/** An unreachable team member, a handoff into an agent that records when this
|
|
48
|
+
* one does not — resolved against state at CALL time, so it is not the list
|
|
49
|
+
* publishing returned. Empty until the token is minted.
|
|
50
|
+
*
|
|
51
|
+
* Populated on the `client` branch, which is the one where this browser is
|
|
52
|
+
* what minted. On the two server-minted branches your own server received
|
|
53
|
+
* them in the token response and this stays empty. */
|
|
54
|
+
warnings: string[];
|
|
55
|
+
};
|
|
56
|
+
/** One session, one call — `start()` it when this mounts and `end()` it on the
|
|
57
|
+
* way out, the lifecycle LiveKit's own session docs describe. A second call is
|
|
58
|
+
* a second mount, so give the component holding this a `key` that changes per
|
|
59
|
+
* call. Starting a finished session again would rejoin the room the last call
|
|
60
|
+
* used, which the API refuses. */
|
|
61
|
+
export declare function useTalqingSession(options: TalqingSessionOptions): TalqingSession;
|
|
62
|
+
export declare function TalqingSessionProvider({ session, children, audio, }: {
|
|
63
|
+
session: TalqingSession;
|
|
64
|
+
children: React.ReactNode;
|
|
65
|
+
audio?: boolean;
|
|
66
|
+
}): React.JSX.Element;
|
|
67
|
+
/** The call itself, read from context — and `room`, which is the supported way
|
|
68
|
+
* down to raw `livekit-client` for anything this layer does not cover. */
|
|
69
|
+
export declare function useTalqingConnection(): {
|
|
70
|
+
isConnected: boolean;
|
|
71
|
+
connectionState: import("livekit-client").ConnectionState;
|
|
72
|
+
room: Room;
|
|
73
|
+
start: (options?: import("@livekit/components-react").SessionConnectOptions) => Promise<void>;
|
|
74
|
+
end: () => Promise<void>;
|
|
75
|
+
};
|
|
76
|
+
export {};
|
|
77
|
+
//# sourceMappingURL=session.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../../src/session.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAyC,MAAM,OAAO,CAAC;AAC9D,OAAO,EAAE,IAAI,EAAE,KAAK,WAAW,EAAE,MAAM,gBAAgB,CAAC;AACxD,OAAO,EAKL,KAAK,gBAAgB,EACtB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAGL,KAAK,sBAAsB,EAC5B,MAAM,iBAAiB,CAAC;AACzB,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAEhE;4CAC4C;AAC5C,MAAM,MAAM,kBAAkB,GAAG,IAAI,CAAC,YAAY,EAAE,UAAU,CAAC,CAAC;AAmBhE,KAAK,eAAe;AAClB,gFAAgF;AAC9E;IACE,KAAK,EAAE,sBAAsB,CAAC;IAC9B,UAAU,CAAC,EAAE,KAAK,CAAC;IACnB,MAAM,CAAC,EAAE,KAAK,CAAC;IACf,OAAO,CAAC,EAAE,KAAK,CAAC;IAChB,WAAW,CAAC,EAAE,KAAK,CAAC;CACrB;AACH,kEAAkE;GAChE;IACE,UAAU,EAAE,MAAM,OAAO,CAAC,sBAAsB,CAAC,CAAC;IAClD,KAAK,CAAC,EAAE,KAAK,CAAC;IACd,MAAM,CAAC,EAAE,KAAK,CAAC;IACf,OAAO,CAAC,EAAE,KAAK,CAAC;IAChB,WAAW,CAAC,EAAE,KAAK,CAAC;CACrB;AACH;;;;+BAI+B;GAC7B;IACE,MAAM,EAAE,aAAa,CAAC;IACtB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB;;;kBAGc;IACd,WAAW,CAAC,EAAE,kBAAkB,CAAC;IACjC,KAAK,CAAC,EAAE,KAAK,CAAC;IACd,UAAU,CAAC,EAAE,KAAK,C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