ota-hub-reactjs 0.0.16 → 0.0.19

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.
@@ -1,5 +1,5 @@
1
1
  import { useEffect } from "react";
2
- import { MultiDeviceWhisperer } from "../base/device-whisperer.js";
2
+ import { MultiDeviceWhisperer, } from "../base/device-whisperer.js";
3
3
  export function WebsocketMultiDeviceWhisperer({ server_url, server_port, ...props }) {
4
4
  const base = MultiDeviceWhisperer(props);
5
5
  const defaultOnReceive = (uuid, data) => {
@@ -22,7 +22,7 @@ export function WebsocketMultiDeviceWhisperer({ server_url, server_port, ...prop
22
22
  const lines = combined.split(/\r?\n/);
23
23
  base.updateConnection(uuid, (c) => ({
24
24
  ...c,
25
- readBufferLeftover: lines.pop() || ""
25
+ readBufferLeftover: lines.pop() || "",
26
26
  }));
27
27
  for (const line of lines) {
28
28
  const trimmed = line.trim();
@@ -38,9 +38,7 @@ export function WebsocketMultiDeviceWhisperer({ server_url, server_port, ...prop
38
38
  const conn = base.getConnection(uuid);
39
39
  if (!conn || !conn.ws)
40
40
  return;
41
- const asString = typeof data === "string"
42
- ? data
43
- : btoa(String.fromCharCode(...data));
41
+ const asString = typeof data === "string" ? data : btoa(String.fromCharCode(...data));
44
42
  base.appendLog(uuid, {
45
43
  level: 3,
46
44
  message: asString,
@@ -57,7 +55,11 @@ export function WebsocketMultiDeviceWhisperer({ server_url, server_port, ...prop
57
55
  console.log(`[client] Closing existing WS before reconnect for ${uuid}`);
58
56
  conn.ws.close();
59
57
  }
60
- base.updateConnection(uuid, (c) => ({ ...c, isConnecting: true, autoConnect: true }));
58
+ base.updateConnection(uuid, (c) => ({
59
+ ...c,
60
+ isConnecting: true,
61
+ autoConnect: true,
62
+ }));
61
63
  try {
62
64
  const pre = server_port !== 443 ? "ws" : "wss";
63
65
  const ws = new WebSocket(`${pre}://${server_url}:${server_port}/ui/${uuid}`);
@@ -68,11 +70,11 @@ export function WebsocketMultiDeviceWhisperer({ server_url, server_port, ...prop
68
70
  ws,
69
71
  isConnected: true,
70
72
  isConnecting: false,
71
- lastAttempt: attempt
73
+ lastAttempt: attempt,
72
74
  }));
73
75
  base.appendLog(uuid, {
74
76
  level: 2,
75
- message: "[✓] WebSocket connected"
77
+ message: "[✓] WebSocket connected",
76
78
  });
77
79
  conn?.onConnect?.();
78
80
  };
@@ -89,7 +91,7 @@ export function WebsocketMultiDeviceWhisperer({ server_url, server_port, ...prop
89
91
  ws.onerror = (err) => {
90
92
  base.appendLog(uuid, {
91
93
  level: 0,
92
- message: `[x] WS error: ${err}`
94
+ message: `[x] WS error: ${err}`,
93
95
  });
94
96
  };
95
97
  ws.onclose = async () => {
@@ -97,7 +99,7 @@ export function WebsocketMultiDeviceWhisperer({ server_url, server_port, ...prop
97
99
  ...c,
98
100
  isConnected: false,
99
101
  isConnecting: false,
100
- ws: undefined
102
+ ws: undefined,
101
103
  }));
102
104
  base.appendLog(uuid, { level: 0, message: "[!] WS disconnected" });
103
105
  const updated_conn = base.getConnection(uuid);
@@ -107,7 +109,10 @@ export function WebsocketMultiDeviceWhisperer({ server_url, server_port, ...prop
107
109
  }
108
110
  // Auto reconnect if enabled
109
111
  if (updated_conn.autoConnect && attempt < MAX_RETRIES) {
110
- base.appendLog(uuid, { level: 2, message: `[~] Reconnecting in ${RETRY_DELAY_MS}ms... (attempt ${attempt + 1})` });
112
+ base.appendLog(uuid, {
113
+ level: 2,
114
+ message: `[~] Reconnecting in ${RETRY_DELAY_MS}ms... (attempt ${attempt + 1})`,
115
+ });
111
116
  setTimeout(() => connect(uuid, attempt + 1), RETRY_DELAY_MS);
112
117
  }
113
118
  };
@@ -119,8 +124,11 @@ export function WebsocketMultiDeviceWhisperer({ server_url, server_port, ...prop
119
124
  isConnecting: false,
120
125
  logs: [
121
126
  ...c.logs,
122
- { level: 0, message: `[x] WS connection error: ${err?.message || "Unknown error"}` }
123
- ]
127
+ {
128
+ level: 0,
129
+ message: `[x] WS connection error: ${err?.message || "Unknown error"}`,
130
+ },
131
+ ],
124
132
  }));
125
133
  await disconnect(uuid);
126
134
  }
@@ -135,12 +143,12 @@ export function WebsocketMultiDeviceWhisperer({ server_url, server_port, ...prop
135
143
  isConnecting: false,
136
144
  autoConnect: false,
137
145
  ws: undefined,
138
- readBufferLeftover: ""
146
+ readBufferLeftover: "",
139
147
  }));
140
148
  conn.ws.close();
141
149
  await conn?.onDisconnect?.();
142
150
  };
143
- const addConnection = async ({ uuid, propCreator }) => {
151
+ const addConnection = async ({ uuid, propCreator, }) => {
144
152
  return await base.addConnection({
145
153
  uuid,
146
154
  propCreator: (id) => {
@@ -148,9 +156,9 @@ export function WebsocketMultiDeviceWhisperer({ server_url, server_port, ...prop
148
156
  return {
149
157
  send: props?.send || ((d) => defaultSend(id, d)),
150
158
  onReceive: props?.onReceive || ((d) => defaultOnReceive(id, d)),
151
- ...props
159
+ ...props,
152
160
  };
153
- }
161
+ },
154
162
  });
155
163
  };
156
164
  const removeConnection = async (uuid) => {
@@ -174,7 +182,7 @@ export function WebsocketMultiDeviceWhisperer({ server_url, server_port, ...prop
174
182
  }
175
183
  };
176
184
  const reconnectAll = async (...connectionProps) => {
177
- const connectionIds = base.connections.map(c => c.uuid);
185
+ const connectionIds = base.connections.map((c) => c.uuid);
178
186
  await Promise.all(connectionIds.map(async (id) => {
179
187
  const c = base.getConnection(id);
180
188
  if (!c)
@@ -194,6 +202,6 @@ export function WebsocketMultiDeviceWhisperer({ server_url, server_port, ...prop
194
202
  connect,
195
203
  disconnect,
196
204
  checkForNewDevices,
197
- reconnectAll
205
+ reconnectAll,
198
206
  };
199
207
  }
@@ -1,3 +1 @@
1
- ;
2
- ;
3
1
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ota-hub-reactjs",
3
- "version": "0.0.16",
3
+ "version": "0.0.19",
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",