@@ -60,7 +60,7 @@ export class WebChannelConnection extends RestConnection {
60
60
private readonly longPollingOptions : ExperimentalLongPollingOptions ;
61
61
62
62
/** A collection of open WebChannel instances */
63
- private webChannels : WebChannel [ ] = [ ] ;
63
+ private openWebChannels : WebChannel [ ] = [ ] ;
64
64
65
65
constructor ( info : DatabaseInfo ) {
66
66
super ( info ) ;
@@ -242,7 +242,7 @@ export class WebChannelConnection extends RestConnection {
242
242
request
243
243
) ;
244
244
const channel = webchannelTransport . createWebChannel ( url , request ) ;
245
- this . trackWebChannel ( channel ) ;
245
+ this . addOpenWebChannel ( channel ) ;
246
246
247
247
// WebChannel supports sending the first message with the handshake - saving
248
248
// a network round trip. However, it will have to call send in the same
@@ -325,7 +325,7 @@ export class WebChannelConnection extends RestConnection {
325
325
`RPC '${ rpcName } ' stream ${ streamId } transport closed`
326
326
) ;
327
327
streamBridge . callOnClose ( ) ;
328
- this . untrackWebChannel ( channel ) ;
328
+ this . removeOpenWebChannel ( channel ) ;
329
329
}
330
330
} ) ;
331
331
@@ -437,16 +437,26 @@ export class WebChannelConnection extends RestConnection {
437
437
* Closes and cleans up any resources associated with the connection.
438
438
*/
439
439
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 = [ ] ;
442
444
}
443
445
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 ) ;
446
452
}
447
453
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 (
450
460
instance => instance === webChannel
451
461
) ;
452
462
}
0 commit comments