@trap_stevo/filetide-client 0.0.71 → 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,
@@ -189,13 +188,12 @@ class FileTideClient {
189
188
  * originClientID
190
189
  * currentTideChannel
191
190
  */
192
- this.fileMessagerInstance.clientTide.emitEvent(this.deviceName, "client-online", this.deviceName, socket.tideID, this.currentDeviceName, socket.id, fileTide.transferBarrier, this.originDeviceName, this.currentRoom);
193
- 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);
194
192
  if (typeof onConnect === "function") {
195
193
  await onConnect(this.fileMessagerInstance, ...connectionArguments);
196
194
  }
197
195
  };
198
- fileTide.launchMessager({
196
+ this.fileTide.launchMessager({
199
197
  serverUrl: this.tideUrl,
200
198
  ...clientOptions
201
199
  }, {
@@ -203,12 +201,30 @@ class FileTideClient {
203
201
  pingTimeout: 3600000,
204
202
  pingInterval: 60000,
205
203
  ...connectionOptions
206
- }, 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;
207
208
  this.fileMessagerInstance = fileMessager;
208
- fileMessagerInstance = fileMessager;
209
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
+ });
210
226
  if (typeof onLaunch === "function") {
211
- onLaunch(fileMessager, roomEntry);
227
+ onLaunch(fileMessager, roomEntry, resolvedClientID);
212
228
  }
213
229
  if (pendingConnectionArguments) {
214
230
  const connectionArguments = pendingConnectionArguments;
@@ -244,6 +260,18 @@ class FileTideClient {
244
260
  this.startClient(this.clientOptions, this.connectionOptions, this.transportOptions, this.messagerSettings, onReconnect, onDisconnect, clientConfigurations);
245
261
  }
246
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
+
247
275
  // --- FileTide Client Transfer Management ---
248
276
 
249
277
  async requestFileTransfer(senderID, filePath, destinationPath, filterContent = [], transferRequestExpirationTime = 30000) {
@@ -251,106 +279,106 @@ class FileTideClient {
251
279
  return await this.fileMessagerInstance.requestTransfer(this.deviceName, senderID, filePath, destinationPath, filterContent, transferRequestExpirationTime);
252
280
  }
253
281
  async transferFiles(recipientID, filePath, destinationPath, filterContent = [], tideSize = 200, tidalSize = 500, minTideSize = 10, maxTideSize = 2000, transferRequestExpirationTime = 30000, metadata = {}) {
254
- 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);
255
283
  }
256
284
  listFiles(recipientID, depth = 1) {
257
- return fileTide.listFilesFromClient(recipientID, depth);
285
+ return this.fileTide.listFilesFromClient(recipientID, depth);
258
286
  }
259
287
 
260
288
  // --- FileTide Client Transfer State Management ---
261
289
 
262
290
  getTransferStats(transferID) {
263
- return fileTide.getTransferStats(transferID);
291
+ return this.fileTide.getTransferStats(transferID);
264
292
  }
265
293
  getTransferStatsOverview() {
266
- return fileTide.getTransferStatsOverview();
294
+ return this.fileTide.getTransferStatsOverview();
267
295
  }
268
296
 
269
297
  // --- FileTide Client Transfer History Management ---
270
298
 
271
299
  async getTransferHistory(options = {}) {
272
- return await fileTide.getTransferHistory(options);
300
+ return await this.fileTide.getTransferHistory(options);
273
301
  }
274
302
  async getTransferHistoryEntry(transferID, options = {}) {
275
- return await fileTide.getTransferHistoryEntry(transferID, options);
303
+ return await this.fileTide.getTransferHistoryEntry(transferID, options);
276
304
  }
277
305
  async clearTransferHistory(options = {}) {
278
- return await fileTide.clearTransferHistory(options);
306
+ return await this.fileTide.clearTransferHistory(options);
279
307
  }
280
308
  async pruneTransferHistory(maxEntries, options = {}) {
281
- return await fileTide.pruneTransferHistory(maxEntries, options);
309
+ return await this.fileTide.pruneTransferHistory(maxEntries, options);
282
310
  }
283
311
 
284
312
  // --- FileTide Client Shore Policy Management ---
285
313
 
286
314
  async clearShorePolicies(clientID = this.deviceName) {
287
- return await fileTide.clearShorePolicies(clientID);
315
+ return await this.fileTide.clearShorePolicies(clientID);
288
316
  }
289
317
  async removeShorePolicies(shores = [], clientID = this.deviceName) {
290
- return await fileTide.removeShorePolicies(clientID, shores);
318
+ return await this.fileTide.removeShorePolicies(clientID, shores);
291
319
  }
292
320
  async addShorePolicies(shores = [], clientID = this.deviceName) {
293
- return await fileTide.addShorePolicies(clientID, shores);
321
+ return await this.fileTide.addShorePolicies(clientID, shores);
294
322
  }
295
323
  async setShorePolicies(shores = [], clientID = this.deviceName) {
296
- return await fileTide.setShorePolicies(clientID, shores);
324
+ return await this.fileTide.setShorePolicies(clientID, shores);
297
325
  }
298
326
  async resetShorePolicies(clientID = this.deviceName) {
299
- return await fileTide.resetShorePolicies(clientID);
327
+ return await this.fileTide.resetShorePolicies(clientID);
300
328
  }
301
329
  async pathWithinShorePolicies(inputPath, clientID = this.deviceName) {
302
- return await fileTide.pathWithinShorePolicies(clientID, inputPath);
330
+ return await this.fileTide.pathWithinShorePolicies(clientID, inputPath);
303
331
  }
304
332
  async getShorePolicies(clientID = this.deviceName) {
305
- return await fileTide.getShorePolicies(clientID);
333
+ return await this.fileTide.getShorePolicies(clientID);
306
334
  }
307
335
  getDefaultShorePolicies() {
308
- return fileTide.getDefaultShorePolicies();
336
+ return this.fileTide.getDefaultShorePolicies();
309
337
  }
310
338
  async getResolvedShorePolicies(clientID = this.deviceName) {
311
- return await fileTide.getResolvedShorePolicies(clientID);
339
+ return await this.fileTide.getResolvedShorePolicies(clientID);
312
340
  }
313
341
 
314
342
  // --- FileTide Client Shortcut Management ---
315
343
 
316
344
  getDefaultShortcuts() {
317
- return fileTide.getDefaultShortcuts();
345
+ return this.fileTide.getDefaultShortcuts();
318
346
  }
319
347
  getShortcuts() {
320
- return fileTide.getShortcuts();
348
+ return this.fileTide.getShortcuts();
321
349
  }
322
350
  getShortcut(shortcut) {
323
- return fileTide.getShortcut(shortcut);
351
+ return this.fileTide.getShortcut(shortcut);
324
352
  }
325
353
  hasShortcut(shortcut) {
326
- return fileTide.hasShortcut(shortcut);
354
+ return this.fileTide.hasShortcut(shortcut);
327
355
  }
328
356
  addShortcut(shortcut, targetPath) {
329
- return fileTide.addShortcut(shortcut, targetPath);
357
+ return this.fileTide.addShortcut(shortcut, targetPath);
330
358
  }
331
359
  setShortcut(shortcut, targetPath) {
332
- return fileTide.setShortcut(shortcut, targetPath);
360
+ return this.fileTide.setShortcut(shortcut, targetPath);
333
361
  }
334
362
  updateShortcut(shortcut, targetPath) {
335
- return fileTide.updateShortcut(shortcut, targetPath);
363
+ return this.fileTide.updateShortcut(shortcut, targetPath);
336
364
  }
337
365
  renameShortcut(shortcut, nextShortcut) {
338
- return fileTide.renameShortcut(shortcut, nextShortcut);
366
+ return this.fileTide.renameShortcut(shortcut, nextShortcut);
339
367
  }
340
368
  removeShortcut(shortcut) {
341
- return fileTide.removeShortcut(shortcut);
369
+ return this.fileTide.removeShortcut(shortcut);
342
370
  }
343
371
  setShortcuts(shortcuts = {}) {
344
- return fileTide.setShortcuts(shortcuts);
372
+ return this.fileTide.setShortcuts(shortcuts);
345
373
  }
346
374
  clearShortcuts() {
347
- return fileTide.clearShortcuts();
375
+ return this.fileTide.clearShortcuts();
348
376
  }
349
377
  resetShortcut(shortcut) {
350
- return fileTide.resetShortcut(shortcut);
378
+ return this.fileTide.resetShortcut(shortcut);
351
379
  }
352
380
  resetShortcuts() {
353
- return fileTide.resetShortcuts();
381
+ return this.fileTide.resetShortcuts();
354
382
  }
355
383
 
356
384
  // --- FileTide Client Client Settings Management ---
@@ -363,30 +391,17 @@ class FileTideClient {
363
391
  completion(room, true);
364
392
  }
365
393
  }
366
- async changeClientID(clientID, completion, reconnectClient = true, onReconnect = this.onConnect, onDisconnect = this.onDisconnect, clientConfigurations = this.clientConfigurations) {
367
- const clientOnline = await this.fileMessagerInstance.clientTide.emitEventWithResponse(clientID, "check-client-online", "retrieved-client-online", {
368
- clientID
369
- }, 5000);
370
- let updatedClientID = false;
371
- if (clientOnline && clientOnline.online && clientOnline.client.id !== this.connectionID) {
372
- FileTide.outputGradient(`[${this.deviceName}] Client name taken ~ ${this.deviceName}`, ["#4D96FF", "#89CFF0"]);
373
- } else if (!clientOnline || !clientOnline.online || clientOnline.client.id === this.connectionID) {
374
- const pDeviceName = this.deviceName;
375
- this.currentDeviceName = pDeviceName;
376
- this.clientDisconnected = true;
377
- this.fileMessagerInstance.clientTide.emitEvent(pDeviceName, "client-offline", {
378
- clientID: pDeviceName,
379
- connectionID: this.connectionID
380
- });
381
- this.fileMessagerInstance.clientTide.closeSocket(this.deviceName);
382
- this.deviceName = clientID;
383
- FileTide.outputGradient(`[${pDeviceName}] Updated client name to ${this.deviceName}`, ["#4D96FF", "#89CFF0"]);
384
- this.refreshConnection(reconnectClient, onReconnect, onDisconnect, clientConfigurations);
385
- updatedClientID = true;
386
- }
387
- if (completion) {
388
- 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);
389
403
  }
404
+ return result;
390
405
  }
391
406
  changeTideUrl(url, completion, reconnectClient = true, onReconnect = this.onConnect, onDisconnect = this.onDisconnect, clientConfigurations = this.clientConfigurations) {
392
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.71",
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.4",
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
  }