@@ -9,6 +9,22 @@ <h1>Hello, World!</h1>
99 let headers = new Map ( ) ;
1010 let lineNumbers = new Map ( ) ;
1111 let running = new Set ( ) ;
12+ let requestCount = 0 ;
13+
14+ function merge ( a , b ) {
15+ var r = { } ;
16+ for ( var k in a ) {
17+ if ( a . hasOwnProperty ( k ) ) {
18+ r [ k ] = a [ k ] ;
19+ }
20+ }
21+ for ( var k in b ) {
22+ if ( b . hasOwnProperty ( k ) ) {
23+ r [ k ] = b [ k ] ;
24+ }
25+ }
26+ return r ;
27+ }
1228
1329
1430 // Display a message so ther user can see it
@@ -38,8 +54,13 @@ <h1>Hello, World!</h1>
3854 throw new Error ( "Have no record of " + streamName ) ;
3955 }
4056 return headers . get ( streamName ) . reduce (
41- ( acc , k , i ) => {
42- return { ...acc , [ k ] : csvRow [ i ] } ;
57+ function ( acc , k , i ) {
58+ const r = { } ;
59+ if ( ( ! csvRow ) || ( ! csvRow . length ) || ( csvRow . length < i ) ) {
60+ return acc ;
61+ }
62+ r [ k ] = csvRow [ i ] ;
63+ return merge ( acc , r ) ;
4364 } ,
4465 { }
4566 ) ;
@@ -65,7 +86,7 @@ <h1>Hello, World!</h1>
6586
6687 // Decorate the data received with the stream name and the row number.
6788 lineNumbers . set ( msg . name , lineNumbers . get ( msg . name ) + 1 ) ;
68- const j = Object . assign (
89+ const j = merge (
6990 {
7091 "Stream Name" : msg . name ,
7192 "Line Number" : lineNumbers . get ( msg . name ) ,
@@ -83,16 +104,26 @@ <h1>Hello, World!</h1>
83104
84105 // If there is a parameter "request_count" then use that as the amount of
85106 // lines to request.
107+
108+ function filterForRequestCount ( ob ) {
109+ if ( ob && ob . name && ob . name == "request_count" ) {
110+ return true ;
111+ }
112+ return false ;
113+ }
114+
86115 if ( msg . type == "params" ) {
87- msg . params . filter ( ( { name } ) => name == "request_count" ) . forEach ( ( { value } ) => {
88- requestCount = parseInt ( value , 10 ) ;
89- } ) ;
116+ msg . params . filter ( filterForRequestCount ) . forEach (
117+ function ( ob ) {
118+ requestCount = parseInt ( ob . value , 10 ) ;
119+ }
120+ ) ;
90121 send ( { "msg" :"streamList" } ) ;
91122 }
92123
93124 // Start all streams that don't include the word "in".
94125 if ( msg . type == "streamList" ) {
95- msg . streams . forEach ( ( strm ) => {
126+ msg . streams . forEach ( function ( strm ) {
96127 send ( { msg : "streamStart" , name : strm , count : requestCount } ) ;
97128 running . add ( strm ) ;
98129 } ) ;
@@ -101,8 +132,8 @@ <h1>Hello, World!</h1>
101132 // All data from WV Linewise is processed immediately (with no promises or
102133 // callbacks) so as soon as a stream pauses, start it right back up again.
103134 if ( msg . type == "paused" ) {
104- setTimeout ( ( ) => {
105- send ( { "msg" :"streamContinue" , "name" :msg . name } ) ;
135+ setTimeout ( function ( ) {
136+ send ( { "msg" : "streamContinue" , "name" :msg . name } ) ;
106137 } , 1000 ) ;
107138 }
108139
@@ -115,21 +146,22 @@ <h1>Hello, World!</h1>
115146 running . delete ( msg . name ) ;
116147 if ( running . size == 0 ) {
117148 disp ( 'SENDING \'{"msg":"exit", "status": 0}\' - in 10 seconds' ) ;
118- setTimeout ( ( ) => {
149+ setTimeout ( function ( ) {
119150 send ( { "msg" :"exit" , "status" : 0 } ) ;
120151 } , 10000 ) ;
121152 }
122153 }
123154
124155 }
125156
126- window . onerror = ( e ) => disp ( e && e . msg || e ) ;
157+ window . onerror = function ( e ) { disp ( e && e . msg || e ) } ;
127158
128- setInterval ( ( ) => {
159+ setInterval ( function ( ) {
129160 document . querySelector ( "h1" ) . innerText = new Date ( ) ;
130161 } , 1000 ) ;
131162
132163 send ( { "msg" :"params" } ) ;
133164
134165 </ script >
135166</ html >
167+
0 commit comments