@@ -60,7 +60,7 @@ export class WebChannelConnection extends RestConnection {
6060 private readonly longPollingOptions : ExperimentalLongPollingOptions ;
6161
6262 /** A collection of open WebChannel instances */
63- private webChannels : WebChannel [ ] = [ ] ;
63+ private openWebChannels : WebChannel [ ] = [ ] ;
6464
6565 constructor ( info : DatabaseInfo ) {
6666 super ( info ) ;
@@ -242,7 +242,7 @@ export class WebChannelConnection extends RestConnection {
242242 request
243243 ) ;
244244 const channel = webchannelTransport . createWebChannel ( url , request ) ;
245- this . trackWebChannel ( channel ) ;
245+ this . addOpenWebChannel ( channel ) ;
246246
247247 // WebChannel supports sending the first message with the handshake - saving
248248 // a network round trip. However, it will have to call send in the same
@@ -325,7 +325,7 @@ export class WebChannelConnection extends RestConnection {
325325 `RPC '${ rpcName } ' stream ${ streamId } transport closed`
326326 ) ;
327327 streamBridge . callOnClose ( ) ;
328- this . untrackWebChannel ( channel ) ;
328+ this . removeOpenWebChannel ( channel ) ;
329329 }
330330 } ) ;
331331
@@ -437,16 +437,26 @@ export class WebChannelConnection extends RestConnection {
437437 * Closes and cleans up any resources associated with the connection.
438438 */
439439 terminate ( ) : void {
440- this . webChannels . forEach ( webChannel => webChannel . close ( ) ) ;
441- this . webChannels = [ ] ;
440+ // If the Firestore instance is terminated, we will explicitly
441+ // close any remaining open WebChannel instances.
442+ this . openWebChannels . forEach ( webChannel => webChannel . close ( ) ) ;
443+ this . openWebChannels = [ ] ;
442444 }
443445
444- trackWebChannel ( webChannel : WebChannel ) : void {
445- this . webChannels . push ( webChannel ) ;
446+ /**
447+ * Add a WebChannel instance to the collection of open instances.
448+ * @param webChannel
449+ */
450+ addOpenWebChannel ( webChannel : WebChannel ) : void {
451+ this . openWebChannels . push ( webChannel ) ;
446452 }
447453
448- untrackWebChannel ( webChannel : WebChannel ) : void {
449- this . webChannels = this . webChannels . filter (
454+ /**
455+ * Remove a WebChannel instance to the collection of open instances.
456+ * @param webChannel
457+ */
458+ removeOpenWebChannel ( webChannel : WebChannel ) : void {
459+ this . openWebChannels = this . openWebChannels . filter (
450460 instance => instance === webChannel
451461 ) ;
452462 }
0 commit comments