@@ -14,6 +14,8 @@ const API_BASE_URL = '/api/v1';
1414} )
1515export class ApiService {
1616 private websocketSubject : Observable < IMempoolDefaultResponse > = webSocket < IMempoolDefaultResponse | any > ( WEB_SOCKET_URL ) ;
17+ private lastWant : string [ ] | null = null ;
18+ private goneOffline = false ;
1719
1820 constructor (
1921 private httpClient : HttpClient ,
@@ -27,7 +29,10 @@ export class ApiService {
2729 . pipe (
2830 retryWhen ( ( errors : any ) => errors
2931 . pipe (
30- tap ( ( ) => this . memPoolService . isOffline$ . next ( true ) ) ,
32+ tap ( ( ) => {
33+ this . goneOffline = true ;
34+ this . memPoolService . isOffline$ . next ( true ) ;
35+ } ) ,
3136 delay ( 5000 ) ,
3237 )
3338 ) ,
@@ -92,17 +97,31 @@ export class ApiService {
9297 if ( response [ 'live-2h-chart' ] ) {
9398 this . memPoolService . live2Chart$ . next ( response [ 'live-2h-chart' ] ) ;
9499 }
100+
101+ if ( this . goneOffline === true ) {
102+ this . goneOffline = false ;
103+ if ( this . lastWant ) {
104+ this . webSocketWant ( this . lastWant ) ;
105+ }
106+ }
95107 } ,
96108 ( err : Error ) => {
97109 console . log ( err ) ;
110+ this . goneOffline = true ;
98111 console . log ( 'Error, retrying in 10 sec' ) ;
99112 setTimeout ( ( ) => this . startSubscription ( ) , 10000 ) ;
100113 } ) ;
101114 }
102115
103- sendWebSocket ( data : any ) {
116+ webSocketStartTrackTx ( txId : string ) {
117+ // @ts -ignore
118+ this . websocketSubject . next ( { 'action' : 'track-tx' , 'txId' : txId } ) ;
119+ }
120+
121+ webSocketWant ( data : string [ ] ) {
104122 // @ts -ignore
105- this . websocketSubject . next ( data ) ;
123+ this . websocketSubject . next ( { 'action' : 'want' , data : data } ) ;
124+ this . lastWant = data ;
106125 }
107126
108127 listTransactionsForBlock$ ( height : number ) : Observable < IBlockTransaction [ ] > {
0 commit comments