ota-hub-reactjs 0.0.13 → 0.0.14

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.
@@ -27,7 +27,6 @@ export type DeviceConnectionState = {
27
27
  export declare function createDefaultInitialDeviceState<T extends DeviceConnectionState>(uuid: string, props?: any): T;
28
28
  export type DeviceWhispererProps<T extends DeviceConnectionState> = {
29
29
  createInitialConnectionState?: (uuid: string) => Partial<T>;
30
- connectOn?: boolean;
31
30
  };
32
31
  export declare function MultiDeviceWhisperer<T extends DeviceConnectionState>({ createInitialConnectionState, }?: DeviceWhispererProps<T>): {
33
32
  connections: T[];
@@ -256,7 +256,7 @@ export function ESP32MultiDeviceWhisperer({ ...props } = {}) {
256
256
  const port = await navigator.serial.requestPort({
257
257
  filters: [{ usbVendorId: 0x303a }]
258
258
  });
259
- return await base.addConnection({
259
+ const return_uuid = await base.addConnection({
260
260
  uuid,
261
261
  propCreator: (id) => {
262
262
  const props = propCreator?.(id);
@@ -271,6 +271,10 @@ export function ESP32MultiDeviceWhisperer({ ...props } = {}) {
271
271
  };
272
272
  }
273
273
  });
274
+ const conn = base.getConnection(return_uuid);
275
+ if (conn?.autoConnect)
276
+ await connect(return_uuid);
277
+ return return_uuid;
274
278
  };
275
279
  const removeConnection = async (uuid) => {
276
280
  try {
@@ -3,7 +3,7 @@ export type MQTTConnectionState = DeviceConnectionState & {
3
3
  pingFunction?: (props?: any) => void;
4
4
  touchHeartbeat?: () => void;
5
5
  };
6
- export declare function MQTTMultiDeviceWhisperer<AppOrMessageLayer extends MQTTConnectionState>({ serverUrl, uuidFromMessage, subTopicFromUuid, pubTopicFromUuid, serverPort, clientId, username, password, autoConnect, ...props }: {
6
+ export declare function MQTTMultiDeviceWhisperer<AppOrMessageLayer extends MQTTConnectionState>({ serverUrl, uuidFromMessage, subTopicFromUuid, pubTopicFromUuid, serverPort, clientId, username, password, serverAutoConnect, serverConnectOn, ...props }: {
7
7
  serverUrl: string;
8
8
  uuidFromMessage: (topic: string, payload: Buffer<ArrayBufferLike>) => string;
9
9
  subTopicFromUuid?: (uuid: string) => string;
@@ -12,7 +12,8 @@ export declare function MQTTMultiDeviceWhisperer<AppOrMessageLayer extends MQTTC
12
12
  clientId?: string;
13
13
  username?: string;
14
14
  password?: string;
15
- autoConnect?: boolean;
15
+ serverAutoConnect?: boolean;
16
+ serverConnectOn?: boolean;
16
17
  } & DeviceWhispererProps<AppOrMessageLayer>): {
17
18
  addConnection: ({ uuid, propCreator }: AddConnectionProps<AppOrMessageLayer>) => Promise<string | undefined>;
18
19
  removeConnection: (uuid: string) => Promise<void>;
@@ -1,7 +1,7 @@
1
1
  import { useEffect, useRef } from "react";
2
2
  import { MultiDeviceWhisperer } from "../base/device-whisperer.js";
3
3
  import mqtt from "mqtt";
4
- export function MQTTMultiDeviceWhisperer({ serverUrl, uuidFromMessage, subTopicFromUuid = undefined, pubTopicFromUuid = undefined, serverPort = 8883, clientId = undefined, username = undefined, password = undefined, autoConnect = true, ...props }) {
4
+ export function MQTTMultiDeviceWhisperer({ serverUrl, uuidFromMessage, subTopicFromUuid = undefined, pubTopicFromUuid = undefined, serverPort = 8883, clientId = undefined, username = undefined, password = undefined, serverAutoConnect = true, serverConnectOn = false, ...props }) {
5
5
  const base = MultiDeviceWhisperer(props);
6
6
  const clientRef = useRef(null);
7
7
  const isUnmountedRef = useRef(false);
@@ -211,7 +211,9 @@ export function MQTTMultiDeviceWhisperer({ serverUrl, uuidFromMessage, subTopicF
211
211
  // Delete this adding connections item
212
212
  addingConnections.current.delete(uuid);
213
213
  // Connect immediately
214
- connect(uuid);
214
+ const conn = base.getConnection(uuid);
215
+ if (conn?.autoConnect)
216
+ await connect(uuid);
215
217
  return uuid;
216
218
  };
217
219
  const removeConnection = async (uuid) => {
@@ -228,11 +230,11 @@ export function MQTTMultiDeviceWhisperer({ serverUrl, uuidFromMessage, subTopicF
228
230
  }
229
231
  };
230
232
  useEffect(() => {
231
- if (!(autoConnect || props.connectOn))
233
+ if (!(serverAutoConnect || serverConnectOn))
232
234
  return;
233
235
  const cleanup = connectToMQTTServer();
234
236
  return cleanup;
235
- }, [serverUrl, props.connectOn]);
237
+ }, [serverUrl, serverConnectOn]);
236
238
  return {
237
239
  ...base,
238
240
  addConnection,
@@ -292,7 +292,7 @@ export function SerialMultiDeviceWhisperer({ ...props } = {}) {
292
292
  const device = await navigator.usb.requestDevice({
293
293
  filters: []
294
294
  });
295
- return await base.addConnection({
295
+ const return_uuid = await base.addConnection({
296
296
  uuid,
297
297
  propCreator: (id) => {
298
298
  const props = propCreator?.(id);
@@ -308,6 +308,10 @@ export function SerialMultiDeviceWhisperer({ ...props } = {}) {
308
308
  };
309
309
  }
310
310
  });
311
+ const conn = base.getConnection(return_uuid);
312
+ if (conn?.autoConnect)
313
+ await connect(return_uuid);
314
+ return return_uuid;
311
315
  }
312
316
  catch (e) {
313
317
  console.log("User cancelled or no device selected");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ota-hub-reactjs",
3
- "version": "0.0.13",
3
+ "version": "0.0.14",
4
4
  "description": "ReactJS tools for building web apps to flash MCU devices such as esp32, brought to you by OTA Hub.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",