Skip to content

Commit a3f8b2a

Browse files
committed
added chat
1 parent d516cc5 commit a3f8b2a

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

src/modules/chat.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,11 @@ class CustomEventEmitter extends EventEmitter {}
1313
* Chat module to interact with the WebSocket server.
1414
*/
1515
const cbchat = {
16+
/**
17+
* @private
18+
*/
1619
eventEmitter: new CustomEventEmitter(),
17-
20+
1821
/**
1922
* Retrieves the chat history from the server.
2023
* @returns {Promise<ChatMessage[]>} A promise that resolves with an array of ChatMessage objects representing the chat history.
@@ -34,8 +37,8 @@ const cbchat = {
3437
},
3538

3639
/**
37-
* @method setupMessageListener
38-
* @description Sets up a listener for incoming WebSocket messages.
40+
* Sets up a listener for incoming WebSocket messages and emits a custom event when a message is received.
41+
* @returns {EventEmitter} The event emitter used for emitting custom events.
3942
*/
4043
userMessageListener: () => {
4144
if (!cbws.getWebsocket) return;
@@ -84,7 +87,7 @@ const cbchat = {
8487
* Notifies the server that a process has started and sets up an event listener for stopProcessClicked events.
8588
* @returns An object containing the event emitter and a stopProcess method.
8689
*/
87-
processStarted() {
90+
processStarted: () => {
8891
// Send the process started message
8992
cbws.getWebsocket.send(JSON.stringify({
9093
"type": "processStarted"
@@ -96,12 +99,12 @@ const cbchat = {
9699
if(message.type==='stopProcessClicked')
97100

98101
// Emit a custom event based on the message type
99-
this.eventEmitter.emit("stopProcessClicked", message);
102+
cbchat.eventEmitter.emit("stopProcessClicked", message);
100103
});
101104

102105
// Return an object that includes the event emitter and the stopProcess method
103106
return {
104-
event: this.eventEmitter,
107+
event: cbchat.eventEmitter,
105108
stopProcess: () => {
106109
// Implement the logic to stop the process here
107110
console.log("Stopping process...");
@@ -112,6 +115,10 @@ const cbchat = {
112115
}
113116
};
114117
},
118+
/**
119+
* Stops the ongoing process.
120+
* Sends a specific message to the server to stop the process.
121+
*/
115122
stopProcess: () => {
116123
// Implement the logic to stop the process here
117124
console.log("Stopping process...");

0 commit comments

Comments
 (0)