1- import { fromEvent as observableFromEvent , Observable } from " rxjs" ;
2- import { filter , first , map , takeWhile } from " rxjs/operators" ;
3- import { Commands } from " ../configuration/xcWebSocketBridgeConfiguration" ;
4- import { CompositionModel , DeserializedData , Serializer , Deserializer } from " ./xcomponentMessages" ;
5- import " rxjs/add/observable/fromEvent" ;
6- import { Logger } from " log4ts" ;
7- import { DefaultApiConfigurationParser } from " ../configuration/apiConfigurationParser" ;
8- import { ApiConfiguration } from " ../configuration/apiConfiguration" ;
1+ import { fromEvent as observableFromEvent , Observable } from ' rxjs' ;
2+ import { filter , first , map , takeWhile } from ' rxjs/operators' ;
3+ import { Commands } from ' ../configuration/xcWebSocketBridgeConfiguration' ;
4+ import { CompositionModel , DeserializedData , Serializer , Deserializer } from ' ./xcomponentMessages' ;
5+ import ' rxjs/add/observable/fromEvent' ;
6+ import { Logger } from ' log4ts' ;
7+ import { DefaultApiConfigurationParser } from ' ../configuration/apiConfigurationParser' ;
8+ import { ApiConfiguration } from ' ../configuration/apiConfiguration' ;
99
1010export class WebSocketBridgeCommunication {
11- private logger : Logger = Logger . getLogger ( " HeartbeatManager" ) ;
11+ private logger : Logger = Logger . getLogger ( ' HeartbeatManager' ) ;
1212 private updates$ : Observable < DeserializedData > ;
1313 private deserializer : Deserializer ;
1414 private serializer : Serializer ;
@@ -19,18 +19,21 @@ export class WebSocketBridgeCommunication {
1919 this . deserializer = new Deserializer ( ) ;
2020 this . serializer = new Serializer ( ) ;
2121 let thisWebSocketBridgeCommunication = this ;
22- this . updates$ = observableFromEvent ( this . webSocket , " message" ) . pipe (
22+ this . updates$ = observableFromEvent ( this . webSocket , ' message' ) . pipe (
2323 takeWhile ( ( rawMessage : MessageEvent ) => this . runnning ) ,
24- map ( ( rawMessage : MessageEvent ) => thisWebSocketBridgeCommunication . deserializer . deserializeWithoutTopic ( rawMessage . data || rawMessage ) ) ) ;
24+ map ( ( rawMessage : MessageEvent ) =>
25+ thisWebSocketBridgeCommunication . deserializer . deserializeWithoutTopic ( rawMessage . data || rawMessage )
26+ )
27+ ) ;
2528 }
2629
2730 public startHeartbeat ( heartbeatIntervalSeconds : number ) : void {
2831 let thisWebSocketBridgeCommunication = this ;
2932 let command = Commands [ Commands . hb ] ;
30- this . updates$ . pipe (
31- filter ( ( data : DeserializedData ) => data . command === command ) )
33+ this . updates$
34+ . pipe ( filter ( ( data : DeserializedData ) => data . command === command ) )
3235 . subscribe ( ( data : DeserializedData ) => {
33- this . logger . trace ( " Heartbeat received successfully" ) ;
36+ this . logger . trace ( ' Heartbeat received successfully' ) ;
3437 } ) ;
3538 let commandData = {
3639 Command : command ,
@@ -39,32 +42,36 @@ export class WebSocketBridgeCommunication {
3942 let input = thisWebSocketBridgeCommunication . serializer . convertCommandDataToWebsocketInputFormat ( commandData ) ;
4043 this . heartbeatTimer = setInterval ( ( ) => {
4144 thisWebSocketBridgeCommunication . webSocket . send ( input ) ;
42- this . logger . trace ( " Heartbeat sent" ) ;
45+ this . logger . trace ( ' Heartbeat sent' ) ;
4346 } , heartbeatIntervalSeconds * 1000 ) ;
4447 }
4548
4649 public getCompositionModel ( apiName : string ) : Promise < CompositionModel > {
4750 const thisWebSocketBridgeCommunication = this ;
4851 const command = Commands [ Commands . getModel ] ;
49- const promise = this . updates$ . pipe (
50- filter ( ( data : DeserializedData ) => data . command === command ) ,
51- first ( ) ,
52- map ( ( data : DeserializedData ) => {
53- return thisWebSocketBridgeCommunication . deserializer . getJsonDataFromGetModelRequest ( data . stringData ) ;
54- } ) )
52+ const promise = this . updates$
53+ . pipe (
54+ filter ( ( data : DeserializedData ) => data . command === command ) ,
55+ first ( ) ,
56+ map ( ( data : DeserializedData ) => {
57+ return thisWebSocketBridgeCommunication . deserializer . getJsonDataFromGetModelRequest (
58+ data . stringData
59+ ) ;
60+ } )
61+ )
5562 . toPromise ( )
5663 . then ( ( compositionModel : CompositionModel | undefined ) => {
5764 if ( ! compositionModel ) {
58- const errorMessage = " Model " + apiName + " not found" ;
65+ const errorMessage = ' Model ' + apiName + ' not found' ;
5966 this . logger . error ( errorMessage ) ;
6067 throw new Error ( errorMessage ) ;
6168 }
62- this . logger . info ( " Model " + apiName + " received successfully" ) ;
69+ this . logger . info ( ' Model ' + apiName + ' received successfully' ) ;
6370 return compositionModel ;
6471 } ) ;
6572 const commandData = {
6673 Command : command ,
67- Data : { " Name" : apiName }
74+ Data : { Name : apiName }
6875 } ;
6976 const input = thisWebSocketBridgeCommunication . serializer . convertCommandDataToWebsocketInputFormat ( commandData ) ;
7077 this . webSocket . send ( input ) ;
@@ -74,32 +81,40 @@ export class WebSocketBridgeCommunication {
7481 public getXcApiList ( ) : Promise < Array < string > > {
7582 const thisWebSocketBridgeCommunication = this ;
7683 const command = Commands [ Commands . getXcApiList ] ;
77- const promise = this . updates$ . pipe (
78- filter ( ( data : DeserializedData ) => data . command === command ) ,
79- first ( ) ,
80- map ( ( data : DeserializedData ) => {
81- this . logger . info ( "ApiList received successfully" ) ;
82- return thisWebSocketBridgeCommunication . deserializer . getJsonDataFromGetXcApiListRequest ( data . stringData ) ;
83- } ) )
84+ const promise = this . updates$
85+ . pipe (
86+ filter ( ( data : DeserializedData ) => data . command === command ) ,
87+ first ( ) ,
88+ map ( ( data : DeserializedData ) => {
89+ this . logger . info ( 'ApiList received successfully' ) ;
90+ return thisWebSocketBridgeCommunication . deserializer . getJsonDataFromGetXcApiListRequest (
91+ data . stringData
92+ ) ;
93+ } )
94+ )
8495 . toPromise ( ) ;
8596 const commandData = {
8697 Command : command ,
8798 Data : { }
8899 } ;
89- this . webSocket . send ( thisWebSocketBridgeCommunication . serializer . convertCommandDataToWebsocketInputFormat ( commandData ) ) ;
100+ this . webSocket . send (
101+ thisWebSocketBridgeCommunication . serializer . convertCommandDataToWebsocketInputFormat ( commandData )
102+ ) ;
90103 return promise ;
91104 }
92105
93106 public getXcApiConfiguration ( apiName : string ) : Promise < ApiConfiguration > {
94107 const thisWebSocketBridgeCommunication = this ;
95108 const command = Commands [ Commands . getXcApi ] ;
96- const promise = this . updates$ . pipe (
97- filter ( ( data : DeserializedData ) => data . command === command ) ,
98- first ( ) ,
99- map ( ( data : DeserializedData ) => {
100- this . logger . info ( apiName + " " + "received successfully" ) ;
101- return thisWebSocketBridgeCommunication . deserializer . getJsonDataFromXcApiRequest ( data . stringData ) ;
102- } ) )
109+ const promise = this . updates$
110+ . pipe (
111+ filter ( ( data : DeserializedData ) => data . command === command ) ,
112+ first ( ) ,
113+ map ( ( data : DeserializedData ) => {
114+ this . logger . info ( apiName + ' ' + 'received successfully' ) ;
115+ return thisWebSocketBridgeCommunication . deserializer . getJsonDataFromXcApiRequest ( data . stringData ) ;
116+ } )
117+ )
103118 . toPromise ( )
104119 . then ( ( xcApi : string | undefined ) => {
105120 if ( ! xcApi ) {
@@ -114,12 +129,14 @@ export class WebSocketBridgeCommunication {
114129 Command : command ,
115130 Data : { Name : apiName }
116131 } ;
117- this . webSocket . send ( thisWebSocketBridgeCommunication . serializer . convertCommandDataToWebsocketInputFormat ( commandData ) ) ;
132+ this . webSocket . send (
133+ thisWebSocketBridgeCommunication . serializer . convertCommandDataToWebsocketInputFormat ( commandData )
134+ ) ;
118135 return promise ;
119136 }
120137
121138 public dispose ( ) : void {
122139 clearInterval ( this . heartbeatTimer ) ;
123140 this . runnning = false ;
124141 }
125- }
142+ }
0 commit comments