@trap_stevo/filetide 0.0.88 → 0.0.90

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.
@@ -77,7 +77,7 @@ class FileMessagerClient {
77
77
  }, options, headers, onConnect, onDisconnect, authURL, authHeaders, useAuthentication, queryAuthToken);
78
78
  return () => {
79
79
  this.clientTide.joinChannel(socketName, roomName, userID, () => {
80
- FileTideDebugUtilityManager.outputGradient(`\n[FileTide ~ Tider] ~ Client ~ ${userID} joined room ${roomName} successfully!`, significantMessageColors);
80
+ FileTideDebugUtilityManager.outputGradient(`\n[FileTide ~ Tider] ~ ${userID} joined room ${roomName} successfully!`, significantMessageColors);
81
81
  this.clients.set(userID, {
82
82
  roomName
83
83
  });
@@ -363,7 +363,7 @@ function _createClientInstance(clientID, clientOptions, options = {}, headers =
363
363
  await onDisconnect(...disconnectArguments);
364
364
  }
365
365
  });
366
- FileTideDebugUtilityManager.outputGradient(`\n[FileTide ~ Tider] ~ Created client with ID ${clientID} and socket ${clientID}!`, significantMessageColors);
366
+ FileTideDebugUtilityManager.outputGradient(`\n[FileTide ~ Tider] ~ Created with ID '${clientID}' and origin '${clientID}'!`, significantMessageColors);
367
367
  return clientID;
368
368
  }
