@@ -6,16 +6,24 @@ import { EmulatorRegistry } from "./registry";
6
6
import { FirebaseError } from "../error" ;
7
7
import { EmulatorLogger } from "./emulatorLogger" ;
8
8
import { Constants } from "./constants" ;
9
- import { emulatorSession } from "../track" ;
9
+ import { AnalyticsSession , emulatorSession } from "../track" ;
10
10
import { ExpressBasedEmulator } from "./ExpressBasedEmulator" ;
11
11
import { ALL_EXPERIMENTS , ExperimentName , isEnabled } from "../experiments" ;
12
- import { EmulatorHub } from "./hub" ;
12
+ import { EmulatorHub , GetEmulatorsResponse } from "./hub" ;
13
+ import { maybeUsePortForwarding } from "./env" ;
13
14
14
15
export interface EmulatorUIOptions {
15
16
listen : ListenSpec [ ] ;
16
17
projectId : string ;
17
18
}
18
19
20
+ // Response shape for /api/config endpoint. Contains info about which emulators are running and where.
21
+ interface EmulatorConfigInfo extends GetEmulatorsResponse {
22
+ projectId : string ;
23
+ experiments : string [ ] ;
24
+ analytics ?: AnalyticsSession ;
25
+ }
26
+
19
27
export class EmulatorUI extends ExpressBasedEmulator {
20
28
constructor ( private args : EmulatorUIOptions ) {
21
29
super ( {
@@ -49,27 +57,18 @@ export class EmulatorUI extends ExpressBasedEmulator {
49
57
50
58
// Exposes the host and port of various emulators to facilitate accessing
51
59
// them using client SDKs. For features that involve multiple emulators or
52
- // hard to accomplish using client SDKs, consider adding an API below.
60
+ // hard to accomplish using client SDKs, consider adding an API below
53
61
app . get (
54
62
"/api/config" ,
55
63
this . jsonHandler ( ( ) => {
56
- const json = {
64
+ const emulatorInfos = ( hub ! as EmulatorHub ) . getRunningEmulatorsMapping ( ) ;
65
+ maybeUsePortForwarding ( Object . values ( emulatorInfos ) ) ;
66
+ const json : EmulatorConfigInfo = {
57
67
projectId,
58
- experiments : [ ] ,
59
- ...( hub ! as EmulatorHub ) . getRunningEmulatorsMapping ( ) ,
68
+ experiments : enabledExperiments ?? [ ] ,
69
+ analytics : emulatorGaSession ,
70
+ ...emulatorInfos ,
60
71
} ;
61
-
62
- // Googlers: see go/firebase-emulator-ui-usage-collection-design?pli=1#heading=h.jwz7lj6r67z8
63
- // for more detail
64
- if ( emulatorGaSession ) {
65
- json . analytics = emulatorGaSession ;
66
- }
67
-
68
- // pick up any experiments enabled with `firebase experiment:enable`
69
- if ( enabledExperiments ) {
70
- json . experiments = enabledExperiments ;
71
- }
72
-
73
72
return Promise . resolve ( json ) ;
74
73
} ) ,
75
74
) ;
0 commit comments