Merge pull request #3706 from mempool/mononaut/reconnect-dead-websocket
reconnect websocket after closed by server
This commit is contained in:
		
						commit
						6b978f9262
					
				| @ -76,15 +76,20 @@ export class WebsocketService { | |||||||
| 
 | 
 | ||||||
|         this.stateService.resetChainTip(); |         this.stateService.resetChainTip(); | ||||||
| 
 | 
 | ||||||
|  |         this.reconnectWebsocket(); | ||||||
|  |       }); | ||||||
|  |     } | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   reconnectWebsocket(retrying = false, hasInitData = false) { | ||||||
|  |     console.log('reconnecting websocket'); | ||||||
|     this.websocketSubject.complete(); |     this.websocketSubject.complete(); | ||||||
|     this.subscription.unsubscribe(); |     this.subscription.unsubscribe(); | ||||||
|     this.websocketSubject = webSocket<WebsocketResponse>( |     this.websocketSubject = webSocket<WebsocketResponse>( | ||||||
|       this.webSocketUrl.replace('{network}', this.network ? '/' + this.network : '') |       this.webSocketUrl.replace('{network}', this.network ? '/' + this.network : '') | ||||||
|     ); |     ); | ||||||
| 
 | 
 | ||||||
|         this.startSubscription(); |     this.startSubscription(retrying, hasInitData); | ||||||
|       }); |  | ||||||
|     } |  | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   startSubscription(retrying = false, hasInitData = false) { |   startSubscription(retrying = false, hasInitData = false) { | ||||||
| @ -237,7 +242,7 @@ export class WebsocketService { | |||||||
|     this.goneOffline = true; |     this.goneOffline = true; | ||||||
|     this.stateService.connectionState$.next(0); |     this.stateService.connectionState$.next(0); | ||||||
|     window.setTimeout(() => { |     window.setTimeout(() => { | ||||||
|       this.startSubscription(true); |       this.reconnectWebsocket(true); | ||||||
|     }, retryDelay); |     }, retryDelay); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user