369
369
  function _getAdaptiveTideSize(chunkSize, tideSize = 500, minTideSize = 10, maxTideSize = 2000) {
@@ -373,11 +373,6 @@ function _getAdaptiveTideSize(chunkSize, tideSize = 500, minTideSize = 10, maxTi
373
373
  if (networkStatus.state === NETWORK_TRAFFIC_STATES.CONGESTED) {
374
374
  tideDurationMs *= 0.50;
375
375
  }
376
-
377
- /*
378
- * Determine how many chunks current network conditions
379
- * can reasonably support during one Tide duration.
380
- */
381
376
  const networkTideBytes = Math.max(sendRateBps * (tideDurationMs / 1000), chunkSize);
382
377
  const networkTideSize = Math.max(1, Math.floor(networkTideBytes / chunkSize));
383
378
  const normalizedMinTideSize = Math.max(1, minTideSize);
@@ -48,6 +48,8 @@ class FileTide {
48
48
  /**
49
49
  * Set up file transfer event listeners natively.
50
50
  * Automatically checks and creates directories as needed.
51
+ * @param {Object} [options = {}] - Additional messager and transfer lifecycle options.
52
+ * @param {Boolean} [options.displayTransferOutput=true] - Whether FileTide should render transfer lifecycle output directly to the terminal.
51
53
  */
52
54
  _classPrivateMethodInitSpec(this, _FileTide_brand);
53
55
  this.transferStatsManager = new FileTransferStatsManager();
@@ -434,7 +436,27 @@ class FileTide {
434
436
 
435
437
  // --- FileTide Display Management ---
436
438
 
437
- static outputGradient(text, colors) {
439
+ static setOutputHandler(handler = null) {
440
+ FileTide.outputHandler = typeof handler === "function" ? handler : null;
441
+ return FileTide.outputHandler;
442
+ }
443
+ static getOutputHandler() {
444
+ return FileTide.outputHandler;
445
+ }
446
+ static clearOutputHandler() {
447
+ FileTide.outputHandler = null;
448
+ return true;
449
+ }
450
+ static outputGradient(text, colors, metadata = {}) {
451
+ if (typeof FileTide.outputHandler === "function") {
452
+ FileTide.outputHandler({
453
+ text: String(text ?? ""),
454
+ colors,
455
+ type: "gradient",
456
+ metadata: metadata || {}
457
+ });
458
+ return;
459
+ }
438
460
  FileTideDebugUtilityManager.outputGradient(text, colors);
439
461
  return;
440
462
  }
@@ -463,7 +485,8 @@ function _setupFileEventListeners(userID, client, onTransferProgress, onIncoming
463
485
  onCurrentClientIDAlreadyOnline,
464
486
  onCurrentClientUnauthorized,
465
487
  onBeforeCurrentClientUnauthorizedDisconnect,
466
- onCurrentClientUnauthorizedDisconnect
488
+ onCurrentClientUnauthorizedDisconnect,
489
+ displayTransferOutput = true
467
490
  } = options;
468
491
  const fileTransferReceiver = new FileTransferReceiverManager();
469
492
  client.clientTide.onEvent(userID, "current-online-clients", data => {
@@ -581,7 +604,7 @@ function _setupFileEventListeners(userID, client, onTransferProgress, onIncoming
581
604
  const {
582
605
  currentSender
583
606
  } = data;
584
- if (currentSender && currentSender === userID) {
607
+ if (currentSender && currentSender === userID && displayTransferOutput) {
585
608
  _FileTide.outputGradient(`[${userID}] Transfer successfully sent to ${data.recipientID}`, significantMessageColors);
586
609
  return;
587
610
  }
@@ -721,7 +744,9 @@ function _setupFileEventListeners(userID, client, onTransferProgress, onIncoming
721
744
  client.clientTide.onEvent(userID, "transfer-complete", data => {
722
745
  const savePath = FileUtilityManager.getTidePath(path.join(data.filePath, data.fileName));
723
746
  try {
724
- _FileTide.outputGradient(`[${userID}] File transfer complete ~ ${data.fileName}`, significantMessageColors);
747
+ if (displayTransferOutput) {
748
+ _FileTide.outputGradient(`[${userID}] File transfer complete ~ ${data.fileName}`, significantMessageColors);
749
+ }
725
750
  const transferState = FileTransferTrackingManager.getTransfer(data.fileName);
726
751
  FileTideDebugUtilityManager.log("notice", true, `Transfer state ~ ${data.fileName} active | ${transferState !== null && transferState !== undefined ? true : false}`);
727
752
  if (!transferState) {
@@ -729,9 +754,9 @@ function _setupFileEventListeners(userID, client, onTransferProgress, onIncoming
729
754
  }
730
755
  if (transferState.fileStream) {
731
756
  fileTransferReceiver.completeTransfer(data, (transferData, transfers, success, error) => {
732
- if (success) {
757
+ if (success && displayTransferOutput) {
733
758
  _FileTide.outputGradient(`[${userID}] File saved at ~ ${savePath}\n`, significantMessageColors);
734
- } else if (!success) {
759
+ } else if (!success && displayTransferOutput) {
735
760
  _FileTide.outputGradient(`[${userID}] Did not save file at ~ ${savePath}\n\t${error}\n`, errorMessageColors);
736
761
  }
737
762
  const transferStats = success ? this.transferStatsManager.completeTransfer(data.transferId || data.fileName) : this.transferStatsManager.failTransfer(data.transferId || data.fileName);
@@ -747,7 +772,9 @@ function _setupFileEventListeners(userID, client, onTransferProgress, onIncoming
747
772
  return;
748
773
  }
749
774
  FileTransferTrackingManager.untrackTransfer(data.fileName);
750
- _FileTide.outputGradient(`[${userID}] Transfer successfully sent to ~ ${data.recipientId} and saved at ~ ${path.join(data.filePath, data.fileName)}\n`, significantMessageColors);
775
+ if (displayTransferOutput) {
776
+ _FileTide.outputGradient(`[${userID}] Transfer successfully sent to ~ ${data.recipientId} and saved at ~ ${path.join(data.filePath, data.fileName)}\n`, significantMessageColors);
777
+ }
751
778
  const transferStats = this.transferStatsManager.completeTransfer(data.transferId || data.fileName);
752
779
  if (onTransferComplete) {
753
780
  onTransferComplete({
@@ -755,10 +782,14 @@ function _setupFileEventListeners(userID, client, onTransferProgress, onIncoming
755
782
  stats: transferStats
756
783
  }, FileTransferTrackingManager.activeTransfers, true);
757
784
  }
758
- FileTransferTrackingManager.outputCurrentTransfers();
785
+ if (displayTransferOutput) {
786
+ FileTransferTrackingManager.outputCurrentTransfers();
787
+ }
759
788
  this.transferStatsManager.clearTransfer(data.transferId || data.fileName);
760
789
  } catch (error) {
761
- _FileTide.outputGradient(`[${userID}] Did not save file at ~ ${savePath}\n${error}`, errorMessageColors);
790
+ if (displayTransferOutput) {
791
+ _FileTide.outputGradient(`[${userID}] Did not save file at ~ ${savePath}\n${error}`, errorMessageColors);
792
+ }
762
793
  const transferStats = this.transferStatsManager.failTransfer(data.transferId || data.fileName);
763
794
  if (onTransferComplete) {
764
795
  onTransferComplete({
@@ -766,13 +797,17 @@ function _setupFileEventListeners(userID, client, onTransferProgress, onIncoming
766
797
  stats: transferStats
767
798
  }, FileTransferTrackingManager.activeTransfers, false);
768
799
  }
769
- FileTransferTrackingManager.outputCurrentTransfers();
800
+ if (displayTransferOutput) {
801
+ FileTransferTrackingManager.outputCurrentTransfers();
802
+ }
770
803
  this.transferStatsManager.clearTransfer(data.transferId || data.fileName);
771
804
  }
772
805
  });
773
806
  client.clientTide.onEvent(userID, "transfer-failed", async data => {
774
807
  const transferState = FileTransferTrackingManager.getTransfer(data.fileName);
775
- _FileTide.outputGradient(`[${userID}] File transfer failed ~ ${data.fileName}${data.reason ? `\n${data.reason}` : ""}`, errorMessageColors);
808
+ if (displayTransferOutput) {
809
+ _FileTide.outputGradient(`[${userID}] File transfer failed ~ ${data.fileName}${data.reason ? `\n${data.reason}` : ""}`, errorMessageColors);
810
+ }
776
811
  if (transferState?.fileStream) {
777
812
  try {
778
813
  await new Promise(resolve => {
@@ -794,7 +829,9 @@ function _setupFileEventListeners(userID, client, onTransferProgress, onIncoming
794
829
  if (onTransferComplete) {
795
830
  onTransferComplete(failureData, FileTransferTrackingManager.activeTransfers, false);
796
831
  }
797
- FileTransferTrackingManager.outputCurrentTransfers();
832
+ if (displayTransferOutput) {
833
+ FileTransferTrackingManager.outputCurrentTransfers();
834
+ }
798
835
  this.transferStatsManager.clearTransfer(data.transferId || data.fileName);
799
836
  });
800
837
  client.clientTide.onEvent(userID, "transfer-requested", async data => {
@@ -838,7 +875,6 @@ function _setupFileEventListeners(userID, client, onTransferProgress, onIncoming
838
875
  _FileTide.outputGradient(`[${userID} | FileTide Error] ${error}`, errorMessageColors);
839
876
  });
840
877
  client.clientTide.onEvent(userID, "client-file-list-received", async data => {
841
- _FileTide.outputGradient(`[${userID}] Successfully received all ${HUDUtilityManager.convertNumberToMoneyFormat(data.totalItemsSent, false)} contents in ${data.senderID}'s file list!`, significantMessageColors);
842
878
  if (onFileListReceived) {
843
879
  onFileListReceived(data);
844
880
  }
@@ -848,7 +884,6 @@ function _setupFileEventListeners(userID, client, onTransferProgress, onIncoming
848
884
  clientID: userID,
849
885
  tideID: client.clientTide.sockets[userID].tideID
850
886
  });
851
- _FileTide.outputGradient(`[${userID}] Received ${HUDUtilityManager.convertNumberToMoneyFormat(data.totalItems, false)} directory contents from ${data.senderID}'s file list!`, significantMessageColors);
852
887
  if (onListFiles) {
853
888
  onListFiles(data);
854
889
  }
@@ -857,4 +892,5 @@ function _setupFileEventListeners(userID, client, onTransferProgress, onIncoming
857
892
  return;
858
893
  }
859
894
  ;
895
+ FileTide.outputHandler = null;
860
896
  module.exports = FileTide;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trap_stevo/filetide",
3
- "version": "0.0.88",
3
+ "version": "0.0.90",
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": {