@@ -180,41 +180,51 @@ exports.monitor = function(options) {
180
180
*/
181
181
io . on ( 'connection' , function ( socket ) {
182
182
var env = monitoring . getEnvironment ( ) ;
183
- var result = [ ] ;
183
+ var envData = [ ] ;
184
184
var json ;
185
185
for ( var entry in env ) {
186
186
switch ( entry ) {
187
187
case 'command.line' :
188
188
json = { } ;
189
189
json [ 'Parameter' ] = 'Command Line' ;
190
190
json [ 'Value' ] = env [ entry ] ;
191
- result . push ( json ) ;
191
+ envData . push ( json ) ;
192
192
break ;
193
193
case 'environment.HOSTNAME' :
194
194
json = { } ;
195
195
json [ 'Parameter' ] = 'Hostname' ;
196
196
json [ 'Value' ] = env [ entry ] ;
197
- result . push ( json ) ;
197
+ envData . push ( json ) ;
198
198
break ;
199
199
case 'os.arch' :
200
200
json = { } ;
201
201
json [ 'Parameter' ] = 'OS Architecture' ;
202
202
json [ 'Value' ] = env [ entry ] ;
203
- result . push ( json ) ;
203
+ envData . push ( json ) ;
204
204
break ;
205
205
case 'number.of.processors' :
206
206
json = { } ;
207
207
json [ 'Parameter' ] = 'Number of Processors' ;
208
208
json [ 'Value' ] = env [ entry ] ;
209
- result . push ( json ) ;
209
+ envData . push ( json ) ;
210
210
break ;
211
211
default :
212
212
break ;
213
213
}
214
214
}
215
- socket . emit ( 'environment' , JSON . stringify ( result ) ) ;
215
+ // Send static data ASAP but re-send below in case the client isn't ready.
216
+ socket . emit ( 'environment' , JSON . stringify ( envData ) ) ;
216
217
socket . emit ( 'title' , JSON . stringify ( { title : title , docs : docs } ) ) ;
217
218
socket . emit ( 'status' , JSON . stringify ( { profiling_enabled : profiling_enabled } ) ) ;
219
+
220
+ // When the client confirms it's connected and has listeners ready,
221
+ // re-send the static data.
222
+ socket . on ( 'connected' , ( ) => {
223
+ socket . emit ( 'environment' , JSON . stringify ( envData ) ) ;
224
+ socket . emit ( 'title' , JSON . stringify ( { title : title , docs : docs } ) ) ;
225
+ socket . emit ( 'status' , JSON . stringify ( { profiling_enabled : profiling_enabled } ) ) ;
226
+ } ) ;
227
+
218
228
/*
219
229
* Support enabling/disabling profiling data
220
230
*/
0 commit comments