Damien Arrachequesne
08cff77a48
chore: bump prettier to version 3
...
This change is necessary to be able to write "import type { ... }".
2024-02-05 18:20:30 +01:00
Damien Arrachequesne
9efa1d0aec
test: add more stream decoding tests
2023-08-05 00:34:20 +02:00
Damien Arrachequesne
0b5e98591e
refactor: prepend a header to each WebTransport chunk
...
This commit updates the format of the header added in [1], in order to
match the format used for a WebSocket frame ([2]).
Two advantages:
- small payloads only need 1 byte instead of 4
- payloads larger than 2^31 bytes are supported
[1]: 6142324fa6
[2]: https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API/Writing_WebSocket_servers#decoding_payload_length
2023-08-02 00:29:45 +02:00
Damien Arrachequesne
6142324fa6
feat: prepend a header to each WebTransport chunk
...
WebTransport is a stream-based protocol, so chunking boundaries are not
always preserved.
That's why we will now prepend a 4-bytes header to each chunk:
- first bit indicates whether the payload is plain text (0) or binary (1)
- next 31 bits indicate the length of the payload
See also: https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API/Writing_WebSocket_servers#format
2023-07-31 08:09:27 +02:00
Damien Arrachequesne
bed70a4f25
feat: implement WebTransport-related encoding/decoding
2023-06-11 07:41:51 +02:00
Mauricio Narvaez
351ba8245b
fix: properly encode empty buffer in base64 encoding ( #131 )
...
An empty buffer was encoded into `bundefined` instead of `b`
(reproduced on Chrome v108 / Ubuntu).
Co-authored-by: Mauricio Narvaez <nvz@fb.com >
2023-01-06 11:26:29 +01:00
Damien Arrachequesne
ad5bd7ddf5
refactor: add additional types
...
Merged from https://github.com/socketio/engine.io/pull/630
2022-01-17 10:23:16 +01:00
Damien Arrachequesne
e4d9fce4d8
chore: migrate to TypeScript
...
This change introduces an ESM build which will allow tree shaking. A
CJS build is also provided for backward compatibility.
2021-10-01 10:39:52 +02:00
Damien Arrachequesne
78cd3bc7b9
test: remove duplicate test
2021-08-29 08:05:05 +02:00
Damien Arrachequesne
6d7dd76130
fix: respect the offset and length of TypedArray objects
...
The parser now returns the TypedArray object instead of the underlying
array buffer, so its offset and length are now taken in account (which
is the behavior of the classic WebSocket implementation).
Notes:
- this was already the case for the Node.js implementation
- in v3, the TypedArray object was always converted to an array buffer
because a byte was added at the beginning ("message" type)
- we could also have used "data.slice().buffer", but it would have
resulted in the copy of the buffer
Related:
- https://github.com/socketio/engine.io-parser/issues/122
- https://github.com/socketio/engine.io-client/issues/677
2021-08-29 07:54:03 +02:00
Damien Arrachequesne
cab7db0404
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).
2020-05-19 15:07:53 +02:00
Damien Arrachequesne
415332fc7c
test: actually test empty payload handling ( #113 )
...
Fixes https://github.com/socketio/engine.io-parser/issues/112
2020-04-15 14:53:41 +02:00
Damien Arrachequesne
a947ae59a2
feat: remove packet type when encoding binary packets
...
Only packets of 'message' type can contain binary data, so it makes sense to remove the prefix in
order to avoid the concatenation of the packet type.
Breaking change: the packet containing binary data will now be sent without any transformation
Protocol v3: { type: 'message', data: <Buffer 01 02 03> } => <Buffer 04 01 02 03>
Protocol v4: { type: 'message', data: <Buffer 01 02 03> } => <Buffer 01 02 03>
2020-01-14 21:54:05 +01:00
Damien Arrachequesne
744bf40d4f
refactor: migrate to ES6 syntax and use prettier to format code
2020-01-14 13:28:12 +01:00
Matthias Ludwig
72f7463be9
[test] fix a typo in the tests ( #111 )
...
should encode payloads as string: there is no type 'post'.
2019-09-13 10:50:31 +02:00
Matthias Ludwig
e9a20cb1ca
[test] ensure the message packet is properly coerced to string ( #110 )
...
result is string '1' not number1
2019-09-13 10:49:08 +02:00
Damien Arrachequesne
aedf8eb29e
[refactor] Use Buffer.allocUnsafe instead of new Buffer ( #104 )
...
Breaking change: drop support for Node.js 4 (since Buffer.allocUnsafe was added in v5.10.0)
Reference: https://nodejs.org/docs/latest/api/buffer.html#buffer_class_method_buffer_allocunsafe_size
2019-03-19 23:56:03 +01:00
Damien Arrachequesne
ebdf467371
[test] Add a basic test for UTF-8 encoding/decoding ( #106 )
2018-11-01 06:26:13 +01:00
Damien Arrachequesne
292c00c183
[fix] Encode string payloads as strings even if binary supported ( #85 )
...
This reverts commit 44c7aa5 , which caused string payloads to be encoded
as binary (so that huge string payloads were needlessly UTF-8-encoded).
Related: https://github.com/socketio/socket.io/issues/2872
2017-03-06 12:24:11 +01:00
Damien Arrachequesne
d1c2680ca9
[fix] Sanitize strings by removing lone surrogates ( #82 )
2016-12-21 22:01:19 +01:00
Damien Arrachequesne
181acef657
[fix] Fix double utf8 encoding for payloads ( #81 )
2016-12-21 09:15:07 +01:00
Damien Arrachequesne
6741900f37
[fix] Handle undefined case properly when decoding packet ( #74 )
2016-10-20 14:39:04 +02:00
jm
5aecaa914d
[fix] decodePacket now accepts both Buffer and ArrayBuffer as data
...
Closes #64 , fixes #60
2016-10-20 14:17:02 +02:00
Damien Arrachequesne
96fa4f907a
Fix ArrayBuffer encoding in base64 string
2015-12-02 10:49:33 +01:00
nkzawa
685cb719e8
fix encoding blob as base64
2015-11-22 16:05:26 +09:00
Tony Kovanen
44c7aa5ab9
Fix parse error
...
We always need to send binary when encoding payloads when sending from
server to client, because the polling transport has to know the response
type ahead of time.
2015-01-16 21:19:27 +02:00
Guillermo Rauch
e53e9f5931
Merge pull request #36 from cvlchinet/patch
...
Allow sending binary data without ArrayBuffer (e. g. IE8)
2014-12-10 17:57:26 -03:00
Tony Kovanen
68d89ab7a9
encode into binary only if needed
2014-12-03 02:07:10 +02:00
Chi Vinh Le
1e337d3f65
Add test cases for base64 object encoding.
2014-11-20 23:38:49 +01:00
Tony Kovanen
b10666cf94
Test that utf8 encoding is not on by default but can be switched on manually.
2014-07-17 01:21:41 +03:00
Tony Kovanen
95840ca6b6
Don't UTF-8 encode packets unless asked.
...
Still done in payload encoding for polling, but no need with WebSockets since it deals with UTF-8 itself.
2014-07-17 00:54:00 +03:00
Naoyuki Kanezawa
4dc1a13750
handle invalid utf8 errors gracefully
2014-06-29 18:22:53 +09:00
Tony Kovanen
4ff516b94a
Adjust test to use proper data types and to only run for supporting browsers when testing the memory leak fix
2014-06-25 10:17:56 +03:00
Christoph Witzko
d41f8e06da
fix decodePayloadAsBinary memory leak
2014-06-24 23:49:57 +02:00
Tony Kovanen
37ede5ffdd
Add parser encode/decode test with long dash
2014-05-30 16:20:36 +03:00
Tony Kovanen
134897a1e0
Cleaned up logic for deciding if blob tests should be run
2014-03-09 01:01:17 +02:00
Tony Kovanen
8e5557d712
Added zuul configurations and testing for browsers
2014-02-19 21:26:27 +02:00
Guillermo Rauch
105fb8befe
moving code from engine.io-protocol
2014-02-18 13:06:06 -08:00