@@ -13,19 +13,31 @@ class cbws {
1313 */
1414 constructor ( ) {
1515 const uniqueConnectionId = this . getUniqueConnectionId ( ) ;
16+ const initialMessage = this . getInitialMessage ( ) ;
1617 console . log ( uniqueConnectionId )
1718 this . websocket = new WebSocket ( `ws://localhost:12345/codebolt?id=${ uniqueConnectionId } ` ) ;
18- this . initializeWebSocket ( ) . catch ( error => {
19+ this . initializeWebSocket ( initialMessage ) . catch ( error => {
1920 console . error ( "WebSocket connection failed:" , error ) ;
2021 } ) ;
2122 }
2223 private getUniqueConnectionId ( ) : string {
2324 try {
24- let fileContents = fs . readFileSync ( './codebotagent .yml' , 'utf8' ) ;
25+ let fileContents = fs . readFileSync ( './codeboltagent .yml' , 'utf8' ) ;
2526 let data :any = yaml . load ( fileContents ) ;
2627 return data . uniqueConnectionId ;
2728 } 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.' ) ;
2941 return '' ;
3042 }
3143 }
@@ -35,7 +47,7 @@ class cbws {
3547 * when the WebSocket connection is successfully opened.
3648 * @returns {Promise<WebSocket> } A promise that resolves with the WebSocket instance.
3749 */
38- private async initializeWebSocket ( ) : Promise < WebSocket > {
50+ private async initializeWebSocket ( initialMessage : string ) : Promise < WebSocket > {
3951 return new Promise ( ( resolve , reject ) => {
4052 this . websocket . on ( 'error' , ( error : Error ) => {
4153 console . log ( 'WebSocket error:' , error ) ;
@@ -45,6 +57,7 @@ class cbws {
4557 this . websocket . on ( 'open' , ( ) => {
4658 console . log ( 'WebSocket connected' ) ;
4759 if ( this . websocket ) {
60+ this . websocket . send ( initialMessage ) ;
4861 resolve ( this . websocket ) ;
4962 }
5063 } ) ;
0 commit comments