@trap_stevo/filetide-client 0.0.70 → 0.0.72

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.
@@ -9,8 +9,6 @@ const os = require("os");
9
9
  let currentRoom = "file-room";
10
10
  let tideUrl = "http://localhost:9269";
11
11
  const deviceName = os.hostname();
12
- let fileTide;
13
- let fileMessagerInstance;
14
12
  const gradients = {
15
13
  success: ["\x1b[38;5;48m", "\x1b[38;5;49m", "\x1b[38;5;50m"],
16
14
  indicator: ["\x1b[38;5;30m", "\x1b[38;5;37m", "\x1b[38;5;44m", "\x1b[38;5;51m", "\x1b[38;5;147m"],
@@ -25,13 +23,13 @@ class FileTideClient {
25
23
  constructor(inputDeviceName, inputTideURL, inputCurrentRoom, displayTitle = true, showAuthor = false, showCLITitle = false, debugMode = false) {
26
24
  // --- FileTide Client Cleanup Management ---
27
25
  _classPrivateMethodInitSpec(this, _FileTideClient_brand);
28
- fileTide = new FileTide(debugMode);
26
+ this.fileTide = new FileTide(debugMode);
29
27
  this.currentDeviceName = inputDeviceName || deviceName;
30
28
  this.originDeviceName = inputDeviceName || deviceName;
31
29
  this.deviceName = inputDeviceName || deviceName;
32
30
  this.tideUrl = inputTideURL || tideUrl;
33
31
  this.currentRoom = inputCurrentRoom || currentRoom;
34
- this.fileMessagerInstance = fileMessagerInstance;
32
+ this.fileMessagerInstance = null;
35
33
  this.clientDisconnected = false;
36
34
  this.connectionID = null;
37
35
  _assertClassBrand(_FileTideClient_brand, this, _setupProcessEvents).call(this);
@@ -57,31 +55,31 @@ class FileTideClient {
57
55
  // --- FileTide Client TideToken Enforcement Management ---
58
56
 
59
57
  updateTideTokenEnforcementCallbackConfigurations(updatedConfigurations = {}) {
60
- fileTide.updateTideTokenEnforcementCallbackConfigurations(updatedConfigurations);
58
+ this.fileTide.updateTideTokenEnforcementCallbackConfigurations(updatedConfigurations);
61
59
  }
62
60
  async registerTideToken(tideToken, meta = {}) {
63
- return await fileTide.registerTideToken(tideToken, meta);
61
+ return await this.fileTide.registerTideToken(tideToken, meta);
64
62
  }
65
63
  async inspectTideToken(tideToken) {
66
- return await fileTide.inspectTideToken(tideToken);
64
+ return await this.fileTide.inspectTideToken(tideToken);
67
65
  }
68
66
  getTideTokenEnforcerOverviewMetrics() {
69
- return fileTide.getTideTokenEnforcerOverviewMetrics();
67
+ return this.fileTide.getTideTokenEnforcerOverviewMetrics();
70
68
  }
71
69
  getTideToken(scope = "default") {
72
- return fileTide.getTideToken(scope);
70
+ return this.fileTide.getTideToken(scope);
73
71
  }
74
72
 
75
73
  // --- FileTide Client Storage Management ---
76
74
 
77
75
  async initializeStorage(options = {}) {
78
- return await fileTide.initializeStorage(options);
76
+ return await this.fileTide.initializeStorage(options);
79
77
  }
80
78
  storage(namespace) {
81
- return fileTide.storage(namespace);
79
+ return this.fileTide.storage(namespace);
82
80
  }
83
81
  getStorageManager() {
84
- return fileTide.getStorageManager();
82
+ return this.fileTide.getStorageManager();
85
83
  }
86
84
  broadcastClientOffline(fileMessager, forceBroadcast = false) {
87
85
  if (fileMessager && !this.clientDisconnected) {
@@ -104,7 +102,7 @@ class FileTideClient {
104
102
  FileTide.outputGradient(`[${this.deviceName}] Disconnected from the Anchor.`, ["#00C897", "#00E0FF"]);
105
103
  }
106
104
  async closeAllClients(onBeforeClientDisconnect, onClientDisconnect, onCompletion) {
107
- await fileTide.stopAllMessagers(async (...data) => {
105
+ await this.fileTide.stopAllMessagers(async (...data) => {
108
106
  this.broadcastClientOffline(this.fileMessagerInstance);
109
107
  if (typeof onBeforeClientDisconnect === "function") {
110
108
  await onBeforeClientDisconnect(...data);
@@ -112,7 +110,7 @@ class FileTideClient {
112
110
  }, onClientDisconnect, onCompletion);
113
111
  }
114
112
  async closeClient(userID, onBeforeDisconnect, onDisconnect, onCompletion) {
115
- await fileTide.stopMessager(userID, async (...data) => {
113
+ await this.fileTide.stopMessager(userID, async (...data) => {
116
114
  this.broadcastClientOffline(this.fileMessagerInstance);
117
115
  if (typeof onBeforeDisconnect === "function") {
118
116
  await onBeforeDisconnect(...data);
@@ -132,6 +130,7 @@ class FileTideClient {
132
130
  }, onConnect = null, onDisconnect = null, clientConfigurations = {}) {
133
131
  const {
134
132
  onLaunch = null,
133
+ onReady = null,
135
134
  onIncomingFile = null,
136
135
  onIncomingTransfer = null,
137
136
  onTransferBarrier = null,
@@ -158,22 +157,21 @@ class FileTideClient {
158
157
  }
159
158
  let enterRoom = null;
160
159
  let pendingConnectionArguments = null;
161
- let connectionHandled = false;
160
+ let handledConnectionID = null;
162
161
  const handleConnection = async (...connectionArguments) => {
163
162
  if (typeof enterRoom !== "function") {
164
163
  pendingConnectionArguments = connectionArguments;
165
164
  return;
166
165
  }
167
- if (connectionHandled) {
168
- return;
169
- }
170
- connectionHandled = true;
171
- this.clientDisconnected = false;
172
166
  const socket = this.fileMessagerInstance?.clientTide?.sockets?.[this.deviceName];
173
167
  if (!socket) {
174
- connectionHandled = false;
175
168
  return;
176
169
  }
170
+ if (handledConnectionID === socket.id) {
171
+ return;
172
+ }
173
+ handledConnectionID = socket.id;
174
+ this.clientDisconnected = false;
177
175
  this.connectionID = socket.id;
178
176
 
179
177
  /*
@@ -190,13 +188,12 @@ class FileTideClient {
190
188
  * originClientID
191
189
  * currentTideChannel
192
190
  */
193
- this.fileMessagerInstance.clientTide.emitEvent(this.deviceName, "client-online", this.deviceName, socket.tideID, this.currentDeviceName, socket.id, fileTide.transferBarrier, this.originDeviceName, this.currentRoom);
194
- enterRoom();
191
+ this.fileMessagerInstance.clientTide.emitEvent(this.deviceName, "client-online", this.deviceName, socket.tideID, this.currentDeviceName, socket.id, this.fileTide.transferBarrier, this.originDeviceName, this.currentRoom);
195
192
  if (typeof onConnect === "function") {
196
193
  await onConnect(this.fileMessagerInstance, ...connectionArguments);
197
194
  }
198
195
  };
199
- fileTide.launchMessager({
196
+ this.fileTide.launchMessager({
200
197
  serverUrl: this.tideUrl,
201
198
  ...clientOptions
202
199
  }, {
@@ -204,12 +201,30 @@ class FileTideClient {
204
201
  pingTimeout: 3600000,
205
202
  pingInterval: 60000,
206
203
  ...connectionOptions
207
- }, transportOptions, messagerSettings, this.currentRoom, this.deviceName, (fileMessager, roomEntry) => {
204
+ }, transportOptions, messagerSettings, this.currentRoom, this.deviceName, (fileMessager, roomEntry, resolvedClientID) => {
205
+ this.deviceName = resolvedClientID;
206
+ this.currentDeviceName = resolvedClientID;
207
+ this.originDeviceName = resolvedClientID;
208
208
  this.fileMessagerInstance = fileMessager;
209
- fileMessagerInstance = fileMessager;
210
209
  enterRoom = roomEntry;
210
+ let readyConnectionID = null;
211
+ const launchSocket = fileMessager.clientTide.sockets[this.deviceName];
212
+ launchSocket.on("filetide-identity-authorized", async authorization => {
213
+ const socket = fileMessager.clientTide.sockets?.[this.deviceName];
214
+ if (authorization?.clientID !== this.deviceName || !socket?.connected || !this.getClientAuthorizationState().authenticated || readyConnectionID === socket.id) {
215
+ return;
216
+ }
217
+ readyConnectionID = socket.id;
218
+ enterRoom();
219
+ if (typeof onReady === "function") {
220
+ await onReady(fileMessager, authorization);
221
+ }
222
+ });
223
+ launchSocket.on("disconnect", () => {
224
+ readyConnectionID = null;
225
+ });
211
226
  if (typeof onLaunch === "function") {
212
- onLaunch(fileMessager, roomEntry);
227
+ onLaunch(fileMessager, roomEntry, resolvedClientID);
213
228
  }
214
229
  if (pendingConnectionArguments) {
215
230
  const connectionArguments = pendingConnectionArguments;
@@ -245,6 +260,18 @@ class FileTideClient {
245
260
  this.startClient(this.clientOptions, this.connectionOptions, this.transportOptions, this.messagerSettings, onReconnect, onDisconnect, clientConfigurations);
246
261
  }
247
262
 
263
+ // --- FileTide Client Identity Management ---
264
+
265
+ getClientAuthorizationState() {
266
+ return this.fileTide.getClientAuthorizationState(this.deviceName);
267
+ }
268
+ async associateClientID(targetClientID) {
269
+ return await this.fileTide.associateClientID(this.deviceName, targetClientID);
270
+ }
271
+ async recoverClientID(targetClientID, destinationIdentity) {
272
+ return await this.fileTide.recoverClientID(this.deviceName, targetClientID, destinationIdentity);
273
+ }
274
+
248
275
  // --- FileTide Client Transfer Management ---
249
276
 
250
277
  async requestFileTransfer(senderID, filePath, destinationPath, filterContent = [], transferRequestExpirationTime = 30000) {
@@ -252,106 +279,106 @@ class FileTideClient {
252
279
  return await this.fileMessagerInstance.requestTransfer(this.deviceName, senderID, filePath, destinationPath, filterContent, transferRequestExpirationTime);
253
280
  }
254
281
  async transferFiles(recipientID, filePath, destinationPath, filterContent = [], tideSize = 200, tidalSize = 500, minTideSize = 10, maxTideSize = 2000, transferRequestExpirationTime = 30000, metadata = {}) {
255
- return await fileTide.sendToDevice(recipientID, filePath, destinationPath, filterContent, tideSize, tidalSize, minTideSize, maxTideSize, transferRequestExpirationTime, metadata);
282
+ return await this.fileTide.sendToDevice(recipientID, filePath, destinationPath, filterContent, tideSize, tidalSize, minTideSize, maxTideSize, transferRequestExpirationTime, metadata);
256
283
  }
257
284
  listFiles(recipientID, depth = 1) {
258
- return fileTide.listFilesFromClient(recipientID, depth);
285
+ return this.fileTide.listFilesFromClient(recipientID, depth);
259
286
  }
260
287
 
261
288
  // --- FileTide Client Transfer State Management ---
262
289
 
263
290
  getTransferStats(transferID) {
264
- return fileTide.getTransferStats(transferID);
291
+ return this.fileTide.getTransferStats(transferID);
265
292
  }
266
293
  getTransferStatsOverview() {
267
- return fileTide.getTransferStatsOverview();
294
+ return this.fileTide.getTransferStatsOverview();
268
295
  }
269
296
 
270
297
  // --- FileTide Client Transfer History Management ---
271
298
 
272
299
  async getTransferHistory(options = {}) {
273
- return await fileTide.getTransferHistory(options);
300
+ return await this.fileTide.getTransferHistory(options);
274
301
  }
275
302
  async getTransferHistoryEntry(transferID, options = {}) {
276
- return await fileTide.getTransferHistoryEntry(transferID, options);
303
+ return await this.fileTide.getTransferHistoryEntry(transferID, options);
277
304
  }
278
305
  async clearTransferHistory(options = {}) {
279
- return await fileTide.clearTransferHistory(options);
306
+ return await this.fileTide.clearTransferHistory(options);
280
307
  }
281
308
  async pruneTransferHistory(maxEntries, options = {}) {
282
- return await fileTide.pruneTransferHistory(maxEntries, options);
309
+ return await this.fileTide.pruneTransferHistory(maxEntries, options);
283
310
  }
284
311
 
285
312
  // --- FileTide Client Shore Policy Management ---
286
313
 
287
314
  async clearShorePolicies(clientID = this.deviceName) {
288
- return await fileTide.clearShorePolicies(clientID);
315
+ return await this.fileTide.clearShorePolicies(clientID);
289
316
  }
290
317
  async removeShorePolicies(shores = [], clientID = this.deviceName) {
291
- return await fileTide.removeShorePolicies(clientID, shores);
318
+ return await this.fileTide.removeShorePolicies(clientID, shores);
292
319
  }
293
320
  async addShorePolicies(shores = [], clientID = this.deviceName) {
294
- return await fileTide.addShorePolicies(clientID, shores);
321
+ return await this.fileTide.addShorePolicies(clientID, shores);
295
322
  }
296
323
  async setShorePolicies(shores = [], clientID = this.deviceName) {
297
- return await fileTide.setShorePolicies(clientID, shores);
324
+ return await this.fileTide.setShorePolicies(clientID, shores);
298
325
  }
299
326
  async resetShorePolicies(clientID = this.deviceName) {
300
- return await fileTide.resetShorePolicies(clientID);
327
+ return await this.fileTide.resetShorePolicies(clientID);
301
328
  }
302
329
  async pathWithinShorePolicies(inputPath, clientID = this.deviceName) {
303
- return await fileTide.pathWithinShorePolicies(clientID, inputPath);
330
+ return await this.fileTide.pathWithinShorePolicies(clientID, inputPath);
304
331
  }
305
332
  async getShorePolicies(clientID = this.deviceName) {
306
- return await fileTide.getShorePolicies(clientID);
333
+ return await this.fileTide.getShorePolicies(clientID);
307
334
  }
308
335
  getDefaultShorePolicies() {
309
- return fileTide.getDefaultShorePolicies();
336
+ return this.fileTide.getDefaultShorePolicies();
310
337
  }
311
338
  async getResolvedShorePolicies(clientID = this.deviceName) {
312
- return await fileTide.getResolvedShorePolicies(clientID);
339
+ return await this.fileTide.getResolvedShorePolicies(clientID);
313
340
  }
314
341
 
315
342
  // --- FileTide Client Shortcut Management ---
316
343
 
317
344
  getDefaultShortcuts() {
318
- return fileTide.getDefaultShortcuts();
345
+ return this.fileTide.getDefaultShortcuts();
319
346
  }
320
347
  getShortcuts() {
321
- return fileTide.getShortcuts();
348
+ return this.fileTide.getShortcuts();
322
349
  }
323
350
  getShortcut(shortcut) {
324
- return fileTide.getShortcut(shortcut);
351
+ return this.fileTide.getShortcut(shortcut);
325
352
  }
326
353
  hasShortcut(shortcut) {
327
- return fileTide.hasShortcut(shortcut);
354
+ return this.fileTide.hasShortcut(shortcut);
328
355
  }
329
356
  addShortcut(shortcut, targetPath) {
330
- return fileTide.addShortcut(shortcut, targetPath);
357
+ return this.fileTide.addShortcut(shortcut, targetPath);
331
358
  }
332
359
  setShortcut(shortcut, targetPath) {
333
- return fileTide.setShortcut(shortcut, targetPath);
360
+ return this.fileTide.setShortcut(shortcut, targetPath);
334
361
  }
335
362
  updateShortcut(shortcut, targetPath) {
336
- return fileTide.updateShortcut(shortcut, targetPath);
363
+ return this.fileTide.updateShortcut(shortcut, targetPath);
337
364
  }
338
365
  renameShortcut(shortcut, nextShortcut) {
339
- return fileTide.renameShortcut(shortcut, nextShortcut);
366
+ return this.fileTide.renameShortcut(shortcut, nextShortcut);
340
367
  }
341
368
  removeShortcut(shortcut) {
342
- return fileTide.removeShortcut(shortcut);
369
+ return this.fileTide.removeShortcut(shortcut);
343
370
  }
344
371
  setShortcuts(shortcuts = {}) {
345
- return fileTide.setShortcuts(shortcuts);
372
+ return this.fileTide.setShortcuts(shortcuts);
346
373
  }
347
374
  clearShortcuts() {
348
- return fileTide.clearShortcuts();
375
+ return this.fileTide.clearShortcuts();
349
376
  }
350
377
  resetShortcut(shortcut) {
351
- return fileTide.resetShortcut(shortcut);
378
+ return this.fileTide.resetShortcut(shortcut);
352
379
  }
353
380
  resetShortcuts() {
354
- return fileTide.resetShortcuts();
381
+ return this.fileTide.resetShortcuts();
355
382
  }
356
383
 
357
384
  // --- FileTide Client Client Settings Management ---
@@ -364,30 +391,17 @@ class FileTideClient {
364
391
  completion(room, true);
365
392
  }
366
393
  }
367
- async changeClientID(clientID, completion, reconnectClient = true, onReconnect = this.onConnect, onDisconnect = this.onDisconnect, clientConfigurations = this.clientConfigurations) {
368
- const clientOnline = await this.fileMessagerInstance.clientTide.emitEventWithResponse(clientID, "check-client-online", "retrieved-client-online", {
369
- clientID
370
- }, 5000);
371
- let updatedClientID = false;
372
- if (clientOnline && clientOnline.online && clientOnline.client.id !== this.connectionID) {
373
- FileTide.outputGradient(`[${this.deviceName}] Client name taken ~ ${this.deviceName}`, ["#4D96FF", "#89CFF0"]);
374
- } else if (!clientOnline || !clientOnline.online || clientOnline.client.id === this.connectionID) {
375
- const pDeviceName = this.deviceName;
376
- this.currentDeviceName = pDeviceName;
377
- this.clientDisconnected = true;
378
- this.fileMessagerInstance.clientTide.emitEvent(pDeviceName, "client-offline", {
379
- clientID: pDeviceName,
380
- connectionID: this.connectionID
381
- });
382
- this.fileMessagerInstance.clientTide.closeSocket(this.deviceName);
383
- this.deviceName = clientID;
384
- FileTide.outputGradient(`[${pDeviceName}] Updated client name to ${this.deviceName}`, ["#4D96FF", "#89CFF0"]);
385
- this.refreshConnection(reconnectClient, onReconnect, onDisconnect, clientConfigurations);
386
- updatedClientID = true;
387
- }
388
- if (completion) {
389
- completion(clientID, updatedClientID);
394
+ async changeClientID(clientID, completion, reconnectClient = true, onReconnect = this.onConnect, onDisconnect = this.onDisconnect, clientConfigurations = this.clientConfigurations, renameOptions = {}) {
395
+ const previousClientID = this.deviceName;
396
+ const result = await this.fileTide.updateClientID(previousClientID, clientID, renameOptions);
397
+ this.deviceName = clientID;
398
+ this.currentDeviceName = clientID;
399
+ this.originDeviceName = clientID;
400
+ this.connectionID = result.connectionID;
401
+ if (typeof completion === "function") {
402
+ completion(clientID, true);
390
403
  }
404
+ return result;
391
405
  }
392
406
  changeTideUrl(url, completion, reconnectClient = true, onReconnect = this.onConnect, onDisconnect = this.onDisconnect, clientConfigurations = this.clientConfigurations) {
393
407
  this.tideUrl = url;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trap_stevo/filetide-client",
3
- "version": "0.0.70",
3
+ "version": "0.0.72",
4
4
  "description": "Seamless, real-time file transfers between devices with effortless connectivity. Allowing for powerful, instant, secure, and cross-platform file sharing, enabling efficient and reliable data transfers in any network environment.",
5
5
  "main": "dist/cjs/FileTideClient.js",
6
6
  "exports": {
@@ -37,8 +37,8 @@
37
37
  "author": "Steven Compton",
38
38
  "license": "SCL-1.0-Universal",
39
39
  "dependencies": {
40
- "@trap_stevo/filetide": "^0.1.3",
41
- "@trap_stevo/iotide": "^0.0.46",
40
+ "@trap_stevo/filetide": "^0.1.5",
41
+ "@trap_stevo/iotide": "^0.0.48",
42
42
  "@trap_stevo/legendarybuilderpronodejs-utilities": "^1.0.51",
43
43
  "chalk": "^4.1.2"
44
44
  },
@@ -46,6 +46,7 @@
46
46
  "@babel/cli": "^7.24.8",
47
47
  "@babel/core": "^7.25.2",
48
48
  "@babel/plugin-proposal-class-properties": "^7.18.6",
49
+ "@babel/plugin-transform-private-methods": "^7.24.7",
49
50
  "@babel/plugin-transform-runtime": "^7.24.7",
50
51
  "@babel/preset-env": "^7.25.3"
51
52
  }