@trap_stevo/filetide-client 0.0.11 → 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.
- package/dist/cjs/FileTideClient.js +70 -57
- package/package.json +3 -2
|
@@ -105,9 +105,9 @@ class FileTideClient {
|
|
|
105
105
|
this.tideUrl = inputTideURL || tideUrl;
|
|
106
106
|
this.currentRoom = inputCurrentRoom || currentRoom;
|
|
107
107
|
this.fileMessagerInstance = fileMessagerInstance;
|
|
108
|
-
this.fileTide = fileTide;
|
|
109
108
|
this.clientDisconnected = false;
|
|
110
109
|
this.shortcuts = shortcuts;
|
|
110
|
+
this.connectionID = null;
|
|
111
111
|
_assertClassBrand(_FileTideClient_brand, this, _setupProcessEvents).call(this);
|
|
112
112
|
if (displayTitle) {
|
|
113
113
|
this.displayTitle(showCLITitle);
|
|
@@ -153,73 +153,77 @@ class FileTideClient {
|
|
|
153
153
|
broadcastClientOffline(fileMessager) {
|
|
154
154
|
if (fileMessager && !this.clientDisconnected) {
|
|
155
155
|
this.clientDisconnected = true;
|
|
156
|
-
|
|
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
|
+
});
|
|
157
162
|
FileTide.outputGradient(`[${this.deviceName}] Disconnected from the file net.`, ["#00C897", "#00E0FF"]);
|
|
158
163
|
}
|
|
159
164
|
}
|
|
160
165
|
startClient(clientOptions = {}, connectionOptions = {}, onConnect = null, ...clientConfigurations) {
|
|
161
|
-
|
|
162
|
-
this.fileMessagerInstance.clientTide
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
this.
|
|
174
|
-
|
|
175
|
-
this.
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
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();
|
|
187
205
|
}
|
|
188
206
|
requestFileTransfer(senderID, filePath, destinationPath, filterContent = []) {
|
|
189
207
|
FileTide.outputGradient(`[${this.deviceName}] Requesting ${path.basename(filePath)} from client ~ ${senderID}...`, ["#00C897", "#00E0FF"]);
|
|
190
208
|
this.fileMessagerInstance.requestTransfer(this.deviceName, senderID, filePath, destinationPath, filterContent);
|
|
191
209
|
return;
|
|
192
210
|
}
|
|
193
|
-
async transferFiles(recipientID, filePath, destinationPath, filterContent = []) {
|
|
194
|
-
|
|
195
|
-
if (!fileDetails) {
|
|
196
|
-
FileTide.outputGradient(`[${this.deviceName}] File at path ${filePath} not found.`, ["#F94144", "#F3722C"]);
|
|
197
|
-
return;
|
|
198
|
-
}
|
|
199
|
-
if (fileDetails.type === "file") {
|
|
200
|
-
FileTide.outputGradient(`[${this.deviceName}] Sending file ~ ${fileDetails.content.fileName} to client ~ ${recipientID}...`, ["#00C897", "#00E0FF"]);
|
|
201
|
-
this.fileMessagerInstance.sendFile(this.deviceName, recipientID, fileDetails.content.fileName, fileDetails.content.fileData, destinationPath, fileDetails.content.size);
|
|
202
|
-
return;
|
|
203
|
-
}
|
|
204
|
-
if (fileDetails.type === "directory") {
|
|
205
|
-
FileTide.outputGradient(`[${this.deviceName}] Sending ${fileDetails.content.length} files in directory ~ ${path.basename(filePath)} to client ~ ${recipientID}...`, ["#00C897", "#00E0FF"]);
|
|
206
|
-
this.fileMessagerInstance.sendDirectoryFiles(this.deviceName, recipientID, fileDetails.content, this.fileTide.getTidePath(filePath), destinationPath);
|
|
207
|
-
return;
|
|
208
|
-
}
|
|
211
|
+
async transferFiles(recipientID, filePath, destinationPath, filterContent = [], tideSize = 500, minTideSize = 10, maxTideSize = 2000) {
|
|
212
|
+
await fileTide.sendToDevice(recipientID, filePath, destinationPath, filterContent, tideSize, minTideSize, maxTideSize);
|
|
209
213
|
return;
|
|
210
214
|
}
|
|
211
215
|
listFiles(recipientID, depth = 1) {
|
|
212
|
-
|
|
216
|
+
fileTide.listFilesFromClient(recipientID, depth);
|
|
213
217
|
return;
|
|
214
218
|
}
|
|
215
219
|
clearShorePolicies(clientID, shores = []) {
|
|
216
|
-
return
|
|
220
|
+
return fileTide.clearShorePolicies(clientID, shores);
|
|
217
221
|
}
|
|
218
222
|
addShorePolicies(clientID, shores = []) {
|
|
219
|
-
return
|
|
223
|
+
return fileTide.addShorePolicies(clientID, shores);
|
|
220
224
|
}
|
|
221
225
|
getShorePolicies(clientID) {
|
|
222
|
-
return
|
|
226
|
+
return fileTide.getShorePolicies(clientID);
|
|
223
227
|
}
|
|
224
228
|
addShortcuts(inputShortcuts) {
|
|
225
229
|
for (const [key, value] of Object.entries(inputShortcuts)) {
|
|
@@ -255,18 +259,27 @@ class FileTideClient {
|
|
|
255
259
|
FileTide.outputGradient(`[${this.deviceName}] Updated room to ${this.currentRoom}`, ["#4D96FF", "#89CFF0"]);
|
|
256
260
|
this.startClient({}, {}, onReconnect);
|
|
257
261
|
if (completion) {
|
|
258
|
-
completion(room);
|
|
262
|
+
completion(room, true);
|
|
259
263
|
}
|
|
260
264
|
return;
|
|
261
265
|
}
|
|
262
|
-
changeClientID(clientID, completion, onReconnect) {
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
this.
|
|
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
|
+
}
|
|
268
281
|
if (completion) {
|
|
269
|
-
completion(clientID);
|
|
282
|
+
completion(clientID, updatedClientID);
|
|
270
283
|
}
|
|
271
284
|
return;
|
|
272
285
|
}
|
|
@@ -275,7 +288,7 @@ class FileTideClient {
|
|
|
275
288
|
FileTide.outputGradient(`[${this.deviceName}] Updated tide URL to ${this.tideUrl}`, ["#4D96FF", "#89CFF0"]);
|
|
276
289
|
this.startClient({}, {}, onReconnect);
|
|
277
290
|
if (completion) {
|
|
278
|
-
completion(url);
|
|
291
|
+
completion(url, true);
|
|
279
292
|
}
|
|
280
293
|
return;
|
|
281
294
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trap_stevo/filetide-client",
|
|
3
|
-
"version": "0.0.
|
|
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.
|
|
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",
|