@trap_stevo/filetide 0.0.39 → 0.0.41
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 +306 -83
- package/dist/cjs/FileMessagerClient.js +149 -43
- package/dist/cjs/FileTide.js +116 -17
- 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 +3 -3
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
|
|
@@ -24,23 +27,27 @@ class FileMessager {
|
|
|
24
27
|
this.transferQueue = new HUDTargetQueue();
|
|
25
28
|
this.currentTransferBarrierTransfers = new Map();
|
|
26
29
|
this.clientTransferBarriers = new Map();
|
|
30
|
+
this.currentTidingTransfers = new Map();
|
|
27
31
|
this.fileNet = new IoTide(serverOptions.port, serverOptions, true, this.onConnect.bind(this), this.onDisconnect.bind(this));
|
|
28
|
-
this.onlineClients = new
|
|
32
|
+
this.onlineClients = new OmniMap();
|
|
29
33
|
return;
|
|
30
34
|
}
|
|
31
35
|
onConnect(socket) {
|
|
32
|
-
console.log(`Client connected
|
|
36
|
+
console.log(`Client connected ~ ${socket.id}`);
|
|
33
37
|
this.onlineClients.set(socket.id, socket);
|
|
34
38
|
return;
|
|
35
39
|
}
|
|
36
40
|
onDisconnect(connectionRes, socket) {
|
|
37
|
-
console.log(`Client disconnected
|
|
41
|
+
console.log(`Client disconnected ~ ${socket.id}`);
|
|
38
42
|
this.onlineClients.delete(socket.id);
|
|
39
43
|
return;
|
|
40
44
|
}
|
|
41
45
|
start() {
|
|
42
46
|
this.fileNet.on("get-client-transfer-barrier-response", this.handleClientTransferBarrierResponse.bind(this));
|
|
47
|
+
this.fileNet.on("get-client-transfer-state", this.handleGetClientTransferState.bind(this));
|
|
48
|
+
this.fileNet.on("get-client", this.handleGetClient.bind(this));
|
|
43
49
|
this.fileNet.on("notify-transfer-barrier", this.handleNotifyTransferBarrier.bind(this));
|
|
50
|
+
this.fileNet.on("send-current-transfer-state", this.handleSendCurrentTransferState.bind(this));
|
|
44
51
|
this.fileNet.on("send-file-list-to-client", this.handleSendFileListToClient.bind(this));
|
|
45
52
|
this.fileNet.on("list-client-files", this.handleListClientFiles.bind(this));
|
|
46
53
|
this.fileNet.on("transfer-start", this.handleFileTransferStart.bind(this));
|
|
@@ -48,9 +55,11 @@ class FileMessager {
|
|
|
48
55
|
this.fileNet.on("transfer-complete", this.handleFileTransferComplete.bind(this));
|
|
49
56
|
this.fileNet.on("request-transfer-from-client", this.handleRequestTransferFromClient.bind(this));
|
|
50
57
|
this.fileNet.on("client-to-client-transfer", this.handleClientToClientTransfer.bind(this));
|
|
58
|
+
this.fileNet.on("check-client-online", this.handleCheckClientOnline.bind(this));
|
|
51
59
|
this.fileNet.on("client-offline", this.handleClientOffline.bind(this));
|
|
52
60
|
this.fileNet.on("clients-online", this.handleClientsOnline.bind(this));
|
|
53
61
|
this.fileNet.on("client-online", this.handleClientOnline.bind(this));
|
|
62
|
+
this.fileNet.on("client-tiding", this.handleClientTiding.bind(this));
|
|
54
63
|
return;
|
|
55
64
|
}
|
|
56
65
|
getClientFromID(clientID) {
|
|
@@ -102,6 +111,7 @@ class FileMessager {
|
|
|
102
111
|
});
|
|
103
112
|
}
|
|
104
113
|
this.fileNet.emitToTide(client.tideID, "transfer-progress", {
|
|
114
|
+
senderName: senderData.userID,
|
|
105
115
|
senderID: senderData.id,
|
|
106
116
|
fileName,
|
|
107
117
|
fileChunk,
|
|
@@ -115,7 +125,13 @@ class FileMessager {
|
|
|
115
125
|
this.fileNet.emitToTide(senderClient.tideID, "transfer-status", {
|
|
116
126
|
status: `Chunk ${chunkIndex} of ${fileName} sent to client ${clientData.userID}!`,
|
|
117
127
|
recipientID: clientData.userID,
|
|
118
|
-
success: true
|
|
128
|
+
success: true,
|
|
129
|
+
fileName,
|
|
130
|
+
chunkIndex,
|
|
131
|
+
totalChunks,
|
|
132
|
+
chunkSize,
|
|
133
|
+
path: filePath,
|
|
134
|
+
fileSize
|
|
119
135
|
});
|
|
120
136
|
}
|
|
121
137
|
}
|
|
@@ -131,20 +147,26 @@ class FileMessager {
|
|
|
131
147
|
handleSendFileListToClient(listData) {
|
|
132
148
|
const {
|
|
133
149
|
listedFiles,
|
|
150
|
+
totalItems,
|
|
134
151
|
recipientID,
|
|
135
152
|
senderID
|
|
136
153
|
} = listData;
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
154
|
+
try {
|
|
155
|
+
const recipientConnectionID = FileNetClientManager.getOnlineClient(recipientID).id;
|
|
156
|
+
const senderConnectionID = FileNetClientManager.getOnlineClient(senderID).id;
|
|
157
|
+
const senderClient = this.getClientFromID(senderConnectionID);
|
|
158
|
+
const client = this.getClientFromID(recipientConnectionID);
|
|
159
|
+
if (!client || !senderClient) {
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
this.fileNet.emitToTide(client.tideID, "client-file-list", {
|
|
163
|
+
senderID,
|
|
164
|
+
totalItems,
|
|
165
|
+
listedFiles
|
|
166
|
+
});
|
|
167
|
+
} catch (error) {
|
|
142
168
|
return;
|
|
143
169
|
}
|
|
144
|
-
this.fileNet.emitToTide(client.tideID, "client-file-list", {
|
|
145
|
-
senderID,
|
|
146
|
-
listedFiles
|
|
147
|
-
});
|
|
148
170
|
}
|
|
149
171
|
handleListClientFiles(clientData) {
|
|
150
172
|
const {
|
|
@@ -152,81 +174,188 @@ class FileMessager {
|
|
|
152
174
|
recipientID,
|
|
153
175
|
depth = 1
|
|
154
176
|
} = clientData;
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
177
|
+
try {
|
|
178
|
+
const recipientConnectionID = FileNetClientManager.getOnlineClient(recipientID).id;
|
|
179
|
+
const senderConnectionID = FileNetClientManager.getOnlineClient(requesterID).id;
|
|
180
|
+
const senderClient = this.getClientFromID(senderConnectionID);
|
|
181
|
+
const client = this.getClientFromID(recipientConnectionID);
|
|
182
|
+
if (!client || !senderClient) {
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
this.fileNet.emitToTide(client.tideID, "list-files", {
|
|
186
|
+
senderID: requesterID,
|
|
187
|
+
recipientID,
|
|
188
|
+
depth
|
|
189
|
+
});
|
|
190
|
+
} catch (error) {
|
|
160
191
|
return;
|
|
161
192
|
}
|
|
162
|
-
this.fileNet.emitToTide(client.tideID, "list-files", {
|
|
163
|
-
senderID: requesterID,
|
|
164
|
-
recipientID,
|
|
165
|
-
depth
|
|
166
|
-
});
|
|
167
193
|
}
|
|
168
194
|
handleClientToClientTransfer(transferData) {
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
195
|
+
try {
|
|
196
|
+
const {
|
|
197
|
+
chunkBatch
|
|
198
|
+
} = transferData;
|
|
199
|
+
if (chunkBatch && chunkBatch.length > 0) {
|
|
200
|
+
for (const chunkData of chunkBatch) {
|
|
201
|
+
const {
|
|
202
|
+
senderID,
|
|
203
|
+
recipientId,
|
|
204
|
+
fileName,
|
|
205
|
+
fileChunk,
|
|
206
|
+
fileSize,
|
|
207
|
+
filePath,
|
|
208
|
+
chunkIndex,
|
|
209
|
+
chunkSize,
|
|
210
|
+
completedChunks,
|
|
211
|
+
totalChunks
|
|
212
|
+
} = chunkData;
|
|
213
|
+
console.log(`[FileTide ~ File Messager] ~ Transferring file ~ ${fileName} | chunk ${chunkIndex + 1} >> ${completedChunks} of ${totalChunks} to client (${recipientId})`);
|
|
214
|
+
this.sendFileChunkToClient({
|
|
215
|
+
userID: senderID,
|
|
216
|
+
id: FileNetClientManager.getOnlineClient(senderID).id
|
|
217
|
+
}, {
|
|
218
|
+
userID: recipientId,
|
|
219
|
+
id: FileNetClientManager.getOnlineClient(recipientId).id
|
|
220
|
+
}, fileChunk, fileName, chunkIndex, chunkSize, totalChunks, filePath, fileSize);
|
|
221
|
+
if (completedChunks === totalChunks) {
|
|
222
|
+
this.fileNet.emit("transfer-complete", {
|
|
223
|
+
senderID,
|
|
224
|
+
recipientId,
|
|
225
|
+
fileName,
|
|
226
|
+
filePath
|
|
227
|
+
});
|
|
228
|
+
console.log(`[FileTide ~ File Messager] ~ File transfer completed: ${fileName} from ${senderID} to ${recipientId}`);
|
|
229
|
+
const tidingTransfers = this.currentTidingTransfers.get(senderID);
|
|
230
|
+
if (tidingTransfers) {
|
|
231
|
+
tidingTransfers.delete(recipientId);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
const {
|
|
190
238
|
senderID,
|
|
191
239
|
recipientId,
|
|
192
240
|
fileName,
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
241
|
+
fileChunk,
|
|
242
|
+
fileSize,
|
|
243
|
+
filePath,
|
|
244
|
+
chunkIndex,
|
|
245
|
+
chunkSize,
|
|
246
|
+
completedChunks,
|
|
247
|
+
totalChunks
|
|
248
|
+
} = transferData;
|
|
249
|
+
console.log(`[FileTide ~ File Messager] ~ Transferring file ~ ${fileName} | chunk ${chunkIndex + 1} >> ${completedChunks} of ${totalChunks} to client (${recipientId})`);
|
|
250
|
+
this.sendFileChunkToClient({
|
|
251
|
+
userID: senderID,
|
|
252
|
+
id: FileNetClientManager.getOnlineClient(senderID).id
|
|
253
|
+
}, {
|
|
254
|
+
userID: recipientId,
|
|
255
|
+
id: FileNetClientManager.getOnlineClient(recipientId).id
|
|
256
|
+
}, fileChunk, fileName, chunkIndex, chunkSize, totalChunks, filePath, fileSize);
|
|
257
|
+
if (chunkIndex + 1 === totalChunks) {
|
|
258
|
+
this.fileNet.emit("transfer-complete", {
|
|
259
|
+
senderID,
|
|
260
|
+
recipientId,
|
|
261
|
+
fileName,
|
|
262
|
+
filePath
|
|
263
|
+
});
|
|
264
|
+
console.log(`[FileTide ~ File Messager] ~ File transfer completed: ${fileName} from ${senderID} to ${recipientId}`);
|
|
265
|
+
const tidingTransfers = this.currentTidingTransfers.get(senderID);
|
|
266
|
+
if (tidingTransfers) {
|
|
267
|
+
tidingTransfers.delete(recipientId);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
} catch (error) {
|
|
271
|
+
console.log(error);
|
|
272
|
+
return;
|
|
196
273
|
}
|
|
197
274
|
}
|
|
198
275
|
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
|
-
|
|
276
|
+
console.log(`[FileTide ~ Net] Checking ${data.recipientID}'s transfer barrier for transfer ~ ${data.transferID}...`);
|
|
277
|
+
try {
|
|
278
|
+
const recipientConnectionID = FileNetClientManager.getOnlineClient(data.recipientID).id;
|
|
279
|
+
const senderConnectionID = FileNetClientManager.getOnlineClient(data.clientID).id;
|
|
280
|
+
const senderClient = this.getClientFromID(senderConnectionID);
|
|
281
|
+
const client = this.getClientFromID(recipientConnectionID);
|
|
282
|
+
if (!client || !senderClient) {
|
|
283
|
+
return;
|
|
284
|
+
}
|
|
285
|
+
this.fileNet.emitToTide(client.tideID, "queue-incoming-transfer", {
|
|
286
|
+
...data,
|
|
287
|
+
transferType: "send"
|
|
288
|
+
});
|
|
289
|
+
this.transferQueue.waitForData(data.transferID, () => this.currentTransferBarrierTransfers.get(data.transferID), [true, false], 100, 50000).then(accepted => {
|
|
290
|
+
console.log(`[FileTide ~ Net Barrier] ~ Transfer ${accepted ? "accepted!" : "denied."}`);
|
|
291
|
+
this.fileNet.emitToTide(senderClient.tideID, "transfer-barrier-response", accepted);
|
|
292
|
+
this.currentTransferBarrierTransfers.delete(data.transferID);
|
|
293
|
+
if (accepted) {
|
|
294
|
+
this.fileNet.emitToTide(client.tideID, "accepted-transfer", {
|
|
295
|
+
accepted,
|
|
296
|
+
...data
|
|
297
|
+
});
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
300
|
+
this.fileNet.emitToTide(client.tideID, "denied-transfer", {
|
|
217
301
|
accepted,
|
|
218
302
|
...data
|
|
219
303
|
});
|
|
304
|
+
}).catch(error => {
|
|
305
|
+
console.error(error.message);
|
|
306
|
+
});
|
|
307
|
+
return;
|
|
308
|
+
} catch (error) {
|
|
309
|
+
return;
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
handleSendCurrentTransferState(data) {
|
|
313
|
+
try {
|
|
314
|
+
const senderConnectionID = FileNetClientManager.getOnlineClient(data.senderID).id;
|
|
315
|
+
const senderClient = this.getClientFromID(senderConnectionID);
|
|
316
|
+
if (!senderClient) {
|
|
220
317
|
return;
|
|
221
318
|
}
|
|
222
|
-
this.fileNet.emitToTide(
|
|
223
|
-
|
|
224
|
-
|
|
319
|
+
this.fileNet.emitToTide(senderClient.tideID, "sent-current-transfer-state", data.transferState || {
|
|
320
|
+
transferredSize: 0,
|
|
321
|
+
lastChunkSent: 0
|
|
225
322
|
});
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
}
|
|
229
|
-
|
|
323
|
+
} catch (error) {
|
|
324
|
+
return;
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
handleGetClientTransferState(data) {
|
|
328
|
+
const filePath = data.filePath || data.path;
|
|
329
|
+
console.log(`[FileTide ~ Net] Getting ${data.recipientID}'s transfer state for ~ ${filePath}...`);
|
|
330
|
+
try {
|
|
331
|
+
const recipientConnectionID = FileNetClientManager.getOnlineClient(data.recipientID).id;
|
|
332
|
+
const client = this.getClientFromID(recipientConnectionID);
|
|
333
|
+
if (!client) {
|
|
334
|
+
return;
|
|
335
|
+
}
|
|
336
|
+
this.fileNet.emitToTide(client.tideID, "current-transfer-state", {
|
|
337
|
+
senderID: data.senderID,
|
|
338
|
+
filePath
|
|
339
|
+
});
|
|
340
|
+
} catch (error) {
|
|
341
|
+
return;
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
handleGetClient(data) {
|
|
345
|
+
console.log(`[FileTide ~ Net] Getting client ~ ${data.clientID}...`);
|
|
346
|
+
try {
|
|
347
|
+
const senderConnectionID = FileNetClientManager.getOnlineClient(data.senderID).id;
|
|
348
|
+
const clientConnectionID = FileNetClientManager.getOnlineClient(data.clientID).id;
|
|
349
|
+
const senderClient = this.getClientFromID(clientConnectionID);
|
|
350
|
+
const client = this.getClientFromID(clientConnectionID);
|
|
351
|
+
if (!client || !senderClient) {
|
|
352
|
+
return;
|
|
353
|
+
}
|
|
354
|
+
console.log(`[FileTide ~ Net] Got client ~ ${data.clientID}!`);
|
|
355
|
+
this.fileNet.emitToTide(senderClient.tideID, "retrieved-current-client", client);
|
|
356
|
+
} catch (error) {
|
|
357
|
+
return;
|
|
358
|
+
}
|
|
230
359
|
}
|
|
231
360
|
handleNotifyTransferBarrier(data, emitToChannel) {
|
|
232
361
|
const accepted = data.accepted;
|
|
@@ -234,13 +363,40 @@ class FileMessager {
|
|
|
234
363
|
this.currentTransferBarrierTransfers.set(transferID, accepted);
|
|
235
364
|
}
|
|
236
365
|
handleFileTransferStart(data, emitToChannel) {
|
|
237
|
-
console.log(`Alerting client of incoming transfer from ${data.senderID}...`);
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
366
|
+
console.log(`[FileTide ~ File Messager] ~ Alerting client of incoming transfer from ${data.senderID}...`);
|
|
367
|
+
try {
|
|
368
|
+
const recipientConnectionID = FileNetClientManager.getOnlineClient(data.recipientID).id;
|
|
369
|
+
const senderConnectionID = FileNetClientManager.getOnlineClient(data.senderID).id;
|
|
370
|
+
const senderClient = this.getClientFromID(senderConnectionID);
|
|
371
|
+
const client = this.getClientFromID(recipientConnectionID);
|
|
372
|
+
if (!client || !senderClient) {
|
|
373
|
+
return;
|
|
374
|
+
}
|
|
375
|
+
this.fileNet.emitToTide(client.tideID, "incoming-transfer", data);
|
|
376
|
+
this.fileNet.emitToTide(senderClient.tideID, "incoming-transfer", {
|
|
377
|
+
...data,
|
|
378
|
+
currentSender: data.senderID
|
|
379
|
+
});
|
|
380
|
+
if (!this.currentTidingTransfers.get(senderID) || this.currentTidingTransfers.get(senderID).length <= 0) {
|
|
381
|
+
const tidingTransfers = new Map();
|
|
382
|
+
tidingTransfers.set(data.recipientID, {
|
|
383
|
+
recipientID: data.recipientID,
|
|
384
|
+
startedOn: new Date(),
|
|
385
|
+
size: data.fileSize,
|
|
386
|
+
path: data.path
|
|
387
|
+
});
|
|
388
|
+
this.currentTidingTransfers.set(data.senderID, tidingTransfers);
|
|
389
|
+
return;
|
|
390
|
+
}
|
|
391
|
+
this.currentTidingTransfers.get(senderID).set(data.recipientID, {
|
|
392
|
+
recipientID: data.recipientID,
|
|
393
|
+
startedOn: new Date(),
|
|
394
|
+
size: data.fileSize,
|
|
395
|
+
path: data.path
|
|
396
|
+
});
|
|
397
|
+
} catch (error) {
|
|
241
398
|
return;
|
|
242
399
|
}
|
|
243
|
-
this.fileNet.emitToTide(client.tideID, "incoming-transfer", data);
|
|
244
400
|
}
|
|
245
401
|
handleFileTransferProgress(data, emitToChannel) {
|
|
246
402
|
console.log(`Progress: ${data.progress}`);
|
|
@@ -248,22 +404,51 @@ class FileMessager {
|
|
|
248
404
|
handleFileTransferComplete(data) {
|
|
249
405
|
console.log(`File transfer completed: ${data.fileName}`);
|
|
250
406
|
}
|
|
407
|
+
handleCheckClientOnline(data) {
|
|
408
|
+
console.log(`[FileTide ~ Net Activity] ~ Checking if client ~ ${data.clientID} online...`);
|
|
409
|
+
try {
|
|
410
|
+
const client = FileNetClientManager.getOnlineClient(data.clientID);
|
|
411
|
+
if (!client) {
|
|
412
|
+
this.fileNet.emit("retrieved-client-online", {
|
|
413
|
+
online: false,
|
|
414
|
+
client: null
|
|
415
|
+
});
|
|
416
|
+
return;
|
|
417
|
+
}
|
|
418
|
+
console.log(`[FileTide ~ Net Activity] ~ Client ~ ${data.clientID} online!`);
|
|
419
|
+
this.fileNet.emit("retrieved-client-online", {
|
|
420
|
+
online: true,
|
|
421
|
+
client
|
|
422
|
+
});
|
|
423
|
+
} catch (error) {
|
|
424
|
+
this.fileNet.emit("retrieved-client-online", {
|
|
425
|
+
online: false,
|
|
426
|
+
client: null
|
|
427
|
+
});
|
|
428
|
+
return;
|
|
429
|
+
}
|
|
430
|
+
}
|
|
251
431
|
handleClientsOnline(clientID) {
|
|
252
432
|
const connectionDetails = FileNetClientManager.getOnlineClient(clientID);
|
|
253
433
|
if (!connectionDetails) {
|
|
254
|
-
console.log(`Client ~ ${clientID} not authorized.`);
|
|
434
|
+
console.log(`[FileTide ~ Net Activity] ~ Client ~ ${clientID} not authorized.`);
|
|
255
435
|
return;
|
|
256
436
|
}
|
|
257
437
|
const client = this.onlineClients.get(connectionDetails.id);
|
|
258
438
|
if (!client) {
|
|
259
|
-
console.log(`Client ~ ${clientID} not found.`);
|
|
439
|
+
console.log(`[FileTide ~ Net Activity] ~ Client ~ ${clientID} not found.`);
|
|
260
440
|
return;
|
|
261
441
|
}
|
|
262
442
|
this.fileNet.emitToTide(connectionDetails.tideID, "current-online-clients", Object.fromEntries(FileNetClientManager.getOnlineClients()));
|
|
263
443
|
return;
|
|
264
444
|
}
|
|
265
445
|
handleClientOnline(clientID, tideID, pClientID, connectionID, activeTransferBarrier) {
|
|
266
|
-
if (!this.onlineClients.
|
|
446
|
+
if (!this.onlineClients.contains(connectionID)) {
|
|
447
|
+
return;
|
|
448
|
+
}
|
|
449
|
+
if (FileNetClientManager.getOnlineClient(clientID) && this.onlineClients.get(connectionID)) {
|
|
450
|
+
clientID = `${clientID}_${connectionID.slice(0, 4)}`;
|
|
451
|
+
this.fileNet.emitToTide(tideID, "current-client-id-already-online", clientID);
|
|
267
452
|
return;
|
|
268
453
|
}
|
|
269
454
|
FileNetClientManager.addOnlineClient(clientID, pClientID, tideID, connectionID);
|
|
@@ -275,11 +460,49 @@ class FileMessager {
|
|
|
275
460
|
this.fileNet.emit("current-clients", Object.fromEntries(FileNetClientManager.getOnlineClients()));
|
|
276
461
|
return;
|
|
277
462
|
}
|
|
278
|
-
handleClientOffline(
|
|
279
|
-
|
|
280
|
-
|
|
463
|
+
handleClientOffline(clientData) {
|
|
464
|
+
console.log(`Client ~ ${clientData.clientID} | connection origin ~ ${clientData.connectionID} going offline...`);
|
|
465
|
+
try {
|
|
466
|
+
const clientDetails = FileNetClientManager.getOnlineClient(clientData.clientID);
|
|
467
|
+
if (!clientDetails || clientDetails.id !== clientData.connectionID) {
|
|
468
|
+
console.log(!clientDetails ? `[FileTide ~ Net Activity] ~ Client ~ ${clientData.clientID} already offline.` : `[FileTide ~ Net Activity] ~ Unauthorized offline signal from connection ID ~ ${clientData.connectionID}.`);
|
|
469
|
+
return;
|
|
470
|
+
}
|
|
471
|
+
FileNetClientManager.clearOnlineClient(clientData.clientID);
|
|
472
|
+
this.fileNet.emit("current-clients", Object.fromEntries(FileNetClientManager.getOnlineClients()));
|
|
473
|
+
this.fileNet.emit("save-current-transfer-states", {
|
|
474
|
+
clientID: clientData.clientID
|
|
475
|
+
});
|
|
476
|
+
const tidingTransfers = this.currentTidingTransfers.get(clientData.clientID);
|
|
477
|
+
if (tidingTransfers && tidingTransfers.size > 0) {
|
|
478
|
+
for (let recipientID of tidingTransfers.keys()) {
|
|
479
|
+
this.fileNet.emit("save-current-transfer-states", {
|
|
480
|
+
clientID: recipientID
|
|
481
|
+
});
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
this.currentTidingTransfers.delete(clientData.clientID);
|
|
485
|
+
} catch (error) {
|
|
486
|
+
console.log(`[FileTide ~ Net Activity] ~ Did not process client ~ ${clientData} offline signal ~ ${error}`);
|
|
487
|
+
}
|
|
281
488
|
return;
|
|
282
489
|
}
|
|
490
|
+
handleClientTiding(data) {
|
|
491
|
+
try {
|
|
492
|
+
const senderConnectionID = FileNetClientManager.getOnlineClient(data.senderID).id;
|
|
493
|
+
const senderClient = this.getClientFromID(senderConnectionID);
|
|
494
|
+
if (!senderClient) {
|
|
495
|
+
return;
|
|
496
|
+
}
|
|
497
|
+
console.log(`[FileTide ~ Net Activity] ~ Received client ~ ${data.senderID} tiding.`);
|
|
498
|
+
this.fileNet.emitToTide(senderClient.tideID, "current-client-tiding", {
|
|
499
|
+
message: data.message
|
|
500
|
+
});
|
|
501
|
+
return;
|
|
502
|
+
} catch (error) {
|
|
503
|
+
return;
|
|
504
|
+
}
|
|
505
|
+
}
|
|
283
506
|
}
|
|
284
507
|
;
|
|
285
508
|
module.exports = FileMessager;
|