@trap_stevo/filetide 0.0.9 → 0.0.10

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.
@@ -48,7 +48,9 @@ class FileMessager {
48
48
  console.log(`Client ~ ${clientId} not authorized.`);
49
49
  return;
50
50
  }
51
+ const senderConnectionID = this.messagerClients.get(senderID);
51
52
  const connectionID = this.messagerClients.get(clientId);
53
+ const senderClient = this.onlineClients.get(connectionID);
52
54
  const client = this.onlineClients.get(connectionID);
53
55
  if (!client) {
54
56
  console.log(`Client ~ ${clientId} not found.`);
@@ -59,12 +61,14 @@ class FileMessager {
59
61
  fileData,
60
62
  path: filePath
61
63
  });
62
- console.log(`[FileTide ~ File Messager] ~ File ${fileName} sent to client ${clientId}!`);
63
- this.fileNet.emitToTide(senderID, "transfer-status", {
64
- status: `[FileTide ~ File Messager] ~ File ${fileName} sent to client ${clientId}!`,
65
- recipientID: clientId,
66
- success: true
67
- });
64
+ console.log(`[FileTide ~ File Messager] ~ File ${fileName} sent to client ~ ${clientId}!`);
65
+ if (senderClient) {
66
+ senderClient.emit("transfer-status", {
67
+ status: `[FileTide ~ File Messager] ~ File ${fileName} sent to client ~ ${clientId}!`,
68
+ recipientID: clientId,
69
+ success: true
70
+ });
71
+ }
68
72
  return;
69
73
  }
70
74
 
@@ -83,8 +87,18 @@ class FileMessager {
83
87
  this.sendFileToClient(senderID, recipientId, fileData, fileName, filePath);
84
88
  return;
85
89
  }
86
- handleClientsOnline() {
87
- this.fileNet.emit("clients-online", {
90
+ handleClientsOnline(clientID) {
91
+ if (!this.messagerClients.has(clientID)) {
92
+ console.log(`Client ~ ${clientID} not authorized.`);
93
+ return;
94
+ }
95
+ const connectionID = this.messagerClients.get(clientID);
96
+ const client = this.onlineClients.get(connectionID);
97
+ if (!client) {
98
+ console.log(`Client ~ ${clientID} not found.`);
99
+ return;
100
+ }
101
+ client.emit("current-clients-online", {
88
102
  currentClients: this.messagerClients
89
103
  });
90
104
  return;
@@ -116,4 +130,5 @@ class FileMessager {
116
130
  return;
117
131
  }
118
132
  }
133
+ ;
119
134
  module.exports = FileMessager;
@@ -58,7 +58,7 @@ class FileMessagerClient {
58
58
  }
59
59
  handleIncomingFile(userID) {
60
60
  this.clientTide.onEvent(userID, "incoming-file", data => {
61
- console.log(`[FileTide ~ File Messager] ~ Received file for user ${userID}: ${data.fileName}.`);
61
+ console.log(`\n[FileTide ~ File Messager] ~ Received file for user ${userID}: ${data.fileName}.`);
62
62
  FileUtilityManager.saveFile(data.fileName, data.fileData, data.path, data.name);
63
63
  });
64
64
  }
@@ -41,7 +41,7 @@ class FileTide {
41
41
  * @param {String} userID - The ID of the client user
42
42
  * @param {Function} onLaunch - Callback for when a file messager launches
43
43
  */
44
- launchMessager(clientOptions = {}, roomName, userID, onLaunch, onIncomingFile) {
44
+ launchMessager(clientOptions = {}, roomName, userID, onLaunch, onIncomingFile, onTransferCompletion, onClientsOnline) {
45
45
  if (this.clients.has(userID)) {
46
46
  this.stopMessager(userID);
47
47
  }
@@ -50,7 +50,7 @@ class FileTide {
50
50
  newClient.handleMultipleClientsTransfer();
51
51
  this.clients.set(userID, newClient);
52
52
  console.log(`[FileTide] ~ Messager launched successfully for client ~ ${userID}!`);
53
- _assertClassBrand(_FileTide_brand, this, _setupFileEventListeners).call(this, userID, newClient, onIncomingFile);
53
+ _assertClassBrand(_FileTide_brand, this, _setupFileEventListeners).call(this, userID, newClient, onIncomingFile, onTransferCompletion, onClientsOnline);
54
54
  if (onLaunch) {
55
55
  onLaunch(newClient);
56
56
  }
@@ -137,7 +137,7 @@ class FileTide {
137
137
  return;
138
138
  }
139
139
  }
140
- function _setupFileEventListeners(userID, client, onIncomingFile) {
140
+ function _setupFileEventListeners(userID, client, onIncomingFile, onTransferCompletion, onClientsOnline) {
141
141
  client.clientTide.onEvent(userID, "incoming-file", data => {
142
142
  console.log(`[${userID}] Received file: ${data.fileName}`);
143
143
  const saveDir = data.path;
@@ -154,6 +154,16 @@ function _setupFileEventListeners(userID, client, onIncomingFile) {
154
154
  onIncomingFile(data);
155
155
  }
156
156
  });
157
+ client.clientTide.onEvent(userID, "transfer-status", data => {
158
+ if (onTransferCompletion) {
159
+ onTransferCompletion(data);
160
+ }
161
+ });
162
+ client.clientTide.onEvent(userID, "current-clients-online", data => {
163
+ if (onClientsOnline) {
164
+ onClientsOnline(data);
165
+ }
166
+ });
157
167
  return;
158
168
  }
159
169
  ;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trap_stevo/filetide",
3
- "version": "0.0.9",
3
+ "version": "0.0.10",
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": {