@trap_stevo/filetide 0.0.57 → 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.
@@ -63,9 +63,10 @@ class FileTide {
63
63
  * Initialize and start the server.
64
64
  * @param {Object} serverOptions - Configuration for server (e.g., port, useCors, useHTTPS)
65
65
  * @param {Function} onLaunch - Callback for when a file tide instance launches
66
+ * @param {...any} tideConfigurations - Additional configuration objects for customizing FileTide behavior
66
67
  */
67
- launchFileTide(serverOptions = {}, onLaunch) {
68
- this.fileNet = new FileMessager(serverOptions);
68
+ launchFileTide(serverOptions = {}, onLaunch, ...tideConfigurations) {
69
+ this.fileNet = new FileMessager(serverOptions, ...tideConfigurations);
69
70
  this.fileNet.start();
70
71
  FileTide.outputGradient("[FileTide] ~ FileNet launched successfully!", significantMessageColors);
71
72
  if (onLaunch) {
@@ -248,7 +249,7 @@ class FileTide {
248
249
  }
249
250
 
250
251
  /**
251
- * Stop the server if it"s running.
252
+ * Stop the server if running.
252
253
  */
253
254
  stopFileTide() {
254
255
  if (this.fileNet) {
@@ -262,16 +263,27 @@ class FileTide {
262
263
  /**
263
264
  * Stop a specific client.
264
265
  * @param {String} userID - The ID of the client user to stop
266
+ * @param {Function} onDisconnect - Executes upon messager disconnection
265
267
  */
266
- stopMessager(userID) {
268
+ async stopMessager(userID, onDisconnect) {
267
269
  if (this.clients.has(userID)) {
268
270
  FileTide.outputGradient(`Stopping messager for user ${userID}...`, significantMessageColors);
269
271
  const connectionOrigin = this.clients.get(userID);
270
- if (connectionOrigin) {
271
- 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
+ }
272
281
  }
273
282
  this.clients.delete(userID);
274
283
  FileTide.outputGradient(`Stopped messager for user ${userID}.`, significantMessageColors);
284
+ if (typeof onDisconnect === "function") {
285
+ await onDisconnect(this);
286
+ }
275
287
  return;
276
288
  }
277
289
  FileTide.outputGradient(`No active messager found for user ${userID}.`, errorMessageColors);
@@ -280,11 +292,33 @@ class FileTide {
280
292
 
281
293
  /**
282
294
  * Stop all active clients.
295
+ * @param {Function} onDisconnect - Executes upon all messager disconnection
283
296
  */
284
- stopAllMessagers() {
297
+ async stopAllMessagers(onDisconnect) {
285
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);
286
317
  this.clients.clear();
287
318
  FileTide.outputGradient("All messagers stopped.", significantMessageColors);
319
+ if (typeof onDisconnect === "function") {
320
+ await onDisconnect(this);
321
+ }
288
322
  return;
289
323
  }
290
324
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trap_stevo/filetide",
3
- "version": "0.0.57",
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": {