@trap_stevo/filetide 0.0.0
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/FileMessager.js +82 -0
- package/dist/cjs/FileMessagerClient.js +71 -0
- package/dist/cjs/FileTide.js +151 -0
- package/dist/cjs/HUDManagers/FileMessagerConfigManager.js +34 -0
- package/dist/cjs/HUDManagers/FileUtilityManager.js +48 -0
- package/dist/cjs/HUDManagers/LomlLoggingSystem.js +379 -0
- package/package.json +40 -0
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const IoTide = require("@trap_stevo/iotide");
|
|
4
|
+
const {
|
|
5
|
+
FileMessagerConfigManager
|
|
6
|
+
} = require("./HUDManagers/FileMessagerConfigManager");
|
|
7
|
+
const {
|
|
8
|
+
FileUtilityManager
|
|
9
|
+
} = require("./HUDManagers/FileUtilityManager");
|
|
10
|
+
class FileMessager {
|
|
11
|
+
constructor(options = {}) {
|
|
12
|
+
const serverOptions = FileMessagerConfigManager.getServerOptions(options);
|
|
13
|
+
this.ioTide = new IoTide(serverOptions.port, serverOptions, true, this.onConnect.bind(this), this.onDisconnect.bind(this));
|
|
14
|
+
this.onlineClients = new Map();
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
onConnect(socket) {
|
|
18
|
+
console.log(`Client connected: ${socket.id}`);
|
|
19
|
+
this.onlineClients.set(socket.id, socket);
|
|
20
|
+
socket.on("client-to-client-transfer", this.handleClientToClientTransfer.bind(this));
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
onDisconnect(connectionRes, socket) {
|
|
24
|
+
console.log(`Client disconnected: ${socket.id}`);
|
|
25
|
+
this.onlineClients.delete(socket.id);
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
start() {
|
|
29
|
+
this.ioTide.on("transfer-start", this.handleFileTransferStart.bind(this));
|
|
30
|
+
this.ioTide.on("transfer-progress", this.handleFileTransferProgress.bind(this));
|
|
31
|
+
this.ioTide.on("transfer-complete", this.handleFileTransferComplete.bind(this));
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Send file to a specific client
|
|
37
|
+
* @param {String} clientId - The ID of the client (socket ID)
|
|
38
|
+
* @param {Buffer} fileData - The file data to send
|
|
39
|
+
* @param {String} fileName - The name of the file
|
|
40
|
+
*/
|
|
41
|
+
sendFileToClient(clientId, fileData, fileName, filePath = process.cwd()) {
|
|
42
|
+
const client = this.onlineClients.get(clientId);
|
|
43
|
+
if (!client) {
|
|
44
|
+
console.log(`Client with ID ${clientId} not found.`);
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
client.emit("incoming-file", {
|
|
48
|
+
fileName,
|
|
49
|
+
fileData,
|
|
50
|
+
path: filePath
|
|
51
|
+
});
|
|
52
|
+
console.log(`File ${fileName} sent to client ${clientId}!`);
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Handle file transfer requests between clients
|
|
58
|
+
* @param {Object} transferData - The data containing the sender, recipient, and file details
|
|
59
|
+
*/
|
|
60
|
+
handleClientToClientTransfer(transferData) {
|
|
61
|
+
const {
|
|
62
|
+
recipientId,
|
|
63
|
+
fileName,
|
|
64
|
+
fileData
|
|
65
|
+
} = transferData;
|
|
66
|
+
this.sendFileToClient(recipientId, fileData, fileName);
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
handleFileTransferStart(fileData, emitToChannel) {
|
|
70
|
+
console.log(`Starting file transfer: ${fileData.fileName}`);
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
handleFileTransferProgress(data, emitToChannel) {
|
|
74
|
+
console.log(`Progress: ${data.progress}`);
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
handleFileTransferComplete(data) {
|
|
78
|
+
console.log(`File transfer completed: ${data.fileName}`);
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
module.exports = FileMessager;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const {
|
|
4
|
+
HUDIoTide
|
|
5
|
+
} = require("@trap_stevo/iotide-client");
|
|
6
|
+
const {
|
|
7
|
+
FileMessagerConfigManager
|
|
8
|
+
} = require("./HUDManagers/FileMessagerConfigManager");
|
|
9
|
+
const {
|
|
10
|
+
FileUtilityManager
|
|
11
|
+
} = require("./HUDManagers/FileUtilityManager");
|
|
12
|
+
class FileMessagerClient {
|
|
13
|
+
constructor(options = {}) {
|
|
14
|
+
this.clientOptions = FileMessagerConfigManager.getClientOptions(options);
|
|
15
|
+
this.clientTide = new HUDIoTide();
|
|
16
|
+
this.clients = new Map();
|
|
17
|
+
}
|
|
18
|
+
createClientInstance(clientID, clientOptions) {
|
|
19
|
+
this.clientTide.createIO(clientID, clientOptions.url, {
|
|
20
|
+
transports: ["websocket"]
|
|
21
|
+
});
|
|
22
|
+
console.log(`[FileMessagerClient] ~ Created client with ID ${clientID} and socket ${clientID}`);
|
|
23
|
+
return clientID;
|
|
24
|
+
}
|
|
25
|
+
joinRoom(userID, roomName) {
|
|
26
|
+
const socketName = this.createClientInstance(userID, {
|
|
27
|
+
url: this.clientOptions.url
|
|
28
|
+
});
|
|
29
|
+
this.clientTide.joinChannel(socketName, roomName, userID, () => {
|
|
30
|
+
console.log(`Client ${userID} joined room ${roomName} successfully.`);
|
|
31
|
+
this.clients.set(userID, {
|
|
32
|
+
roomName
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
sendFile(recipientId, fileName, fileData, path = process.cwd()) {
|
|
37
|
+
this.clientTide.emitEvent("client-to-client-transfer", {
|
|
38
|
+
recipientId,
|
|
39
|
+
fileName,
|
|
40
|
+
fileData,
|
|
41
|
+
path
|
|
42
|
+
});
|
|
43
|
+
console.log(`File ${fileName} sent to client ${recipientId}.`);
|
|
44
|
+
}
|
|
45
|
+
onFileChunkReceived(userID) {
|
|
46
|
+
this.clientTide.onEvent(userID, "transfer-progress", data => {
|
|
47
|
+
console.log(`Receiving file chunk for user ${userID}: `, data.fileChunk);
|
|
48
|
+
console.log("Progress: ", data.progress);
|
|
49
|
+
FileUtilityManager.saveChunk(userID, data.fileChunk, data.path, data.name);
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
onFileTransferComplete(userID) {
|
|
53
|
+
this.clientTide.onEvent(userID, "transfer-complete", data => {
|
|
54
|
+
console.log(`File transfer completed for user ${userID}.`);
|
|
55
|
+
FileUtilityManager.assembleFile(userID);
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
handleIncomingFile(userID) {
|
|
59
|
+
this.clientTide.onEvent(userID, "incoming-file", data => {
|
|
60
|
+
console.log(`Received file for user ${userID}: ${data.fileName}.`);
|
|
61
|
+
FileUtilityManager.saveFile(data.fileName, data.fileData, data.path, data.name);
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
handleMultipleClientsTransfer() {
|
|
65
|
+
this.clients.forEach((userID, roomData) => {
|
|
66
|
+
this.onFileChunkReceived(userID);
|
|
67
|
+
this.onFileTransferComplete(userID);
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
module.exports = FileMessagerClient;
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
function _classPrivateMethodInitSpec(e, a) { _checkPrivateRedeclaration(e, a), a.add(e); }
|
|
4
|
+
function _checkPrivateRedeclaration(e, t) { if (t.has(e)) throw new TypeError("Cannot initialize the same private elements twice on an object"); }
|
|
5
|
+
function _assertClassBrand(e, t, n) { if ("function" == typeof e ? e === t : e.has(t)) return arguments.length < 3 ? t : n; throw new TypeError("Private element is not present on this object"); }
|
|
6
|
+
const FileMessagerClient = require("./FileMessagerClient");
|
|
7
|
+
const FileMessager = require("./FileMessager");
|
|
8
|
+
const path = require("path");
|
|
9
|
+
const fs = require("fs");
|
|
10
|
+
var _FileTide_brand = /*#__PURE__*/new WeakSet();
|
|
11
|
+
class FileTide {
|
|
12
|
+
constructor(config = {}) {
|
|
13
|
+
/**
|
|
14
|
+
* Set up file transfer event listeners natively.
|
|
15
|
+
* Automatically checks and creates directories as needed.
|
|
16
|
+
*/
|
|
17
|
+
_classPrivateMethodInitSpec(this, _FileTide_brand);
|
|
18
|
+
this.config = config;
|
|
19
|
+
this.fileNet = null;
|
|
20
|
+
this.clients = new Map();
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Initialize and start the server.
|
|
26
|
+
* @param {Object} serverOptions - Configuration for server (e.g., port, useCors, useHTTPS)
|
|
27
|
+
* @param {Function} onLaunch - Callback for when a file tide instance launches
|
|
28
|
+
*/
|
|
29
|
+
launchFileTide(serverOptions = {}, onLaunch) {
|
|
30
|
+
this.fileNet = new FileMessager(serverOptions);
|
|
31
|
+
this.fileNet.start();
|
|
32
|
+
console.log("[FileTide] ~ FileNet launched successfully!");
|
|
33
|
+
if (onLaunch) {
|
|
34
|
+
onLaunch(this.fileNet);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Initialize and start a new client for each user.
|
|
40
|
+
* @param {Object} clientOptions - Configuration for client (e.g., serverUrl)
|
|
41
|
+
* @param {String} roomName - The name of the room to join
|
|
42
|
+
* @param {String} userID - The ID of the client user
|
|
43
|
+
* @param {Function} onLaunch - Callback for when a file messager launches
|
|
44
|
+
*/
|
|
45
|
+
launchMessager(clientOptions = {}, roomName, userID, onLaunch, onIncomingFile) {
|
|
46
|
+
if (this.clients.has(userID)) {
|
|
47
|
+
console.log(`[FileTide] ~ Client for user ${userID} already exists.`);
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
const newClient = new FileMessagerClient(clientOptions);
|
|
51
|
+
newClient.joinRoom(userID, roomName);
|
|
52
|
+
newClient.handleMultipleClientsTransfer();
|
|
53
|
+
this.clients.set(userID, newClient);
|
|
54
|
+
console.log(`[FileTide] ~ Messager launched successfully for user ${userID}!`);
|
|
55
|
+
_assertClassBrand(_FileTide_brand, this, _setupFileEventListeners).call(this, userID, newClient, onIncomingFile);
|
|
56
|
+
if (onLaunch) {
|
|
57
|
+
onLaunch(newClient);
|
|
58
|
+
}
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Send a file directly to a device without it needing to create a client.
|
|
63
|
+
* @param {String} userID - The ID of the client device to send the file to
|
|
64
|
+
* @param {Buffer} fileData - The file data to send
|
|
65
|
+
* @param {String} fileName - The name of the file
|
|
66
|
+
*/
|
|
67
|
+
sendFileToDevice(userID, fileData, filePath, fileName) {
|
|
68
|
+
if (this.fileNet.onlineClients.has(userID)) {
|
|
69
|
+
console.log(`[FileTide] ~ Sending file to user ${userID}...`);
|
|
70
|
+
this.fileNet.sendFileToClient(userID, fileData, filePath, fileName);
|
|
71
|
+
console.log(`[FileTide] ~ File sent to user ${userID}!`);
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
console.log(`[FileTide] ~ No active client found for user ${userID}.`);
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Check if running in server mode.
|
|
80
|
+
* @returns {Boolean} - True if running as a server
|
|
81
|
+
*/
|
|
82
|
+
fileTideOperational() {
|
|
83
|
+
return this.fileNet !== null;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Check if running in client mode.
|
|
88
|
+
* @returns {Boolean} - True if any client is active
|
|
89
|
+
*/
|
|
90
|
+
messagerOperational() {
|
|
91
|
+
return this.clients.size > 0;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Stop the server if it"s running.
|
|
96
|
+
*/
|
|
97
|
+
stopFileTide() {
|
|
98
|
+
if (this.fileNet) {
|
|
99
|
+
console.log("Stopping FileTide...");
|
|
100
|
+
this.fileNet = null;
|
|
101
|
+
console.log("Stopped FileTide.");
|
|
102
|
+
}
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Stop a specific client.
|
|
108
|
+
* @param {String} userID - The ID of the client user to stop
|
|
109
|
+
*/
|
|
110
|
+
stopMessager(userID) {
|
|
111
|
+
if (this.clients.has(userID)) {
|
|
112
|
+
console.log(`Stopping messager for user ${userID}...`);
|
|
113
|
+
this.clients.delete(userID);
|
|
114
|
+
console.log(`Stopped messager for user ${userID}.`);
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
console.log(`No active messager found for user ${userID}.`);
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Stop all active clients.
|
|
123
|
+
*/
|
|
124
|
+
stopAllMessagers() {
|
|
125
|
+
console.log("Stopping all messagers...");
|
|
126
|
+
this.clients.clear();
|
|
127
|
+
console.log("All messagers stopped.");
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
function _setupFileEventListeners(userID, client, onIncomingFile) {
|
|
132
|
+
client.clientTide.onEvent(userID, "incoming-file", data => {
|
|
133
|
+
console.log(`[Client] Received file: ${data.fileName}`);
|
|
134
|
+
const saveDir = data.path;
|
|
135
|
+
if (!fs.existsSync(saveDir)) {
|
|
136
|
+
fs.mkdirSync(saveDir, {
|
|
137
|
+
recursive: true
|
|
138
|
+
});
|
|
139
|
+
console.log(`[Client] Created directory: ${saveDir}`);
|
|
140
|
+
}
|
|
141
|
+
const savePath = path.join(saveDir, data.fileName);
|
|
142
|
+
fs.writeFileSync(savePath, Buffer.from(data.fileData));
|
|
143
|
+
console.log(`[Client] File saved at: ${savePath}`);
|
|
144
|
+
if (onIncomingFile) {
|
|
145
|
+
onIncomingFile(data);
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
;
|
|
151
|
+
module.exports = FileTide;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
class FileMessagerConfigManager {
|
|
4
|
+
static getServerOptions({
|
|
5
|
+
port = 9269,
|
|
6
|
+
useCors = true,
|
|
7
|
+
useHTTPS = false,
|
|
8
|
+
corsOrigin = "*",
|
|
9
|
+
...rest
|
|
10
|
+
} = {}) {
|
|
11
|
+
return {
|
|
12
|
+
port,
|
|
13
|
+
useCors,
|
|
14
|
+
useHTTPS,
|
|
15
|
+
socketOptions: {
|
|
16
|
+
cors: {
|
|
17
|
+
origin: corsOrigin,
|
|
18
|
+
methods: ["GET", "POST"]
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
...rest
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
static getClientOptions({
|
|
25
|
+
serverUrl = 'http://localhost:3000'
|
|
26
|
+
} = {}) {
|
|
27
|
+
return {
|
|
28
|
+
url: serverUrl
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
module.exports = {
|
|
33
|
+
FileMessagerConfigManager
|
|
34
|
+
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const path = require('path');
|
|
4
|
+
const fs = require('fs');
|
|
5
|
+
const filesPath = path.join(__dirname, '../files');
|
|
6
|
+
class FileUtilityManager {
|
|
7
|
+
/**
|
|
8
|
+
* Save a chunk of a file for a specific user to the specified path with a custom file name.
|
|
9
|
+
* @param {String} userID - The ID of the user for whom the file is being saved.
|
|
10
|
+
* @param {Buffer} chunk - The file chunk to save.
|
|
11
|
+
* @param {String} savePath - The directory where the file should be saved.
|
|
12
|
+
* @param {String} fileName - The name of the file being saved.
|
|
13
|
+
*/
|
|
14
|
+
static saveChunk(userID, chunk, savePath, fileName = "${Date.now()}_temp_file") {
|
|
15
|
+
const filePath = path.join(savePath || filesPath, fileName || `${userID}_${Date.now()}`);
|
|
16
|
+
fs.appendFileSync(filePath, chunk);
|
|
17
|
+
console.log(`Saved chunk for user ${userID} to ${filePath}.`);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Assemble the final file from chunks for a specific user with a custom file name.
|
|
22
|
+
* @param {String} userID - The ID of the user whose file is being assembled.
|
|
23
|
+
* @param {String} savePath - The directory where the file should be saved.
|
|
24
|
+
* @param {String} fileName - The name of the final file to assemble.
|
|
25
|
+
*/
|
|
26
|
+
static assembleFile(userID, savePath, fileName = `${Date.now()}_final_file`) {
|
|
27
|
+
const tempFilePath = path.join(savePath || filesPath, `${userID}_${Date.now()}`);
|
|
28
|
+
const finalFilePath = path.join(savePath || filesPath, fileName || `${userID}_${Date.now()}`);
|
|
29
|
+
fs.renameSync(tempFilePath, finalFilePath);
|
|
30
|
+
console.log(`Assembled file for user ${userID} at ${finalFilePath}.`);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Save a complete file directly to a specified path with a custom file name.
|
|
35
|
+
* @param {String} fileName - The name of the file to save.
|
|
36
|
+
* @param {Buffer} fileData - The complete file data to save.
|
|
37
|
+
* @param {String} savePath - The directory where the file should be saved.
|
|
38
|
+
*/
|
|
39
|
+
static saveFile(fileName = "${Date.now()}_temp_file", fileData, savePath) {
|
|
40
|
+
const filePath = path.join(savePath || filesPath, fileName || `${userID}_${Date.now()}`);
|
|
41
|
+
fs.writeFileSync(filePath, fileData);
|
|
42
|
+
console.log(`Saved file ${fileName} to ${filePath}.`);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
module.exports = {
|
|
46
|
+
FileUtilityManager,
|
|
47
|
+
filesPath
|
|
48
|
+
};
|
|
@@ -0,0 +1,379 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const {
|
|
4
|
+
HUDIoTide
|
|
5
|
+
} = require("@trap_stevo/iotide-client");
|
|
6
|
+
const IoTide = require("@trap_stevo/iotide");
|
|
7
|
+
const Loml = require("@trap_stevo/loml");
|
|
8
|
+
class LomlLoggingSystem {
|
|
9
|
+
constructor(config = {}, ...args) {
|
|
10
|
+
this.lomlLogging = null;
|
|
11
|
+
this.clientInstance = config.clientInstance || false;
|
|
12
|
+
this.serverInstance = config.serverInstance || false;
|
|
13
|
+
this.setupIoTideInstance(config.lomlLoggingSystemOptions, ...args);
|
|
14
|
+
if (this.clientInstance) {
|
|
15
|
+
this.lomlLoggerClient = new HUDIoTide();
|
|
16
|
+
this.initializeClient(config.clientOptions);
|
|
17
|
+
}
|
|
18
|
+
if (this.serverInstance) {
|
|
19
|
+
this.lomlLogging.on("external-log", data => {
|
|
20
|
+
this.processExternalLog(data);
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
setupIoTideInstance(lomlLoggingSystemOptions, ...args) {
|
|
25
|
+
if (this.serverInstance) {
|
|
26
|
+
this.lomlLogging = new IoTide(lomlLoggingSystemOptions.port || 3069, lomlLoggingSystemOptions.options || {}, ...args);
|
|
27
|
+
this.lomlLogging.server.listen(lomlLoggingSystemOptions.port || 3069, "0.0.0.0", () => {
|
|
28
|
+
console.log(`LomlLoggingSystem ~ ${lomlLoggingSystemOptions.port || 3069}`);
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
initializeClient(clientOptions) {
|
|
33
|
+
const {
|
|
34
|
+
socketName,
|
|
35
|
+
url,
|
|
36
|
+
options,
|
|
37
|
+
onConnect
|
|
38
|
+
} = clientOptions;
|
|
39
|
+
this.lomlLoggerClient.createIO(socketName, url, options);
|
|
40
|
+
this.lomlLoggerClient.onEvent(socketName, "connect", () => {
|
|
41
|
+
console.log("Connected to the LomlLoggingSystem!");
|
|
42
|
+
if (onConnect) {
|
|
43
|
+
onConnect(this.lomlLoggerClient);
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
processExternalLog(data) {
|
|
48
|
+
const {
|
|
49
|
+
roomName,
|
|
50
|
+
tideID,
|
|
51
|
+
text,
|
|
52
|
+
styles,
|
|
53
|
+
colors,
|
|
54
|
+
direction,
|
|
55
|
+
href,
|
|
56
|
+
tag,
|
|
57
|
+
type,
|
|
58
|
+
protocol
|
|
59
|
+
} = data;
|
|
60
|
+
const loml = new Loml();
|
|
61
|
+
let formattedMessage;
|
|
62
|
+
switch (type) {
|
|
63
|
+
case "text":
|
|
64
|
+
formattedMessage = loml.text(text, styles).build();
|
|
65
|
+
break;
|
|
66
|
+
case "bold":
|
|
67
|
+
formattedMessage = loml.bold(text, styles).build();
|
|
68
|
+
break;
|
|
69
|
+
case "italic":
|
|
70
|
+
formattedMessage = loml.italic(text, styles).build();
|
|
71
|
+
break;
|
|
72
|
+
case "link":
|
|
73
|
+
formattedMessage = loml.link(text, href, styles).build();
|
|
74
|
+
break;
|
|
75
|
+
case "color":
|
|
76
|
+
formattedMessage = loml.color(text, styles.color, styles).build();
|
|
77
|
+
break;
|
|
78
|
+
case "gradientText":
|
|
79
|
+
formattedMessage = loml.gradientText(text, colors, direction, styles).build();
|
|
80
|
+
break;
|
|
81
|
+
case "customElement":
|
|
82
|
+
formattedMessage = loml.element(tag, text, styles).build();
|
|
83
|
+
break;
|
|
84
|
+
default:
|
|
85
|
+
formattedMessage = loml.text(text, styles).build();
|
|
86
|
+
}
|
|
87
|
+
if (protocol && protocol === "system") {
|
|
88
|
+
this.lomlLogging.emitTide("log", {
|
|
89
|
+
message: formattedMessage
|
|
90
|
+
});
|
|
91
|
+
return formattedMessage;
|
|
92
|
+
}
|
|
93
|
+
if (roomName) {
|
|
94
|
+
this.lomlLogging.emitToChannel(tideID, roomName, "log", {
|
|
95
|
+
message: formattedMessage
|
|
96
|
+
});
|
|
97
|
+
return formattedMessage;
|
|
98
|
+
}
|
|
99
|
+
this.lomlLogging.emit("log", {
|
|
100
|
+
message: formattedMessage
|
|
101
|
+
});
|
|
102
|
+
return formattedMessage;
|
|
103
|
+
}
|
|
104
|
+
logToAll(text, styles = {}) {
|
|
105
|
+
const loml = new Loml();
|
|
106
|
+
const formattedMessage = loml.text(text, styles).build();
|
|
107
|
+
this.lomlLogging.emit("log", {
|
|
108
|
+
message: formattedMessage
|
|
109
|
+
});
|
|
110
|
+
return formattedMessage;
|
|
111
|
+
}
|
|
112
|
+
logToRoom(tideID, roomName, text, styles = {}) {
|
|
113
|
+
const loml = new Loml();
|
|
114
|
+
const formattedMessage = loml.text(text, styles).build();
|
|
115
|
+
this.lomlLogging.emitToChannel(tideID, roomName, "log", {
|
|
116
|
+
message: formattedMessage
|
|
117
|
+
});
|
|
118
|
+
return formattedMessage;
|
|
119
|
+
}
|
|
120
|
+
logBoldToAll(text, styles = {}) {
|
|
121
|
+
const loml = new Loml();
|
|
122
|
+
const formattedMessage = loml.bold(text, styles).build();
|
|
123
|
+
this.lomlLogging.emit("log", {
|
|
124
|
+
message: formattedMessage
|
|
125
|
+
});
|
|
126
|
+
return formattedMessage;
|
|
127
|
+
}
|
|
128
|
+
logBoldToRoom(tideID, roomName, text, styles = {}) {
|
|
129
|
+
const loml = new Loml();
|
|
130
|
+
const formattedMessage = loml.bold(text, styles).build();
|
|
131
|
+
this.lomlLogging.emitToChannel(tideID, roomName, "log", {
|
|
132
|
+
message: formattedMessage
|
|
133
|
+
});
|
|
134
|
+
return formattedMessage;
|
|
135
|
+
}
|
|
136
|
+
logItalicToAll(text, styles = {}) {
|
|
137
|
+
const loml = new Loml();
|
|
138
|
+
const formattedMessage = loml.italic(text, styles).build();
|
|
139
|
+
this.lomlLogging.emit("log", {
|
|
140
|
+
message: formattedMessage
|
|
141
|
+
});
|
|
142
|
+
return formattedMessage;
|
|
143
|
+
}
|
|
144
|
+
logItalicToRoom(tideID, roomName, text, styles = {}) {
|
|
145
|
+
const loml = new Loml();
|
|
146
|
+
const formattedMessage = loml.italic(text, styles).build();
|
|
147
|
+
this.lomlLogging.emitToChannel(tideID, roomName, "log", {
|
|
148
|
+
message: formattedMessage
|
|
149
|
+
});
|
|
150
|
+
return formattedMessage;
|
|
151
|
+
}
|
|
152
|
+
logLinkToAll(text, href, styles = {}) {
|
|
153
|
+
const loml = new Loml();
|
|
154
|
+
const formattedMessage = loml.link(text, href, styles).build();
|
|
155
|
+
this.lomlLogging.emit("log", {
|
|
156
|
+
message: formattedMessage
|
|
157
|
+
});
|
|
158
|
+
return formattedMessage;
|
|
159
|
+
}
|
|
160
|
+
logLinkToRoom(tideID, roomName, text, href, styles = {}) {
|
|
161
|
+
const loml = new Loml();
|
|
162
|
+
const formattedMessage = loml.link(text, href, styles).build();
|
|
163
|
+
this.lomlLogging.emitToChannel(tideID, roomName, "log", {
|
|
164
|
+
message: formattedMessage
|
|
165
|
+
});
|
|
166
|
+
return formattedMessage;
|
|
167
|
+
}
|
|
168
|
+
logColorToAll(text, color, styles = {}) {
|
|
169
|
+
const loml = new Loml();
|
|
170
|
+
const formattedMessage = loml.color(text, color, styles).build();
|
|
171
|
+
this.lomlLogging.emit("log", {
|
|
172
|
+
message: formattedMessage
|
|
173
|
+
});
|
|
174
|
+
return formattedMessage;
|
|
175
|
+
}
|
|
176
|
+
logColorToRoom(tideID, roomName, text, color, styles = {}) {
|
|
177
|
+
const loml = new Loml();
|
|
178
|
+
const formattedMessage = loml.color(text, color, styles).build();
|
|
179
|
+
this.lomlLogging.emitToChannel(tideID, roomName, "log", {
|
|
180
|
+
message: formattedMessage
|
|
181
|
+
});
|
|
182
|
+
return formattedMessage;
|
|
183
|
+
}
|
|
184
|
+
logGradientTextToRoom(tideID, roomName, text, colors, direction = "to right", styles = {}) {
|
|
185
|
+
const loml = new Loml();
|
|
186
|
+
const formattedMessage = loml.gradientText(text, colors, direction, styles).build();
|
|
187
|
+
this.lomlLogging.emitToChannel(tideID, roomName, "log", {
|
|
188
|
+
message: formattedMessage
|
|
189
|
+
});
|
|
190
|
+
return formattedMessage;
|
|
191
|
+
}
|
|
192
|
+
logGradientTextToAll(text, colors, direction = "to right", styles = {}) {
|
|
193
|
+
const loml = new Loml();
|
|
194
|
+
const formattedMessage = loml.gradientText(text, colors, direction, styles).build();
|
|
195
|
+
this.lomlLogging.emit("log", {
|
|
196
|
+
message: formattedMessage
|
|
197
|
+
});
|
|
198
|
+
return formattedMessage;
|
|
199
|
+
}
|
|
200
|
+
logCustomElementToAll(tag, text, styles = {}) {
|
|
201
|
+
const loml = new Loml();
|
|
202
|
+
const formattedMessage = loml.element(tag, text, styles).build();
|
|
203
|
+
this.lomlLogging.emit("log", {
|
|
204
|
+
message: formattedMessage
|
|
205
|
+
});
|
|
206
|
+
return formattedMessage;
|
|
207
|
+
}
|
|
208
|
+
logCustomElementToRoom(tideID, roomName, tag, text, styles = {}) {
|
|
209
|
+
const loml = new Loml();
|
|
210
|
+
const formattedMessage = loml.element(tag, text, styles).build();
|
|
211
|
+
this.lomlLogging.emitToChannel(tideID, roomName, "log", {
|
|
212
|
+
message: formattedMessage
|
|
213
|
+
});
|
|
214
|
+
return formattedMessage;
|
|
215
|
+
}
|
|
216
|
+
logLineBreakToAll() {
|
|
217
|
+
const loml = new Loml();
|
|
218
|
+
const formattedMessage = loml.br().build();
|
|
219
|
+
this.lomlLogging.emit("log", {
|
|
220
|
+
message: formattedMessage
|
|
221
|
+
});
|
|
222
|
+
return formattedMessage;
|
|
223
|
+
}
|
|
224
|
+
logLineBreakToRoom(tideID, roomName) {
|
|
225
|
+
const loml = new Loml();
|
|
226
|
+
const formattedMessage = loml.br().build();
|
|
227
|
+
this.lomlLogging.emitToChannel(tideID, roomName, "log", {
|
|
228
|
+
message: formattedMessage
|
|
229
|
+
});
|
|
230
|
+
return formattedMessage;
|
|
231
|
+
}
|
|
232
|
+
logStyledMessageToAll(messageParts) {
|
|
233
|
+
const loml = new Loml();
|
|
234
|
+
messageParts.forEach(part => {
|
|
235
|
+
if (typeof loml[part.method] === "function") {
|
|
236
|
+
loml[part.method](...part.args);
|
|
237
|
+
}
|
|
238
|
+
});
|
|
239
|
+
const formattedMessage = loml.build();
|
|
240
|
+
this.lomlLogging.emit("log", {
|
|
241
|
+
message: formattedMessage
|
|
242
|
+
});
|
|
243
|
+
return formattedMessage;
|
|
244
|
+
}
|
|
245
|
+
logStyledMessageToRoom(tideID, roomName, messageParts) {
|
|
246
|
+
const loml = new Loml();
|
|
247
|
+
messageParts.forEach(part => {
|
|
248
|
+
if (typeof loml[part.method] === "function") {
|
|
249
|
+
loml[part.method](...part.args);
|
|
250
|
+
}
|
|
251
|
+
});
|
|
252
|
+
const formattedMessage = loml.build();
|
|
253
|
+
this.lomlLogging.emitToChannel(tideID, roomName, "log", {
|
|
254
|
+
message: formattedMessage
|
|
255
|
+
});
|
|
256
|
+
return formattedMessage;
|
|
257
|
+
}
|
|
258
|
+
logTextToSystem(text, styles = {}) {
|
|
259
|
+
const loml = new Loml();
|
|
260
|
+
const formattedMessage = loml.text(text, styles).build();
|
|
261
|
+
this.lomlLogging.emitTide("log", {
|
|
262
|
+
message: formattedMessage
|
|
263
|
+
});
|
|
264
|
+
return formattedMessage;
|
|
265
|
+
}
|
|
266
|
+
logBoldToSystem(text, styles = {}) {
|
|
267
|
+
const loml = new Loml();
|
|
268
|
+
const formattedMessage = loml.bold(text, styles).build();
|
|
269
|
+
this.lomlLogging.emitTide("log", {
|
|
270
|
+
message: formattedMessage
|
|
271
|
+
});
|
|
272
|
+
return formattedMessage;
|
|
273
|
+
}
|
|
274
|
+
logItalicToSystem(text, styles = {}) {
|
|
275
|
+
const loml = new Loml();
|
|
276
|
+
const formattedMessage = loml.italic(text, styles).build();
|
|
277
|
+
this.lomlLogging.emitTide("log", {
|
|
278
|
+
message: formattedMessage
|
|
279
|
+
});
|
|
280
|
+
return formattedMessage;
|
|
281
|
+
}
|
|
282
|
+
logLinkToSystem(text, href, styles = {}) {
|
|
283
|
+
const loml = new Loml();
|
|
284
|
+
const formattedMessage = loml.link(text, href, styles).build();
|
|
285
|
+
this.lomlLogging.emitTide("log", {
|
|
286
|
+
message: formattedMessage
|
|
287
|
+
});
|
|
288
|
+
return formattedMessage;
|
|
289
|
+
}
|
|
290
|
+
logColorToSystem(text, color, styles = {}) {
|
|
291
|
+
const loml = new Loml();
|
|
292
|
+
const formattedMessage = loml.color(text, color, styles).build();
|
|
293
|
+
this.lomlLogging.emitTide("log", {
|
|
294
|
+
message: formattedMessage
|
|
295
|
+
});
|
|
296
|
+
return formattedMessage;
|
|
297
|
+
}
|
|
298
|
+
logGradientTextToSystem(text, colors, direction = "to right", styles = {}) {
|
|
299
|
+
const loml = new Loml();
|
|
300
|
+
const formattedMessage = loml.gradientText(text, colors, direction, styles).build();
|
|
301
|
+
this.lomlLogging.emitTide("log", {
|
|
302
|
+
message: formattedMessage
|
|
303
|
+
});
|
|
304
|
+
return formattedMessage;
|
|
305
|
+
}
|
|
306
|
+
logCustomElementToSystem(tag, text, styles = {}) {
|
|
307
|
+
const loml = new Loml();
|
|
308
|
+
const formattedMessage = loml.element(tag, text, styles).build();
|
|
309
|
+
this.lomlLogging.emitTide("log", {
|
|
310
|
+
message: formattedMessage
|
|
311
|
+
});
|
|
312
|
+
return formattedMessage;
|
|
313
|
+
}
|
|
314
|
+
logLineBreakToSystem() {
|
|
315
|
+
const loml = new Loml();
|
|
316
|
+
const formattedMessage = loml.br().build();
|
|
317
|
+
this.lomlLogging.emitTide("log", {
|
|
318
|
+
message: formattedMessage
|
|
319
|
+
});
|
|
320
|
+
return formattedMessage;
|
|
321
|
+
}
|
|
322
|
+
logStyledMessageToSystem(messageParts) {
|
|
323
|
+
const loml = new Loml();
|
|
324
|
+
messageParts.forEach(part => {
|
|
325
|
+
if (typeof loml[part.method] === "function") {
|
|
326
|
+
loml[part.method](...part.args);
|
|
327
|
+
}
|
|
328
|
+
});
|
|
329
|
+
const formattedMessage = loml.build();
|
|
330
|
+
this.lomlLogging.emitTide("log", {
|
|
331
|
+
message: formattedMessage
|
|
332
|
+
});
|
|
333
|
+
return formattedMessage;
|
|
334
|
+
}
|
|
335
|
+
static log(options = {}) {
|
|
336
|
+
const {
|
|
337
|
+
text = "Sample text",
|
|
338
|
+
type = "text",
|
|
339
|
+
direction = "to right",
|
|
340
|
+
colors = [],
|
|
341
|
+
styles = {},
|
|
342
|
+
href = "",
|
|
343
|
+
tag = "span",
|
|
344
|
+
logToConsole = true
|
|
345
|
+
} = options;
|
|
346
|
+
const loml = new Loml();
|
|
347
|
+
let formattedMessage;
|
|
348
|
+
switch (type) {
|
|
349
|
+
case "text":
|
|
350
|
+
formattedMessage = loml.text(text, styles).build();
|
|
351
|
+
break;
|
|
352
|
+
case "bold":
|
|
353
|
+
formattedMessage = loml.bold(text, styles).build();
|
|
354
|
+
break;
|
|
355
|
+
case "italic":
|
|
356
|
+
formattedMessage = loml.italic(text, styles).build();
|
|
357
|
+
break;
|
|
358
|
+
case "link":
|
|
359
|
+
formattedMessage = loml.link(text, href, styles).build();
|
|
360
|
+
break;
|
|
361
|
+
case "color":
|
|
362
|
+
formattedMessage = loml.color(text, styles.color, styles).build();
|
|
363
|
+
break;
|
|
364
|
+
case "gradientText":
|
|
365
|
+
formattedMessage = loml.gradientText(text, colors, direction, styles).build();
|
|
366
|
+
break;
|
|
367
|
+
case "customElement":
|
|
368
|
+
formattedMessage = loml.element(tag, text, styles).build();
|
|
369
|
+
break;
|
|
370
|
+
default:
|
|
371
|
+
formattedMessage = loml.text(text, styles).build();
|
|
372
|
+
}
|
|
373
|
+
if (logToConsole) {
|
|
374
|
+
console.log(`${type.charAt(0).toUpperCase() + type.slice(1)} Log:`, formattedMessage);
|
|
375
|
+
}
|
|
376
|
+
return formattedMessage;
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
module.exports = LomlLoggingSystem;
|
package/package.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@trap_stevo/filetide",
|
|
3
|
+
"version": "0.0.0",
|
|
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
|
+
"main": "dist/cjs/FileTide.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"build": "babel src -d dist/cjs --env-name cjs",
|
|
8
|
+
"start": "node dist/cjs/FileTide.js"
|
|
9
|
+
},
|
|
10
|
+
"keywords": [
|
|
11
|
+
"real-time",
|
|
12
|
+
"nodejs",
|
|
13
|
+
"ota",
|
|
14
|
+
"over-the-air",
|
|
15
|
+
"file communication",
|
|
16
|
+
"file transfer",
|
|
17
|
+
"device-to-device",
|
|
18
|
+
"cross-platform",
|
|
19
|
+
"instant messaging",
|
|
20
|
+
"file sharing",
|
|
21
|
+
"peer-to-peer",
|
|
22
|
+
"P2P",
|
|
23
|
+
"network transfer",
|
|
24
|
+
"data transfer",
|
|
25
|
+
"seamless connectivity"
|
|
26
|
+
],
|
|
27
|
+
"author": "Steven Compton",
|
|
28
|
+
"license": "ISC",
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"@trap_stevo/iotide": "^0.0.36",
|
|
31
|
+
"@trap_stevo/iotide-client": "^0.0.14"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@babel/cli": "^7.24.8",
|
|
35
|
+
"@babel/core": "^7.25.2",
|
|
36
|
+
"@babel/plugin-proposal-class-properties": "^7.18.6",
|
|
37
|
+
"@babel/plugin-transform-runtime": "^7.24.7",
|
|
38
|
+
"@babel/preset-env": "^7.25.3"
|
|
39
|
+
}
|
|
40
|
+
}
|