Sends whole ArrayBuffer instead of fragment
Kamil93 opened this issue · 3 comments
Describe the bug
Engine.io-client(websocket transport) in opposite to raw WebSocket client, when sending binary data represented by Uint8Array
which uses larger ArrayBuffer
than that Uint8Array
states, (eio-client) sends whole ArrayBuffer
instead of Uint8Array
fragment.
Engine.IO server version: 5.1.1
Server - unimportant part in this bug
import http from "http";
import eio from "engine.io"
const server = http.createServer();
const eios = eio.listen(5678);
eios.on('connection', socket => {});
Engine.IO client version: 5.1.2
Client
function CreateFragBuffer() {
const buffer = new ArrayBuffer(8000);
const fragBuffer = new Uint8Array(buffer, 5000, 100);
fragBuffer.forEach((currVal, index, arr) => arr[index] = index);
console.log("CreateFragBuffer()", fragBuffer.byteLength, fragBuffer.buffer.byteLength)
return fragBuffer;
}
const socket = eio('ws://localhost:5678', {transports: ["websocket"]});
socket.on('open', () => {
socket.on('error', (...args) => console.error("EIO", ...args));
socket.send(CreateFragBuffer());
});
Expected behavior
engine.io-client should (like raw WebSocket in browsers) sends only that part of ArrayBuffer
that is used by Uint8Array
that is being sent
Platform:
- Device: PC
- OS: Windows 10
Ran in the same issue a few moments ago.
One workaround is:
socket.send(Buffer.from(CreateFragBuffer()));
But this copies the data twice (bad performance).
I could indeed reproduce, thanks. I'm working on this.
This should be fixed by socketio/engine.io-parser@6d7dd76.
Thanks a lot for the detailed report 👍