@trap_stevo/filetide 0.0.58 → 0.0.59

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,27 @@ 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
266
267
  */
267
- stopMessager(userID) {
268
+ async stopMessager(userID, onDisconnect) {
268
269
  if (this.clients.has(userID)) {
269
270
  FileTide.outputGradient(`Stopping messager for user ${userID}...`, significantMessageColors);
270
271
  const connectionOrigin = this.clients.get(userID);
271
- if (connectionOrigin) {
272
- connectionOrigin.clientTide.closeSocket(userID);
272
+ if (connectionOrigin?.clientTide?.closeSocket) {
273
+ const result = connectionOrigin.clientTide.closeSocket(userID);
274
+ if (result instanceof Promise) {
275
+ try {
276
+ await result;
277
+ } catch (error) {
278
+ FileTide.outputGradient(`Did not disconnect ~ ${userID} ~ ${error.message}`, errorMessageColors);
279
+ }
280
+ }
273
281
  }
274
282
  this.clients.delete(userID);
275
283
  FileTide.outputGradient(`Stopped messager for user ${userID}.`, significantMessageColors);
284
+ if (typeof onDisconnect === "function") {
285
+ await onDisconnect(this);
286
+ }
276
287
  return;
277
288
  }
278
289
  FileTide.outputGradient(`No active messager found for user ${userID}.`, errorMessageColors);
@@ -281,11 +292,33 @@ class FileTide {
281
292
 
282
293
  /**
283
294
  * Stop all active clients.
295
+ * @param {Function} onDisconnect - Executes upon all messager disconnection
284
296
  */
285
- stopAllMessagers() {
297
+ async stopAllMessagers(onDisconnect) {
286
298
  FileTide.outputGradient("Stopping all messagers...", significantMessageColors);
299
+ const disconnectTasks = [];
300
+ for (let [userID, connectionOrigin] of this.clients.entries()) {
301
+ if (connectionOrigin?.clientTide?.closeSocket) {
302
+ const task = async () => {
303
+ try {
304
+ const result = connectionOrigin.clientTide.closeSocket(userID);
305
+ if (result instanceof Promise) {
306
+ await result;
307
+ }
308
+ FileTide.outputGradient(`Disconnected ~ ${userID}`, significantMessageColors);
309
+ } catch (error) {
310
+ FileTide.outputGradient(`Did not disconnect ~ ${userID} - ${error.message}`, errorMessageColors);
311
+ }
312
+ };
313
+ disconnectTasks.push(task());
314
+ }
315
+ }
316
+ await Promise.all(disconnectTasks);
287
317
  this.clients.clear();
288
318
  FileTide.outputGradient("All messagers stopped.", significantMessageColors);
319
+ if (typeof onDisconnect === "function") {
320
+ await onDisconnect(this);
321
+ }
289
322
  return;
290
323
  }
291
324
  }
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.59",
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": {