@@ -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 ( './codebotagent .yml' , 'utf8' ) ;
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 codebotagent.yml file.' ) ;
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
} ) ;
0 commit comments