@reactor-team/js-sdk 1.0.22 → 2.0.1
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 +2 -51
- package/dist/index.d.mts +14 -1
- package/dist/index.d.ts +14 -1
- package/dist/index.js +27 -195
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +26 -195
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -4
package/README.md
CHANGED
|
@@ -9,61 +9,12 @@ There are two main ways to use the frontend SDK:
|
|
|
9
9
|
1. **Imperative API**: Use it in any TS/JS application.
|
|
10
10
|
2. **React API**: Use it in a React applications.
|
|
11
11
|
|
|
12
|
-
## Setup
|
|
13
|
-
|
|
14
|
-
### Fetching Protobuf Types
|
|
15
|
-
|
|
16
|
-
The SDK uses generated TypeScript types from the [reactor-proto](https://github.com/reactor-team/reactor-proto) repository. These are fetched from GitHub releases and placed in `src/generated/`.
|
|
17
|
-
|
|
18
|
-
1. Set your GitHub token (required for private repo access):
|
|
19
|
-
|
|
20
|
-
```bash
|
|
21
|
-
export GH_TOKEN=your_github_token
|
|
22
|
-
```
|
|
23
|
-
|
|
24
|
-
2. Fetch the protobuf types:
|
|
25
|
-
|
|
26
|
-
```bash
|
|
27
|
-
pnpm proto
|
|
28
|
-
```
|
|
29
|
-
|
|
30
|
-
This will download the types matching the version specified in `package.json` under `protobufsVersion`.
|
|
31
|
-
|
|
32
|
-
### Updating Protobuf Version
|
|
33
|
-
|
|
34
|
-
To update to a new protobuf version:
|
|
35
|
-
|
|
36
|
-
1. Update `protobufsVersion` in `package.json` to the new semver (e.g., `"0.3.4"`)
|
|
37
|
-
2. Run `pnpm proto` to fetch the new types
|
|
38
|
-
|
|
39
|
-
### Cleaning Generated Files
|
|
40
|
-
|
|
41
|
-
To remove the generated protobuf types:
|
|
42
|
-
|
|
43
|
-
```bash
|
|
44
|
-
pnpm clean
|
|
45
|
-
```
|
|
46
|
-
|
|
47
12
|
## Building the SDK
|
|
48
13
|
|
|
49
|
-
Set up the environment variables:
|
|
50
|
-
|
|
51
|
-
```bash
|
|
52
|
-
cp .env.example .env
|
|
53
|
-
```
|
|
54
|
-
|
|
55
|
-
Then add your NPM_TOKEN to the .env file.
|
|
56
|
-
|
|
57
|
-
Build the SDK:
|
|
58
|
-
|
|
59
14
|
```bash
|
|
60
15
|
pnpm build
|
|
61
16
|
```
|
|
62
17
|
|
|
63
|
-
##
|
|
18
|
+
## Documentation
|
|
64
19
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
```bash
|
|
68
|
-
./publish_package.sh
|
|
69
|
-
```
|
|
20
|
+
- [Getting Started](https://docs.reactor.inc)
|
package/dist/index.d.mts
CHANGED
|
@@ -171,4 +171,17 @@ declare function useReactor<T>(selector: (state: ReactorStore) => T): T;
|
|
|
171
171
|
*/
|
|
172
172
|
declare function useReactorMessage(handler: (message: any) => void): void;
|
|
173
173
|
|
|
174
|
-
|
|
174
|
+
/**
|
|
175
|
+
* ⚠️ INSECURE: Fetches a JWT token directly from the client.
|
|
176
|
+
*
|
|
177
|
+
* WARNING: This function exposes your API key in client-side code.
|
|
178
|
+
* Only use this for local development or testing purposes.
|
|
179
|
+
* In production, call /tokens from your server and pass the JWT to your frontend.
|
|
180
|
+
*
|
|
181
|
+
* @param apiKey - Your Reactor API key (will be exposed in client code!)
|
|
182
|
+
* @param coordinatorUrl - Optional coordinator URL, defaults to production
|
|
183
|
+
* @returns string containing the JWT token
|
|
184
|
+
*/
|
|
185
|
+
declare function fetchInsecureJwtToken(apiKey: string, coordinatorUrl?: string): Promise<string>;
|
|
186
|
+
|
|
187
|
+
export { type Options, PROD_COORDINATOR_URL, Reactor, ReactorController, type ReactorControllerProps, type ReactorError, type ReactorEvent, ReactorProvider, type ReactorState$1 as ReactorState, type ReactorStatus, ReactorView, type ReactorViewProps, WebcamStream, fetchInsecureJwtToken, useReactor, useReactorMessage, useReactorStore };
|
package/dist/index.d.ts
CHANGED
|
@@ -171,4 +171,17 @@ declare function useReactor<T>(selector: (state: ReactorStore) => T): T;
|
|
|
171
171
|
*/
|
|
172
172
|
declare function useReactorMessage(handler: (message: any) => void): void;
|
|
173
173
|
|
|
174
|
-
|
|
174
|
+
/**
|
|
175
|
+
* ⚠️ INSECURE: Fetches a JWT token directly from the client.
|
|
176
|
+
*
|
|
177
|
+
* WARNING: This function exposes your API key in client-side code.
|
|
178
|
+
* Only use this for local development or testing purposes.
|
|
179
|
+
* In production, call /tokens from your server and pass the JWT to your frontend.
|
|
180
|
+
*
|
|
181
|
+
* @param apiKey - Your Reactor API key (will be exposed in client code!)
|
|
182
|
+
* @param coordinatorUrl - Optional coordinator URL, defaults to production
|
|
183
|
+
* @returns string containing the JWT token
|
|
184
|
+
*/
|
|
185
|
+
declare function fetchInsecureJwtToken(apiKey: string, coordinatorUrl?: string): Promise<string>;
|
|
186
|
+
|
|
187
|
+
export { type Options, PROD_COORDINATOR_URL, Reactor, ReactorController, type ReactorControllerProps, type ReactorError, type ReactorEvent, ReactorProvider, type ReactorState$1 as ReactorState, type ReactorStatus, ReactorView, type ReactorViewProps, WebcamStream, fetchInsecureJwtToken, useReactor, useReactorMessage, useReactorStore };
|
package/dist/index.js
CHANGED
|
@@ -85,195 +85,13 @@ __export(index_exports, {
|
|
|
85
85
|
ReactorProvider: () => ReactorProvider,
|
|
86
86
|
ReactorView: () => ReactorView,
|
|
87
87
|
WebcamStream: () => WebcamStream,
|
|
88
|
+
fetchInsecureJwtToken: () => fetchInsecureJwtToken,
|
|
88
89
|
useReactor: () => useReactor,
|
|
89
90
|
useReactorMessage: () => useReactorMessage,
|
|
90
91
|
useReactorStore: () => useReactorStore
|
|
91
92
|
});
|
|
92
93
|
module.exports = __toCommonJS(index_exports);
|
|
93
94
|
|
|
94
|
-
// src/generated/api/types/api_types.ts
|
|
95
|
-
var import_wire2 = require("@bufbuild/protobuf/wire");
|
|
96
|
-
|
|
97
|
-
// src/generated/api/types/base.ts
|
|
98
|
-
var import_wire = require("@bufbuild/protobuf/wire");
|
|
99
|
-
|
|
100
|
-
// src/generated/api/types/api_types.ts
|
|
101
|
-
function createBaseSDPParamsResponse() {
|
|
102
|
-
return { sdpAnswer: "", extraArgs: {} };
|
|
103
|
-
}
|
|
104
|
-
var SDPParamsResponse = {
|
|
105
|
-
encode(message, writer = new import_wire2.BinaryWriter()) {
|
|
106
|
-
if (message.sdpAnswer !== "") {
|
|
107
|
-
writer.uint32(10).string(message.sdpAnswer);
|
|
108
|
-
}
|
|
109
|
-
globalThis.Object.entries(message.extraArgs).forEach(
|
|
110
|
-
([key, value]) => {
|
|
111
|
-
SDPParamsResponse_ExtraArgsEntry.encode(
|
|
112
|
-
{ key, value },
|
|
113
|
-
writer.uint32(18).fork()
|
|
114
|
-
).join();
|
|
115
|
-
}
|
|
116
|
-
);
|
|
117
|
-
return writer;
|
|
118
|
-
},
|
|
119
|
-
decode(input, length) {
|
|
120
|
-
const reader = input instanceof import_wire2.BinaryReader ? input : new import_wire2.BinaryReader(input);
|
|
121
|
-
const end = length === void 0 ? reader.len : reader.pos + length;
|
|
122
|
-
const message = createBaseSDPParamsResponse();
|
|
123
|
-
while (reader.pos < end) {
|
|
124
|
-
const tag = reader.uint32();
|
|
125
|
-
switch (tag >>> 3) {
|
|
126
|
-
case 1: {
|
|
127
|
-
if (tag !== 10) {
|
|
128
|
-
break;
|
|
129
|
-
}
|
|
130
|
-
message.sdpAnswer = reader.string();
|
|
131
|
-
continue;
|
|
132
|
-
}
|
|
133
|
-
case 2: {
|
|
134
|
-
if (tag !== 18) {
|
|
135
|
-
break;
|
|
136
|
-
}
|
|
137
|
-
const entry2 = SDPParamsResponse_ExtraArgsEntry.decode(
|
|
138
|
-
reader,
|
|
139
|
-
reader.uint32()
|
|
140
|
-
);
|
|
141
|
-
if (entry2.value !== void 0) {
|
|
142
|
-
message.extraArgs[entry2.key] = entry2.value;
|
|
143
|
-
}
|
|
144
|
-
continue;
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
if ((tag & 7) === 4 || tag === 0) {
|
|
148
|
-
break;
|
|
149
|
-
}
|
|
150
|
-
reader.skip(tag & 7);
|
|
151
|
-
}
|
|
152
|
-
return message;
|
|
153
|
-
},
|
|
154
|
-
fromJSON(object) {
|
|
155
|
-
return {
|
|
156
|
-
sdpAnswer: isSet(object.sdpAnswer) ? globalThis.String(object.sdpAnswer) : "",
|
|
157
|
-
extraArgs: isObject(object.extraArgs) ? globalThis.Object.entries(object.extraArgs).reduce(
|
|
158
|
-
(acc, [key, value]) => {
|
|
159
|
-
acc[key] = globalThis.String(value);
|
|
160
|
-
return acc;
|
|
161
|
-
},
|
|
162
|
-
{}
|
|
163
|
-
) : {}
|
|
164
|
-
};
|
|
165
|
-
},
|
|
166
|
-
toJSON(message) {
|
|
167
|
-
const obj = {};
|
|
168
|
-
if (message.sdpAnswer !== "") {
|
|
169
|
-
obj.sdpAnswer = message.sdpAnswer;
|
|
170
|
-
}
|
|
171
|
-
if (message.extraArgs) {
|
|
172
|
-
const entries = globalThis.Object.entries(message.extraArgs);
|
|
173
|
-
if (entries.length > 0) {
|
|
174
|
-
obj.extraArgs = {};
|
|
175
|
-
entries.forEach(([k, v]) => {
|
|
176
|
-
obj.extraArgs[k] = v;
|
|
177
|
-
});
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
return obj;
|
|
181
|
-
},
|
|
182
|
-
create(base) {
|
|
183
|
-
return SDPParamsResponse.fromPartial(base != null ? base : {});
|
|
184
|
-
},
|
|
185
|
-
fromPartial(object) {
|
|
186
|
-
var _a, _b;
|
|
187
|
-
const message = createBaseSDPParamsResponse();
|
|
188
|
-
message.sdpAnswer = (_a = object.sdpAnswer) != null ? _a : "";
|
|
189
|
-
message.extraArgs = globalThis.Object.entries((_b = object.extraArgs) != null ? _b : {}).reduce(
|
|
190
|
-
(acc, [key, value]) => {
|
|
191
|
-
if (value !== void 0) {
|
|
192
|
-
acc[key] = globalThis.String(value);
|
|
193
|
-
}
|
|
194
|
-
return acc;
|
|
195
|
-
},
|
|
196
|
-
{}
|
|
197
|
-
);
|
|
198
|
-
return message;
|
|
199
|
-
}
|
|
200
|
-
};
|
|
201
|
-
function createBaseSDPParamsResponse_ExtraArgsEntry() {
|
|
202
|
-
return { key: "", value: "" };
|
|
203
|
-
}
|
|
204
|
-
var SDPParamsResponse_ExtraArgsEntry = {
|
|
205
|
-
encode(message, writer = new import_wire2.BinaryWriter()) {
|
|
206
|
-
if (message.key !== "") {
|
|
207
|
-
writer.uint32(10).string(message.key);
|
|
208
|
-
}
|
|
209
|
-
if (message.value !== "") {
|
|
210
|
-
writer.uint32(18).string(message.value);
|
|
211
|
-
}
|
|
212
|
-
return writer;
|
|
213
|
-
},
|
|
214
|
-
decode(input, length) {
|
|
215
|
-
const reader = input instanceof import_wire2.BinaryReader ? input : new import_wire2.BinaryReader(input);
|
|
216
|
-
const end = length === void 0 ? reader.len : reader.pos + length;
|
|
217
|
-
const message = createBaseSDPParamsResponse_ExtraArgsEntry();
|
|
218
|
-
while (reader.pos < end) {
|
|
219
|
-
const tag = reader.uint32();
|
|
220
|
-
switch (tag >>> 3) {
|
|
221
|
-
case 1: {
|
|
222
|
-
if (tag !== 10) {
|
|
223
|
-
break;
|
|
224
|
-
}
|
|
225
|
-
message.key = reader.string();
|
|
226
|
-
continue;
|
|
227
|
-
}
|
|
228
|
-
case 2: {
|
|
229
|
-
if (tag !== 18) {
|
|
230
|
-
break;
|
|
231
|
-
}
|
|
232
|
-
message.value = reader.string();
|
|
233
|
-
continue;
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
if ((tag & 7) === 4 || tag === 0) {
|
|
237
|
-
break;
|
|
238
|
-
}
|
|
239
|
-
reader.skip(tag & 7);
|
|
240
|
-
}
|
|
241
|
-
return message;
|
|
242
|
-
},
|
|
243
|
-
fromJSON(object) {
|
|
244
|
-
return {
|
|
245
|
-
key: isSet(object.key) ? globalThis.String(object.key) : "",
|
|
246
|
-
value: isSet(object.value) ? globalThis.String(object.value) : ""
|
|
247
|
-
};
|
|
248
|
-
},
|
|
249
|
-
toJSON(message) {
|
|
250
|
-
const obj = {};
|
|
251
|
-
if (message.key !== "") {
|
|
252
|
-
obj.key = message.key;
|
|
253
|
-
}
|
|
254
|
-
if (message.value !== "") {
|
|
255
|
-
obj.value = message.value;
|
|
256
|
-
}
|
|
257
|
-
return obj;
|
|
258
|
-
},
|
|
259
|
-
create(base) {
|
|
260
|
-
return SDPParamsResponse_ExtraArgsEntry.fromPartial(base != null ? base : {});
|
|
261
|
-
},
|
|
262
|
-
fromPartial(object) {
|
|
263
|
-
var _a, _b;
|
|
264
|
-
const message = createBaseSDPParamsResponse_ExtraArgsEntry();
|
|
265
|
-
message.key = (_a = object.key) != null ? _a : "";
|
|
266
|
-
message.value = (_b = object.value) != null ? _b : "";
|
|
267
|
-
return message;
|
|
268
|
-
}
|
|
269
|
-
};
|
|
270
|
-
function isObject(value) {
|
|
271
|
-
return typeof value === "object" && value !== null;
|
|
272
|
-
}
|
|
273
|
-
function isSet(value) {
|
|
274
|
-
return value !== null && value !== void 0;
|
|
275
|
-
}
|
|
276
|
-
|
|
277
95
|
// src/core/CoordinatorClient.ts
|
|
278
96
|
var INITIAL_BACKOFF_MS = 500;
|
|
279
97
|
var MAX_BACKOFF_MS = 3e4;
|
|
@@ -312,7 +130,7 @@ var CoordinatorClient = class {
|
|
|
312
130
|
}),
|
|
313
131
|
body: JSON.stringify(requestBody)
|
|
314
132
|
});
|
|
315
|
-
if (response.
|
|
133
|
+
if (!response.ok) {
|
|
316
134
|
const errorText = yield response.text();
|
|
317
135
|
throw new Error(
|
|
318
136
|
`Failed to create session: ${response.status} ${errorText}`
|
|
@@ -347,7 +165,7 @@ var CoordinatorClient = class {
|
|
|
347
165
|
headers: this.getAuthHeaders()
|
|
348
166
|
}
|
|
349
167
|
);
|
|
350
|
-
if (response.
|
|
168
|
+
if (!response.ok) {
|
|
351
169
|
const errorText = yield response.text();
|
|
352
170
|
throw new Error(`Failed to get session: ${response.status} ${errorText}`);
|
|
353
171
|
}
|
|
@@ -375,13 +193,7 @@ var CoordinatorClient = class {
|
|
|
375
193
|
headers: this.getAuthHeaders()
|
|
376
194
|
}
|
|
377
195
|
);
|
|
378
|
-
if (response.
|
|
379
|
-
const data = yield response.json();
|
|
380
|
-
console.debug(
|
|
381
|
-
"[CoordinatorClient] Session terminated:",
|
|
382
|
-
data.session_id,
|
|
383
|
-
data.status
|
|
384
|
-
);
|
|
196
|
+
if (response.ok) {
|
|
385
197
|
this.currentSessionId = void 0;
|
|
386
198
|
return;
|
|
387
199
|
}
|
|
@@ -477,9 +289,7 @@ var CoordinatorClient = class {
|
|
|
477
289
|
}
|
|
478
290
|
);
|
|
479
291
|
if (response.status === 200) {
|
|
480
|
-
const answerData =
|
|
481
|
-
yield response.json()
|
|
482
|
-
);
|
|
292
|
+
const answerData = yield response.json();
|
|
483
293
|
console.debug("[CoordinatorClient] Received SDP answer via polling");
|
|
484
294
|
return answerData.sdp_answer;
|
|
485
295
|
}
|
|
@@ -2319,6 +2129,27 @@ function WebcamStream({
|
|
|
2319
2129
|
}
|
|
2320
2130
|
);
|
|
2321
2131
|
}
|
|
2132
|
+
|
|
2133
|
+
// src/utils/tokens.ts
|
|
2134
|
+
function fetchInsecureJwtToken(_0) {
|
|
2135
|
+
return __async(this, arguments, function* (apiKey, coordinatorUrl = PROD_COORDINATOR_URL) {
|
|
2136
|
+
console.warn(
|
|
2137
|
+
"[Reactor] \u26A0\uFE0F SECURITY WARNING: fetchInsecureJwtToken() exposes your API key in client-side code. This should ONLY be used for local development or testing. In production, fetch tokens from your server instead."
|
|
2138
|
+
);
|
|
2139
|
+
const response = yield fetch(`${coordinatorUrl}/tokens`, {
|
|
2140
|
+
method: "GET",
|
|
2141
|
+
headers: {
|
|
2142
|
+
"X-API-Key": apiKey
|
|
2143
|
+
}
|
|
2144
|
+
});
|
|
2145
|
+
if (!response.ok) {
|
|
2146
|
+
const error = yield response.text();
|
|
2147
|
+
throw new Error(`Failed to create token: ${response.status} ${error}`);
|
|
2148
|
+
}
|
|
2149
|
+
const { jwt } = yield response.json();
|
|
2150
|
+
return jwt;
|
|
2151
|
+
});
|
|
2152
|
+
}
|
|
2322
2153
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2323
2154
|
0 && (module.exports = {
|
|
2324
2155
|
PROD_COORDINATOR_URL,
|
|
@@ -2327,6 +2158,7 @@ function WebcamStream({
|
|
|
2327
2158
|
ReactorProvider,
|
|
2328
2159
|
ReactorView,
|
|
2329
2160
|
WebcamStream,
|
|
2161
|
+
fetchInsecureJwtToken,
|
|
2330
2162
|
useReactor,
|
|
2331
2163
|
useReactorMessage,
|
|
2332
2164
|
useReactorStore
|