@reactor-team/js-sdk 1.0.14 → 1.0.16

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 CHANGED
@@ -1,13 +1,25 @@
1
- import { z } from 'zod';
1
+ import z$1, { z } from 'zod';
2
2
  import * as react_jsx_runtime from 'react/jsx-runtime';
3
3
  import React, { ReactNode } from 'react';
4
4
  import { RemoteVideoTrack } from 'livekit-client';
5
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
+
6
19
  type ReactorStatus = "disconnected" | "connecting" | "waiting" | "ready";
7
- interface ReactorWaitingInfo {
8
- position?: number;
9
- estimatedWaitTime?: number;
10
- averageWaitTime?: number;
20
+ interface ReactorWaitingInfo extends z$1.infer<typeof WaitingInfoDataSchema> {
21
+ }
22
+ interface ReactorSessionExpiration extends z$1.infer<typeof SessionExpirationDataSchema> {
11
23
  }
12
24
  interface ReactorError {
13
25
  code: string;
@@ -22,7 +34,7 @@ interface ReactorState$1 {
22
34
  waitingInfo?: ReactorWaitingInfo;
23
35
  lastError?: ReactorError;
24
36
  }
25
- type ReactorEvent = "statusChanged" | "waitingInfoChanged" | "newMessage" | "fps" | "streamChanged" | "error";
37
+ type ReactorEvent = "statusChanged" | "waitingInfoChanged" | "newMessage" | "fps" | "streamChanged" | "error" | "sessionExpirationChanged";
26
38
 
27
39
  declare const OptionsSchema: z.ZodObject<{
28
40
  directConnection: z.ZodOptional<z.ZodObject<{
@@ -34,6 +46,7 @@ declare const OptionsSchema: z.ZodObject<{
34
46
  coordinatorUrl: z.ZodDefault<z.ZodString>;
35
47
  modelName: z.ZodString;
36
48
  queueing: z.ZodDefault<z.ZodBoolean>;
49
+ local: z.ZodDefault<z.ZodBoolean>;
37
50
  }, z.core.$strip>;
38
51
  type Options = z.input<typeof OptionsSchema>;
39
52
  type EventHandler = (...args: any[]) => void;
@@ -50,6 +63,7 @@ declare class Reactor {
50
63
  private modelName;
51
64
  private modelVersion;
52
65
  private queueing;
66
+ private sessionExpiration?;
53
67
  constructor(options: Options);
54
68
  private eventListeners;
55
69
  on(event: ReactorEvent, handler: EventHandler): void;
@@ -91,6 +105,11 @@ declare class Reactor {
91
105
  disconnect(): Promise<void>;
92
106
  private setStatus;
93
107
  private setWaitingInfo;
108
+ /**
109
+ * Set the session expiration time.
110
+ * @param newSessionExpiration The new session expiration time in seconds.
111
+ */
112
+ private setSessionExpiration;
94
113
  getStatus(): ReactorStatus;
95
114
  /**
96
115
  * Get the current state including status, error, and waiting info
@@ -116,6 +135,7 @@ interface ReactorState {
116
135
  fps?: number;
117
136
  waitingInfo?: ReactorWaitingInfo;
118
137
  lastError?: ReactorError;
138
+ sessionExpiration?: number;
119
139
  }
120
140
  interface ReactorActions {
121
141
  sendMessage(message: any): Promise<void>;
@@ -172,4 +192,4 @@ declare function useReactor<T>(selector: (state: ReactorStore) => T): T;
172
192
  */
173
193
  declare function useReactorMessage(handler: (message: any) => void): void;
174
194
 
175
- export { type Options, Reactor, type ReactorError, type ReactorEvent, ReactorProvider, type ReactorState$1 as ReactorState, type ReactorStatus, ReactorView, type ReactorViewProps, type ReactorWaitingInfo, WebcamStream, useReactor, useReactorMessage, useReactorStore };
195
+ export { type Options, Reactor, type ReactorError, type ReactorEvent, ReactorProvider, type ReactorSessionExpiration, type ReactorState$1 as ReactorState, type ReactorStatus, ReactorView, type ReactorViewProps, type ReactorWaitingInfo, WebcamStream, useReactor, useReactorMessage, useReactorStore };
package/dist/index.d.ts CHANGED
@@ -1,13 +1,25 @@
1
- import { z } from 'zod';
1
+ import z$1, { z } from 'zod';
2
2
  import * as react_jsx_runtime from 'react/jsx-runtime';
3
3
  import React, { ReactNode } from 'react';
4
4
  import { RemoteVideoTrack } from 'livekit-client';
5
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
+
6
19
  type ReactorStatus = "disconnected" | "connecting" | "waiting" | "ready";
7
- interface ReactorWaitingInfo {
8
- position?: number;
9
- estimatedWaitTime?: number;
10
- averageWaitTime?: number;
20
+ interface ReactorWaitingInfo extends z$1.infer<typeof WaitingInfoDataSchema> {
21
+ }
22
+ interface ReactorSessionExpiration extends z$1.infer<typeof SessionExpirationDataSchema> {
11
23
  }
12
24
  interface ReactorError {
13
25
  code: string;
@@ -22,7 +34,7 @@ interface ReactorState$1 {
22
34
  waitingInfo?: ReactorWaitingInfo;
23
35
  lastError?: ReactorError;
24
36
  }
25
- type ReactorEvent = "statusChanged" | "waitingInfoChanged" | "newMessage" | "fps" | "streamChanged" | "error";
37
+ type ReactorEvent = "statusChanged" | "waitingInfoChanged" | "newMessage" | "fps" | "streamChanged" | "error" | "sessionExpirationChanged";
26
38
 
27
39
  declare const OptionsSchema: z.ZodObject<{
28
40
  directConnection: z.ZodOptional<z.ZodObject<{
@@ -34,6 +46,7 @@ declare const OptionsSchema: z.ZodObject<{
34
46
  coordinatorUrl: z.ZodDefault<z.ZodString>;
35
47
  modelName: z.ZodString;
36
48
  queueing: z.ZodDefault<z.ZodBoolean>;
49
+ local: z.ZodDefault<z.ZodBoolean>;
37
50
  }, z.core.$strip>;
38
51
  type Options = z.input<typeof OptionsSchema>;
39
52
  type EventHandler = (...args: any[]) => void;
@@ -50,6 +63,7 @@ declare class Reactor {
50
63
  private modelName;
51
64
  private modelVersion;
52
65
  private queueing;
66
+ private sessionExpiration?;
53
67
  constructor(options: Options);
54
68
  private eventListeners;
55
69
  on(event: ReactorEvent, handler: EventHandler): void;
@@ -91,6 +105,11 @@ declare class Reactor {
91
105
  disconnect(): Promise<void>;
92
106
  private setStatus;
93
107
  private setWaitingInfo;
108
+ /**
109
+ * Set the session expiration time.
110
+ * @param newSessionExpiration The new session expiration time in seconds.
111
+ */
112
+ private setSessionExpiration;
94
113
  getStatus(): ReactorStatus;
95
114
  /**
96
115
  * Get the current state including status, error, and waiting info
@@ -116,6 +135,7 @@ interface ReactorState {
116
135
  fps?: number;
117
136
  waitingInfo?: ReactorWaitingInfo;
118
137
  lastError?: ReactorError;
138
+ sessionExpiration?: number;
119
139
  }
120
140
  interface ReactorActions {
121
141
  sendMessage(message: any): Promise<void>;
@@ -172,4 +192,4 @@ declare function useReactor<T>(selector: (state: ReactorStore) => T): T;
172
192
  */
173
193
  declare function useReactorMessage(handler: (message: any) => void): void;
174
194
 
175
- export { type Options, Reactor, type ReactorError, type ReactorEvent, ReactorProvider, type ReactorState$1 as ReactorState, type ReactorStatus, ReactorView, type ReactorViewProps, type ReactorWaitingInfo, WebcamStream, useReactor, useReactorMessage, useReactorStore };
195
+ export { type Options, Reactor, type ReactorError, type ReactorEvent, ReactorProvider, type ReactorSessionExpiration, type ReactorState$1 as ReactorState, type ReactorStatus, ReactorView, type ReactorViewProps, type ReactorWaitingInfo, WebcamStream, useReactor, useReactorMessage, useReactorStore };
package/dist/index.js CHANGED
@@ -119,11 +119,19 @@ var WaitingInfoMessageSchema = import_zod.z.object({
119
119
  type: import_zod.z.literal("waiting-info"),
120
120
  data: WaitingInfoDataSchema
121
121
  });
122
+ var SessionExpirationDataSchema = import_zod.z.object({
123
+ expire: import_zod.z.number()
124
+ });
125
+ var SessionExpirationMessageSchema = import_zod.z.object({
126
+ type: import_zod.z.literal("session-expiration"),
127
+ data: SessionExpirationDataSchema
128
+ });
122
129
  var CoordinatorMessageSchema = import_zod.z.discriminatedUnion("type", [
123
130
  WelcomeMessageSchema,
124
131
  GPUMachineAssignmentMessageSchema,
125
132
  EchoMessageSchema,
126
- WaitingInfoMessageSchema
133
+ WaitingInfoMessageSchema,
134
+ SessionExpirationMessageSchema
127
135
  ]);
128
136
  var GPUMachineSendMessageSchema = import_zod.z.discriminatedUnion("type", [
129
137
  ApplicationMessageSchema
@@ -548,6 +556,9 @@ var GPUMachineClient = class {
548
556
 
549
557
  // src/core/Reactor.ts
550
558
  var import_zod3 = require("zod");
559
+ var LOCAL_COORDINATOR_URL = "ws://localhost:8080/ws";
560
+ var LOCAL_INSECURE_API_KEY = "1234";
561
+ var PROD_COORDINATOR_URL = "wss://api.reactor.inc/ws";
551
562
  var OptionsSchema2 = import_zod3.z.object({
552
563
  directConnection: import_zod3.z.object({
553
564
  livekitJwtToken: import_zod3.z.string(),
@@ -555,13 +566,14 @@ var OptionsSchema2 = import_zod3.z.object({
555
566
  }).optional(),
556
567
  insecureApiKey: import_zod3.z.string().optional(),
557
568
  jwtToken: import_zod3.z.string().optional(),
558
- coordinatorUrl: import_zod3.z.string().default("wss://api.reactor.inc/ws"),
569
+ coordinatorUrl: import_zod3.z.string().default(PROD_COORDINATOR_URL),
559
570
  modelName: import_zod3.z.string(),
560
- queueing: import_zod3.z.boolean().default(false)
571
+ queueing: import_zod3.z.boolean().default(false),
572
+ local: import_zod3.z.boolean().default(false)
561
573
  }).refine(
562
- (data) => data.directConnection || data.insecureApiKey || data.jwtToken,
574
+ (data) => data.directConnection || data.insecureApiKey || data.jwtToken || data.local,
563
575
  {
564
- message: "At least one of directConnection, insecureApiKey, or jwtToken must be provided."
576
+ message: "At least one of directConnection, insecureApiKey, or jwtToken or local must be provided."
565
577
  }
566
578
  );
567
579
  var Reactor = class {
@@ -578,6 +590,10 @@ var Reactor = class {
578
590
  this.modelName = validatedOptions.modelName;
579
591
  this.queueing = validatedOptions.queueing;
580
592
  this.modelVersion = "1.0.0";
593
+ if (validatedOptions.local) {
594
+ this.coordinatorUrl = LOCAL_COORDINATOR_URL;
595
+ this.insecureApiKey = LOCAL_INSECURE_API_KEY;
596
+ }
581
597
  }
582
598
  // Event Emitter API
583
599
  on(event, handler) {
@@ -778,6 +794,12 @@ var Reactor = class {
778
794
  this.setWaitingInfo(__spreadValues(__spreadValues({}, this.waitingInfo), waitingData));
779
795
  }
780
796
  );
797
+ this.coordinatorClient.on(
798
+ "session-expiration",
799
+ (sessionExpirationData) => {
800
+ this.setSessionExpiration(sessionExpirationData.expire);
801
+ }
802
+ );
781
803
  this.coordinatorClient.on(
782
804
  "statusChanged",
783
805
  (newStatus) => {
@@ -843,7 +865,8 @@ var Reactor = class {
843
865
  this.machineClient = void 0;
844
866
  }
845
867
  this.setStatus("disconnected");
846
- this.waitingInfo = void 0;
868
+ this.setSessionExpiration(void 0);
869
+ this.setWaitingInfo(void 0);
847
870
  });
848
871
  }
849
872
  setStatus(newStatus) {
@@ -865,6 +888,20 @@ var Reactor = class {
865
888
  this.emit("waitingInfoChanged", newWaitingInfo);
866
889
  }
867
890
  }
891
+ /**
892
+ * Set the session expiration time.
893
+ * @param newSessionExpiration The new session expiration time in seconds.
894
+ */
895
+ setSessionExpiration(newSessionExpiration) {
896
+ console.debug(
897
+ "[Reactor] Setting session expiration:",
898
+ newSessionExpiration
899
+ );
900
+ if (this.sessionExpiration !== newSessionExpiration) {
901
+ this.sessionExpiration = newSessionExpiration;
902
+ this.emit("sessionExpirationChanged", newSessionExpiration);
903
+ }
904
+ }
868
905
  getStatus() {
869
906
  return this.status;
870
907
  }
@@ -920,7 +957,8 @@ var defaultInitState = {
920
957
  videoTrack: null,
921
958
  fps: void 0,
922
959
  waitingInfo: void 0,
923
- lastError: void 0
960
+ lastError: void 0,
961
+ sessionExpiration: void 0
924
962
  };
925
963
  var initReactorStore = (props) => {
926
964
  return __spreadValues(__spreadValues({}, defaultInitState), props);
@@ -947,6 +985,13 @@ var createReactorStore = (initProps, publicState = defaultInitState) => {
947
985
  });
948
986
  set({ waitingInfo: newWaitingInfo });
949
987
  });
988
+ reactor.on("sessionExpirationChanged", (newSessionExpiration) => {
989
+ console.debug("[ReactorStore] Session expiration changed", {
990
+ oldSessionExpiration: get().sessionExpiration,
991
+ newSessionExpiration
992
+ });
993
+ set({ sessionExpiration: newSessionExpiration });
994
+ });
950
995
  reactor.on("streamChanged", (videoTrack) => {
951
996
  console.debug("[ReactorStore] Stream changed", {
952
997
  hasVideoTrack: !!videoTrack,
@@ -1061,7 +1106,8 @@ function ReactorProvider(_a) {
1061
1106
  jwtToken,
1062
1107
  insecureApiKey,
1063
1108
  directConnection,
1064
- queueing
1109
+ queueing,
1110
+ local
1065
1111
  } = props;
1066
1112
  (0, import_react3.useEffect)(() => {
1067
1113
  if (firstRender.current) {
@@ -1106,7 +1152,8 @@ function ReactorProvider(_a) {
1106
1152
  jwtToken,
1107
1153
  insecureApiKey,
1108
1154
  directConnection,
1109
- queueing
1155
+ queueing,
1156
+ local
1110
1157
  })
1111
1158
  );
1112
1159
  const current = storeRef.current;
@@ -1139,7 +1186,8 @@ function ReactorProvider(_a) {
1139
1186
  insecureApiKey,
1140
1187
  directConnection,
1141
1188
  queueing,
1142
- autoConnect
1189
+ autoConnect,
1190
+ local
1143
1191
  ]);
1144
1192
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ReactorContext.Provider, { value: storeRef.current, children });
1145
1193
  }