@reactor-team/js-sdk 2.2.2 → 2.3.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.
- package/dist/index.d.mts +44 -13
- package/dist/index.d.ts +44 -13
- package/dist/index.js +125 -51
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +125 -51
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -3,6 +3,12 @@ import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
|
3
3
|
import React, { ReactNode } from 'react';
|
|
4
4
|
|
|
5
5
|
type ReactorStatus = "disconnected" | "connecting" | "waiting" | "ready";
|
|
6
|
+
/**
|
|
7
|
+
* The message scope identifies the envelope layer a data channel message belongs to.
|
|
8
|
+
* - "application": model-defined commands (client->runtime) and model-emitted payloads (runtime->client).
|
|
9
|
+
* - "runtime": platform-level control messages (e.g., capabilities exchange).
|
|
10
|
+
*/
|
|
11
|
+
type MessageScope = "application" | "runtime";
|
|
6
12
|
interface ReactorError {
|
|
7
13
|
code: string;
|
|
8
14
|
message: string;
|
|
@@ -18,6 +24,13 @@ interface ReactorState$1 {
|
|
|
18
24
|
status: ReactorStatus;
|
|
19
25
|
lastError?: ReactorError;
|
|
20
26
|
}
|
|
27
|
+
/**
|
|
28
|
+
* Options for configuring the connect polling behavior.
|
|
29
|
+
*/
|
|
30
|
+
interface ConnectOptions {
|
|
31
|
+
/** Maximum number of SDP polling attempts before giving up. Default: 6. */
|
|
32
|
+
maxAttempts?: number;
|
|
33
|
+
}
|
|
21
34
|
type ReactorEvent = "statusChanged" | "sessionIdChanged" | "newMessage" | "streamChanged" | "error" | "sessionExpirationChanged";
|
|
22
35
|
|
|
23
36
|
declare const PROD_COORDINATOR_URL = "https://api.reactor.inc";
|
|
@@ -45,11 +58,14 @@ declare class Reactor {
|
|
|
45
58
|
emit(event: ReactorEvent, ...args: any[]): void;
|
|
46
59
|
/**
|
|
47
60
|
* Public method to send a message to the machine.
|
|
48
|
-
*
|
|
49
|
-
* @param
|
|
61
|
+
* Wraps the message in the specified channel envelope (defaults to "application").
|
|
62
|
+
* @param command The command name to send.
|
|
63
|
+
* @param data The command payload.
|
|
64
|
+
* @param scope The envelope scope – "application" (default) for model commands,
|
|
65
|
+
* "runtime" for platform-level messages (e.g. requestCapabilities).
|
|
50
66
|
* @throws Error if not in ready state
|
|
51
67
|
*/
|
|
52
|
-
sendCommand(command: string, data: any): Promise<void>;
|
|
68
|
+
sendCommand(command: string, data: any, scope?: MessageScope): Promise<void>;
|
|
53
69
|
/**
|
|
54
70
|
* Public method to publish a track to the machine.
|
|
55
71
|
* @param track The track to send to the machine.
|
|
@@ -61,14 +77,17 @@ declare class Reactor {
|
|
|
61
77
|
unpublishTrack(): Promise<void>;
|
|
62
78
|
/**
|
|
63
79
|
* Public method for reconnecting to an existing session, that may have been interrupted but can be recovered.
|
|
80
|
+
* @param options Optional connect options (e.g. maxAttempts for SDP polling)
|
|
64
81
|
*/
|
|
65
|
-
reconnect(): Promise<void>;
|
|
82
|
+
reconnect(options?: ConnectOptions): Promise<void>;
|
|
66
83
|
/**
|
|
67
84
|
* Connects to the coordinator and waits for a GPU to be assigned.
|
|
68
85
|
* Once a GPU is assigned, the Reactor will connect to the gpu machine via WebRTC.
|
|
69
86
|
* If no authentication is provided and not in local mode, an error is thrown.
|
|
87
|
+
* @param jwtToken Optional JWT token for authentication
|
|
88
|
+
* @param options Optional connect options (e.g. maxAttempts for SDP polling)
|
|
70
89
|
*/
|
|
71
|
-
connect(jwtToken?: string): Promise<void>;
|
|
90
|
+
connect(jwtToken?: string, options?: ConnectOptions): Promise<void>;
|
|
72
91
|
/**
|
|
73
92
|
* Sets up event handlers for the machine client.
|
|
74
93
|
*/
|
|
@@ -111,12 +130,12 @@ interface ReactorState {
|
|
|
111
130
|
jwtToken?: string;
|
|
112
131
|
}
|
|
113
132
|
interface ReactorActions {
|
|
114
|
-
sendCommand(command: string, data: any): Promise<void>;
|
|
115
|
-
connect(jwtToken?: string): Promise<void>;
|
|
133
|
+
sendCommand(command: string, data: any, scope?: MessageScope): Promise<void>;
|
|
134
|
+
connect(jwtToken?: string, options?: ConnectOptions): Promise<void>;
|
|
116
135
|
disconnect(recoverable?: boolean): Promise<void>;
|
|
117
136
|
publishVideoStream(stream: MediaStream): Promise<void>;
|
|
118
137
|
unpublishVideoStream(): Promise<void>;
|
|
119
|
-
reconnect(): Promise<void>;
|
|
138
|
+
reconnect(options?: ConnectOptions): Promise<void>;
|
|
120
139
|
}
|
|
121
140
|
interface ReactorInternalState {
|
|
122
141
|
reactor: Reactor;
|
|
@@ -128,12 +147,20 @@ interface ReactorInitializationProps extends Options {
|
|
|
128
147
|
jwtToken?: string;
|
|
129
148
|
}
|
|
130
149
|
|
|
131
|
-
|
|
150
|
+
/**
|
|
151
|
+
* Options for the React provider's connect behavior.
|
|
152
|
+
* Extends the core ConnectOptions with autoConnect for the React lifecycle.
|
|
153
|
+
*/
|
|
154
|
+
interface ReactorConnectOptions extends ConnectOptions {
|
|
155
|
+
/** Whether to automatically connect when the provider mounts. Default: false. */
|
|
132
156
|
autoConnect?: boolean;
|
|
157
|
+
}
|
|
158
|
+
interface ReactorProviderProps extends ReactorInitializationProps {
|
|
159
|
+
connectOptions?: ReactorConnectOptions;
|
|
133
160
|
jwtToken?: string;
|
|
134
161
|
children: ReactNode;
|
|
135
162
|
}
|
|
136
|
-
declare function ReactorProvider({ children,
|
|
163
|
+
declare function ReactorProvider({ children, connectOptions, jwtToken, ...props }: ReactorProviderProps): react_jsx_runtime.JSX.Element;
|
|
137
164
|
declare function useReactorStore<T = ReactorStore>(selector: (state: ReactorStore) => T): T;
|
|
138
165
|
|
|
139
166
|
interface ReactorViewProps {
|
|
@@ -170,9 +197,13 @@ declare function useReactor<T>(selector: (state: ReactorStore) => T): T;
|
|
|
170
197
|
/**
|
|
171
198
|
* Hook for handling message subscriptions with proper React lifecycle management.
|
|
172
199
|
*
|
|
173
|
-
*
|
|
200
|
+
* The handler receives the message payload and the scope it arrived on:
|
|
201
|
+
* - "application" for model-defined messages (via get_ctx().send())
|
|
202
|
+
* - "runtime" for platform-level messages (e.g., capabilities response)
|
|
203
|
+
*
|
|
204
|
+
* @param handler - The message handler function (message, scope)
|
|
174
205
|
*/
|
|
175
|
-
declare function useReactorMessage(handler: (message: any) => void): void;
|
|
206
|
+
declare function useReactorMessage(handler: (message: any, scope: MessageScope) => void): void;
|
|
176
207
|
|
|
177
208
|
/**
|
|
178
209
|
* ⚠️ INSECURE: Fetches a JWT token directly from the client.
|
|
@@ -187,4 +218,4 @@ declare function useReactorMessage(handler: (message: any) => void): void;
|
|
|
187
218
|
*/
|
|
188
219
|
declare function fetchInsecureJwtToken(apiKey: string, coordinatorUrl?: string): Promise<string>;
|
|
189
220
|
|
|
190
|
-
export { ConflictError, 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 };
|
|
221
|
+
export { ConflictError, type ConnectOptions, type MessageScope, type Options, PROD_COORDINATOR_URL, Reactor, type ReactorConnectOptions, 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
|
@@ -3,6 +3,12 @@ import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
|
3
3
|
import React, { ReactNode } from 'react';
|
|
4
4
|
|
|
5
5
|
type ReactorStatus = "disconnected" | "connecting" | "waiting" | "ready";
|
|
6
|
+
/**
|
|
7
|
+
* The message scope identifies the envelope layer a data channel message belongs to.
|
|
8
|
+
* - "application": model-defined commands (client->runtime) and model-emitted payloads (runtime->client).
|
|
9
|
+
* - "runtime": platform-level control messages (e.g., capabilities exchange).
|
|
10
|
+
*/
|
|
11
|
+
type MessageScope = "application" | "runtime";
|
|
6
12
|
interface ReactorError {
|
|
7
13
|
code: string;
|
|
8
14
|
message: string;
|
|
@@ -18,6 +24,13 @@ interface ReactorState$1 {
|
|
|
18
24
|
status: ReactorStatus;
|
|
19
25
|
lastError?: ReactorError;
|
|
20
26
|
}
|
|
27
|
+
/**
|
|
28
|
+
* Options for configuring the connect polling behavior.
|
|
29
|
+
*/
|
|
30
|
+
interface ConnectOptions {
|
|
31
|
+
/** Maximum number of SDP polling attempts before giving up. Default: 6. */
|
|
32
|
+
maxAttempts?: number;
|
|
33
|
+
}
|
|
21
34
|
type ReactorEvent = "statusChanged" | "sessionIdChanged" | "newMessage" | "streamChanged" | "error" | "sessionExpirationChanged";
|
|
22
35
|
|
|
23
36
|
declare const PROD_COORDINATOR_URL = "https://api.reactor.inc";
|
|
@@ -45,11 +58,14 @@ declare class Reactor {
|
|
|
45
58
|
emit(event: ReactorEvent, ...args: any[]): void;
|
|
46
59
|
/**
|
|
47
60
|
* Public method to send a message to the machine.
|
|
48
|
-
*
|
|
49
|
-
* @param
|
|
61
|
+
* Wraps the message in the specified channel envelope (defaults to "application").
|
|
62
|
+
* @param command The command name to send.
|
|
63
|
+
* @param data The command payload.
|
|
64
|
+
* @param scope The envelope scope – "application" (default) for model commands,
|
|
65
|
+
* "runtime" for platform-level messages (e.g. requestCapabilities).
|
|
50
66
|
* @throws Error if not in ready state
|
|
51
67
|
*/
|
|
52
|
-
sendCommand(command: string, data: any): Promise<void>;
|
|
68
|
+
sendCommand(command: string, data: any, scope?: MessageScope): Promise<void>;
|
|
53
69
|
/**
|
|
54
70
|
* Public method to publish a track to the machine.
|
|
55
71
|
* @param track The track to send to the machine.
|
|
@@ -61,14 +77,17 @@ declare class Reactor {
|
|
|
61
77
|
unpublishTrack(): Promise<void>;
|
|
62
78
|
/**
|
|
63
79
|
* Public method for reconnecting to an existing session, that may have been interrupted but can be recovered.
|
|
80
|
+
* @param options Optional connect options (e.g. maxAttempts for SDP polling)
|
|
64
81
|
*/
|
|
65
|
-
reconnect(): Promise<void>;
|
|
82
|
+
reconnect(options?: ConnectOptions): Promise<void>;
|
|
66
83
|
/**
|
|
67
84
|
* Connects to the coordinator and waits for a GPU to be assigned.
|
|
68
85
|
* Once a GPU is assigned, the Reactor will connect to the gpu machine via WebRTC.
|
|
69
86
|
* If no authentication is provided and not in local mode, an error is thrown.
|
|
87
|
+
* @param jwtToken Optional JWT token for authentication
|
|
88
|
+
* @param options Optional connect options (e.g. maxAttempts for SDP polling)
|
|
70
89
|
*/
|
|
71
|
-
connect(jwtToken?: string): Promise<void>;
|
|
90
|
+
connect(jwtToken?: string, options?: ConnectOptions): Promise<void>;
|
|
72
91
|
/**
|
|
73
92
|
* Sets up event handlers for the machine client.
|
|
74
93
|
*/
|
|
@@ -111,12 +130,12 @@ interface ReactorState {
|
|
|
111
130
|
jwtToken?: string;
|
|
112
131
|
}
|
|
113
132
|
interface ReactorActions {
|
|
114
|
-
sendCommand(command: string, data: any): Promise<void>;
|
|
115
|
-
connect(jwtToken?: string): Promise<void>;
|
|
133
|
+
sendCommand(command: string, data: any, scope?: MessageScope): Promise<void>;
|
|
134
|
+
connect(jwtToken?: string, options?: ConnectOptions): Promise<void>;
|
|
116
135
|
disconnect(recoverable?: boolean): Promise<void>;
|
|
117
136
|
publishVideoStream(stream: MediaStream): Promise<void>;
|
|
118
137
|
unpublishVideoStream(): Promise<void>;
|
|
119
|
-
reconnect(): Promise<void>;
|
|
138
|
+
reconnect(options?: ConnectOptions): Promise<void>;
|
|
120
139
|
}
|
|
121
140
|
interface ReactorInternalState {
|
|
122
141
|
reactor: Reactor;
|
|
@@ -128,12 +147,20 @@ interface ReactorInitializationProps extends Options {
|
|
|
128
147
|
jwtToken?: string;
|
|
129
148
|
}
|
|
130
149
|
|
|
131
|
-
|
|
150
|
+
/**
|
|
151
|
+
* Options for the React provider's connect behavior.
|
|
152
|
+
* Extends the core ConnectOptions with autoConnect for the React lifecycle.
|
|
153
|
+
*/
|
|
154
|
+
interface ReactorConnectOptions extends ConnectOptions {
|
|
155
|
+
/** Whether to automatically connect when the provider mounts. Default: false. */
|
|
132
156
|
autoConnect?: boolean;
|
|
157
|
+
}
|
|
158
|
+
interface ReactorProviderProps extends ReactorInitializationProps {
|
|
159
|
+
connectOptions?: ReactorConnectOptions;
|
|
133
160
|
jwtToken?: string;
|
|
134
161
|
children: ReactNode;
|
|
135
162
|
}
|
|
136
|
-
declare function ReactorProvider({ children,
|
|
163
|
+
declare function ReactorProvider({ children, connectOptions, jwtToken, ...props }: ReactorProviderProps): react_jsx_runtime.JSX.Element;
|
|
137
164
|
declare function useReactorStore<T = ReactorStore>(selector: (state: ReactorStore) => T): T;
|
|
138
165
|
|
|
139
166
|
interface ReactorViewProps {
|
|
@@ -170,9 +197,13 @@ declare function useReactor<T>(selector: (state: ReactorStore) => T): T;
|
|
|
170
197
|
/**
|
|
171
198
|
* Hook for handling message subscriptions with proper React lifecycle management.
|
|
172
199
|
*
|
|
173
|
-
*
|
|
200
|
+
* The handler receives the message payload and the scope it arrived on:
|
|
201
|
+
* - "application" for model-defined messages (via get_ctx().send())
|
|
202
|
+
* - "runtime" for platform-level messages (e.g., capabilities response)
|
|
203
|
+
*
|
|
204
|
+
* @param handler - The message handler function (message, scope)
|
|
174
205
|
*/
|
|
175
|
-
declare function useReactorMessage(handler: (message: any) => void): void;
|
|
206
|
+
declare function useReactorMessage(handler: (message: any, scope: MessageScope) => void): void;
|
|
176
207
|
|
|
177
208
|
/**
|
|
178
209
|
* ⚠️ INSECURE: Fetches a JWT token directly from the client.
|
|
@@ -187,4 +218,4 @@ declare function useReactorMessage(handler: (message: any) => void): void;
|
|
|
187
218
|
*/
|
|
188
219
|
declare function fetchInsecureJwtToken(apiKey: string, coordinatorUrl?: string): Promise<string>;
|
|
189
220
|
|
|
190
|
-
export { ConflictError, 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 };
|
|
221
|
+
export { ConflictError, type ConnectOptions, type MessageScope, type Options, PROD_COORDINATOR_URL, Reactor, type ReactorConnectOptions, ReactorController, type ReactorControllerProps, type ReactorError, type ReactorEvent, ReactorProvider, type ReactorState$1 as ReactorState, type ReactorStatus, ReactorView, type ReactorViewProps, WebcamStream, fetchInsecureJwtToken, useReactor, useReactorMessage, useReactorStore };
|