@codebolt/codeboltjs 1.1.44 → 1.1.46
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/index.d.ts +1 -1
- package/modules/chat.d.ts +1 -1
- package/modules/chat.js +4 -3
- package/package.json +1 -1
- package/src/modules/chat.ts +13 -11
package/index.d.ts
CHANGED
|
@@ -107,7 +107,7 @@ declare class Codebolt {
|
|
|
107
107
|
stopProcess: () => void;
|
|
108
108
|
};
|
|
109
109
|
stopProcess: () => void;
|
|
110
|
-
sendConfirmationRequest: (confirmationMessage: string) => Promise<string>;
|
|
110
|
+
sendConfirmationRequest: (confirmationMessage: string, buttons?: string[]) => Promise<string>;
|
|
111
111
|
};
|
|
112
112
|
terminal: {
|
|
113
113
|
eventEmitter: {
|
package/modules/chat.d.ts
CHANGED
|
@@ -48,6 +48,6 @@ declare const cbchat: {
|
|
|
48
48
|
* Sends a confirmation request to the server with two options: Yes or No.
|
|
49
49
|
* @returns {Promise<string>} A promise that resolves with the server's response.
|
|
50
50
|
*/
|
|
51
|
-
sendConfirmationRequest: (confirmationMessage: string) => Promise<string>;
|
|
51
|
+
sendConfirmationRequest: (confirmationMessage: string, buttons?: string[]) => Promise<string>;
|
|
52
52
|
};
|
|
53
53
|
export default cbchat;
|
package/modules/chat.js
CHANGED
|
@@ -130,16 +130,17 @@ const cbchat = {
|
|
|
130
130
|
* Sends a confirmation request to the server with two options: Yes or No.
|
|
131
131
|
* @returns {Promise<string>} A promise that resolves with the server's response.
|
|
132
132
|
*/
|
|
133
|
-
sendConfirmationRequest: (confirmationMessage) => {
|
|
133
|
+
sendConfirmationRequest: (confirmationMessage, buttons = []) => {
|
|
134
134
|
return new Promise((resolve, reject) => {
|
|
135
135
|
websocket_1.default.getWebsocket.send(JSON.stringify({
|
|
136
136
|
"type": "confirmationRequest",
|
|
137
|
-
"message": confirmationMessage
|
|
137
|
+
"message": confirmationMessage,
|
|
138
|
+
buttons: buttons
|
|
138
139
|
}));
|
|
139
140
|
websocket_1.default.getWebsocket.on('message', (data) => {
|
|
140
141
|
const response = JSON.parse(data);
|
|
141
142
|
if (response.type === "confirmationResponse") {
|
|
142
|
-
resolve(response
|
|
143
|
+
resolve(response); // Resolve the Promise with the server's response
|
|
143
144
|
}
|
|
144
145
|
});
|
|
145
146
|
});
|
package/package.json
CHANGED
package/src/modules/chat.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
// chat.ts
|
|
2
2
|
import cbws from './websocket';
|
|
3
3
|
import { EventEmitter } from 'events';
|
|
4
|
-
import {ChatMessage,UserMessage} from
|
|
4
|
+
import { ChatMessage, UserMessage } from '@codebolt/types'
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* CustomEventEmitter class that extends the Node.js EventEmitter class.
|
|
10
10
|
*/
|
|
11
|
-
class CustomEventEmitter extends EventEmitter {}
|
|
12
|
-
let
|
|
11
|
+
class CustomEventEmitter extends EventEmitter { }
|
|
12
|
+
let eventEmitter = new CustomEventEmitter()
|
|
13
13
|
/**
|
|
14
14
|
* Chat module to interact with the WebSocket server.
|
|
15
15
|
*/
|
|
@@ -49,7 +49,7 @@ const cbchat = {
|
|
|
49
49
|
"type": "processStoped"
|
|
50
50
|
}));
|
|
51
51
|
});
|
|
52
|
-
}
|
|
52
|
+
}
|
|
53
53
|
});
|
|
54
54
|
return eventEmitter;
|
|
55
55
|
},
|
|
@@ -81,7 +81,7 @@ const cbchat = {
|
|
|
81
81
|
const response = JSON.parse(data);
|
|
82
82
|
if (response.type === "waitFormessageResponse") {
|
|
83
83
|
resolve(response); // Resolve the Promise with the response data
|
|
84
|
-
}
|
|
84
|
+
}
|
|
85
85
|
});
|
|
86
86
|
});
|
|
87
87
|
},
|
|
@@ -99,10 +99,10 @@ const cbchat = {
|
|
|
99
99
|
cbws.getWebsocket.on('message', (data: string) => {
|
|
100
100
|
const message = JSON.parse(data);
|
|
101
101
|
console.log("Received message:", message);
|
|
102
|
-
if(message.type==='stopProcessClicked')
|
|
102
|
+
if (message.type === 'stopProcessClicked')
|
|
103
103
|
|
|
104
|
-
|
|
105
|
-
|
|
104
|
+
// Emit a custom event based on the message type
|
|
105
|
+
eventEmitter.emit("stopProcessClicked", message);
|
|
106
106
|
});
|
|
107
107
|
|
|
108
108
|
// Return an object that includes the event emitter and the stopProcess method
|
|
@@ -135,16 +135,18 @@ const cbchat = {
|
|
|
135
135
|
* Sends a confirmation request to the server with two options: Yes or No.
|
|
136
136
|
* @returns {Promise<string>} A promise that resolves with the server's response.
|
|
137
137
|
*/
|
|
138
|
-
sendConfirmationRequest: (confirmationMessage: string): Promise<string> => {
|
|
138
|
+
sendConfirmationRequest: (confirmationMessage: string, buttons: string[] = []): Promise<string> => {
|
|
139
139
|
return new Promise((resolve, reject) => {
|
|
140
140
|
cbws.getWebsocket.send(JSON.stringify({
|
|
141
141
|
"type": "confirmationRequest",
|
|
142
|
-
"message": confirmationMessage
|
|
142
|
+
"message": confirmationMessage,
|
|
143
|
+
buttons: buttons
|
|
144
|
+
|
|
143
145
|
}));
|
|
144
146
|
cbws.getWebsocket.on('message', (data: string) => {
|
|
145
147
|
const response = JSON.parse(data);
|
|
146
148
|
if (response.type === "confirmationResponse") {
|
|
147
|
-
resolve(response
|
|
149
|
+
resolve(response); // Resolve the Promise with the server's response
|
|
148
150
|
}
|
|
149
151
|
});
|
|
150
152
|
});
|