@@ -180,41 +180,51 @@ exports.monitor = function(options) {
180180 */
181181 io . on ( 'connection' , function ( socket ) {
182182 var env = monitoring . getEnvironment ( ) ;
183- var result = [ ] ;
183+ var envData = [ ] ;
184184 var json ;
185185 for ( var entry in env ) {
186186 switch ( entry ) {
187187 case 'command.line' :
188188 json = { } ;
189189 json [ 'Parameter' ] = 'Command Line' ;
190190 json [ 'Value' ] = env [ entry ] ;
191- result . push ( json ) ;
191+ envData . push ( json ) ;
192192 break ;
193193 case 'environment.HOSTNAME' :
194194 json = { } ;
195195 json [ 'Parameter' ] = 'Hostname' ;
196196 json [ 'Value' ] = env [ entry ] ;
197- result . push ( json ) ;
197+ envData . push ( json ) ;
198198 break ;
199199 case 'os.arch' :
200200 json = { } ;
201201 json [ 'Parameter' ] = 'OS Architecture' ;
202202 json [ 'Value' ] = env [ entry ] ;
203- result . push ( json ) ;
203+ envData . push ( json ) ;
204204 break ;
205205 case 'number.of.processors' :
206206 json = { } ;
207207 json [ 'Parameter' ] = 'Number of Processors' ;
208208 json [ 'Value' ] = env [ entry ] ;
209- result . push ( json ) ;
209+ envData . push ( json ) ;
210210 break ;
211211 default :
212212 break ;
213213 }
214214 }
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 ) ) ;
216217 socket . emit ( 'title' , JSON . stringify ( { title : title , docs : docs } ) ) ;
217218 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+
218228 /*
219229 * Support enabling/disabling profiling data
220230 */
0 commit comments