11// chat.ts
22import cbws from './websocket' ;
33import { EventEmitter } from 'events' ;
4- import { ChatMessage , UserMessage } from '@codebolt/types'
4+ import { ChatMessage , UserMessage } from '@codebolt/types'
55
66
77
88/**
99 * CustomEventEmitter class that extends the Node.js EventEmitter class.
1010 */
11- class CustomEventEmitter extends EventEmitter { }
12- let eventEmitter = new CustomEventEmitter ( )
11+ class CustomEventEmitter extends EventEmitter { }
12+ let eventEmitter = new CustomEventEmitter ( )
1313/**
1414 * Chat module to interact with the WebSocket server.
1515 */
@@ -49,7 +49,7 @@ const cbchat = {
4949 "type" : "processStoped"
5050 } ) ) ;
5151 } ) ;
52- }
52+ }
5353 } ) ;
5454 return eventEmitter ;
5555 } ,
@@ -81,7 +81,7 @@ const cbchat = {
8181 const response = JSON . parse ( data ) ;
8282 if ( response . type === "waitFormessageResponse" ) {
8383 resolve ( response ) ; // Resolve the Promise with the response data
84- }
84+ }
8585 } ) ;
8686 } ) ;
8787 } ,
@@ -99,10 +99,10 @@ const cbchat = {
9999 cbws . getWebsocket . on ( 'message' , ( data : string ) => {
100100 const message = JSON . parse ( data ) ;
101101 console . log ( "Received message:" , message ) ;
102- if ( message . type === 'stopProcessClicked' )
102+ if ( message . type === 'stopProcessClicked' )
103103
104- // Emit a custom event based on the message type
105- eventEmitter . emit ( "stopProcessClicked" , message ) ;
104+ // Emit a custom event based on the message type
105+ eventEmitter . emit ( "stopProcessClicked" , message ) ;
106106 } ) ;
107107
108108 // Return an object that includes the event emitter and the stopProcess method
@@ -135,11 +135,13 @@ const cbchat = {
135135 * Sends a confirmation request to the server with two options: Yes or No.
136136 * @returns {Promise<string> } A promise that resolves with the server's response.
137137 */
138- sendConfirmationRequest : ( confirmationMessage : string ) : Promise < string > => {
138+ sendConfirmationRequest : ( confirmationMessage : string , buttons : string [ ] = [ ] ) : Promise < string > => {
139139 return new Promise ( ( resolve , reject ) => {
140140 cbws . getWebsocket . send ( JSON . stringify ( {
141141 "type" : "confirmationRequest" ,
142- "message" : confirmationMessage
142+ "message" : confirmationMessage ,
143+ buttons : buttons
144+
143145 } ) ) ;
144146 cbws . getWebsocket . on ( 'message' , ( data : string ) => {
145147 const response = JSON . parse ( data ) ;
0 commit comments