Skip to content

Commit 76d2475

Browse files
changes
1 parent fefbef4 commit 76d2475

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/modules/websocket.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import WebSocket from 'ws';
2+
import fs from 'fs';
3+
import yaml from 'js-yaml';
24

35
/**
46
* Class representing a WebSocket connection.
@@ -10,11 +12,23 @@ class cbws {
1012
* Constructs a new cbws instance and initializes the WebSocket connection.
1113
*/
1214
constructor() {
13-
this.websocket = new WebSocket("ws://localhost:12345/codebolt");
15+
const uniqueConnectionId = this.getUniqueConnectionId();
16+
console.log(uniqueConnectionId)
17+
this.websocket = new WebSocket(`ws://localhost:12345/codebolt?id=${uniqueConnectionId}`);
1418
this.initializeWebSocket().catch(error => {
1519
console.error("WebSocket connection failed:", error);
1620
});
1721
}
22+
private getUniqueConnectionId(): string {
23+
try {
24+
let fileContents = fs.readFileSync('./codebotagent.yml', 'utf8');
25+
let data = yaml.safeLoad(fileContents);
26+
return data.uniqueConnectionId;
27+
} catch (e) {
28+
console.log(e);
29+
return '';
30+
}
31+
}
1832

1933
/**
2034
* Initializes the WebSocket by setting up event listeners and returning a promise that resolves

0 commit comments

Comments
 (0)