@trap_stevo/filetide 0.0.58 → 0.0.60

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.
@@ -249,7 +249,7 @@ class FileTide {
249
249
  }
250
250
 
251
251
  /**
252
- * Stop the server if it"s running.
252
+ * Stop the server if running.
253
253
  */
254
254
  stopFileTide() {
255
255
  if (this.fileNet) {
@@ -263,16 +263,31 @@ 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} onDisconnect - Executes upon messager disconnection
267
+ * @param {Function} onCompletion - Executes upon messager disconnection completion
266
268
  */
267
- stopMessager(userID) {
269
+ async stopMessager(userID, onDisconnect, onCompletion) {
268
270
  if (this.clients.has(userID)) {
269
271
  FileTide.outputGradient(`Stopping messager for user ${userID}...`, significantMessageColors);
270
272
  const connectionOrigin = this.clients.get(userID);
271
- if (connectionOrigin) {
272
- connectionOrigin.clientTide.closeSocket(userID);
273
+ if (connectionOrigin?.clientTide?.closeSocket) {
274
+ const result = connectionOrigin.clientTide.closeSocket(userID);
275
+ if (result instanceof Promise) {
276
+ try {
277
+ await result;
278
+ } catch (error) {
279
+ FileTide.outputGradient(`Did not disconnect ~ ${userID} ~ ${error.message}`, errorMessageColors);
280
+ }
281
+ }
282
+ if (typeof onDisconnect === "function") {
283
+ await onDisconnect(this);
284
+ }
273
285
  }
274
286
  this.clients.delete(userID);
275
287
  FileTide.outputGradient(`Stopped messager for user ${userID}.`, significantMessageColors);
288
+ if (typeof onCompletion === "function") {
289
+ await onCompletion(this);
290
+ }
276
291
  return;
277
292
  }
278
293
  FileTide.outputGradient(`No active messager found for user ${userID}.`, errorMessageColors);
@@ -281,11 +296,37 @@ class FileTide {
281
296
 
282
297
  /**
283
298
  * Stop all active clients.
299
+ * @param {Function} onClientDisconnect - Executes upon each messager disconnection
300
+ * @param {Function} onCompletion - Executes upon all messager disconnection
284
301
  */
285
- stopAllMessagers() {
302
+ async stopAllMessagers(onClientDisconnect, onCompletion) {
286
303
  FileTide.outputGradient("Stopping all messagers...", significantMessageColors);
304
+ const disconnectTasks = [];
305
+ for (let [userID, connectionOrigin] of this.clients.entries()) {
306
+ if (connectionOrigin?.clientTide?.closeSocket) {
307
+ const task = async () => {
308
+ try {
309
+ const result = connectionOrigin.clientTide.closeSocket(userID);
310
+ if (result instanceof Promise) {
311
+ await result;
312
+ }
313
+ if (typeof onClientDisconnect === "function") {
314
+ onClientDisconnect(userID, connectionOrigin);
315
+ }
316
+ FileTide.outputGradient(`Disconnected ~ ${userID}`, significantMessageColors);
317
+ } catch (error) {
318
+ FileTide.outputGradient(`Did not disconnect ~ ${userID} - ${error.message}`, errorMessageColors);
319
+ }
320
+ };
321
+ disconnectTasks.push(task());
322
+ }
323
+ }
324
+ await Promise.all(disconnectTasks);
287
325
  this.clients.clear();
288
326
  FileTide.outputGradient("All messagers stopped.", significantMessageColors);
327
+ if (typeof onCompletion === "function") {
328
+ await onCompletion(this);
329
+ }
289
330
  return;
290
331
  }
291
332
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trap_stevo/filetide",
3
- "version": "0.0.58",
3
+ "version": "0.0.60",
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": {