@@ -59,6 +59,9 @@ export class WebChannelConnection extends RestConnection {
5959 private readonly useFetchStreams : boolean ;
6060 private readonly longPollingOptions : ExperimentalLongPollingOptions ;
6161
62+ /** A collection of open WebChannel instances */
63+ private webChannels : WebChannel [ ] = [ ] ;
64+
6265 constructor ( info : DatabaseInfo ) {
6366 super ( info ) ;
6467 this . forceLongPolling = info . forceLongPolling ;
@@ -239,6 +242,7 @@ export class WebChannelConnection extends RestConnection {
239242 request
240243 ) ;
241244 const channel = webchannelTransport . createWebChannel ( url , request ) ;
245+ this . trackWebChannel ( channel ) ;
242246
243247 // WebChannel supports sending the first message with the handshake - saving
244248 // a network round trip. However, it will have to call send in the same
@@ -321,6 +325,7 @@ export class WebChannelConnection extends RestConnection {
321325 `RPC '${ rpcName } ' stream ${ streamId } transport closed`
322326 ) ;
323327 streamBridge . callOnClose ( ) ;
328+ this . untrackWebChannel ( channel ) ;
324329 }
325330 } ) ;
326331
@@ -427,4 +432,22 @@ export class WebChannelConnection extends RestConnection {
427432 } , 0 ) ;
428433 return streamBridge ;
429434 }
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+ }
430453}
0 commit comments