@trap_stevo/filetide-client 0.0.0 → 0.0.2

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.
@@ -156,7 +156,7 @@ class FileTideClient {
156
156
  FileTide.outputGradient(`[${this.currentDeviceName}] Disconnected from the file net.`, ["#00C897", "#00E0FF"]);
157
157
  }
158
158
  }
159
- startClient(clientOptions = {}, connectionOptions = {}, ...clientConfigurations) {
159
+ startClient(clientOptions = {}, connectionOptions = {}, onConnect = null, ...clientConfigurations) {
160
160
  if (this.fileMessagerInstance && this.fileMessagerInstance.clientTide) {
161
161
  this.fileMessagerInstance.clientTide.closeSocket(this.currentDeviceName);
162
162
  }
@@ -175,6 +175,9 @@ class FileTideClient {
175
175
  FileTide.outputGradient(`[${this.deviceName}] Connected to FileTide ~ ${this.tideUrl} in ${this.currentRoom}!`, ["#00C897", "#00E0FF"]);
176
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
177
  FileTide.outputGradient(`[${this.currentDeviceName}] Getting connected clients...`, ["#00C897", "#00E0FF"]);
178
+ if (onConnect) {
179
+ onConnect(fileMessager);
180
+ }
178
181
  });
179
182
  fileMessager.clientTide.onEvent(this.deviceName, "disconnect", () => {
180
183
  this.broadcastClientOffline(fileMessager);
@@ -186,7 +189,7 @@ class FileTideClient {
186
189
  this.fileMessagerInstance.requestTransfer(this.deviceName, senderID, filePath, destinationPath);
187
190
  return;
188
191
  }
189
- sendFileTransfer(recipientID, filePath, destinationPath) {
192
+ transferFiles(recipientID, filePath, destinationPath) {
190
193
  const fileDetails = fileTide.getPathData(filePath);
191
194
  if (!fileDetails) {
192
195
  FileTide.outputGradient(`[${this.deviceName}] File at path ${filePath} not found.`, ["#F94144", "#F3722C"]);
@@ -215,31 +218,51 @@ class FileTideClient {
215
218
  }
216
219
  return shortcuts;
217
220
  }
221
+ clearShortcuts(inputShortcuts) {
222
+ for (const key of inputShortcuts) {
223
+ if (shortcuts[key]) {
224
+ delete this.shortcuts[key];
225
+ }
226
+ }
227
+ return shortcuts;
228
+ }
218
229
  getShortcuts() {
219
230
  return shortcuts;
220
231
  }
221
- getOnlineClients() {
232
+ getOnlineClients(completion) {
222
233
  this.fileMessagerInstance.clientTide.emitEvent(this.deviceName, "clients-online", this.deviceName);
234
+ if (completion) {
235
+ completion();
236
+ }
223
237
  return;
224
238
  }
225
- changeRoom(room) {
239
+ changeRoom(room, completion) {
226
240
  this.currentRoom = room;
227
241
  FileTide.outputGradient(`[${this.deviceName}] Updated room to ${this.currentRoom}`, ["#4D96FF", "#89CFF0"]);
228
242
  this.startClient();
243
+ if (completion) {
244
+ completion();
245
+ }
229
246
  return;
230
247
  }
231
- changeClientID(clientID) {
248
+ changeClientID(clientID, completion) {
232
249
  this.currentDeviceName = this.deviceName;
233
250
  this.deviceName = clientID;
234
251
  this.fileMessagerInstance.clientTide.emitEvent(this.currentDeviceName, "client-offline", this.currentDeviceName);
235
252
  FileTide.outputGradient(`[${this.deviceName}] Updated client name to ${this.deviceName}`, ["#4D96FF", "#89CFF0"]);
236
253
  this.startClient();
254
+ if (completion) {
255
+ completion();
256
+ }
237
257
  return;
238
258
  }
239
- changeTideUrl(url) {
259
+ changeTideUrl(url, completion) {
240
260
  this.tideUrl = url;
241
261
  FileTide.outputGradient(`[${this.deviceName}] Updated tide URL to ${this.tideUrl}`, ["#4D96FF", "#89CFF0"]);
242
262
  this.startClient();
263
+ if (completion) {
264
+ completion();
265
+ }
243
266
  return;
244
267
  }
245
268
  displayTitle(cli = false) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trap_stevo/filetide-client",
3
- "version": "0.0.0",
3
+ "version": "0.0.2",
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": {
@@ -1,349 +0,0 @@
1
- "use strict";
2
-
3
- const chalk = require("chalk");
4
- class ConsoleTable {
5
- constructor(options = {}) {
6
- this.options = {
7
- padding: 1,
8
- headerAlign: "center",
9
- cellAlign: "left",
10
- borderStyle: "solid",
11
- headerColor: null,
12
- borderColor: null,
13
- cellColor: (content, columnName, rowData) => content,
14
- columnOrder: null,
15
- columnNames: {},
16
- title: "",
17
- tableNumber: null,
18
- gradient: {
19
- title: null,
20
- header: null,
21
- border: null,
22
- cell: null
23
- },
24
- ...options
25
- };
26
- this.borderChars = this.getBorderChars(this.options.borderStyle);
27
- }
28
- getBorderChars(style) {
29
- const styles = {
30
- solid: {
31
- topLeft: "┌",
32
- topRight: "┐",
33
- bottomLeft: "└",
34
- bottomRight: "┘",
35
- horizontal: "─",
36
- vertical: "│",
37
- topJoin: "┬",
38
- bottomJoin: "┴",
39
- leftJoin: "├",
40
- rightJoin: "┤",
41
- center: "┼"
42
- },
43
- double: {
44
- topLeft: "╔",
45
- topRight: "╗",
46
- bottomLeft: "╚",
47
- bottomRight: "╝",
48
- horizontal: "═",
49
- vertical: "║",
50
- topJoin: "╦",
51
- bottomJoin: "╩",
52
- leftJoin: "╠",
53
- rightJoin: "╣",
54
- center: "╬"
55
- },
56
- round: {
57
- topLeft: "╭",
58
- topRight: "╮",
59
- bottomLeft: "╰",
60
- bottomRight: "╯",
61
- horizontal: "─",
62
- vertical: "│",
63
- topJoin: "┬",
64
- bottomJoin: "┴",
65
- leftJoin: "├",
66
- rightJoin: "┤",
67
- center: "┼"
68
- },
69
- bold: {
70
- topLeft: "┏",
71
- topRight: "┓",
72
- bottomLeft: "┗",
73
- bottomRight: "┛",
74
- horizontal: "━",
75
- vertical: "┃",
76
- topJoin: "┳",
77
- bottomJoin: "┻",
78
- leftJoin: "┣",
79
- rightJoin: "┫",
80
- center: "╋"
81
- }
82
- };
83
- return styles[style] || styles["solid"];
84
- }
85
- setData(data) {
86
- if (Array.isArray(data)) {
87
- this.data = data;
88
- } else if (typeof data === "object") {
89
- this.data = Object.values(data);
90
- } else {
91
- throw new Error("Array or an object only.");
92
- }
93
- this.extractColumns();
94
- this.calculateColumnWidths();
95
- }
96
- extractColumns() {
97
- if (this.options.columnOrder && Array.isArray(this.options.columnOrder)) {
98
- this.columns = this.options.columnOrder;
99
- } else {
100
- const columnsSet = new Set();
101
- this.data.forEach(item => {
102
- Object.keys(item).forEach(key => columnsSet.add(key));
103
- });
104
- this.columns = Array.from(columnsSet);
105
- }
106
- }
107
- calculateColumnWidths() {
108
- const {
109
- padding
110
- } = this.options;
111
- this.columnWidths = {};
112
- this.totalWidth = 0;
113
- this.columns.forEach(column => {
114
- const headerName = this.options.columnNames[column] || column;
115
- let maxWidth = String(headerName).length;
116
- this.data.forEach(item => {
117
- const cellContent = item[column] !== undefined ? String(item[column]) : "";
118
- maxWidth = Math.max(maxWidth, cellContent.length);
119
- });
120
- const columnWidth = maxWidth + padding * 2;
121
- this.columnWidths[column] = columnWidth;
122
- this.totalWidth += columnWidth;
123
- });
124
- this.totalWidth += this.columns.length + 1;
125
- }
126
- alignText(text, width, align) {
127
- const {
128
- padding
129
- } = this.options;
130
- const textLength = text.length;
131
- let totalPadding = width - textLength;
132
- let leftPadding = " ".repeat(padding);
133
- let rightPadding = " ".repeat(padding);
134
- if (totalPadding < padding * 2) {
135
- leftPadding = "";
136
- rightPadding = "";
137
- } else {
138
- totalPadding -= padding * 2;
139
- if (align === "left") {
140
- rightPadding += " ".repeat(totalPadding);
141
- } else if (align === "right") {
142
- leftPadding += " ".repeat(totalPadding);
143
- } else {
144
- const half = Math.floor(totalPadding / 2);
145
- leftPadding += " ".repeat(half);
146
- rightPadding += " ".repeat(totalPadding - half);
147
- }
148
- }
149
- return leftPadding + text + rightPadding;
150
- }
151
- generateGradientText(text, startColor, endColor) {
152
- const length = text.length;
153
- const startRGB = this.hexToRgb(startColor);
154
- const endRGB = this.hexToRgb(endColor);
155
- let gradientText = "";
156
- for (let i = 0; i < length; i++) {
157
- const ratio = i / (length - 1 || 1);
158
- const color = {
159
- r: Math.round(startRGB.r + ratio * (endRGB.r - startRGB.r)),
160
- g: Math.round(startRGB.g + ratio * (endRGB.g - startRGB.g)),
161
- b: Math.round(startRGB.b + ratio * (endRGB.b - startRGB.b))
162
- };
163
- gradientText += chalk.rgb(color.r, color.g, color.b)(text[i]);
164
- }
165
- return gradientText;
166
- }
167
- hexToRgb(hex) {
168
- const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
169
- return result ? {
170
- r: parseInt(result[1], 16),
171
- g: parseInt(result[2], 16),
172
- b: parseInt(result[3], 16)
173
- } : null;
174
- }
175
- generateBorder(type) {
176
- const {
177
- columns,
178
- columnWidths
179
- } = this;
180
- let {
181
- horizontal,
182
- vertical,
183
- topLeft,
184
- topRight,
185
- bottomLeft,
186
- bottomRight,
187
- topJoin,
188
- bottomJoin,
189
- leftJoin,
190
- rightJoin,
191
- center
192
- } = this.borderChars;
193
- const {
194
- borderColor
195
- } = this.options;
196
- const borderGradient = this.options.gradient.border;
197
- if (borderGradient && borderGradient.length === 2) {
198
- const chars = [topLeft, topRight, bottomLeft, bottomRight, horizontal, vertical, topJoin, bottomJoin, leftJoin, rightJoin, center];
199
- const coloredChars = {};
200
- chars.forEach((char, index) => {
201
- coloredChars[char] = this.generateGradientText(char, borderGradient[0], borderGradient[1]);
202
- });
203
- bottomRight = coloredChars[bottomRight];
204
- bottomLeft = coloredChars[bottomLeft];
205
- topRight = coloredChars[topRight];
206
- topLeft = coloredChars[topLeft];
207
- horizontal = coloredChars[horizontal];
208
- vertical = coloredChars[vertical];
209
- bottomJoin = coloredChars[bottomJoin];
210
- rightJoin = coloredChars[rightJoin];
211
- leftJoin = coloredChars[leftJoin];
212
- topJoin = coloredChars[topJoin];
213
- center = coloredChars[center];
214
- } else if (borderColor) {
215
- bottomRight = borderColor(bottomRight);
216
- bottomLeft = borderColor(bottomLeft);
217
- topRight = borderColor(topRight);
218
- topLeft = borderColor(topLeft);
219
- horizontal = borderColor(horizontal);
220
- vertical = borderColor(vertical);
221
- bottomJoin = borderColor(bottomJoin);
222
- rightJoin = borderColor(rightJoin);
223
- leftJoin = borderColor(leftJoin);
224
- topJoin = borderColor(topJoin);
225
- center = borderColor(center);
226
- }
227
- let border = "";
228
- columns.forEach((column, index) => {
229
- const first = index === 0;
230
- const last = index === columns.length - 1;
231
- const width = columnWidths[column];
232
- const line = horizontal.repeat(width);
233
- if (type === "top") {
234
- border += first ? topLeft : topJoin;
235
- } else if (type === "bottom") {
236
- border += first ? bottomLeft : bottomJoin;
237
- } else {
238
- border += first ? leftJoin : center;
239
- }
240
- border += line;
241
- if (last) {
242
- if (type === "top") {
243
- border += topRight;
244
- } else if (type === "bottom") {
245
- border += bottomRight;
246
- } else {
247
- border += rightJoin;
248
- }
249
- }
250
- });
251
- return border;
252
- }
253
- generateRow(rowData, headerRow = false) {
254
- const {
255
- columns,
256
- columnWidths
257
- } = this;
258
- let {
259
- vertical
260
- } = this.borderChars;
261
- const {
262
- headerAlign,
263
- cellAlign,
264
- headerColor,
265
- cellColor
266
- } = this.options;
267
- const align = headerRow ? headerAlign : cellAlign;
268
- const headerGradient = this.options.gradient.header;
269
- const cellGradient = this.options.gradient.cell;
270
- const borderGradient = this.options.gradient.border;
271
- if (borderGradient && borderGradient.length === 2) {
272
- vertical = this.generateGradientText(vertical, borderGradient[0], borderGradient[1]);
273
- } else if (this.options.borderColor) {
274
- vertical = this.options.borderColor(vertical);
275
- }
276
- let row = "";
277
- columns.forEach((column, index) => {
278
- const content = rowData[column] !== undefined ? String(rowData[column]) : "";
279
- const width = columnWidths[column];
280
- const alignedText = this.alignText(content, width, align);
281
- let cellContent = alignedText;
282
- const first = index === 0;
283
- if (headerRow) {
284
- if (headerGradient && headerGradient.length === 2) {
285
- cellContent = this.generateGradientText(cellContent, headerGradient[0], headerGradient[1]);
286
- } else if (headerColor) {
287
- cellContent = headerColor(cellContent);
288
- }
289
- } else {
290
- if (cellGradient && cellGradient.length === 2) {
291
- cellContent = this.generateGradientText(cellContent, cellGradient[0], cellGradient[1]);
292
- } else if (cellColor) {
293
- cellContent = cellColor(cellContent, column, rowData);
294
- }
295
- }
296
- if (first) {
297
- row += vertical;
298
- }
299
- row += cellContent + vertical;
300
- });
301
- return row;
302
- }
303
- setTitle(title, tableNumber = null) {
304
- this.options.title = title;
305
- if (tableNumber !== null) {
306
- this.options.tableNumber = tableNumber;
307
- }
308
- }
309
- renderTitle() {
310
- let titleText = this.options.title;
311
- if (this.options.tableNumber !== null) {
312
- titleText = titleText;
313
- }
314
- const totalWidth = this.totalWidth - 2;
315
- const titleLength = titleText.length;
316
- let leftPadding = Math.floor((totalWidth - titleLength) / 2);
317
- if (leftPadding < 0) leftPadding = 0;
318
- let titleLine = " ".repeat(leftPadding) + titleText;
319
- const titleGradient = this.options.gradient.title;
320
- if (titleGradient && titleGradient.length === 2) {
321
- titleLine = this.generateGradientText(titleLine.trim(), titleGradient[0], titleGradient[1]);
322
- }
323
- return titleLine;
324
- }
325
- render() {
326
- const {
327
- data
328
- } = this;
329
- if (!data || data.length === 0) return "";
330
- const lines = [];
331
- if (this.options.title) {
332
- const title = this.renderTitle();
333
- lines.push(title);
334
- }
335
- lines.push(this.generateBorder("top"));
336
- const headerData = {};
337
- this.columns.forEach(column => {
338
- headerData[column] = this.options.columnNames[column] || column;
339
- });
340
- lines.push(this.generateRow(headerData, true));
341
- lines.push(this.generateBorder("middle"));
342
- data.forEach(rowData => {
343
- lines.push(this.generateRow(rowData));
344
- });
345
- lines.push(this.generateBorder("bottom"));
346
- return lines.join("\n");
347
- }
348
- }
349
- module.exports = ConsoleTable;
@@ -1,10 +0,0 @@
1
- #!/usr/bin/env node
2
- "use strict";
3
-
4
- const FileTideClient = require("./FileTideClient.js");
5
- const os = require("os");
6
- const args = process.argv.slice(2);
7
- const tideUrl = args[0] || "http://localhost:9269";
8
- const deviceName = args[1] || os.hostname();
9
- const currentRoom = args[2] || "file-room";
10
- const client = new FileTideClient(deviceName, tideUrl, currentRoom, true, true);