Skip to content

Commit 45740c3

Browse files
changes
1 parent d516cc5 commit 45740c3

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

src/modules/chat.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@ import {ChatMessage} from '@codebolt/types'
99
* CustomEventEmitter class that extends the Node.js EventEmitter class.
1010
*/
1111
class CustomEventEmitter extends EventEmitter {}
12+
let eventEmitter= new CustomEventEmitter()
1213
/**
1314
* Chat module to interact with the WebSocket server.
1415
*/
1516
const cbchat = {
16-
eventEmitter: new CustomEventEmitter(),
17+
1718

1819
/**
1920
* Retrieves the chat history from the server.
@@ -42,10 +43,10 @@ const cbchat = {
4243
cbws.getWebsocket.on('message', (data: string) => {
4344
const response = JSON.parse(data);
4445
if (response.type === "messageResponse") {
45-
cbchat.eventEmitter.emit("userMessage", response.response);
46+
eventEmitter.emit("userMessage", response.response);
4647
}
4748
});
48-
return cbchat.eventEmitter;
49+
return eventEmitter;
4950
},
5051

5152
/**
@@ -96,12 +97,12 @@ const cbchat = {
9697
if(message.type==='stopProcessClicked')
9798

9899
// Emit a custom event based on the message type
99-
this.eventEmitter.emit("stopProcessClicked", message);
100+
eventEmitter.emit("stopProcessClicked", message);
100101
});
101102

102103
// Return an object that includes the event emitter and the stopProcess method
103104
return {
104-
event: this.eventEmitter,
105+
event: eventEmitter,
105106
stopProcess: () => {
106107
// Implement the logic to stop the process here
107108
console.log("Stopping process...");

src/modules/fs.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,25 @@ const cbfs = {
159159
});
160160
});
161161
},
162-
listFile:(folderPath?:string)=>{
163-
162+
/**
163+
* @function listFile
164+
* @description Lists all files.
165+
* @returns {Promise<FileListResponse>} A promise that resolves with the list of files.
166+
*/
167+
listFile: (filePath:string) => {
168+
return new Promise((resolve, reject) => {
169+
cbws.getWebsocket.send(JSON.stringify({
170+
"type": "fsEvent",
171+
"action": "fileList",
172+
173+
}));
174+
cbws.getWebsocket.on('message', (data: string) => {
175+
const response = JSON.parse(data);
176+
if (response.type === "fileListResponse") {
177+
resolve(response);
178+
}
179+
});
180+
});
164181
},
165182

166183
};

0 commit comments

Comments
 (0)