@trap_stevo/filetide 0.0.60 → 0.0.62

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.
@@ -39,6 +39,8 @@ class FileMessager {
39
39
  this.fileNet = new IoTide(serverOptions.port, serverOptions, true, this.onConnect.bind(this), this.onDisconnect.bind(this));
40
40
  this.onlineClients = new OmniMap();
41
41
  this.debugMode = debugMode;
42
+ this.transporterOptions = transportOptions;
43
+ this.options = serverOptions;
42
44
  return;
43
45
  }
44
46
  onConnect(socket) {
@@ -51,6 +53,10 @@ class FileMessager {
51
53
  this.onlineClients.delete(socket.id);
52
54
  return;
53
55
  }
56
+ close() {
57
+ this.fileNet.close();
58
+ return;
59
+ }
54
60
  start() {
55
61
  this.fileNet.on("get-client-transfer-barrier-response", this.handleClientTransferBarrierResponse.bind(this));
56
62
  this.fileNet.on("get-client-transfer-state", this.handleGetClientTransferState.bind(this));
@@ -254,6 +254,7 @@ class FileTide {
254
254
  stopFileTide() {
255
255
  if (this.fileNet) {
256
256
  FileTide.outputGradient("Stopping FileTide...", significantMessageColors);
257
+ this.fileNet.close();
257
258
  this.fileNet = null;
258
259
  FileTide.outputGradient("Stopped FileTide.", significantMessageColors);
259
260
  }
@@ -263,13 +264,17 @@ class FileTide {
263
264
  /**
264
265
  * Stop a specific client.
265
266
  * @param {String} userID - The ID of the client user to stop
267
+ * @param {Function} onBeforeDisconnect - Executes before messager disconnection
266
268
  * @param {Function} onDisconnect - Executes upon messager disconnection
267
269
  * @param {Function} onCompletion - Executes upon messager disconnection completion
268
270
  */
269
- async stopMessager(userID, onDisconnect, onCompletion) {
271
+ async stopMessager(userID, onBeforeDisconnect, onDisconnect, onCompletion) {
270
272
  if (this.clients.has(userID)) {
271
273
  FileTide.outputGradient(`Stopping messager for user ${userID}...`, significantMessageColors);
272
274
  const connectionOrigin = this.clients.get(userID);
275
+ if (typeof onBeforeDisconnect === "function") {
276
+ await onBeforeDisconnect(this, userID, connectionOrigin);
277
+ }
273
278
  if (connectionOrigin?.clientTide?.closeSocket) {
274
279
  const result = connectionOrigin.clientTide.closeSocket(userID);
275
280
  if (result instanceof Promise) {
@@ -280,13 +285,13 @@ class FileTide {
280
285
  }
281
286
  }
282
287
  if (typeof onDisconnect === "function") {
283
- await onDisconnect(this);
288
+ await onDisconnect(this, userID, connectionOrigin);
284
289
  }
285
290
  }
286
291
  this.clients.delete(userID);
287
292
  FileTide.outputGradient(`Stopped messager for user ${userID}.`, significantMessageColors);
288
293
  if (typeof onCompletion === "function") {
289
- await onCompletion(this);
294
+ await onCompletion(this, userID, connectionOrigin);
290
295
  }
291
296
  return;
292
297
  }
@@ -296,13 +301,17 @@ class FileTide {
296
301
 
297
302
  /**
298
303
  * Stop all active clients.
304
+ * @param {Function} onBeforeClientDisconnect - Executes before each messager disconnection
299
305
  * @param {Function} onClientDisconnect - Executes upon each messager disconnection
300
306
  * @param {Function} onCompletion - Executes upon all messager disconnection
301
307
  */
302
- async stopAllMessagers(onClientDisconnect, onCompletion) {
308
+ async stopAllMessagers(onBeforeClientDisconnect, onClientDisconnect, onCompletion) {
303
309
  FileTide.outputGradient("Stopping all messagers...", significantMessageColors);
304
310
  const disconnectTasks = [];
305
311
  for (let [userID, connectionOrigin] of this.clients.entries()) {
312
+ if (typeof onBeforeClientDisconnect === "function") {
313
+ await onBeforeClientDisconnect(this, userID, connectionOrigin);
314
+ }
306
315
  if (connectionOrigin?.clientTide?.closeSocket) {
307
316
  const task = async () => {
308
317
  try {
@@ -311,7 +320,7 @@ class FileTide {
311
320
  await result;
312
321
  }
313
322
  if (typeof onClientDisconnect === "function") {
314
- onClientDisconnect(userID, connectionOrigin);
323
+ await onClientDisconnect(this, userID, connectionOrigin);
315
324
  }
316
325
  FileTide.outputGradient(`Disconnected ~ ${userID}`, significantMessageColors);
317
326
  } catch (error) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trap_stevo/filetide",
3
- "version": "0.0.60",
3
+ "version": "0.0.62",
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": {