Skip to content

Commit cab7db0

Browse files
feat: implement the version 4 of the protocol
See https://github.com/socketio/engine.io-protocol for the list of changes. Note: The 'base64-arraybuffer' dependency must now be explicitly included by the client (not needed by the server).
1 parent 415332f commit cab7db0

25 files changed

+2250
-2639
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
node_modules
2+
.nyc_output

Makefile

Lines changed: 0 additions & 17 deletions
This file was deleted.

benchmarks/index.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ suite
1515
});
1616
}, { defer: true })
1717
.add('encode payload as string', (deferred) => {
18-
parser.encodePayload([{ type: 'message', data: 'test1' }, { type: 'message', data: 'test2' }], true, () => {
18+
parser.encodePayload([{ type: 'message', data: 'test1' }, { type: 'message', data: 'test2' }], () => {
1919
deferred.resolve();
2020
});
2121
}, { defer: true })
2222
.add('encode payload as binary', (deferred) => {
23-
parser.encodePayload([{ type: 'message', data: 'test' }, { type: 'message', data: Buffer.from([1, 2, 3, 4]) }], true, () => {
23+
parser.encodePayload([{ type: 'message', data: 'test' }, { type: 'message', data: Buffer.from([1, 2, 3, 4]) }], () => {
2424
deferred.resolve();
2525
})
2626
}, { defer: true })
@@ -32,15 +32,13 @@ suite
3232
})
3333
.add('decode payload from string', (deferred) => {
3434
let i = 0;
35-
parser.decodePayload('6:4test16:4test2', () => {
36-
if (++i === 2) deferred.resolve();
37-
})
35+
parser.decodePayload('test1\x1etest2');
36+
deferred.resolve();
3837
}, { defer: true })
3938
.add('decode payload from binary', (deferred) => {
40-
let i = 0;
41-
parser.decodePayload(Buffer.from([0x00, 0x05, 0xff, 0x34, 0x74, 0x65, 0x73, 0x74, 0x01, 0x05, 0xff, 0x04, 0x01, 0x02, 0x03, 0x04]), () => {
42-
if (++i === 1) deferred.resolve();
43-
})
39+
parser.decodePayload('test1\x1ebAQIDBA==', 'nodebuffer');
40+
deferred.resolve();
41+
4442
}, { defer: true })
4543
.on('cycle', function(event) {
4644
console.log(String(event.target));

benchmarks/results.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
2+
Current
3+
4+
```
5+
encode packet as string x 175,944 ops/sec ±5.64% (25 runs sampled)
6+
encode packet as binary x 176,945 ops/sec ±16.60% (51 runs sampled)
7+
encode payload as string x 47,836 ops/sec ±9.84% (34 runs sampled)
8+
encode payload as binary x 123,987 ops/sec ±22.03% (53 runs sampled)
9+
decode packet from string x 27,680,068 ops/sec ±0.92% (89 runs sampled)
10+
decode packet from binary x 7,747,089 ops/sec ±1.65% (83 runs sampled)
11+
decode payload from string x 198,908 ops/sec ±27.95% (23 runs sampled)
12+
decode payload from binary x 179,574 ops/sec ±41.32% (23 runs sampled)
13+
```
14+
15+
Results from parser v2 / protocol v3
16+
17+
```
18+
encode packet as string x 228,038 ops/sec ±9.28% (40 runs sampled)
19+
encode packet as binary x 163,392 ops/sec ±8.72% (67 runs sampled)
20+
encode payload as string x 73,457 ops/sec ±14.83% (56 runs sampled)
21+
encode payload as binary x 71,400 ops/sec ±3.63% (75 runs sampled)
22+
decode packet from string x 22,712,325 ops/sec ±3.14% (90 runs sampled)
23+
decode packet from binary x 4,849,781 ops/sec ±1.27% (87 runs sampled)
24+
decode payload from string x 82,514 ops/sec ±49.93% (22 runs sampled)
25+
decode payload from binary x 149,206 ops/sec ±25.90% (76 runs sampled)
26+
```

0 commit comments

Comments
 (0)