@codebolt/codeboltjs 1.1.43 → 1.1.45
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 -0
- package/modules/chat.d.ts +5 -0
- package/modules/chat.js +19 -0
- package/package.json +1 -1
- package/src/modules/chat.ts +29 -8
package/index.d.ts
CHANGED
package/modules/chat.d.ts
CHANGED
|
@@ -44,5 +44,10 @@ declare const cbchat: {
|
|
|
44
44
|
* Sends a specific message to the server to stop the process.
|
|
45
45
|
*/
|
|
46
46
|
stopProcess: () => void;
|
|
47
|
+
/**
|
|
48
|
+
* Sends a confirmation request to the server with two options: Yes or No.
|
|
49
|
+
* @returns {Promise<string>} A promise that resolves with the server's response.
|
|
50
|
+
*/
|
|
51
|
+
sendConfirmationRequest: (confirmationMessage: string, buttons?: string[]) => Promise<string>;
|
|
47
52
|
};
|
|
48
53
|
export default cbchat;
|
package/modules/chat.js
CHANGED
|
@@ -125,6 +125,25 @@ const cbchat = {
|
|
|
125
125
|
websocket_1.default.getWebsocket.send(JSON.stringify({
|
|
126
126
|
"type": "processStoped"
|
|
127
127
|
}));
|
|
128
|
+
},
|
|
129
|
+
/**
|
|
130
|
+
* Sends a confirmation request to the server with two options: Yes or No.
|
|
131
|
+
* @returns {Promise<string>} A promise that resolves with the server's response.
|
|
132
|
+
*/
|
|
133
|
+
sendConfirmationRequest: (confirmationMessage, buttons = []) => {
|
|
134
|
+
return new Promise((resolve, reject) => {
|
|
135
|
+
websocket_1.default.getWebsocket.send(JSON.stringify({
|
|
136
|
+
"type": "confirmationRequest",
|
|
137
|
+
"message": confirmationMessage,
|
|
138
|
+
buttons: buttons
|
|
139
|
+
}));
|
|
140
|
+
websocket_1.default.getWebsocket.on('message', (data) => {
|
|
141
|
+
const response = JSON.parse(data);
|
|
142
|
+
if (response.type === "confirmationResponse") {
|
|
143
|
+
resolve(response.answer); // Resolve the Promise with the server's response
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
});
|
|
128
147
|
}
|
|
129
148
|
};
|
|
130
149
|
exports.default = cbchat;
|
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
|
|
@@ -129,6 +129,27 @@ const cbchat = {
|
|
|
129
129
|
cbws.getWebsocket.send(JSON.stringify({
|
|
130
130
|
"type": "processStoped"
|
|
131
131
|
}));
|
|
132
|
+
},
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Sends a confirmation request to the server with two options: Yes or No.
|
|
136
|
+
* @returns {Promise<string>} A promise that resolves with the server's response.
|
|
137
|
+
*/
|
|
138
|
+
sendConfirmationRequest: (confirmationMessage: string, buttons: string[] = []): Promise<string> => {
|
|
139
|
+
return new Promise((resolve, reject) => {
|
|
140
|
+
cbws.getWebsocket.send(JSON.stringify({
|
|
141
|
+
"type": "confirmationRequest",
|
|
142
|
+
"message": confirmationMessage,
|
|
143
|
+
buttons: buttons
|
|
144
|
+
|
|
145
|
+
}));
|
|
146
|
+
cbws.getWebsocket.on('message', (data: string) => {
|
|
147
|
+
const response = JSON.parse(data);
|
|
148
|
+
if (response.type === "confirmationResponse") {
|
|
149
|
+
resolve(response.answer); // Resolve the Promise with the server's response
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
});
|
|
132
153
|
}
|
|
133
154
|
};
|
|
134
155
|
|