@trap_stevo/filetide 0.0.59 → 0.0.61

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.
@@ -263,12 +263,17 @@ class FileTide {
263
263
  /**
264
264
  * Stop a specific client.
265
265
  * @param {String} userID - The ID of the client user to stop
266
+ * @param {Function} onBeforeDisconnect - Executes before messager disconnection
266
267
  * @param {Function} onDisconnect - Executes upon messager disconnection
268
+ * @param {Function} onCompletion - Executes upon messager disconnection completion
267
269
  */
268
- async stopMessager(userID, onDisconnect) {
270
+ async stopMessager(userID, onBeforeDisconnect, onDisconnect, onCompletion) {
269
271
  if (this.clients.has(userID)) {
270
272
  FileTide.outputGradient(`Stopping messager for user ${userID}...`, significantMessageColors);
271
273
  const connectionOrigin = this.clients.get(userID);
274
+ if (typeof onBeforeDisconnect === "function") {
275
+ await onBeforeDisconnect(this, userID, connectionOrigin);
276
+ }
272
277
  if (connectionOrigin?.clientTide?.closeSocket) {
273
278
  const result = connectionOrigin.clientTide.closeSocket(userID);
274
279
  if (result instanceof Promise) {
@@ -278,11 +283,14 @@ class FileTide {
278
283
  FileTide.outputGradient(`Did not disconnect ~ ${userID} ~ ${error.message}`, errorMessageColors);
279
284
  }
280
285
  }
286
+ if (typeof onDisconnect === "function") {
287
+ await onDisconnect(this, userID, connectionOrigin);
288
+ }
281
289
  }
282
290
  this.clients.delete(userID);
283
291
  FileTide.outputGradient(`Stopped messager for user ${userID}.`, significantMessageColors);
284
- if (typeof onDisconnect === "function") {
285
- await onDisconnect(this);
292
+ if (typeof onCompletion === "function") {
293
+ await onCompletion(this, userID, connectionOrigin);
286
294
  }
287
295
  return;
288
296
  }
@@ -292,12 +300,17 @@ class FileTide {
292
300
 
293
301
  /**
294
302
  * Stop all active clients.
295
- * @param {Function} onDisconnect - Executes upon all messager disconnection
303
+ * @param {Function} onBeforeClientDisconnect - Executes before each messager disconnection
304
+ * @param {Function} onClientDisconnect - Executes upon each messager disconnection
305
+ * @param {Function} onCompletion - Executes upon all messager disconnection
296
306
  */
297
- async stopAllMessagers(onDisconnect) {
307
+ async stopAllMessagers(onBeforeClientDisconnect, onClientDisconnect, onCompletion) {
298
308
  FileTide.outputGradient("Stopping all messagers...", significantMessageColors);
299
309
  const disconnectTasks = [];
300
310
  for (let [userID, connectionOrigin] of this.clients.entries()) {
311
+ if (typeof onBeforeClientDisconnect === "function") {
312
+ await onBeforeClientDisconnect(this, userID, connectionOrigin);
313
+ }
301
314
  if (connectionOrigin?.clientTide?.closeSocket) {
302
315
  const task = async () => {
303
316
  try {
@@ -305,6 +318,9 @@ class FileTide {
305
318
  if (result instanceof Promise) {
306
319
  await result;
307
320
  }
321
+ if (typeof onClientDisconnect === "function") {
322
+ await onClientDisconnect(this, userID, connectionOrigin);
323
+ }
308
324
  FileTide.outputGradient(`Disconnected ~ ${userID}`, significantMessageColors);
309
325
  } catch (error) {
310
326
  FileTide.outputGradient(`Did not disconnect ~ ${userID} - ${error.message}`, errorMessageColors);
@@ -316,8 +332,8 @@ class FileTide {
316
332
  await Promise.all(disconnectTasks);
317
333
  this.clients.clear();
318
334
  FileTide.outputGradient("All messagers stopped.", significantMessageColors);
319
- if (typeof onDisconnect === "function") {
320
- await onDisconnect(this);
335
+ if (typeof onCompletion === "function") {
336
+ await onCompletion(this);
321
337
  }
322
338
  return;
323
339
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trap_stevo/filetide",
3
- "version": "0.0.59",
3
+ "version": "0.0.61",
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": {