|
14 | 14 | // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
15 | 15 | // *****************************************************************************
|
16 | 16 |
|
17 |
| -import { injectable, interfaces, decorate, unmanaged } from 'inversify'; |
| 17 | +import { injectable, interfaces, decorate, unmanaged, postConstruct } from 'inversify'; |
18 | 18 | import { JsonRpcProxyFactory, JsonRpcProxy, Emitter, Event, Channel } from '../../common';
|
19 | 19 | import { Endpoint } from '../endpoint';
|
20 | 20 | import { AbstractConnectionProvider } from '../../common/messaging/abstract-connection-provider';
|
@@ -48,23 +48,15 @@ export class WebSocketConnectionProvider extends AbstractConnectionProvider<WebS
|
48 | 48 | return container.get(WebSocketConnectionProvider).createProxy<T>(path, arg);
|
49 | 49 | }
|
50 | 50 |
|
51 |
| - protected readonly socket: Socket; |
| 51 | + protected socket: Socket; |
52 | 52 |
|
53 | 53 | constructor() {
|
54 | 54 | super();
|
55 |
| - const url = this.createWebSocketUrl(WebSocketChannel.wsPath); |
56 |
| - this.socket = this.createWebSocket(url); |
57 |
| - this.socket.on('connect', () => { |
58 |
| - this.initializeMultiplexer(); |
59 |
| - if (this.reconnectChannelOpeners.length > 0) { |
60 |
| - this.reconnectChannelOpeners.forEach(opener => opener()); |
61 |
| - this.reconnectChannelOpeners = []; |
62 |
| - } |
63 |
| - this.socket.on('disconnect', () => this.fireSocketDidClose()); |
64 |
| - this.socket.on('message', () => this.onIncomingMessageActivityEmitter.fire(undefined)); |
65 |
| - this.fireSocketDidOpen(); |
66 |
| - }); |
67 |
| - this.socket.connect(); |
| 55 | + } |
| 56 | + |
| 57 | + @postConstruct() |
| 58 | + protected init(): void { |
| 59 | + this.connect(); |
68 | 60 | }
|
69 | 61 |
|
70 | 62 | protected createMainChannel(): Channel {
|
@@ -111,6 +103,22 @@ export class WebSocketConnectionProvider extends AbstractConnectionProvider<WebS
|
111 | 103 | return new Endpoint({ path }).getRestUrl().toString();
|
112 | 104 | }
|
113 | 105 |
|
| 106 | + protected connect(path: string = WebSocketChannel.wsPath): void { |
| 107 | + const url = this.createWebSocketUrl(path); |
| 108 | + this.socket = this.createWebSocket(url); |
| 109 | + this.socket.on('connect', () => { |
| 110 | + this.initializeMultiplexer(); |
| 111 | + if (this.reconnectChannelOpeners.length > 0) { |
| 112 | + this.reconnectChannelOpeners.forEach(opener => opener()); |
| 113 | + this.reconnectChannelOpeners = []; |
| 114 | + } |
| 115 | + this.socket.on('disconnect', () => this.fireSocketDidClose()); |
| 116 | + this.socket.on('message', () => this.onIncomingMessageActivityEmitter.fire(undefined)); |
| 117 | + this.fireSocketDidOpen(); |
| 118 | + }); |
| 119 | + this.socket.connect(); |
| 120 | + } |
| 121 | + |
114 | 122 | /**
|
115 | 123 | * Creates a web socket for the given url
|
116 | 124 | */
|
|
0 commit comments