ide на основе vs code · VibeGit
ide на основе vs code Это ide на основе vs code(code oss), в ней будет встроенный умный апи роутинг, свой маркет с плагинами(агент харнесс, поддержка java/kotlin/мобильной разработки, командная разработка проектов, orca, оркестратор агентов
krutaya-ide-na-osnove-vs-code / src / vs / platform / agentHost / common / tunnelAgentHostConnector.ts 520 строк · изменён 14 нояб., 04:52
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
import { raceTimeout } from '../../../base/common/async.js' ;
import { Emitter, Event } from '../../../base/common/event.js' ;
import { Disposable, DisposableMap, IDisposable } from '../../../base/common/lifecycle.js' ;
import { generateUuid } from '../../../base/common/uuid.js' ;
import {
createTunnelGatewaySelectionRejectedError,
parseTunnelGatewayInventory,
parseTunnelGatewaySelectionResponse,
TUNNEL_ADDRESS_PREFIX ,
TUNNEL_AGENT_HOST_PORT ,
TUNNEL_GATEWAY_MIN_PROTOCOL_VERSION ,
TUNNEL_GATEWAY_SELECT_PATH ,
TUNNEL_MIN_PROTOCOL_VERSION ,
TunnelNotFoundError,
TunnelTags
ITunnelDuplexStream ITunnelMessageSocket ITunnelSocketCloseEvent
tunnelId
clusterId
name
labels
status
hostConnectionCount current
port
port ITunnelDuplexStream
tunnel ITunnelDescriptor
ITunnelRelayClient
tunnelId clusterId authProvider token ITunnelRelayClientSession
stream ITunnelDuplexStream path ITunnelMessageSocket
message
message
timeoutMs
stepName
timedOut
result timeoutMs timedOut
timedOut
result
tunnelId
hash crypto subtle tunnelId
result
index index hash length index
first hash index
second hash index
third hash index
result first
result first second
second
result second third
third
result third
result result
tunnel ITunnelDescriptor ITunnelInfo
labels tunnel labels
tags labels
tags protocolVersion
tunnelId clusterId tunnel
tunnelId clusterId
rawCount tunnel status hostConnectionCount
tunnelId
clusterId
name tags name tunnel name tunnelId
tags labels
protocolVersion tags protocolVersion
hostConnectionCount rawCount rawCount rawCount current
_disposed
_onSocketClosedListener IDisposable
address
name
connectionToken
socket ITunnelMessageSocket
relayClient ITunnelRelayClient
_onSocketClosedListener socket
_disposed
_onSocketClosedListener
_disposed
_disposed
_onSocketClosedListener
socket
socket
relayClient
_onDidClose
onDidClose _onDidClose event
_closed
connectionId
address
name
connectionToken
_socket ITunnelMessageSocket
_relayClient ITunnelRelayClient
message
event ITunnelSocketCloseEvent
_socket onMessage
_socket event
event
data
_socket data
override
_closed
_closed
_socket
_socket
_relayClient
_onDidClose
_onDidRelayMessage
onDidRelayMessage Event ITunnelRelayMessage _onDidRelayMessage event
_onDidRelayClose
onDidRelayClose Event _onDidRelayClose event
_connections
_pendingSelections
_relayClientFactory ITunnelRelayClientFactory
_socketFactory ITunnelSocketFactory
_logService ITunnelAgentHostConnectorLogService
token authProvider tunnelId clusterId ITunnelConnectResult
tunnelId
_logService
session _relayClientFactory tunnelId clusterId authProvider token
session
tunnelId
tunnel session
relayClient session
portStream ITunnelDuplexStream
relayClient
_logService
relayClient
portStream relayClient
_logService
err
relayClient
err
connectionToken tunnelId
name tunnel labels name tunnel name tunnelId
connectionId
socket ITunnelMessageSocket
socket
_socketFactory portStream
_logService
err
relayClient
err
connectionId name connectionToken socket relayClient
connectionId
address
name
connectionToken
selected serverType instanceId role lifecycle
token authProvider tunnelId clusterId ITunnelGatewaySelectionSession
session _relayClientFactory tunnelId clusterId authProvider token
session
tunnelId
tunnel session
tags tunnel labels
tags protocolVersion
_logService
relayClient session
socket ITunnelMessageSocket
relayClient
relayClient
portStream relayClient
socket _socketFactory portStream
err
relayClient
err
inventoryText
inventoryText socket
err
socket
relayClient
err
inventory ITunnelGatewayInventory
connectionToken
inventory inventoryText
connectionToken tunnelId
err
socket
relayClient
err
selectionId
_pendingSelections selectionId
tags name tunnel name tunnelId
connectionToken
socket
relayClient
_logService
_pendingSelections selectionId
selectionId inventory
selectionId selection ITunnelGatewaySelection ITunnelConnectResult
pending _pendingSelections selectionId
pending
pending
response ReturnType parseTunnelGatewaySelectionResponse
pending socket selection
responseText pending socket
response responseText
err
pending socket
pending relayClient
err
response ok
pending socket
pending relayClient
connectionId
connectionId pending address pending name pending connectionToken pending socket pending relayClient
_logService
connectionId address pending address name pending name connectionToken pending connectionToken selected response selected
selectionId
_pendingSelections selectionId
connectionId message
_connections connectionId message
connectionId
_connections connectionId
tunnelId operation
address
connectionId connection _connections
connection address address
_logService
_connections connectionId
selectionId pending PendingGatewaySelection
_pendingSelections selectionId pending
selectionId
_pendingSelections selectionId
connectionId address name connectionToken socket ITunnelMessageSocket relayClient ITunnelRelayClient
connection
connectionId
address
name
connectionToken
socket
relayClient
data _onDidRelayMessage connectionId data
event _logService
onConnectionClose connection
onConnectionClose
_connections connectionId
_onDidRelayClose connectionId
_connections connectionId connection
socket ITunnelMessageSocket
resolve reject
subscriptions IDisposable
settled
subscription subscriptions
subscription
onMessage socket message
settled
settled
message
settled
onMessage
subscriptions onMessage
onClose socket event
settled
settled
event error
event error
settled
onClose
subscriptions onClose
socket ITunnelMessageSocket
socket
socket
relayClient ITunnelRelayClient
relayClient
,
type
ITunnelConnectResult
,
type
ITunnelGatewayInventory
,
type
ITunnelGatewaySelection
,
type
ITunnelGatewaySelectionSession
,
type
ITunnelInfo
,
type
ITunnelRelayMessage
,
}
from
'./tunnelAgentHost.js'
;
import
type
{
,
,
}
from
'./tunnelMessageSocket.js'
;
const
LOG_PREFIX
=
'[TunnelAgentHost]'
;
const
BASE64_URL_ALPHABET
=
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_'
;
export
const
TUNNEL_STEP_TIMEOUT_MS
=
30_000
;
export
interface
ITunnelDescriptor
{
readonly
?
:
string
;
readonly
?
:
string
;
readonly
?
:
string
;
readonly
?
:
readonly
string
[
]
;
readonly
?
:
{
readonly
?
:
number
|
{
readonly
?
:
number
}
;
}
;
}
export
interface
ITunnelRelayClient
extends
IDisposable
{
connect
(
)
:
Promise
<
void
>
;
waitForForwardedPort
(
:
number
)
:
Promise
<
void
>
;
connectToForwardedPort
(
:
number
)
:
Promise
<
>
;
}
export
interface
ITunnelRelayClientSession
{
readonly
:
;
createRelayClient
(
)
:
Promise
<
>
;
}
export
interface
ITunnelRelayClientFactory
{
getTunnel
(
:
string
,
:
string
,
:
'github'
|
'microsoft'
,
:
string
)
:
Promise
<
|
undefined
>
;
}
export
interface
ITunnelSocketFactory
{
open
(
:
,
:
string
)
:
Promise
<
>
;
}
export
interface
ITunnelAgentHostConnectorLogService
{
info
(
:
string
)
:
void
;
warn
(
:
string
)
:
void
;
}
export
async
function
withTimeout < T >
(
op
:
(
)
=>
Promise
<
T
>
,
:
number
,
:
string
,
)
:
Promise
<
T
>
{
let
=
false
;
const
=
await
raceTimeout
(
op
(
)
,
,
(
)
=>
{
=
true
;
}
)
;
if
(
)
{
throw
new
Error
(
` ${ LOG_PREFIX } ${ stepName} timed out after ${ timeoutMs} ms `
)
;
}
return
as
T
;
}
export
async
function
deriveConnectionToken
(
:
string
)
:
Promise
<
string
>
{
const
=
new
Uint8Array
(
await
.
.
digest
(
'SHA-256'
,
new
TextEncoder
(
)
.
encode
(
)
)
)
;
let
=
''
;
for
(
let
=
0
;
<
.
;
+=
3
)
{
const
=
[
]
;
const
=
[
+
1
]
;
const
=
[
+
2
]
;
+=
BASE64_URL_ALPHABET
[
>>
2
]
;
+=
BASE64_URL_ALPHABET
[
(
&
0b00000011
)
<<
4
|
(
??
0
)
>>
4
]
;
if
(
!==
undefined
)
{
+=
BASE64_URL_ALPHABET
[
(
&
0b00001111
)
<<
2
|
(
??
0
)
>>
6
]
;
}
if
(
!==
undefined
)
{
+=
BASE64_URL_ALPHABET
[
&
0b00111111
]
;
}
}
return
.
startsWith
(
'-'
)
?
` a ${ result} `
:
;
}
export
function
parseTunnelInfo
(
:
)
:
|
undefined
{
const
=
.
??
[
]
;
const
=
new
TunnelTags
(
)
;
if
(
.
<
TUNNEL_MIN_PROTOCOL_VERSION
)
{
return
undefined
;
}
const
{
,
}
=
;
if
(
!
||
!
)
{
return
undefined
;
}
const
=
.
?.
;
return
{
,
,
:
.
||
.
||
,
:
,
:
.
,
:
typeof
===
'number'
?
:
(
?.
??
0
)
,
}
;
}
export
class
PendingGatewaySelection
implements
IDisposable
{
private
=
false
;
private
readonly
:
;
constructor
(
readonly
:
string
,
readonly
:
string
,
readonly
:
string
,
readonly
:
,
readonly
:
,
private
readonly
_onUnexpectedClose
:
(
)
=>
void
,
)
{
this
.
=
this
.
.
onDidClose
(
(
)
=>
{
if
(
!
this
.
)
{
this
.
_onUnexpectedClose
(
)
;
}
}
)
;
}
detach
(
)
:
void
{
this
.
.
dispose
(
)
;
}
dispose
(
)
:
void
{
if
(
!
this
.
)
{
this
.
=
true
;
this
.
.
dispose
(
)
;
try
{
this
.
.
close
(
)
;
}
catch
{
}
try
{
this
.
.
dispose
(
)
;
}
catch
{
}
try
{
this
.
.
dispose
(
)
;
}
catch
{
}
}
}
}
class
TunnelConnection
extends
Disposable
{
private
readonly
=
this
.
_register
(
new
Emitter< void >
(
)
)
;
readonly
=
this
.
.
;
private
=
false
;
constructor
(
readonly
:
string
,
readonly
:
string
,
readonly
:
string
,
readonly
:
string
,
private
readonly
:
,
private
readonly
:
,
onMessage
:
(
:
string
)
=>
void
,
onSocketClose
:
(
:
)
=>
void
,
)
{
super
(
)
;
this
.
_register
(
this
.
.
onDidReceiveMessage
(
)
)
;
this
.
_register
(
this
.
.
onDidClose
(
=>
{
onSocketClose
(
)
;
this
.
dispose
(
)
;
}
)
)
;
}
relaySend
(
:
string
)
:
void
{
this
.
.
send
(
)
;
}
dispose
(
)
:
void
{
if
(
!
this
.
)
{
this
.
=
true
;
this
.
.
close
(
)
;
this
.
.
dispose
(
)
;
this
.
.
dispose
(
)
;
this
.
.
fire
(
)
;
}
super
.
dispose
(
)
;
}
}
export
class
TunnelAgentHostConnector
extends
Disposable
{
private
readonly
=
this
.
_register
(
new
Emitter< ITunnelRelayMessage>
(
)
)
;
readonly
:
<
>
=
this
.
.
;
private
readonly
=
this
.
_register
(
new
Emitter< string >
(
)
)
;
readonly
:
<
string
>
=
this
.
.
;
private
readonly
=
this
.
_register
(
new
DisposableMap< string , TunnelConnection>
(
)
)
;
private
readonly
=
this
.
_register
(
new
DisposableMap< string , PendingGatewaySelection>
(
)
)
;
constructor
(
private
readonly
:
,
private
readonly
:
,
private
readonly
:
,
)
{
super
(
)
;
}
async
connect
(
:
string
,
:
'github'
|
'microsoft'
,
:
string
,
:
string
)
:
Promise
<
>
{
this
.
closeTunnelConnections
(
,
'reconnecting'
)
;
this
.
.
info
(
` ${ LOG_PREFIX } Connecting to tunnel ${ tunnelId} in cluster ${ clusterId} ... `
)
;
const
=
await
this
.
.
getTunnel
(
,
,
,
)
;
if
(
!
)
{
throw
new
TunnelNotFoundError
(
)
;
}
const
{
}
=
;
const
=
await
.
createRelayClient
(
)
;
let
:
;
try
{
await
withTimeout
(
(
)
=>
.
connect
(
)
,
TUNNEL_STEP_TIMEOUT_MS
,
'tunnel relay connect'
)
;
this
.
.
info
(
` ${ LOG_PREFIX } Tunnel relay connected, waiting for port ${ TUNNEL_AGENT_HOST_PORT } ... `
)
;
await
withTimeout
(
(
)
=>
.
waitForForwardedPort
(
TUNNEL_AGENT_HOST_PORT
)
,
TUNNEL_STEP_TIMEOUT_MS
,
` wait for forwarded port ${ TUNNEL_AGENT_HOST_PORT } `
)
;
=
await
withTimeout
(
(
)
=>
.
connectToForwardedPort
(
TUNNEL_AGENT_HOST_PORT
)
,
TUNNEL_STEP_TIMEOUT_MS
,
` connect to forwarded port ${ TUNNEL_AGENT_HOST_PORT } `
)
;
this
.
.
info
(
` ${ LOG_PREFIX } Connected to forwarded port ${ TUNNEL_AGENT_HOST_PORT } `
)
;
}
catch
(
)
{
this
.
_disposeRelayClient
(
)
;
throw
;
}
const
=
await
deriveConnectionToken
(
)
;
const
=
new
TunnelTags
(
.
)
.
||
.
||
;
const
=
generateUuid
(
)
;
let
:
;
try
{
=
await
withTimeout
(
(
)
=>
this
.
.
open
(
,
` /?tkn= ${ encodeURIComponent ( connectionToken) } `
)
,
TUNNEL_STEP_TIMEOUT_MS
,
'WebSocket relay open'
,
)
;
this
.
.
info
(
` ${ LOG_PREFIX } WebSocket relay connected to agent host via tunnel `
)
;
}
catch
(
)
{
this
.
_disposeRelayClient
(
)
;
throw
;
}
this
.
_createConnection
(
,
` ${ TUNNEL_ADDRESS_PREFIX } ${ tunnelId} `
,
,
,
,
)
;
return
{
,
:
` ${ TUNNEL_ADDRESS_PREFIX } ${ tunnelId} `
,
,
,
:
{
:
'unknown'
,
:
''
,
:
'primary'
,
:
'external'
}
,
}
;
}
async
prepareSelection
(
:
string
,
:
'github'
|
'microsoft'
,
:
string
,
:
string
)
:
Promise
<
|
undefined
>
{
const
=
await
this
.
.
getTunnel
(
,
,
,
)
;
if
(
!
)
{
throw
new
TunnelNotFoundError
(
)
;
}
const
{
}
=
;
const
=
new
TunnelTags
(
.
)
;
if
(
.
<
TUNNEL_GATEWAY_MIN_PROTOCOL_VERSION
)
{
return
undefined
;
}
this
.
.
info
(
` ${ LOG_PREFIX } Preparing gateway selection for tunnel ${ tunnelId} in cluster ${ clusterId} ... `
)
;
const
=
await
.
createRelayClient
(
)
;
let
:
;
try
{
await
withTimeout
(
(
)
=>
.
connect
(
)
,
TUNNEL_STEP_TIMEOUT_MS
,
'tunnel relay connect'
)
;
await
withTimeout
(
(
)
=>
.
waitForForwardedPort
(
TUNNEL_AGENT_HOST_PORT
)
,
TUNNEL_STEP_TIMEOUT_MS
,
` wait for forwarded port ${ TUNNEL_AGENT_HOST_PORT } `
)
;
const
=
await
withTimeout
(
(
)
=>
.
connectToForwardedPort
(
TUNNEL_AGENT_HOST_PORT
)
,
TUNNEL_STEP_TIMEOUT_MS
,
` connect to forwarded port ${ TUNNEL_AGENT_HOST_PORT } `
)
;
=
await
withTimeout
(
(
)
=>
this
.
.
open
(
,
TUNNEL_GATEWAY_SELECT_PATH
)
,
TUNNEL_STEP_TIMEOUT_MS
,
'gateway selection WebSocket open'
)
;
}
catch
(
)
{
this
.
_disposeRelayClient
(
)
;
throw
;
}
let
:
string
;
try
{
=
await
withTimeout
(
(
)
=>
this
.
_readNextGatewayMessage
(
)
,
TUNNEL_STEP_TIMEOUT_MS
,
'gateway inventory message'
)
;
}
catch
(
)
{
this
.
_disposeSocket
(
)
;
this
.
_disposeRelayClient
(
)
;
throw
;
}
let
:
;
let
:
string
;
try
{
=
parseTunnelGatewayInventory
(
)
;
=
await
deriveConnectionToken
(
)
;
}
catch
(
)
{
this
.
_disposeSocket
(
)
;
this
.
_disposeRelayClient
(
)
;
throw
;
}
const
=
generateUuid
(
)
;
this
.
.
set
(
,
new
PendingGatewaySelection
(
` ${ TUNNEL_ADDRESS_PREFIX } ${ tunnelId} `
,
.
||
.
||
,
,
,
,
(
)
=>
{
this
.
.
warn
(
` ${ LOG_PREFIX } Gateway selection WebSocket for ${ selectionId} closed before a selection was made `
)
;
this
.
.
deleteAndDispose
(
)
;
}
,
)
)
;
return
{
,
}
;
}
async
completeSelection
(
:
string
,
:
)
:
Promise
<
>
{
const
=
this
.
.
deleteAndLeak
(
)
;
if
(
!
)
{
throw
new
Error
(
` ${ LOG_PREFIX } No pending gateway selection with id ${ selectionId} `
)
;
}
.
detach
(
)
;
let
:
<
typeof
>
;
try
{
.
.
send
(
JSON
.
stringify
(
)
)
;
const
=
await
withTimeout
(
(
)
=>
this
.
_readNextGatewayMessage
(
.
)
,
TUNNEL_STEP_TIMEOUT_MS
,
'gateway selection acknowledgement'
)
;
=
parseTunnelGatewaySelectionResponse
(
)
;
}
catch
(
)
{
this
.
_disposeSocket
(
.
)
;
this
.
_disposeRelayClient
(
.
)
;
throw
;
}
if
(
!
.
)
{
this
.
_disposeSocket
(
.
)
;
this
.
_disposeRelayClient
(
.
)
;
throw
createTunnelGatewaySelectionRejectedError
(
` ${ LOG_PREFIX } ${ response. error} `
)
;
}
const
=
generateUuid
(
)
;
this
.
_createConnection
(
,
.
,
.
,
.
,
.
,
.
)
;
this
.
.
info
(
` ${ LOG_PREFIX } Gateway selection ${ selectionId} completed: selected ${ response. selected. serverType} ${ response. selected. instanceId} `
)
;
return
{
,
:
.
,
:
.
,
:
.
,
:
.
}
;
}
async
cancelSelection
(
:
string
)
:
Promise
<
void
>
{
this
.
.
deleteAndDispose
(
)
;
}
async
relaySend
(
:
string
,
:
string
)
:
Promise
<
void
>
{
this
.
.
get
(
)
?.
relaySend
(
)
;
}
async
disconnect
(
:
string
)
:
Promise
<
void
>
{
this
.
.
deleteAndDispose
(
)
;
}
closeTunnelConnections
(
:
string
,
:
'deleting'
|
'reconnecting'
)
:
void
{
const
=
` ${ TUNNEL_ADDRESS_PREFIX } ${ tunnelId} `
;
for
(
const
[
,
]
of
this
.
)
{
if
(
.
===
)
{
this
.
.
info
(
` ${ LOG_PREFIX } Closing existing relay for tunnel ${ tunnelId} before ${ operation} `
)
;
this
.
.
deleteAndDispose
(
)
;
}
}
}
setPendingGatewaySelectionForTests
(
:
string
,
:
)
:
void
{
this
.
.
set
(
,
)
;
}
deletePendingGatewaySelectionForTests
(
:
string
)
:
void
{
this
.
.
deleteAndDispose
(
)
;
}
private
_createConnection
(
:
string
,
:
string
,
:
string
,
:
string
,
:
,
:
)
:
void
{
const
=
new
TunnelConnection
(
,
,
,
,
,
,
=>
this
.
.
fire
(
{
,
}
)
,
=>
this
.
.
info
(
` ${ LOG_PREFIX } WebSocket relay closed for connection ${ connectionId} ; code= ${ event. code} , reason= ${ event. reason || '(empty)' } `
)
,
)
;
const
=
.
onDidClose
(
(
)
=>
{
.
dispose
(
)
;
this
.
.
deleteAndLeak
(
)
;
this
.
.
fire
(
)
;
}
)
;
this
.
.
set
(
,
)
;
}
private
_readNextGatewayMessage
(
:
)
:
Promise
<
string
>
{
return
new
Promise
(
(
,
)
=>
{
const
:
[
]
=
[
]
;
let
=
false
;
const
cleanup
=
(
)
=>
{
for
(
const
of
.
splice
(
0
)
)
{
.
dispose
(
)
;
}
}
;
const
=
.
onDidReceiveMessage
(
=>
{
if
(
)
{
return
;
}
=
true
;
cleanup
(
)
;
resolve
(
)
;
}
)
;
if
(
)
{
.
dispose
(
)
;
return
;
}
.
push
(
)
;
const
=
.
onDidClose
(
=>
{
if
(
)
{
return
;
}
=
true
;
cleanup
(
)
;
if
(
.
)
{
reject
(
.
)
;
}
else
{
reject
(
new
Error
(
` ${ LOG_PREFIX } Gateway WebSocket closed before expected message; code= ${ event. code} , reason= ${ event. reason || '(empty)' } `
)
)
;
}
}
)
;
if
(
)
{
.
dispose
(
)
;
}
else
{
.
push
(
)
;
}
}
)
;
}
private
_disposeSocket
(
:
)
:
void
{
try
{
.
close
(
)
;
}
catch
{
}
try
{
.
dispose
(
)
;
}
catch
{
}
}
private
_disposeRelayClient
(
:
)
:
void
{
try
{
.
dispose
(
)
;
}
catch
{
}
}
}