@codebolt/codeboltjs 1.1.47 → 1.1.48
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/modules/websocket.d.ts +1 -0
- package/modules/websocket.js +17 -4
- package/package.json +1 -1
- package/src/modules/websocket.ts +17 -4
package/modules/websocket.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ declare class cbws {
|
|
|
9
9
|
*/
|
|
10
10
|
constructor();
|
|
11
11
|
private getUniqueConnectionId;
|
|
12
|
+
private getInitialMessage;
|
|
12
13
|
/**
|
|
13
14
|
* Initializes the WebSocket by setting up event listeners and returning a promise that resolves
|
|
14
15
|
* when the WebSocket connection is successfully opened.
|
package/modules/websocket.js
CHANGED
|
@@ -15,20 +15,32 @@ class cbws {
|
|
|
15
15
|
*/
|
|
16
16
|
constructor() {
|
|
17
17
|
const uniqueConnectionId = this.getUniqueConnectionId();
|
|
18
|
+
const initialMessage = this.getInitialMessage();
|
|
18
19
|
console.log(uniqueConnectionId);
|
|
19
20
|
this.websocket = new ws_1.default(`ws://localhost:12345/codebolt?id=${uniqueConnectionId}`);
|
|
20
|
-
this.initializeWebSocket().catch(error => {
|
|
21
|
+
this.initializeWebSocket(initialMessage).catch(error => {
|
|
21
22
|
console.error("WebSocket connection failed:", error);
|
|
22
23
|
});
|
|
23
24
|
}
|
|
24
25
|
getUniqueConnectionId() {
|
|
25
26
|
try {
|
|
26
|
-
let fileContents = fs_1.default.readFileSync('./
|
|
27
|
+
let fileContents = fs_1.default.readFileSync('./codeboltagent.yml', 'utf8');
|
|
27
28
|
let data = js_yaml_1.default.load(fileContents);
|
|
28
29
|
return data.uniqueConnectionId;
|
|
29
30
|
}
|
|
30
31
|
catch (e) {
|
|
31
|
-
console.error('Unable to locate
|
|
32
|
+
console.error('Unable to locate codeboltagent.yml file.');
|
|
33
|
+
return '';
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
getInitialMessage() {
|
|
37
|
+
try {
|
|
38
|
+
let fileContents = fs_1.default.readFileSync('./codeboltagent.yml', 'utf8');
|
|
39
|
+
let data = js_yaml_1.default.load(fileContents);
|
|
40
|
+
return data.initialMessage;
|
|
41
|
+
}
|
|
42
|
+
catch (e) {
|
|
43
|
+
console.error('Unable to locate codeboltagent.yml file.');
|
|
32
44
|
return '';
|
|
33
45
|
}
|
|
34
46
|
}
|
|
@@ -37,7 +49,7 @@ class cbws {
|
|
|
37
49
|
* when the WebSocket connection is successfully opened.
|
|
38
50
|
* @returns {Promise<WebSocket>} A promise that resolves with the WebSocket instance.
|
|
39
51
|
*/
|
|
40
|
-
async initializeWebSocket() {
|
|
52
|
+
async initializeWebSocket(initialMessage) {
|
|
41
53
|
return new Promise((resolve, reject) => {
|
|
42
54
|
this.websocket.on('error', (error) => {
|
|
43
55
|
console.log('WebSocket error:', error);
|
|
@@ -46,6 +58,7 @@ class cbws {
|
|
|
46
58
|
this.websocket.on('open', () => {
|
|
47
59
|
console.log('WebSocket connected');
|
|
48
60
|
if (this.websocket) {
|
|
61
|
+
this.websocket.send(initialMessage);
|
|
49
62
|
resolve(this.websocket);
|
|
50
63
|
}
|
|
51
64
|
});
|
package/package.json
CHANGED
package/src/modules/websocket.ts
CHANGED
|
@@ -13,19 +13,31 @@ class cbws {
|
|
|
13
13
|
*/
|
|
14
14
|
constructor() {
|
|
15
15
|
const uniqueConnectionId = this.getUniqueConnectionId();
|
|
16
|
+
const initialMessage = this.getInitialMessage();
|
|
16
17
|
console.log(uniqueConnectionId)
|
|
17
18
|
this.websocket = new WebSocket(`ws://localhost:12345/codebolt?id=${uniqueConnectionId}`);
|
|
18
|
-
this.initializeWebSocket().catch(error => {
|
|
19
|
+
this.initializeWebSocket(initialMessage).catch(error => {
|
|
19
20
|
console.error("WebSocket connection failed:", error);
|
|
20
21
|
});
|
|
21
22
|
}
|
|
22
23
|
private getUniqueConnectionId(): string {
|
|
23
24
|
try {
|
|
24
|
-
let fileContents = fs.readFileSync('./
|
|
25
|
+
let fileContents = fs.readFileSync('./codeboltagent.yml', 'utf8');
|
|
25
26
|
let data:any = yaml.load(fileContents);
|
|
26
27
|
return data.uniqueConnectionId;
|
|
27
28
|
} catch (e) {
|
|
28
|
-
console.error('Unable to locate
|
|
29
|
+
console.error('Unable to locate codeboltagent.yml file.');
|
|
30
|
+
return '';
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
private getInitialMessage(): string {
|
|
35
|
+
try {
|
|
36
|
+
let fileContents = fs.readFileSync('./codeboltagent.yml', 'utf8');
|
|
37
|
+
let data:any = yaml.load(fileContents);
|
|
38
|
+
return data.initialMessage;
|
|
39
|
+
} catch (e) {
|
|
40
|
+
console.error('Unable to locate codeboltagent.yml file.');
|
|
29
41
|
return '';
|
|
30
42
|
}
|
|
31
43
|
}
|
|
@@ -35,7 +47,7 @@ class cbws {
|
|
|
35
47
|
* when the WebSocket connection is successfully opened.
|
|
36
48
|
* @returns {Promise<WebSocket>} A promise that resolves with the WebSocket instance.
|
|
37
49
|
*/
|
|
38
|
-
private async initializeWebSocket(): Promise<WebSocket> {
|
|
50
|
+
private async initializeWebSocket(initialMessage: string): Promise<WebSocket> {
|
|
39
51
|
return new Promise((resolve, reject) => {
|
|
40
52
|
this.websocket.on('error', (error: Error) => {
|
|
41
53
|
console.log('WebSocket error:', error);
|
|
@@ -45,6 +57,7 @@ class cbws {
|
|
|
45
57
|
this.websocket.on('open', () => {
|
|
46
58
|
console.log('WebSocket connected');
|
|
47
59
|
if (this.websocket) {
|
|
60
|
+
this.websocket.send(initialMessage);
|
|
48
61
|
resolve(this.websocket);
|
|
49
62
|
}
|
|
50
63
|
});
|