@trap_stevo/filetide 0.0.38 → 0.0.40
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/data.json +355185 -0
- package/dist/cjs/FileMessager.js +241 -76
- package/dist/cjs/FileMessagerClient.js +145 -39
- package/dist/cjs/FileTide.js +120 -40
- package/dist/cjs/HUDComponents/ChunkCapacitor.js +35 -0
- package/dist/cjs/HUDComponents/ConsoleProgressBarManager.js +5 -1
- package/dist/cjs/HUDManagers/FileTransferManager.js +134 -20
- package/dist/cjs/HUDManagers/FileTransferReceiverManager.js +82 -0
- package/dist/cjs/HUDManagers/FileTransferRecoveryManager.js +94 -0
- package/dist/cjs/HUDManagers/FileUtilityManager.js +140 -72
- package/package.json +2 -2
package/dist/cjs/FileMessager.js
CHANGED
|
@@ -24,6 +24,7 @@ class FileMessager {
|
|
|
24
24
|
this.transferQueue = new HUDTargetQueue();
|
|
25
25
|
this.currentTransferBarrierTransfers = new Map();
|
|
26
26
|
this.clientTransferBarriers = new Map();
|
|
27
|
+
this.currentTidingTransfers = new Map();
|
|
27
28
|
this.fileNet = new IoTide(serverOptions.port, serverOptions, true, this.onConnect.bind(this), this.onDisconnect.bind(this));
|
|
28
29
|
this.onlineClients = new Map();
|
|
29
30
|
return;
|
|
@@ -40,7 +41,9 @@ class FileMessager {
|
|
|
40
41
|
}
|
|
41
42
|
start() {
|
|
42
43
|
this.fileNet.on("get-client-transfer-barrier-response", this.handleClientTransferBarrierResponse.bind(this));
|
|
44
|
+
this.fileNet.on("get-client-transfer-state", this.handleGetClientTransferState.bind(this));
|
|
43
45
|
this.fileNet.on("notify-transfer-barrier", this.handleNotifyTransferBarrier.bind(this));
|
|
46
|
+
this.fileNet.on("send-current-transfer-state", this.handleSendCurrentTransferState.bind(this));
|
|
44
47
|
this.fileNet.on("send-file-list-to-client", this.handleSendFileListToClient.bind(this));
|
|
45
48
|
this.fileNet.on("list-client-files", this.handleListClientFiles.bind(this));
|
|
46
49
|
this.fileNet.on("transfer-start", this.handleFileTransferStart.bind(this));
|
|
@@ -51,6 +54,7 @@ class FileMessager {
|
|
|
51
54
|
this.fileNet.on("client-offline", this.handleClientOffline.bind(this));
|
|
52
55
|
this.fileNet.on("clients-online", this.handleClientsOnline.bind(this));
|
|
53
56
|
this.fileNet.on("client-online", this.handleClientOnline.bind(this));
|
|
57
|
+
this.fileNet.on("client-tiding", this.handleClientTiding.bind(this));
|
|
54
58
|
return;
|
|
55
59
|
}
|
|
56
60
|
getClientFromID(clientID) {
|
|
@@ -84,7 +88,7 @@ class FileMessager {
|
|
|
84
88
|
* @param {String} fileName - The name of the file
|
|
85
89
|
* @param {Number} chunkIndex - The index of the current chunk
|
|
86
90
|
*/
|
|
87
|
-
sendFileChunkToClient(senderData, clientData, fileChunk, fileName, chunkIndex, totalChunks, filePath = process.cwd(), fileSize = 100) {
|
|
91
|
+
sendFileChunkToClient(senderData, clientData, fileChunk, fileName, chunkIndex, chunkSize, totalChunks, filePath = process.cwd(), fileSize = 100) {
|
|
88
92
|
const senderClient = this.getClientFromID(senderData.id);
|
|
89
93
|
const client = this.getClientFromID(clientData.id);
|
|
90
94
|
if (!client) {
|
|
@@ -102,10 +106,12 @@ class FileMessager {
|
|
|
102
106
|
});
|
|
103
107
|
}
|
|
104
108
|
this.fileNet.emitToTide(client.tideID, "transfer-progress", {
|
|
109
|
+
senderName: senderData.userID,
|
|
105
110
|
senderID: senderData.id,
|
|
106
111
|
fileName,
|
|
107
112
|
fileChunk,
|
|
108
113
|
chunkIndex,
|
|
114
|
+
chunkSize,
|
|
109
115
|
path: filePath,
|
|
110
116
|
fileSize
|
|
111
117
|
});
|
|
@@ -114,7 +120,13 @@ class FileMessager {
|
|
|
114
120
|
this.fileNet.emitToTide(senderClient.tideID, "transfer-status", {
|
|
115
121
|
status: `Chunk ${chunkIndex} of ${fileName} sent to client ${clientData.userID}!`,
|
|
116
122
|
recipientID: clientData.userID,
|
|
117
|
-
success: true
|
|
123
|
+
success: true,
|
|
124
|
+
fileName,
|
|
125
|
+
chunkIndex,
|
|
126
|
+
totalChunks,
|
|
127
|
+
chunkSize,
|
|
128
|
+
path: filePath,
|
|
129
|
+
fileSize
|
|
118
130
|
});
|
|
119
131
|
}
|
|
120
132
|
}
|
|
@@ -130,20 +142,26 @@ class FileMessager {
|
|
|
130
142
|
handleSendFileListToClient(listData) {
|
|
131
143
|
const {
|
|
132
144
|
listedFiles,
|
|
145
|
+
totalItems,
|
|
133
146
|
recipientID,
|
|
134
147
|
senderID
|
|
135
148
|
} = listData;
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
149
|
+
try {
|
|
150
|
+
const recipientConnectionID = FileNetClientManager.getOnlineClient(recipientID).id;
|
|
151
|
+
const senderConnectionID = FileNetClientManager.getOnlineClient(senderID).id;
|
|
152
|
+
const senderClient = this.getClientFromID(senderConnectionID);
|
|
153
|
+
const client = this.getClientFromID(recipientConnectionID);
|
|
154
|
+
if (!client || !senderClient) {
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
this.fileNet.emitToTide(client.tideID, "client-file-list", {
|
|
158
|
+
senderID,
|
|
159
|
+
totalItems,
|
|
160
|
+
listedFiles
|
|
161
|
+
});
|
|
162
|
+
} catch (error) {
|
|
141
163
|
return;
|
|
142
164
|
}
|
|
143
|
-
this.fileNet.emitToTide(client.tideID, "client-file-list", {
|
|
144
|
-
senderID,
|
|
145
|
-
listedFiles
|
|
146
|
-
});
|
|
147
165
|
}
|
|
148
166
|
handleListClientFiles(clientData) {
|
|
149
167
|
const {
|
|
@@ -151,80 +169,172 @@ class FileMessager {
|
|
|
151
169
|
recipientID,
|
|
152
170
|
depth = 1
|
|
153
171
|
} = clientData;
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
172
|
+
try {
|
|
173
|
+
const recipientConnectionID = FileNetClientManager.getOnlineClient(recipientID).id;
|
|
174
|
+
const senderConnectionID = FileNetClientManager.getOnlineClient(requesterID).id;
|
|
175
|
+
const senderClient = this.getClientFromID(senderConnectionID);
|
|
176
|
+
const client = this.getClientFromID(recipientConnectionID);
|
|
177
|
+
if (!client || !senderClient) {
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
this.fileNet.emitToTide(client.tideID, "list-files", {
|
|
181
|
+
senderID: requesterID,
|
|
182
|
+
recipientID,
|
|
183
|
+
depth
|
|
184
|
+
});
|
|
185
|
+
} catch (error) {
|
|
159
186
|
return;
|
|
160
187
|
}
|
|
161
|
-
this.fileNet.emitToTide(client.tideID, "list-files", {
|
|
162
|
-
senderID: requesterID,
|
|
163
|
-
recipientID,
|
|
164
|
-
depth
|
|
165
|
-
});
|
|
166
188
|
}
|
|
167
189
|
handleClientToClientTransfer(transferData) {
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
190
|
+
try {
|
|
191
|
+
const {
|
|
192
|
+
chunkBatch
|
|
193
|
+
} = transferData;
|
|
194
|
+
if (chunkBatch && chunkBatch.length > 0) {
|
|
195
|
+
for (const chunkData of chunkBatch) {
|
|
196
|
+
const {
|
|
197
|
+
senderID,
|
|
198
|
+
recipientId,
|
|
199
|
+
fileName,
|
|
200
|
+
fileChunk,
|
|
201
|
+
fileSize,
|
|
202
|
+
filePath,
|
|
203
|
+
chunkIndex,
|
|
204
|
+
chunkSize,
|
|
205
|
+
completedChunks,
|
|
206
|
+
totalChunks
|
|
207
|
+
} = chunkData;
|
|
208
|
+
console.log(`[FileTide ~ File Messager] ~ Transferring file ~ ${fileName} | chunk ${chunkIndex + 1} >> ${completedChunks} of ${totalChunks} to client (${recipientId})`);
|
|
209
|
+
this.sendFileChunkToClient({
|
|
210
|
+
userID: senderID,
|
|
211
|
+
id: FileNetClientManager.getOnlineClient(senderID).id
|
|
212
|
+
}, {
|
|
213
|
+
userID: recipientId,
|
|
214
|
+
id: FileNetClientManager.getOnlineClient(recipientId).id
|
|
215
|
+
}, fileChunk, fileName, chunkIndex, chunkSize, totalChunks, filePath, fileSize);
|
|
216
|
+
if (completedChunks === totalChunks) {
|
|
217
|
+
this.fileNet.emit("transfer-complete", {
|
|
218
|
+
senderID,
|
|
219
|
+
recipientId,
|
|
220
|
+
fileName,
|
|
221
|
+
filePath
|
|
222
|
+
});
|
|
223
|
+
console.log(`[FileTide ~ File Messager] ~ File transfer completed: ${fileName} from ${senderID} to ${recipientId}`);
|
|
224
|
+
const tidingTransfers = this.currentTidingTransfers.get(senderID);
|
|
225
|
+
if (tidingTransfers) {
|
|
226
|
+
tidingTransfers.delete(recipientId);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
const {
|
|
188
233
|
senderID,
|
|
189
234
|
recipientId,
|
|
190
235
|
fileName,
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
236
|
+
fileChunk,
|
|
237
|
+
fileSize,
|
|
238
|
+
filePath,
|
|
239
|
+
chunkIndex,
|
|
240
|
+
chunkSize,
|
|
241
|
+
completedChunks,
|
|
242
|
+
totalChunks
|
|
243
|
+
} = transferData;
|
|
244
|
+
console.log(`[FileTide ~ File Messager] ~ Transferring file ~ ${fileName} | chunk ${chunkIndex + 1} >> ${completedChunks} of ${totalChunks} to client (${recipientId})`);
|
|
245
|
+
this.sendFileChunkToClient({
|
|
246
|
+
userID: senderID,
|
|
247
|
+
id: FileNetClientManager.getOnlineClient(senderID).id
|
|
248
|
+
}, {
|
|
249
|
+
userID: recipientId,
|
|
250
|
+
id: FileNetClientManager.getOnlineClient(recipientId).id
|
|
251
|
+
}, fileChunk, fileName, chunkIndex, chunkSize, totalChunks, filePath, fileSize);
|
|
252
|
+
if (chunkIndex + 1 === totalChunks) {
|
|
253
|
+
this.fileNet.emit("transfer-complete", {
|
|
254
|
+
senderID,
|
|
255
|
+
recipientId,
|
|
256
|
+
fileName,
|
|
257
|
+
filePath
|
|
258
|
+
});
|
|
259
|
+
console.log(`[FileTide ~ File Messager] ~ File transfer completed: ${fileName} from ${senderID} to ${recipientId}`);
|
|
260
|
+
const tidingTransfers = this.currentTidingTransfers.get(senderID);
|
|
261
|
+
if (tidingTransfers) {
|
|
262
|
+
tidingTransfers.delete(recipientId);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
} catch (error) {
|
|
266
|
+
console.log(error);
|
|
267
|
+
return;
|
|
194
268
|
}
|
|
195
269
|
}
|
|
196
270
|
handleClientTransferBarrierResponse(data) {
|
|
197
|
-
console.log(`Checking ${data.recipientID}'s transfer barrier for transfer ~ ${data.transferID}...`);
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
271
|
+
console.log(`[FileTide ~ Net] Checking ${data.recipientID}'s transfer barrier for transfer ~ ${data.transferID}...`);
|
|
272
|
+
try {
|
|
273
|
+
const recipientConnectionID = FileNetClientManager.getOnlineClient(data.recipientID).id;
|
|
274
|
+
const senderConnectionID = FileNetClientManager.getOnlineClient(data.clientID).id;
|
|
275
|
+
const senderClient = this.getClientFromID(senderConnectionID);
|
|
276
|
+
const client = this.getClientFromID(recipientConnectionID);
|
|
277
|
+
if (!client || !senderClient) {
|
|
278
|
+
return;
|
|
279
|
+
}
|
|
280
|
+
this.fileNet.emitToTide(client.tideID, "queue-incoming-transfer", {
|
|
281
|
+
...data,
|
|
282
|
+
transferType: "send"
|
|
283
|
+
});
|
|
284
|
+
this.transferQueue.waitForData(data.transferID, () => this.currentTransferBarrierTransfers.get(data.transferID), [true, false], 100, 50000).then(accepted => {
|
|
285
|
+
console.log(`[FileTide ~ Net Barrier] ~ Transfer ${accepted ? "accepted!" : "denied."}`);
|
|
286
|
+
this.fileNet.emitToTide(senderClient.tideID, "transfer-barrier-response", accepted);
|
|
287
|
+
this.currentTransferBarrierTransfers.delete(data.transferID);
|
|
288
|
+
if (accepted) {
|
|
289
|
+
this.fileNet.emitToTide(client.tideID, "accepted-transfer", {
|
|
290
|
+
accepted,
|
|
291
|
+
...data
|
|
292
|
+
});
|
|
293
|
+
return;
|
|
294
|
+
}
|
|
295
|
+
this.fileNet.emitToTide(client.tideID, "denied-transfer", {
|
|
215
296
|
accepted,
|
|
216
297
|
...data
|
|
217
298
|
});
|
|
299
|
+
}).catch(error => {
|
|
300
|
+
console.error(error.message);
|
|
301
|
+
});
|
|
302
|
+
return;
|
|
303
|
+
} catch (error) {
|
|
304
|
+
return;
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
handleSendCurrentTransferState(data) {
|
|
308
|
+
try {
|
|
309
|
+
const senderConnectionID = FileNetClientManager.getOnlineClient(data.senderID).id;
|
|
310
|
+
const senderClient = this.getClientFromID(senderConnectionID);
|
|
311
|
+
if (!senderClient) {
|
|
218
312
|
return;
|
|
219
313
|
}
|
|
220
|
-
this.fileNet.emitToTide(
|
|
221
|
-
|
|
222
|
-
|
|
314
|
+
this.fileNet.emitToTide(senderClient.tideID, "sent-current-transfer-state", data.transferState || {
|
|
315
|
+
transferredSize: 0,
|
|
316
|
+
lastChunkSent: 0
|
|
223
317
|
});
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
}
|
|
227
|
-
|
|
318
|
+
} catch (error) {
|
|
319
|
+
return;
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
handleGetClientTransferState(data) {
|
|
323
|
+
const filePath = data.filePath || data.path;
|
|
324
|
+
console.log(`[FileTide ~ Net] Getting ${data.recipientID}'s transfer state for ~ ${filePath}...`);
|
|
325
|
+
try {
|
|
326
|
+
const recipientConnectionID = FileNetClientManager.getOnlineClient(data.recipientID).id;
|
|
327
|
+
const client = this.getClientFromID(recipientConnectionID);
|
|
328
|
+
if (!client) {
|
|
329
|
+
return;
|
|
330
|
+
}
|
|
331
|
+
this.fileNet.emitToTide(client.tideID, "current-transfer-state", {
|
|
332
|
+
senderID: data.senderID,
|
|
333
|
+
filePath
|
|
334
|
+
});
|
|
335
|
+
} catch (error) {
|
|
336
|
+
return;
|
|
337
|
+
}
|
|
228
338
|
}
|
|
229
339
|
handleNotifyTransferBarrier(data, emitToChannel) {
|
|
230
340
|
const accepted = data.accepted;
|
|
@@ -232,13 +342,40 @@ class FileMessager {
|
|
|
232
342
|
this.currentTransferBarrierTransfers.set(transferID, accepted);
|
|
233
343
|
}
|
|
234
344
|
handleFileTransferStart(data, emitToChannel) {
|
|
235
|
-
console.log(`Alerting client of incoming transfer from ${data.senderID}...`);
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
345
|
+
console.log(`[FileTide ~ File Messager] ~ Alerting client of incoming transfer from ${data.senderID}...`);
|
|
346
|
+
try {
|
|
347
|
+
const recipientConnectionID = FileNetClientManager.getOnlineClient(data.recipientID).id;
|
|
348
|
+
const senderConnectionID = FileNetClientManager.getOnlineClient(data.senderID).id;
|
|
349
|
+
const senderClient = this.getClientFromID(senderConnectionID);
|
|
350
|
+
const client = this.getClientFromID(recipientConnectionID);
|
|
351
|
+
if (!client || !senderClient) {
|
|
352
|
+
return;
|
|
353
|
+
}
|
|
354
|
+
this.fileNet.emitToTide(client.tideID, "incoming-transfer", data);
|
|
355
|
+
this.fileNet.emitToTide(senderClient.tideID, "incoming-transfer", {
|
|
356
|
+
...data,
|
|
357
|
+
currentSender: data.senderID
|
|
358
|
+
});
|
|
359
|
+
if (!this.currentTidingTransfers.get(senderID) || this.currentTidingTransfers.get(senderID).length <= 0) {
|
|
360
|
+
const tidingTransfers = new Map();
|
|
361
|
+
tidingTransfers.set(data.recipientID, {
|
|
362
|
+
recipientID: data.recipientID,
|
|
363
|
+
startedOn: new Date(),
|
|
364
|
+
size: data.fileSize,
|
|
365
|
+
path: data.path
|
|
366
|
+
});
|
|
367
|
+
this.currentTidingTransfers.set(data.senderID, tidingTransfers);
|
|
368
|
+
return;
|
|
369
|
+
}
|
|
370
|
+
this.currentTidingTransfers.get(senderID).set(data.recipientID, {
|
|
371
|
+
recipientID: data.recipientID,
|
|
372
|
+
startedOn: new Date(),
|
|
373
|
+
size: data.fileSize,
|
|
374
|
+
path: data.path
|
|
375
|
+
});
|
|
376
|
+
} catch (error) {
|
|
239
377
|
return;
|
|
240
378
|
}
|
|
241
|
-
this.fileNet.emitToTide(client.tideID, "incoming-transfer", data);
|
|
242
379
|
}
|
|
243
380
|
handleFileTransferProgress(data, emitToChannel) {
|
|
244
381
|
console.log(`Progress: ${data.progress}`);
|
|
@@ -249,12 +386,12 @@ class FileMessager {
|
|
|
249
386
|
handleClientsOnline(clientID) {
|
|
250
387
|
const connectionDetails = FileNetClientManager.getOnlineClient(clientID);
|
|
251
388
|
if (!connectionDetails) {
|
|
252
|
-
console.log(`Client ~ ${clientID} not authorized.`);
|
|
389
|
+
console.log(`[FileTide ~ Net Activity] ~ Client ~ ${clientID} not authorized.`);
|
|
253
390
|
return;
|
|
254
391
|
}
|
|
255
392
|
const client = this.onlineClients.get(connectionDetails.id);
|
|
256
393
|
if (!client) {
|
|
257
|
-
console.log(`Client ~ ${clientID} not found.`);
|
|
394
|
+
console.log(`[FileTide ~ Net Activity] ~ Client ~ ${clientID} not found.`);
|
|
258
395
|
return;
|
|
259
396
|
}
|
|
260
397
|
this.fileNet.emitToTide(connectionDetails.tideID, "current-online-clients", Object.fromEntries(FileNetClientManager.getOnlineClients()));
|
|
@@ -276,8 +413,36 @@ class FileMessager {
|
|
|
276
413
|
handleClientOffline(clientID) {
|
|
277
414
|
FileNetClientManager.clearOnlineClient(clientID);
|
|
278
415
|
this.fileNet.emit("current-clients", Object.fromEntries(FileNetClientManager.getOnlineClients()));
|
|
416
|
+
this.fileNet.emit("save-current-transfer-states", {
|
|
417
|
+
clientID
|
|
418
|
+
});
|
|
419
|
+
const tidingTransfers = this.currentTidingTransfers.get(clientID);
|
|
420
|
+
if (tidingTransfers && tidingTransfers.size > 0) {
|
|
421
|
+
for (let recipientID of tidingTransfers.keys()) {
|
|
422
|
+
this.fileNet.emit("save-current-transfer-states", {
|
|
423
|
+
clientID: recipientID
|
|
424
|
+
});
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
this.currentTidingTransfers.delete(clientID);
|
|
279
428
|
return;
|
|
280
429
|
}
|
|
430
|
+
handleClientTiding(data) {
|
|
431
|
+
try {
|
|
432
|
+
const senderConnectionID = FileNetClientManager.getOnlineClient(data.senderID).id;
|
|
433
|
+
const senderClient = this.getClientFromID(senderConnectionID);
|
|
434
|
+
if (!senderClient) {
|
|
435
|
+
return;
|
|
436
|
+
}
|
|
437
|
+
console.log(`[FileTide ~ Net Activity] ~ Received client ~ ${data.senderID} tiding.`);
|
|
438
|
+
this.fileNet.emitToTide(senderClient.tideID, "current-client-tiding", {
|
|
439
|
+
message: data.message
|
|
440
|
+
});
|
|
441
|
+
return;
|
|
442
|
+
} catch (error) {
|
|
443
|
+
return;
|
|
444
|
+
}
|
|
445
|
+
}
|
|
281
446
|
}
|
|
282
447
|
;
|
|
283
448
|
module.exports = FileMessager;
|