@reactor-team/js-sdk 1.0.19 → 2.0.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/README.md CHANGED
@@ -21,6 +21,14 @@ Then add your NPM_TOKEN to the .env file.
21
21
 
22
22
  Build the SDK:
23
23
 
24
+ ```bash
25
+ pnpm build
26
+ ```
27
+
28
+ ## Publishing
29
+
30
+ To publish the SDK:
31
+
24
32
  ```bash
25
33
  ./publish_package.sh
26
34
  ```
package/dist/index.d.mts CHANGED
@@ -1,31 +1,8 @@
1
- import z$1, { z } from 'zod';
1
+ import { z } from 'zod';
2
2
  import * as react_jsx_runtime from 'react/jsx-runtime';
3
3
  import React, { ReactNode } from 'react';
4
- import { RemoteVideoTrack } from 'livekit-client';
5
-
6
- /**
7
- * Internal types for the Reactor SDK.
8
- */
9
-
10
- declare const WaitingInfoDataSchema: z.ZodObject<{
11
- position: z.ZodOptional<z.ZodNumber>;
12
- estimatedWaitTime: z.ZodOptional<z.ZodNumber>;
13
- averageWaitTime: z.ZodOptional<z.ZodNumber>;
14
- }, z.core.$strip>;
15
- declare const SessionExpirationDataSchema: z.ZodObject<{
16
- expire: z.ZodNumber;
17
- }, z.core.$strip>;
18
- declare const ReactorAuthSchema: z.ZodObject<{
19
- insecureApiKey: z.ZodOptional<z.ZodString>;
20
- jwtToken: z.ZodOptional<z.ZodString>;
21
- }, z.core.$strip>;
22
- type ReactorAuth = z.infer<typeof ReactorAuthSchema>;
23
4
 
24
5
  type ReactorStatus = "disconnected" | "connecting" | "waiting" | "ready";
