@@ -59,6 +59,9 @@ export class WebChannelConnection extends RestConnection {
59
59
private readonly useFetchStreams : boolean ;
60
60
private readonly longPollingOptions : ExperimentalLongPollingOptions ;
61
61
62
+ /** A collection of open WebChannel instances */
63
+ private webChannels : WebChannel [ ] = [ ] ;
64
+
62
65
constructor ( info : DatabaseInfo ) {
63
66
super ( info ) ;
64
67
this . forceLongPolling = info . forceLongPolling ;
@@ -239,6 +242,7 @@ export class WebChannelConnection extends RestConnection {
239
242
request
240
243
) ;
241
244
const channel = webchannelTransport . createWebChannel ( url , request ) ;
245
+ this . trackWebChannel ( channel ) ;
242
246
243
247
// WebChannel supports sending the first message with the handshake - saving
244
248
// a network round trip. However, it will have to call send in the same
@@ -321,6 +325,7 @@ export class WebChannelConnection extends RestConnection {
321
325
`RPC '${ rpcName } ' stream ${ streamId } transport closed`
322
326
) ;
323
327
streamBridge . callOnClose ( ) ;
328
+ this . untrackWebChannel ( channel ) ;
324
329
}
325
330
} ) ;
326
331
@@ -427,4 +432,22 @@ export class WebChannelConnection extends RestConnection {
427
432
} , 0 ) ;
428
433
return streamBridge ;
429
434
}
435
+
436
+ /**
437
+ * Closes and cleans up any resources associated with the connection.
438
+ */
439
+ terminate ( ) : void {
440
+ this . webChannels . forEach ( webChannel => webChannel . close ( ) ) ;
441
+ this . webChannels = [ ] ;
442
+ }
443
+
444
+ trackWebChannel ( webChannel : WebChannel ) : void {
445
+ this . webChannels . push ( webChannel ) ;
446
+ }
447
+
448
+ untrackWebChannel ( webChannel : WebChannel ) : void {
449
+ this . webChannels = this . webChannels . filter (
450
+ instance => instance === webChannel
451
+ ) ;
452
+ }
430
453
}
0 commit comments