@trap_stevo/filetide 0.0.39 → 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 +239 -76
- package/dist/cjs/FileMessagerClient.js +142 -38
- package/dist/cjs/FileTide.js +100 -16
- package/dist/cjs/HUDComponents/ChunkCapacitor.js +35 -0
- package/dist/cjs/HUDComponents/ConsoleProgressBarManager.js +5 -1
- package/dist/cjs/HUDManagers/FileTransferManager.js +133 -19
- package/dist/cjs/HUDManagers/FileTransferReceiverManager.js +1 -1
- package/dist/cjs/HUDManagers/FileTransferRecoveryManager.js +94 -0
- package/dist/cjs/HUDManagers/FileUtilityManager.js +118 -61
- 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) {
|
|
@@ -102,6 +106,7 @@ 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,
|
|
@@ -115,7 +120,13 @@ class FileMessager {
|
|
|
115
120
|
this.fileNet.emitToTide(senderClient.tideID, "transfer-status", {
|
|
116
121
|
status: `Chunk ${chunkIndex} of ${fileName} sent to client ${clientData.userID}!`,
|
|
117
122
|
recipientID: clientData.userID,
|
|
118
|
-
success: true
|
|
123
|
+
success: true,
|
|
124
|
+
fileName,
|
|
125
|
+
chunkIndex,
|
|
126
|
+
totalChunks,
|
|
127
|
+
chunkSize,
|
|
128
|
+
path: filePath,
|
|
129
|
+
fileSize
|
|
119
130
|
});
|
|
120
131
|
}
|
|
121
132
|
}
|
|
@@ -131,20 +142,26 @@ class FileMessager {
|
|
|
131
142
|
handleSendFileListToClient(listData) {
|
|
132
143
|
const {
|
|
133
144
|
listedFiles,
|
|
145
|
+
totalItems,
|
|
134
146
|
recipientID,
|
|
135
147
|
senderID
|
|
136
148
|
} = listData;
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
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) {
|
|
142
163
|
return;
|
|
143
164
|
}
|
|
144
|
-
this.fileNet.emitToTide(client.tideID, "client-file-list", {
|
|
145
|
-
senderID,
|
|
146
|
-
listedFiles
|
|
147
|
-
});
|
|
148
165
|
}
|
|
149
166
|
handleListClientFiles(clientData) {
|
|
150
167
|
const {
|
|
@@ -152,81 +169,172 @@ class FileMessager {
|
|
|
152
169
|
recipientID,
|
|
153
170
|
depth = 1
|
|
154
171
|
} = clientData;
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
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) {
|
|
160
186
|
return;
|
|
161
187
|
}
|
|
162
|
-
this.fileNet.emitToTide(client.tideID, "list-files", {
|
|
163
|
-
senderID: requesterID,
|
|
164
|
-
recipientID,
|
|
165
|
-
depth
|
|
166
|
-
});
|
|
167
188
|
}
|
|
168
189
|
handleClientToClientTransfer(transferData) {
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
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 {
|
|
190
233
|
senderID,
|
|
191
234
|
recipientId,
|
|
192
235
|
fileName,
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
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;
|
|
196
268
|
}
|
|
197
269
|
}
|
|
198
270
|
handleClientTransferBarrierResponse(data) {
|
|
199
|
-
console.log(`Checking ${data.recipientID}'s transfer barrier for transfer ~ ${data.transferID}...`);
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
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", {
|
|
217
296
|
accepted,
|
|
218
297
|
...data
|
|
219
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) {
|
|
220
312
|
return;
|
|
221
313
|
}
|
|
222
|
-
this.fileNet.emitToTide(
|
|
223
|
-
|
|
224
|
-
|
|
314
|
+
this.fileNet.emitToTide(senderClient.tideID, "sent-current-transfer-state", data.transferState || {
|
|
315
|
+
transferredSize: 0,
|
|
316
|
+
lastChunkSent: 0
|
|
225
317
|
});
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
}
|
|
229
|
-
|
|
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
|
+
}
|
|
230
338
|
}
|
|
231
339
|
handleNotifyTransferBarrier(data, emitToChannel) {
|
|
232
340
|
const accepted = data.accepted;
|
|
@@ -234,13 +342,40 @@ class FileMessager {
|
|
|
234
342
|
this.currentTransferBarrierTransfers.set(transferID, accepted);
|
|
235
343
|
}
|
|
236
344
|
handleFileTransferStart(data, emitToChannel) {
|
|
237
|
-
console.log(`Alerting client of incoming transfer from ${data.senderID}...`);
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
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) {
|
|
241
377
|
return;
|
|
242
378
|
}
|
|
243
|
-
this.fileNet.emitToTide(client.tideID, "incoming-transfer", data);
|
|
244
379
|
}
|
|
245
380
|
handleFileTransferProgress(data, emitToChannel) {
|
|
246
381
|
console.log(`Progress: ${data.progress}`);
|
|
@@ -251,12 +386,12 @@ class FileMessager {
|
|
|
251
386
|
handleClientsOnline(clientID) {
|
|
252
387
|
const connectionDetails = FileNetClientManager.getOnlineClient(clientID);
|
|
253
388
|
if (!connectionDetails) {
|
|
254
|
-
console.log(`Client ~ ${clientID} not authorized.`);
|
|
389
|
+
console.log(`[FileTide ~ Net Activity] ~ Client ~ ${clientID} not authorized.`);
|
|
255
390
|
return;
|
|
256
391
|
}
|
|
257
392
|
const client = this.onlineClients.get(connectionDetails.id);
|
|
258
393
|
if (!client) {
|
|
259
|
-
console.log(`Client ~ ${clientID} not found.`);
|
|
394
|
+
console.log(`[FileTide ~ Net Activity] ~ Client ~ ${clientID} not found.`);
|
|
260
395
|
return;
|
|
261
396
|
}
|
|
262
397
|
this.fileNet.emitToTide(connectionDetails.tideID, "current-online-clients", Object.fromEntries(FileNetClientManager.getOnlineClients()));
|
|
@@ -278,8 +413,36 @@ class FileMessager {
|
|
|
278
413
|
handleClientOffline(clientID) {
|
|
279
414
|
FileNetClientManager.clearOnlineClient(clientID);
|
|
280
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);
|
|
281
428
|
return;
|
|
282
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
|
+
}
|
|
283
446
|
}
|
|
284
447
|
;
|
|
285
448
|
module.exports = FileMessager;
|