@@ -51,6 +51,7 @@ HTMLFile.prototype.data = function (path, opts, fn) {
51
51
52
52
return this . request ( path , opts , function ( res ) {
53
53
var buf = ''
54
+ , messages = 0
54
55
, state = 0 ;
55
56
56
57
res . on ( 'data' , function ( chunk ) {
@@ -79,7 +80,7 @@ HTMLFile.prototype.data = function (path, opts, fn) {
79
80
var data = buf . slice ( 0 , buf . indexOf ( foot ) )
80
81
, obj = JSON . parse ( data ) ;
81
82
82
- fn ( obj === '' ? obj : parser . decodePayload ( obj ) ) ;
83
+ fn ( obj === '' ? obj : parser . decodePayload ( obj ) , ++ messages ) ;
83
84
84
85
buf = buf . substr ( data . length + foot . length ) ;
85
86
state = 1 ;
@@ -134,10 +135,19 @@ module.exports = {
134
135
} ) ;
135
136
136
137
cl . handshake ( function ( sid ) {
137
- cl . data ( '/socket.io/{protocol}/htmlfile/' + sid , function ( msgs ) {
138
- msgs . should . have . length ( 1 ) ;
139
- msgs [ 0 ] . type . should . eql ( 'heartbeat' ) ;
140
- beat = true ;
138
+ cl . data ( '/socket.io/{protocol}/htmlfile/' + sid , function ( msgs , i ) {
139
+ switch ( i ) {
140
+ case 1 :
141
+ msgs . should . have . length ( 1 ) ;
142
+ msgs [ 0 ] . type . should . eql ( 'connect' ) ;
143
+ msgs [ 0 ] . endpoint . should . eql ( '' ) ;
144
+ break ;
145
+
146
+ case 2 :
147
+ msgs . should . have . length ( 1 ) ;
148
+ msgs [ 0 ] . type . should . eql ( 'heartbeat' ) ;
149
+ beat = true ;
150
+ } ;
141
151
} ) ;
142
152
} ) ;
143
153
} ,
@@ -166,13 +176,25 @@ module.exports = {
166
176
} ) ;
167
177
168
178
cl . handshake ( function ( sid ) {
169
- cl . data ( '/socket.io/{protocol}/htmlfile/' + sid , function ( msgs ) {
170
- heartbeats ++ ;
179
+ cl . data ( '/socket.io/{protocol}/htmlfile/' + sid , function ( msgs , i ) {
180
+ switch ( i ) {
181
+ case 1 :
182
+ msgs . should . have . length ( 1 ) ;
183
+ msgs [ 0 ] . type . should . eql ( 'connect' ) ;
184
+ msgs [ 0 ] . endpoint . should . eql ( '' ) ;
185
+ break ;
186
+
187
+ default :
188
+ msgs . should . have . length ( 1 ) ;
189
+ msgs [ 0 ] . type . should . eql ( 'heartbeat' ) ;
190
+
191
+ heartbeats ++ ;
171
192
172
- if ( heartbeats == 1 ) {
173
- cl . post ( '/socket.io/{protocol}/htmlfile/' + sid , parser . encodePacket ( {
174
- type : 'heartbeat'
175
- } ) ) ;
193
+ if ( heartbeats == 1 ) {
194
+ cl . post ( '/socket.io/{protocol}/htmlfile/' + sid , parser . encodePacket ( {
195
+ type : 'heartbeat'
196
+ } ) ) ;
197
+ }
176
198
}
177
199
} ) ;
178
200
} ) ;
@@ -215,9 +237,9 @@ module.exports = {
215
237
216
238
setTimeout ( function ( ) {
217
239
cl . end ( ) ;
218
- } , 10 ) ;
219
- } , 10 ) ;
220
- } , 10 ) ;
240
+ } , 20 ) ;
241
+ } , 20 ) ;
242
+ } , 20 ) ;
221
243
} ) ;
222
244
} ,
223
245
@@ -259,9 +281,9 @@ module.exports = {
259
281
260
282
setTimeout ( function ( ) {
261
283
cl . end ( ) ;
262
- } , 10 ) ;
263
- } , 10 ) ;
264
- } , 10 ) ;
284
+ } , 20 ) ;
285
+ } , 20 ) ;
286
+ } , 20 ) ;
265
287
} ) ;
266
288
} ,
267
289
@@ -303,9 +325,9 @@ module.exports = {
303
325
304
326
setTimeout ( function ( ) {
305
327
cl . end ( ) ;
306
- } , 10 ) ;
307
- } , 10 ) ;
308
- } , 10 ) ;
328
+ } , 20 ) ;
329
+ } , 20 ) ;
330
+ } , 20 ) ;
309
331
} ) ;
310
332
} ,
311
333
@@ -329,14 +351,23 @@ module.exports = {
329
351
} ) ;
330
352
331
353
cl . handshake ( function ( sid ) {
332
- cl . data ( '/socket.io/{protocol}/htmlfile/' + sid , function ( msgs ) {
333
- msgs . should . have . length ( 1 ) ;
334
- msgs [ 0 ] . should . eql ( {
335
- type : 'message'
336
- , data : 'woot'
337
- , endpoint : ''
338
- } ) ;
339
- cl . end ( ) ;
354
+ cl . data ( '/socket.io/{protocol}/htmlfile/' + sid , function ( msgs , i ) {
355
+ switch ( i ) {
356
+ case 1 :
357
+ msgs . should . have . length ( 1 ) ;
358
+ msgs [ 0 ] . type . should . eql ( 'connect' ) ;
359
+ msgs [ 0 ] . endpoint . should . eql ( '' ) ;
360
+ break ;
361
+
362
+ case 2 :
363
+ msgs . should . have . length ( 1 ) ;
364
+ msgs [ 0 ] . should . eql ( {
365
+ type : 'message'
366
+ , data : 'woot'
367
+ , endpoint : ''
368
+ } ) ;
369
+ cl . end ( ) ;
370
+ }
340
371
} ) ;
341
372
} ) ;
342
373
} ,
@@ -361,14 +392,23 @@ module.exports = {
361
392
} ) ;
362
393
363
394
cl . handshake ( function ( sid ) {
364
- cl . data ( '/socket.io/{protocol}/htmlfile/' + sid , function ( msgs ) {
365
- msgs . should . have . length ( 1 ) ;
366
- msgs [ 0 ] . should . eql ( {
367
- type : 'json'
368
- , data : [ 'woot' ]
369
- , endpoint : ''
370
- } ) ;
371
- cl . end ( ) ;
395
+ cl . data ( '/socket.io/{protocol}/htmlfile/' + sid , function ( msgs , i ) {
396
+ switch ( i ) {
397
+ case 1 :
398
+ msgs . should . have . length ( 1 ) ;
399
+ msgs [ 0 ] . type . should . eql ( 'connect' ) ;
400
+ msgs [ 0 ] . endpoint . should . eql ( '' ) ;
401
+ break ;
402
+
403
+ case 2 :
404
+ msgs . should . have . length ( 1 ) ;
405
+ msgs [ 0 ] . should . eql ( {
406
+ type : 'json'
407
+ , data : [ 'woot' ]
408
+ , endpoint : ''
409
+ } ) ;
410
+ cl . end ( ) ;
411
+ }
372
412
} ) ;
373
413
} ) ;
374
414
} ,
@@ -393,15 +433,24 @@ module.exports = {
393
433
} ) ;
394
434
395
435
cl . handshake ( function ( sid ) {
396
- cl . data ( '/socket.io/{protocol}/htmlfile/' + sid , function ( msgs ) {
397
- msgs . should . have . length ( 1 ) ;
398
- msgs [ 0 ] . should . eql ( {
399
- type : 'event'
400
- , name : 'aaa'
401
- , endpoint : ''
402
- , args : [ ]
403
- } ) ;
404
- cl . end ( ) ;
436
+ cl . data ( '/socket.io/{protocol}/htmlfile/' + sid , function ( msgs , i ) {
437
+ switch ( i ) {
438
+ case 1 :
439
+ msgs . should . have . length ( 1 ) ;
440
+ msgs [ 0 ] . type . should . eql ( 'connect' ) ;
441
+ msgs [ 0 ] . endpoint . should . eql ( '' ) ;
442
+ break ;
443
+
444
+ case 2 :
445
+ msgs . should . have . length ( 1 ) ;
446
+ msgs [ 0 ] . should . eql ( {
447
+ type : 'event'
448
+ , name : 'aaa'
449
+ , endpoint : ''
450
+ , args : [ ]
451
+ } ) ;
452
+ cl . end ( ) ;
453
+ }
405
454
} ) ;
406
455
} ) ;
407
456
}
0 commit comments