@trap_stevo/filetide-client 0.0.12 → 0.0.13

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.
@@ -107,6 +107,7 @@ class FileTideClient {
107
107
  this.fileMessagerInstance = fileMessagerInstance;
108
108
  this.clientDisconnected = false;
109
109
  this.shortcuts = shortcuts;
110
+ this.connectionID = null;
110
111
  _assertClassBrand(_FileTideClient_brand, this, _setupProcessEvents).call(this);
111
112
  if (displayTitle) {
112
113
  this.displayTitle(showCLITitle);
@@ -152,59 +153,63 @@ class FileTideClient {
152
153
  broadcastClientOffline(fileMessager) {
153
154
  if (fileMessager && !this.clientDisconnected) {
154
155
  this.clientDisconnected = true;
155
- fileMessager.clientTide.emitEvent(this.deviceName, "client-offline", this.deviceName);
156
+ const transferStates = fileTide.getTidingTransferStates();
157
+ fileMessager.clientTide.emitEvent(this.deviceName, "client-offline", {
158
+ clientID: this.deviceName,
159
+ connectionID: this.connectionID,
160
+ disconnectedDuringTransfer: transferStates.size > 0 ? true : false
161
+ });
156
162
  FileTide.outputGradient(`[${this.deviceName}] Disconnected from the file net.`, ["#00C897", "#00E0FF"]);
157
163
  }
158
164
  }
159
165
  startClient(clientOptions = {}, connectionOptions = {}, onConnect = null, ...clientConfigurations) {
160
- if (this.fileMessagerInstance && this.fileMessagerInstance.clientTide) {
161
- this.fileMessagerInstance.clientTide.closeSocket(this.deviceName);
162
- }
163
- fileTide.launchMessager({
164
- serverUrl: this.tideUrl,
165
- ...clientOptions
166
- }, {
167
- maxHttpBufferSize: 5e9,
168
- pingTimeout: 3600000,
169
- pingInterval: 60000,
170
- ...connectionOptions
171
- }, this.currentRoom, this.deviceName, fileMessager => {
172
- this.fileMessagerInstance = fileMessager;
173
- fileMessager.clientTide.onEvent(this.deviceName, "connect", () => {
174
- this.clientDisconnected = false;
175
- FileTide.outputGradient(`[${this.deviceName}] Connected to FileTide ~ ${this.tideUrl} in ${this.currentRoom}!`, ["#00C897", "#00E0FF"]);
176
- fileMessager.clientTide.emitEvent(this.deviceName, "client-online", this.deviceName, fileMessager.clientTide.sockets[this.deviceName].tideID, this.pDeviceName, fileMessager.clientTide.sockets[this.deviceName].id);
177
- FileTide.outputGradient(`[${this.deviceName}] Getting connected clients...`, ["#00C897", "#00E0FF"]);
178
- if (onConnect) {
179
- onConnect(fileMessager);
180
- }
181
- });
182
- fileMessager.clientTide.onEvent(this.deviceName, "disconnect", () => {
183
- this.broadcastClientOffline(fileMessager);
184
- });
185
- }, ...clientConfigurations);
166
+ const launchClient = () => {
167
+ if (this.fileMessagerInstance && this.fileMessagerInstance.clientTide) {
168
+ this.fileMessagerInstance.clientTide.closeSocket(this.deviceName);
169
+ }
170
+ fileTide.launchMessager({
171
+ serverUrl: this.tideUrl,
172
+ ...clientOptions
173
+ }, {
174
+ maxHttpBufferSize: 5e9,
175
+ pingTimeout: 3600000,
176
+ pingInterval: 60000,
177
+ ...connectionOptions
178
+ }, this.currentRoom, this.deviceName, (fileMessager, enterRoom) => {
179
+ this.fileMessagerInstance = fileMessager;
180
+ this.connectionID = null;
181
+ fileMessager.clientTide.onEvent(this.deviceName, "connect", async () => {
182
+ this.clientDisconnected = false;
183
+ this.connectionID = fileMessager.clientTide.sockets[this.deviceName].id;
184
+ FileTide.outputGradient(`[${this.deviceName}] Connected to FileTide ~ ${this.tideUrl} in ${this.currentRoom}!`, ["#00C897", "#00E0FF"]);
185
+ fileMessager.clientTide.emitEvent(this.deviceName, "client-online", this.deviceName, fileMessager.clientTide.sockets[this.deviceName].tideID, this.pDeviceName, fileMessager.clientTide.sockets[this.deviceName].id);
186
+ const clientOnline = await fileMessager.clientTide.emitEventWithResponse(this.deviceName, "check-client-online", "retrieved-client-online", {
187
+ clientID: this.deviceName
188
+ }, 5000);
189
+ if (clientOnline && clientOnline.online && clientOnline.client.id !== this.connectionID) {
190
+ launchClient();
191
+ return;
192
+ }
193
+ enterRoom();
194
+ FileTide.outputGradient(`[${this.deviceName}] Getting connected clients...`, ["#00C897", "#00E0FF"]);
195
+ if (onConnect) {
196
+ onConnect(fileMessager);
197
+ }
198
+ });
199
+ fileMessager.clientTide.onEvent(this.deviceName, "disconnect", () => {
200
+ this.broadcastClientOffline(fileMessager);
201
+ });
202
+ }, ...clientConfigurations);
203
+ };
204
+ launchClient();
186
205
  }
187
206
  requestFileTransfer(senderID, filePath, destinationPath, filterContent = []) {
188
207
  FileTide.outputGradient(`[${this.deviceName}] Requesting ${path.basename(filePath)} from client ~ ${senderID}...`, ["#00C897", "#00E0FF"]);
189
208
  this.fileMessagerInstance.requestTransfer(this.deviceName, senderID, filePath, destinationPath, filterContent);
190
209
  return;
191
210
  }
192
- async transferFiles(recipientID, filePath, destinationPath, filterContent = []) {
193
- const fileDetails = await fileTide.getPathData(filePath, filterContent);
194
- if (!fileDetails) {
195
- FileTide.outputGradient(`[${this.deviceName}] File at path ${filePath} not found.`, ["#F94144", "#F3722C"]);
196
- return;
197
- }
198
- if (fileDetails.type === "file") {
199
- FileTide.outputGradient(`[${this.deviceName}] Sending file ~ ${fileDetails.content.fileName} to client ~ ${recipientID}...`, ["#00C897", "#00E0FF"]);
200
- this.fileMessagerInstance.sendFile(this.deviceName, recipientID, fileDetails.content.fileName, fileDetails.content.fileData, destinationPath, fileDetails.content.size);
201
- return;
202
- }
203
- if (fileDetails.type === "directory") {
204
- FileTide.outputGradient(`[${this.deviceName}] Sending ${fileDetails.content.length} files in directory ~ ${path.basename(filePath)} to client ~ ${recipientID}...`, ["#00C897", "#00E0FF"]);
205
- this.fileMessagerInstance.sendDirectoryFiles(this.deviceName, recipientID, fileDetails.content, fileTide.getTidePath(filePath), destinationPath);
206
- return;
207
- }
211
+ async transferFiles(recipientID, filePath, destinationPath, filterContent = [], tideSize = 500, minTideSize = 10, maxTideSize = 2000) {
212
+ await fileTide.sendToDevice(recipientID, filePath, destinationPath, filterContent, tideSize, minTideSize, maxTideSize);
208
213
  return;
209
214
  }
210
215
  listFiles(recipientID, depth = 1) {
@@ -254,18 +259,27 @@ class FileTideClient {
254
259
  FileTide.outputGradient(`[${this.deviceName}] Updated room to ${this.currentRoom}`, ["#4D96FF", "#89CFF0"]);
255
260
  this.startClient({}, {}, onReconnect);
256
261
  if (completion) {
257
- completion(room);
262
+ completion(room, true);
258
263
  }
259
264
  return;
260
265
  }
261
- changeClientID(clientID, completion, onReconnect) {
262
- this.currentDeviceName = this.deviceName;
263
- this.deviceName = clientID;
264
- this.fileMessagerInstance.clientTide.emitEvent(this.currentDeviceName, "client-offline", this.currentDeviceName);
265
- FileTide.outputGradient(`[${this.deviceName}] Updated client name to ${this.deviceName}`, ["#4D96FF", "#89CFF0"]);
266
- this.startClient({}, {}, onReconnect);
266
+ async changeClientID(clientID, completion, onReconnect) {
267
+ const clientOnline = await this.fileMessagerInstance.clientTide.emitEventWithResponse(clientID, "check-client-online", "retrieved-client-online", {
268
+ clientID
269
+ }, 5000);
270
+ let updatedClientID = false;
271
+ if (clientOnline && clientOnline.online && clientOnline.client.id !== this.connectionID) {
272
+ FileTide.outputGradient(`[${this.deviceName}] Client name taken ~ ${this.deviceName}`, ["#4D96FF", "#89CFF0"]);
273
+ } else if (!clientOnline || !clientOnline.online || clientOnline.client.id === this.connectionID) {
274
+ this.currentDeviceName = this.deviceName;
275
+ this.deviceName = clientID;
276
+ this.fileMessagerInstance.clientTide.emitEvent(this.currentDeviceName, "client-offline", this.currentDeviceName);
277
+ FileTide.outputGradient(`[${this.deviceName}] Updated client name to ${this.deviceName}`, ["#4D96FF", "#89CFF0"]);
278
+ this.startClient({}, {}, onReconnect);
279
+ updatedClientID = true;
280
+ }
267
281
  if (completion) {
268
- completion(clientID);
282
+ completion(clientID, updatedClientID);
269
283
  }
270
284
  return;
271
285
  }
@@ -274,7 +288,7 @@ class FileTideClient {
274
288
  FileTide.outputGradient(`[${this.deviceName}] Updated tide URL to ${this.tideUrl}`, ["#4D96FF", "#89CFF0"]);
275
289
  this.startClient({}, {}, onReconnect);
276
290
  if (completion) {
277
- completion(url);
291
+ completion(url, true);
278
292
  }
279
293
  return;
280
294
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trap_stevo/filetide-client",
3
- "version": "0.0.12",
3
+ "version": "0.0.13",
4
4
  "description": "Seamless, real-time file transfers between devices with effortless connectivity. Allowing for powerful, instant, secure, and cross-platform file sharing, enabling efficient and reliable data transfers in any network environment.",
5
5
  "main": "dist/cjs/FileTideClient.js",
6
6
  "exports": {
@@ -8,6 +8,7 @@
8
8
  },
9
9
  "scripts": {
10
10
  "build": "babel src -d dist/cjs --env-name cjs",
11
+ "start-client": "node ./demos/FileTideClientDemo.js",
11
12
  "start": "node ./dist/cjs/FileTideClient.js"
12
13
  },
13
14
  "keywords": [
@@ -36,7 +37,7 @@
36
37
  "author": "Steven Compton",
37
38
  "license": "See License in LICENSE.md",
38
39
  "dependencies": {
39
- "@trap_stevo/filetide": "^0.0.39",
40
+ "@trap_stevo/filetide": "^0.0.44",
40
41
  "@trap_stevo/iotide": "^0.0.37",
41
42
  "@trap_stevo/legendarybuilderpronodejs-utilities": "^1.0.36",
42
43
  "chalk": "^4.1.2",