@trap_stevo/filetide 0.0.40 → 0.0.42
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/cjs/FileMessager.js +84 -20
- package/dist/cjs/FileMessagerClient.js +7 -5
- package/dist/cjs/FileTide.js +31 -7
- package/dist/cjs/HUDManagers/FileTransferManager.js +4 -2
- package/dist/cjs/HUDManagers/FileTransferRecoveryManager.js +0 -1
- package/package.json +2 -2
- package/data.json +0 -355185
package/dist/cjs/FileMessager.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
const {
|
|
4
|
+
OmniMap
|
|
5
|
+
} = require("@trap_stevo/legendarybuilderpronodejs-utilities/HUDStructs");
|
|
3
6
|
const IoTide = require("@trap_stevo/iotide");
|
|
4
7
|
const {
|
|
5
8
|
FileMessagerConfigManager
|
|
@@ -26,22 +29,23 @@ class FileMessager {
|
|
|
26
29
|
this.clientTransferBarriers = new Map();
|
|
27
30
|
this.currentTidingTransfers = new Map();
|
|
28
31
|
this.fileNet = new IoTide(serverOptions.port, serverOptions, true, this.onConnect.bind(this), this.onDisconnect.bind(this));
|
|
29
|
-
this.onlineClients = new
|
|
32
|
+
this.onlineClients = new OmniMap();
|
|
30
33
|
return;
|
|
31
34
|
}
|
|
32
35
|
onConnect(socket) {
|
|
33
|
-
console.log(`Client connected
|
|
36
|
+
console.log(`Client connected ~ ${socket.id}`);
|
|
34
37
|
this.onlineClients.set(socket.id, socket);
|
|
35
38
|
return;
|
|
36
39
|
}
|
|
37
40
|
onDisconnect(connectionRes, socket) {
|
|
38
|
-
console.log(`Client disconnected
|
|
41
|
+
console.log(`Client disconnected ~ ${socket.id}`);
|
|
39
42
|
this.onlineClients.delete(socket.id);
|
|
40
43
|
return;
|
|
41
44
|
}
|
|
42
45
|
start() {
|
|
43
46
|
this.fileNet.on("get-client-transfer-barrier-response", this.handleClientTransferBarrierResponse.bind(this));
|
|
44
47
|
this.fileNet.on("get-client-transfer-state", this.handleGetClientTransferState.bind(this));
|
|
48
|
+
this.fileNet.on("get-client", this.handleGetClient.bind(this));
|
|
45
49
|
this.fileNet.on("notify-transfer-barrier", this.handleNotifyTransferBarrier.bind(this));
|
|
46
50
|
this.fileNet.on("send-current-transfer-state", this.handleSendCurrentTransferState.bind(this));
|
|
47
51
|
this.fileNet.on("send-file-list-to-client", this.handleSendFileListToClient.bind(this));
|
|
@@ -51,6 +55,7 @@ class FileMessager {
|
|
|
51
55
|
this.fileNet.on("transfer-complete", this.handleFileTransferComplete.bind(this));
|
|
52
56
|
this.fileNet.on("request-transfer-from-client", this.handleRequestTransferFromClient.bind(this));
|
|
53
57
|
this.fileNet.on("client-to-client-transfer", this.handleClientToClientTransfer.bind(this));
|
|
58
|
+
this.fileNet.on("check-client-online", this.handleCheckClientOnline.bind(this));
|
|
54
59
|
this.fileNet.on("client-offline", this.handleClientOffline.bind(this));
|
|
55
60
|
this.fileNet.on("clients-online", this.handleClientsOnline.bind(this));
|
|
56
61
|
this.fileNet.on("client-online", this.handleClientOnline.bind(this));
|
|
@@ -321,7 +326,7 @@ class FileMessager {
|
|
|
321
326
|
}
|
|
322
327
|
handleGetClientTransferState(data) {
|
|
323
328
|
const filePath = data.filePath || data.path;
|
|
324
|
-
console.log(`[FileTide ~ Net] Getting ${data.recipientID}'s transfer state for ~ ${filePath}...`);
|
|
329
|
+
console.log(`[FileTide ~ Net] ~ Getting ${data.recipientID}'s transfer state for ~ ${filePath}...`);
|
|
325
330
|
try {
|
|
326
331
|
const recipientConnectionID = FileNetClientManager.getOnlineClient(data.recipientID).id;
|
|
327
332
|
const client = this.getClientFromID(recipientConnectionID);
|
|
@@ -330,12 +335,29 @@ class FileMessager {
|
|
|
330
335
|
}
|
|
331
336
|
this.fileNet.emitToTide(client.tideID, "current-transfer-state", {
|
|
332
337
|
senderID: data.senderID,
|
|
338
|
+
fileName: data.fileName,
|
|
333
339
|
filePath
|
|
334
340
|
});
|
|
335
341
|
} catch (error) {
|
|
336
342
|
return;
|
|
337
343
|
}
|
|
338
344
|
}
|
|
345
|
+
handleGetClient(data) {
|
|
346
|
+
console.log(`[FileTide ~ Net] ~ Getting client ~ ${data.clientID}...`);
|
|
347
|
+
try {
|
|
348
|
+
const senderConnectionID = FileNetClientManager.getOnlineClient(data.senderID).id;
|
|
349
|
+
const clientConnectionID = FileNetClientManager.getOnlineClient(data.clientID).id;
|
|
350
|
+
const senderClient = this.getClientFromID(clientConnectionID);
|
|
351
|
+
const client = this.getClientFromID(clientConnectionID);
|
|
352
|
+
if (!client || !senderClient) {
|
|
353
|
+
return;
|
|
354
|
+
}
|
|
355
|
+
console.log(`[FileTide ~ Net] Got client ~ ${data.clientID}!`);
|
|
356
|
+
this.fileNet.emitToTide(senderClient.tideID, "retrieved-current-client", client);
|
|
357
|
+
} catch (error) {
|
|
358
|
+
return;
|
|
359
|
+
}
|
|
360
|
+
}
|
|
339
361
|
handleNotifyTransferBarrier(data, emitToChannel) {
|
|
340
362
|
const accepted = data.accepted;
|
|
341
363
|
const transferID = data.data.transferID;
|
|
@@ -383,6 +405,30 @@ class FileMessager {
|
|
|
383
405
|
handleFileTransferComplete(data) {
|
|
384
406
|
console.log(`File transfer completed: ${data.fileName}`);
|
|
385
407
|
}
|
|
408
|
+
handleCheckClientOnline(data) {
|
|
409
|
+
console.log(`[FileTide ~ Net Activity] ~ Checking if client ~ ${data.clientID} online...`);
|
|
410
|
+
try {
|
|
411
|
+
const client = FileNetClientManager.getOnlineClient(data.clientID);
|
|
412
|
+
if (!client) {
|
|
413
|
+
this.fileNet.emit("retrieved-client-online", {
|
|
414
|
+
online: false,
|
|
415
|
+
client: null
|
|
416
|
+
});
|
|
417
|
+
return;
|
|
418
|
+
}
|
|
419
|
+
console.log(`[FileTide ~ Net Activity] ~ Client ~ ${data.clientID} online!`);
|
|
420
|
+
this.fileNet.emit("retrieved-client-online", {
|
|
421
|
+
online: true,
|
|
422
|
+
client
|
|
423
|
+
});
|
|
424
|
+
} catch (error) {
|
|
425
|
+
this.fileNet.emit("retrieved-client-online", {
|
|
426
|
+
online: false,
|
|
427
|
+
client: null
|
|
428
|
+
});
|
|
429
|
+
return;
|
|
430
|
+
}
|
|
431
|
+
}
|
|
386
432
|
handleClientsOnline(clientID) {
|
|
387
433
|
const connectionDetails = FileNetClientManager.getOnlineClient(clientID);
|
|
388
434
|
if (!connectionDetails) {
|
|
@@ -398,7 +444,12 @@ class FileMessager {
|
|
|
398
444
|
return;
|
|
399
445
|
}
|
|
400
446
|
handleClientOnline(clientID, tideID, pClientID, connectionID, activeTransferBarrier) {
|
|
401
|
-
if (!this.onlineClients.
|
|
447
|
+
if (!this.onlineClients.contains(connectionID)) {
|
|
448
|
+
return;
|
|
449
|
+
}
|
|
450
|
+
if (FileNetClientManager.getOnlineClient(clientID) && this.onlineClients.get(connectionID)) {
|
|
451
|
+
clientID = `${clientID}_${connectionID.slice(0, 4)}`;
|
|
452
|
+
this.fileNet.emitToTide(tideID, "current-client-id-already-online", clientID);
|
|
402
453
|
return;
|
|
403
454
|
}
|
|
404
455
|
FileNetClientManager.addOnlineClient(clientID, pClientID, tideID, connectionID);
|
|
@@ -406,25 +457,38 @@ class FileMessager {
|
|
|
406
457
|
clientID,
|
|
407
458
|
activeTransferBarrier
|
|
408
459
|
});
|
|
409
|
-
|
|
410
|
-
this.fileNet.emit("current-clients",
|
|
460
|
+
const currentOnlineClients = Object.fromEntries(FileNetClientManager.getOnlineClients());
|
|
461
|
+
this.fileNet.emit("current-online-clients", currentOnlineClients);
|
|
462
|
+
this.fileNet.emit("current-clients", currentOnlineClients);
|
|
411
463
|
return;
|
|
412
464
|
}
|
|
413
|
-
handleClientOffline(
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
465
|
+
handleClientOffline(clientData) {
|
|
466
|
+
console.log(`[FileTide ~ Net Activity] ~ Client ~ ${clientData.clientID} | connection origin ~ ${clientData.connectionID} going offline...`);
|
|
467
|
+
try {
|
|
468
|
+
const clientDetails = FileNetClientManager.getOnlineClient(clientData.clientID);
|
|
469
|
+
if (!clientDetails || clientDetails.id !== clientData.connectionID) {
|
|
470
|
+
console.log(!clientDetails ? `[FileTide ~ Net Activity] ~ Client ~ ${clientData.clientID} already offline.` : `[FileTide ~ Net Activity] ~ Unauthorized offline signal from connection ID ~ ${clientData.connectionID}.`);
|
|
471
|
+
return;
|
|
472
|
+
}
|
|
473
|
+
FileNetClientManager.clearOnlineClient(clientData.clientID);
|
|
474
|
+
const currentOnlineClients = Object.fromEntries(FileNetClientManager.getOnlineClients());
|
|
475
|
+
this.fileNet.emit("current-online-clients", currentOnlineClients);
|
|
476
|
+
this.fileNet.emit("current-clients", currentOnlineClients);
|
|
477
|
+
this.fileNet.emit("save-current-transfer-states", {
|
|
478
|
+
clientID: clientData.clientID
|
|
479
|
+
});
|
|
480
|
+
const tidingTransfers = this.currentTidingTransfers.get(clientData.clientID);
|
|
481
|
+
if (tidingTransfers && tidingTransfers.size > 0) {
|
|
482
|
+
for (let recipientID of tidingTransfers.keys()) {
|
|
483
|
+
this.fileNet.emit("save-current-transfer-states", {
|
|
484
|
+
clientID: recipientID
|
|
485
|
+
});
|
|
486
|
+
}
|
|
425
487
|
}
|
|
488
|
+
this.currentTidingTransfers.delete(clientData.clientID);
|
|
489
|
+
} catch (error) {
|
|
490
|
+
console.log(`[FileTide ~ Net Activity] ~ Did not process client ~ ${clientData} offline signal ~ ${error}`);
|
|
426
491
|
}
|
|
427
|
-
this.currentTidingTransfers.delete(clientID);
|
|
428
492
|
return;
|
|
429
493
|
}
|
|
430
494
|
handleClientTiding(data) {
|
|
@@ -49,12 +49,14 @@ class FileMessagerClient {
|
|
|
49
49
|
const socketName = this.createClientInstance(userID, {
|
|
50
50
|
url: this.clientOptions.url
|
|
51
51
|
}, options, headers, onConnect, onDisconnect, authURL, authHeaders, useAuthentication, queryAuthToken);
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
52
|
+
return () => {
|
|
53
|
+
this.clientTide.joinChannel(socketName, roomName, userID, () => {
|
|
54
|
+
FileNetUtilityManager.outputGradient(`\n[FileTide ~ File Messager] ~ Client ~ ${userID} joined room ${roomName} successfully!`, significantMessageColors);
|
|
55
|
+
this.clients.set(userID, {
|
|
56
|
+
roomName
|
|
57
|
+
});
|
|
56
58
|
});
|
|
57
|
-
}
|
|
59
|
+
};
|
|
58
60
|
}
|
|
59
61
|
async requestTransfer(clientID, senderID, filePath, destinationPath, filterContent = []) {
|
|
60
62
|
const transferAllowed = await this.allowedTransfer(clientID, senderID, destinationPath, "N/A", "requestSend");
|
package/dist/cjs/FileTide.js
CHANGED
|
@@ -90,14 +90,14 @@ class FileTide {
|
|
|
90
90
|
this.stopMessager(userID);
|
|
91
91
|
}
|
|
92
92
|
const newClient = new FileMessagerClient(clientOptions);
|
|
93
|
-
newClient.joinRoom(userID, roomName, connectionOptions, headers, onConnect, onDisconnect, authURL, authHeaders, useAuthentication, queryAuthToken);
|
|
93
|
+
const enterRoom = newClient.joinRoom(userID, roomName, connectionOptions, headers, onConnect, onDisconnect, authURL, authHeaders, useAuthentication, queryAuthToken);
|
|
94
94
|
this.transferBarrier = enableTransferBarrier;
|
|
95
95
|
this.clientShorePolicies.set(userID, [FileUtilityManager.getTidePath(">CurrentUser"), FileUtilityManager.getTidePath(">Downloads"), FileUtilityManager.getTidePath(">Documents")]);
|
|
96
96
|
this.clients.set(userID, newClient);
|
|
97
97
|
FileTide.outputGradient(`[FileTide] ~ Messager launched successfully for client ~ ${userID}!`, significantMessageColors);
|
|
98
98
|
_assertClassBrand(_FileTide_brand, this, _setupFileEventListeners).call(this, userID, newClient, onTransferProgress, onIncomingTransfer, onIncomingFile, onTransferBarrier, options);
|
|
99
99
|
if (onLaunch) {
|
|
100
|
-
onLaunch(newClient);
|
|
100
|
+
onLaunch(newClient, enterRoom);
|
|
101
101
|
}
|
|
102
102
|
return;
|
|
103
103
|
}
|
|
@@ -176,6 +176,13 @@ class FileTide {
|
|
|
176
176
|
FileTide.outputGradient(`[FileTide] Client ~ ${clientID} not found.`, ["#F94144", "#F3722C"]);
|
|
177
177
|
return;
|
|
178
178
|
}
|
|
179
|
+
const recipientOnline = await clientMessager.clientTide.emitEventWithResponse(clientID, "check-client-online", "retrieved-client-online", {
|
|
180
|
+
clientID: recipientID
|
|
181
|
+
}, 5000);
|
|
182
|
+
if (!recipientOnline || !recipientOnline.online) {
|
|
183
|
+
FileTide.outputGradient(`[FileTide] ${recipientID} currently not tiding.`, ["#F94144", "#F3722C"]);
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
179
186
|
const fileDetails = await this.getPathData(filePath, filterDirectoryContent);
|
|
180
187
|
if (!fileDetails) {
|
|
181
188
|
FileTide.outputGradient(`[${clientID}] File at path ${filePath} not found.`, ["#F94144", "#F3722C"]);
|
|
@@ -235,6 +242,10 @@ class FileTide {
|
|
|
235
242
|
stopMessager(userID) {
|
|
236
243
|
if (this.clients.has(userID)) {
|
|
237
244
|
FileTide.outputGradient(`Stopping messager for user ${userID}...`, significantMessageColors);
|
|
245
|
+
const connectionOrigin = this.clients.get(userID);
|
|
246
|
+
if (connectionOrigin) {
|
|
247
|
+
connectionOrigin.clientTide.closeSocket(userID);
|
|
248
|
+
}
|
|
238
249
|
this.clients.delete(userID);
|
|
239
250
|
FileTide.outputGradient(`Stopped messager for user ${userID}.`, significantMessageColors);
|
|
240
251
|
return;
|
|
@@ -262,7 +273,8 @@ function _setupFileEventListeners(userID, client, onTransferProgress, onIncoming
|
|
|
262
273
|
onTransferStatus,
|
|
263
274
|
onListFiles,
|
|
264
275
|
onCurrentOnlineClients,
|
|
265
|
-
onClientTiding
|
|
276
|
+
onClientTiding,
|
|
277
|
+
onCurrentClientIDAlreadyOnline
|
|
266
278
|
} = options;
|
|
267
279
|
const cliTable = new ConsoleTable({
|
|
268
280
|
padding: 2,
|
|
@@ -328,6 +340,16 @@ function _setupFileEventListeners(userID, client, onTransferProgress, onIncoming
|
|
|
328
340
|
onCurrentOnlineClients(currentClients, false);
|
|
329
341
|
}
|
|
330
342
|
});
|
|
343
|
+
client.clientTide.onEvent(userID, "current-client-id-already-online", clientID => {
|
|
344
|
+
if (userID === clientID) {
|
|
345
|
+
return;
|
|
346
|
+
}
|
|
347
|
+
_FileTide.outputGradient(`[FileTide ~ FileNet] ~ Client ~ ${userID} already online.`, significantMessageColors);
|
|
348
|
+
if (onCurrentClientIDAlreadyOnline) {
|
|
349
|
+
onCurrentClientIDAlreadyOnline(clientID);
|
|
350
|
+
}
|
|
351
|
+
return;
|
|
352
|
+
});
|
|
331
353
|
client.clientTide.onEvent(userID, "save-current-transfer-states", async data => {
|
|
332
354
|
this.saveTransferStates();
|
|
333
355
|
return;
|
|
@@ -335,9 +357,10 @@ function _setupFileEventListeners(userID, client, onTransferProgress, onIncoming
|
|
|
335
357
|
client.clientTide.onEvent(userID, "current-transfer-state", async data => {
|
|
336
358
|
const {
|
|
337
359
|
senderID,
|
|
360
|
+
fileName,
|
|
338
361
|
filePath
|
|
339
362
|
} = data;
|
|
340
|
-
const currentTransferState = FileTransferRecoveryManager.getTransferState(userID, senderID, filePath);
|
|
363
|
+
const currentTransferState = FileTransferRecoveryManager.getTransferState(userID, senderID, `${filePath}-${fileName}`);
|
|
341
364
|
client.clientTide.emitEvent(userID, "send-current-transfer-state", {
|
|
342
365
|
recipientID: userID,
|
|
343
366
|
senderID,
|
|
@@ -424,11 +447,11 @@ function _setupFileEventListeners(userID, client, onTransferProgress, onIncoming
|
|
|
424
447
|
}
|
|
425
448
|
await fileTransferReceiver.handleTransferProgress(data);
|
|
426
449
|
this.progressBarManager.updateTaskProgress(data.fileName, data.chunkSize || 512 * 1024);
|
|
427
|
-
const currentTransferState = FileTransferRecoveryManager.getTransferState(userID, data.senderName, data.path) || {
|
|
450
|
+
const currentTransferState = FileTransferRecoveryManager.getTransferState(userID, data.senderName, `${data.path}-${data.fileName}`) || {
|
|
428
451
|
transferredSize: 0
|
|
429
452
|
};
|
|
430
453
|
currentTransferState.transferredSize += data.chunkSize || 512 * 1024;
|
|
431
|
-
FileTransferRecoveryManager.saveTransferState(userID, data.senderName, data.path
|
|
454
|
+
FileTransferRecoveryManager.saveTransferState(userID, data.senderName, `${data.path}-${data.fileName}`, data.chunkIndex, currentTransferState.transferredSize);
|
|
432
455
|
if (onTransferProgress) {
|
|
433
456
|
onTransferProgress(data);
|
|
434
457
|
}
|
|
@@ -458,11 +481,12 @@ function _setupFileEventListeners(userID, client, onTransferProgress, onIncoming
|
|
|
458
481
|
_FileTide.outputGradient(`[${userID}] File transfer complete : ${data.fileName}`, significantMessageColors);
|
|
459
482
|
const transferState = fileTransferReceiver.activeTransfers.get(data.fileName);
|
|
460
483
|
if (!transferState) {
|
|
484
|
+
FileTransferRecoveryManager.clearTransferState(userID, data.senderID, `${data.filePath}-${data.fileName}`);
|
|
461
485
|
return;
|
|
462
486
|
}
|
|
463
487
|
fileTransferReceiver.completeTransfer(data, (transferData, transfers, success, error) => {
|
|
464
488
|
if (success) {
|
|
465
|
-
FileTransferRecoveryManager.clearTransferState(userID, data.senderID, data.filePath);
|
|
489
|
+
FileTransferRecoveryManager.clearTransferState(userID, data.senderID, `${data.filePath}-${data.fileName}`);
|
|
466
490
|
_FileTide.outputGradient(`[${userID}] File saved at : ${savePath}\n`, significantMessageColors);
|
|
467
491
|
} else if (!success) {
|
|
468
492
|
_FileTide.outputGradient(`[${userID}] Did not save file at : ${savePath}\n\t${error}\n`, errorMessageColors);
|
|
@@ -43,7 +43,8 @@ class FileTransferManager {
|
|
|
43
43
|
const recoveredTransferState = (await clientTide.emitEventWithResponse(originDetails.senderID, "get-client-transfer-state", "sent-current-transfer-state", {
|
|
44
44
|
recipientID,
|
|
45
45
|
senderID: originDetails.senderID,
|
|
46
|
-
filePath: fileDetails.destinationPath
|
|
46
|
+
filePath: fileDetails.destinationPath,
|
|
47
|
+
fileName: fileDetails.name
|
|
47
48
|
}, 30000)) || {
|
|
48
49
|
transferredSize: 0,
|
|
49
50
|
lastChunkSent: 0
|
|
@@ -134,7 +135,8 @@ async function _startTransfer(file, transferId, fileDetails, originDetails, onSe
|
|
|
134
135
|
const recoveredTransferState = (await clientTide.emitEventWithResponse(originDetails.senderID, "get-client-transfer-state", "sent-current-transfer-state", {
|
|
135
136
|
recipientID: originDetails.recipientID,
|
|
136
137
|
senderID: originDetails.senderID,
|
|
137
|
-
filePath: fileDetails.destinationPath
|
|
138
|
+
filePath: fileDetails.destinationPath,
|
|
139
|
+
fileName: fileDetails.name
|
|
138
140
|
}, 30000)) || {
|
|
139
141
|
transferredSize: 0,
|
|
140
142
|
lastChunkSent: 0
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trap_stevo/filetide",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.42",
|
|
4
4
|
"description": "Revolutionizing real-time file transfer with seamless, instant communication across any device. Deliver files instantly, regardless of platform, and experience unparalleled speed and control in managing transfers. Elevate your file-sharing capabilities with a tool designed for precision, efficiency, and effortless connectivity.",
|
|
5
5
|
"main": "dist/cjs/FileTide.js",
|
|
6
6
|
"scripts": {
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"@trap_stevo/iotide": "^0.0.37",
|
|
33
33
|
"@trap_stevo/iotide-client": "^0.0.23",
|
|
34
|
-
"@trap_stevo/legendarybuilderpronodejs-utilities": "^1.0.
|
|
34
|
+
"@trap_stevo/legendarybuilderpronodejs-utilities": "^1.0.42",
|
|
35
35
|
"chalk": "^4.1.2",
|
|
36
36
|
"readline": "^1.3.0"
|
|
37
37
|
},
|