25
- interface ReactorWaitingInfo extends z$1.infer<typeof WaitingInfoDataSchema> {
26
- }
27
- interface ReactorSessionExpiration extends z$1.infer<typeof SessionExpirationDataSchema> {
28
- }
29
6
  interface ReactorError {
30
7
  code: string;
31
8
  message: string;
@@ -36,15 +13,14 @@ interface ReactorError {
36
13
  }
37
14
  interface ReactorState$1 {
38
15
  status: ReactorStatus;
39
- waitingInfo?: ReactorWaitingInfo;
40
16
  lastError?: ReactorError;
41
17
  }
42
- type ReactorEvent = "statusChanged" | "waitingInfoChanged" | "newMessage" | "fps" | "streamChanged" | "error" | "sessionExpirationChanged";
18
+ type ReactorEvent = "statusChanged" | "sessionIdChanged" | "newMessage" | "streamChanged" | "error" | "sessionExpirationChanged";
43
19
 
20
+ declare const PROD_COORDINATOR_URL = "https://api.reactor.inc";
44
21
  declare const OptionsSchema: z.ZodObject<{
45
22
  coordinatorUrl: z.ZodDefault<z.ZodString>;
46
23
  modelName: z.ZodString;
47
- queueing: z.ZodDefault<z.ZodBoolean>;
48
24
  local: z.ZodDefault<z.ZodBoolean>;
49
25
  }, z.core.$strip>;
50
26
  type Options = z.input<typeof OptionsSchema>;
@@ -55,12 +31,10 @@ declare class Reactor {
55
31
  private status;
56
32
  private coordinatorUrl;
57
33
  private lastError?;
58
- private waitingInfo?;
59
- private modelName;
60
- private modelVersion;
61
- private queueing;
34
+ private model;
62
35
  private sessionExpiration?;
63
36
  private local;
37
+ private sessionId?;
64
38
  constructor(options: Options);
65
39
  private eventListeners;
66
40
  on(event: ReactorEvent, handler: EventHandler): void;
@@ -72,51 +46,48 @@ declare class Reactor {
72
46
  * @param message The message to send to the machine.
73
47
  * @throws Error if not in ready state
74
48
  */
75
- sendMessage(message: any): Promise<void>;
49
+ sendCommand(command: string, data: any): Promise<void>;
76
50
  /**
77
- * Public method to publish a video stream to the machine.
78
- * @param videoStream The video stream to send to the machine.
51
+ * Public method to publish a track to the machine.
52
+ * @param track The track to send to the machine.
79
53
  */
80
- publishVideoStream(videoStream: MediaStream): Promise<void>;
54
+ publishTrack(track: MediaStreamTrack): Promise<void>;
81
55
  /**
82
- * Public method to unpublish video stream to the machine.
83
- * This unpublishes the video track that was previously sent.
56
+ * Public method to unpublish the currently published track.
84
57
  */
85
- unpublishVideoStream(): Promise<void>;
58
+ unpublishTrack(): Promise<void>;
86
59
  /**
87
- * Connects to the machine via LiveKit and waits for the gpu machine to be ready.
88
- * Once the machine is ready, the Reactor will establish the LiveKit connection.
89
- * @param livekitJwtToken The JWT token for LiveKit authentication
90
- * @param livekitWsUrl The WebSocket URL for LiveKit connection
60
+ * Public method for reconnecting to an existing session, that may have been interrupted but can be recovered.
91
61
  */
92
- private connectToGPUMachine;
62
+ reconnect(): Promise<void>;
93
63
  /**
94
64
  * Connects to the coordinator and waits for a GPU to be assigned.
95
- * Once a GPU is assigned, the Reactor will connect to the gpu machine via LiveKit.
65
+ * Once a GPU is assigned, the Reactor will connect to the gpu machine via WebRTC.
96
66
  * If no authentication is provided and not in local mode, an error is thrown.
97
67
  */
98
- connect(auth?: ReactorAuth): Promise<void>;
68
+ connect(jwtToken?: string): Promise<void>;
69
+ /**
70
+ * Sets up event handlers for the machine client.
71
+ */
72
+ private setupMachineClientHandlers;
99
73
  /**
100
74
  * Disconnects from the coordinator and the gpu machine.
101
75
  * Ensures cleanup completes even if individual disconnections fail.
102
76
  */
103
- disconnect(): Promise<void>;
77
+ disconnect(recoverable?: boolean): Promise<void>;
78
+ private setSessionId;
79
+ getSessionId(): string | undefined;
104
80
  private setStatus;
105
- private setWaitingInfo;
81
+ getStatus(): ReactorStatus;
106
82
  /**
107
83
  * Set the session expiration time.
108
84
  * @param newSessionExpiration The new session expiration time in seconds.
109
85
  */
110
86
  private setSessionExpiration;
111
- getStatus(): ReactorStatus;
112
87
  /**
113
88
  * Get the current state including status, error, and waiting info
114
89
  */
115
90
  getState(): ReactorState$1;
116
- /**
117
- * Get waiting information when status is 'waiting'
118
- */
119
- getWaitingInfo(): ReactorWaitingInfo | undefined;
120
91
  /**
121
92
  * Get the last error that occurred
122
93
  */
@@ -129,20 +100,20 @@ declare class Reactor {
129
100
 
130
101
  interface ReactorState {
131
102
  status: ReactorStatus;
132
- videoTrack: RemoteVideoTrack | null;
133
- fps?: number;
134
- waitingInfo?: ReactorWaitingInfo;
103
+ videoTrack: MediaStreamTrack | null;
135
104
  lastError?: ReactorError;
105
+ sessionId?: string;
136
106
  sessionExpiration?: number;
137
107
  insecureApiKey?: string;
138
108
  jwtToken?: string;
139
109
  }
140
110
  interface ReactorActions {
141
- sendMessage(message: any): Promise<void>;
142
- connect(auth?: ReactorAuth): Promise<void>;
143
- disconnect(): Promise<void>;
111
+ sendCommand(command: string, data: any): Promise<void>;
112
+ connect(jwtToken?: string): Promise<void>;
113
+ disconnect(recoverable?: boolean): Promise<void>;
144
114
  publishVideoStream(stream: MediaStream): Promise<void>;
145
115
  unpublishVideoStream(): Promise<void>;
116
+ reconnect(): Promise<void>;
146
117
  }
147
118
  interface ReactorInternalState {
148
119
  reactor: Reactor;
@@ -151,17 +122,15 @@ type ReactorStore = ReactorState & ReactorActions & {
151
122
  internal: ReactorInternalState;
152
123
  };
153
124
  interface ReactorInitializationProps extends Options {
154
- insecureApiKey?: string;
155
125
  jwtToken?: string;
156
126
  }
157
127
 
158
128
  interface ReactorProviderProps extends ReactorInitializationProps {
159
129
  autoConnect?: boolean;
160
- insecureApiKey?: string;
161
130
  jwtToken?: string;
162
131
  children: ReactNode;
163
132
  }
164
- declare function ReactorProvider({ children, autoConnect, insecureApiKey, jwtToken, ...props }: ReactorProviderProps): react_jsx_runtime.JSX.Element;
133
+ declare function ReactorProvider({ children, autoConnect, jwtToken, ...props }: ReactorProviderProps): react_jsx_runtime.JSX.Element;
165
134
  declare function useReactorStore<T = ReactorStore>(selector: (state: ReactorStore) => T): T;
166
135
 
167
136
  interface ReactorViewProps {
@@ -202,4 +171,4 @@ declare function useReactor<T>(selector: (state: ReactorStore) => T): T;
202
171
  */
203
172
  declare function useReactorMessage(handler: (message: any) => void): void;
204
173
 
205
- export { type Options, Reactor, ReactorController, type ReactorControllerProps, type ReactorError, type ReactorEvent, ReactorProvider, type ReactorSessionExpiration, type ReactorState$1 as ReactorState, type ReactorStatus, ReactorView, type ReactorViewProps, type ReactorWaitingInfo, WebcamStream, useReactor, useReactorMessage, useReactorStore };
174
+ 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, useReactor, useReactorMessage, useReactorStore };
package/dist/index.d.ts CHANGED
@@ -1,31 +1,8 @@
1
- import z$1, { z } from 'zod';
1
+ import { z } from 'zod';
2
2
  import * as react_jsx_runtime from 'react/jsx-runtime';
3
3
  import React, { ReactNode } from 'react';
4
- import { RemoteVideoTrack } from 'livekit-client';
5
-
6
- /**
7
- * Internal types for the Reactor SDK.
8
- */
9
-
10
- declare const WaitingInfoDataSchema: z.ZodObject<{
11
- position: z.ZodOptional<z.ZodNumber>;
12
- estimatedWaitTime: z.ZodOptional<z.ZodNumber>;
13
- averageWaitTime: z.ZodOptional<z.ZodNumber>;
14
- }, z.core.$strip>;
15
- declare const SessionExpirationDataSchema: z.ZodObject<{
16
- expire: z.ZodNumber;
17
- }, z.core.$strip>;
18
- declare const ReactorAuthSchema: z.ZodObject<{
19
- insecureApiKey: z.ZodOptional<z.ZodString>;
20
- jwtToken: z.ZodOptional<z.ZodString>;
21
- }, z.core.$strip>;
22
- type ReactorAuth = z.infer<typeof ReactorAuthSchema>;
23
4
 
24
5
  type ReactorStatus = "disconnected" | "connecting" | "waiting" | "ready";
25
- interface ReactorWaitingInfo extends z$1.infer<typeof WaitingInfoDataSchema> {
26
- }
27
- interface ReactorSessionExpiration extends z$1.infer<typeof SessionExpirationDataSchema> {
28
- }
29
6
  interface ReactorError {
30
7
  code: string;
31
8
  message: string;
@@ -36,15 +13,14 @@ interface ReactorError {
36
13
  }
37
14
  interface ReactorState$1 {
38
15
  status: ReactorStatus;
39
- waitingInfo?: ReactorWaitingInfo;
40
16
  lastError?: ReactorError;
41
17
  }
42
- type ReactorEvent = "statusChanged" | "waitingInfoChanged" | "newMessage" | "fps" | "streamChanged" | "error" | "sessionExpirationChanged";
18
+ type ReactorEvent = "statusChanged" | "sessionIdChanged" | "newMessage" | "streamChanged" | "error" | "sessionExpirationChanged";
43
19
 
20
+ declare const PROD_COORDINATOR_URL = "https://api.reactor.inc";
44
21
  declare const OptionsSchema: z.ZodObject<{
45
22
  coordinatorUrl: z.ZodDefault<z.ZodString>;
46
23
  modelName: z.ZodString;
47
- queueing: z.ZodDefault<z.ZodBoolean>;
48
24
  local: z.ZodDefault<z.ZodBoolean>;
49
25
  }, z.core.$strip>;
50
26
  type Options = z.input<typeof OptionsSchema>;
@@ -55,12 +31,10 @@ declare class Reactor {
55
31
  private status;
56
32
  private coordinatorUrl;
57
33
  private lastError?;
58
- private waitingInfo?;
59
- private modelName;
60
- private modelVersion;
61
- private queueing;
34
+ private model;
62
35
  private sessionExpiration?;
63
36
  private local;
37
+ private sessionId?;
64
38
  constructor(options: Options);
65
39
  private eventListeners;
66
40
  on(event: ReactorEvent, handler: EventHandler): void;
@@ -72,51 +46,48 @@ declare class Reactor {
72
46
  * @param message The message to send to the machine.
73
47
  * @throws Error if not in ready state
74
48
  */
75
- sendMessage(message: any): Promise<void>;
49
+ sendCommand(command: string, data: any): Promise<void>;
76
50
  /**
77
- * Public method to publish a video stream to the machine.
78
- * @param videoStream The video stream to send to the machine.
51
+ * Public method to publish a track to the machine.
52
+ * @param track The track to send to the machine.
79
53
  */
80
- publishVideoStream(videoStream: MediaStream): Promise<void>;
54
+ publishTrack(track: MediaStreamTrack): Promise<void>;
81
55
  /**
82
- * Public method to unpublish video stream to the machine.
83
- * This unpublishes the video track that was previously sent.
56
+ * Public method to unpublish the currently published track.
84
57
  */
85
- unpublishVideoStream(): Promise<void>;
58
+ unpublishTrack(): Promise<void>;
86
59
  /**
87
- * Connects to the machine via LiveKit and waits for the gpu machine to be ready.
88
- * Once the machine is ready, the Reactor will establish the LiveKit connection.
89
- * @param livekitJwtToken The JWT token for LiveKit authentication
90
- * @param livekitWsUrl The WebSocket URL for LiveKit connection
60
+ * Public method for reconnecting to an existing session, that may have been interrupted but can be recovered.
91
61
  */
92
- private connectToGPUMachine;
62
+ reconnect(): Promise<void>;
93
63
  /**
94
64
  * Connects to the coordinator and waits for a GPU to be assigned.
95
- * Once a GPU is assigned, the Reactor will connect to the gpu machine via LiveKit.
65
+ * Once a GPU is assigned, the Reactor will connect to the gpu machine via WebRTC.
96
66
  * If no authentication is provided and not in local mode, an error is thrown.
97
67
  */
98
- connect(auth?: ReactorAuth): Promise<void>;
68
+ connect(jwtToken?: string): Promise<void>;
69
+ /**
70
+ * Sets up event handlers for the machine client.
71
+ */
72
+ private setupMachineClientHandlers;
99
73
  /**
100
74
  * Disconnects from the coordinator and the gpu machine.
101
75
  * Ensures cleanup completes even if individual disconnections fail.
102
76
  */
103
- disconnect(): Promise<void>;
77
+ disconnect(recoverable?: boolean): Promise<void>;
78
+ private setSessionId;
79
+ getSessionId(): string | undefined;
104
80
  private setStatus;
105
- private setWaitingInfo;
81
+ getStatus(): ReactorStatus;
106
82
  /**
107
83
  * Set the session expiration time.
108
84
  * @param newSessionExpiration The new session expiration time in seconds.
109
85
  */
110
86
  private setSessionExpiration;
111
- getStatus(): ReactorStatus;
112
87
  /**
113
88
  * Get the current state including status, error, and waiting info
114
89
  */
115
90
  getState(): ReactorState$1;
116
- /**
117
- * Get waiting information when status is 'waiting'
118
- */
119
- getWaitingInfo(): ReactorWaitingInfo | undefined;
120
91
  /**
121
92
  * Get the last error that occurred
122
93
  */
@@ -129,20 +100,20 @@ declare class Reactor {
129
100
 
130
101
  interface ReactorState {
131
102
  status: ReactorStatus;
132
- videoTrack: RemoteVideoTrack | null;
133
- fps?: number;
134
- waitingInfo?: ReactorWaitingInfo;
103
+ videoTrack: MediaStreamTrack | null;
135
104
  lastError?: ReactorError;
105
+ sessionId?: string;
136
106
  sessionExpiration?: number;
137
107
  insecureApiKey?: string;
138
108
  jwtToken?: string;
139
109
  }
140
110
  interface ReactorActions {
141
- sendMessage(message: any): Promise<void>;
142
- connect(auth?: ReactorAuth): Promise<void>;
143
- disconnect(): Promise<void>;
111
+ sendCommand(command: string, data: any): Promise<void>;
112
+ connect(jwtToken?: string): Promise<void>;
113
+ disconnect(recoverable?: boolean): Promise<void>;
144
114
  publishVideoStream(stream: MediaStream): Promise<void>;
145
115
  unpublishVideoStream(): Promise<void>;
116
+ reconnect(): Promise<void>;
146
117
  }
147
118
  interface ReactorInternalState {
148
119
  reactor: Reactor;
@@ -151,17 +122,15 @@ type ReactorStore = ReactorState & ReactorActions & {
151
122
  internal: ReactorInternalState;
152
123
  };
153
124
  interface ReactorInitializationProps extends Options {
154
- insecureApiKey?: string;
155
125
  jwtToken?: string;
156
126
  }
157
127
 
158
128
  interface ReactorProviderProps extends ReactorInitializationProps {
159
129
  autoConnect?: boolean;
160
- insecureApiKey?: string;
161
130
  jwtToken?: string;
162
131
  children: ReactNode;
163
132
  }
164
- declare function ReactorProvider({ children, autoConnect, insecureApiKey, jwtToken, ...props }: ReactorProviderProps): react_jsx_runtime.JSX.Element;
133
+ declare function ReactorProvider({ children, autoConnect, jwtToken, ...props }: ReactorProviderProps): react_jsx_runtime.JSX.Element;
165
134
  declare function useReactorStore<T = ReactorStore>(selector: (state: ReactorStore) => T): T;
166
135
 
167
136
  interface ReactorViewProps {
@@ -202,4 +171,4 @@ declare function useReactor<T>(selector: (state: ReactorStore) => T): T;
202
171
  */
203
172
  declare function useReactorMessage(handler: (message: any) => void): void;
204
173
 
205
- export { type Options, Reactor, ReactorController, type ReactorControllerProps, type ReactorError, type ReactorEvent, ReactorProvider, type ReactorSessionExpiration, type ReactorState$1 as ReactorState, type ReactorStatus, ReactorView, type ReactorViewProps, type ReactorWaitingInfo, WebcamStream, useReactor, useReactorMessage, useReactorStore };
174
+ 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, useReactor, useReactorMessage, useReactorStore };