File tree Expand file tree Collapse file tree 1 file changed +15
-1
lines changed Expand file tree Collapse file tree 1 file changed +15
-1
lines changed Original file line number Diff line number Diff line change 1
1
import WebSocket from 'ws' ;
2
+ import fs from 'fs' ;
3
+ import yaml from 'js-yaml' ;
2
4
3
5
/**
4
6
* Class representing a WebSocket connection.
@@ -10,11 +12,23 @@ class cbws {
10
12
* Constructs a new cbws instance and initializes the WebSocket connection.
11
13
*/
12
14
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 } ` ) ;
14
18
this . initializeWebSocket ( ) . catch ( error => {
15
19
console . error ( "WebSocket connection failed:" , error ) ;
16
20
} ) ;
17
21
}
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
+ }
18
32
19
33
/**
20
34
* Initializes the WebSocket by setting up event listeners and returning a promise that resolves
You can’t perform that action at this time.
0 commit comments