websockets / ws

Simple to use, blazing fast and thoroughly tested WebSocket client and server for Node.js
MIT License
21.34k stars 2.3k forks source link

Bug: v8.18.0 released major breaking change (not minor) and data sent as Blob (not Buffer) #2239

Open titanism opened 5 days ago

titanism commented 5 days ago

Is there an existing issue for this?

Description

See comment here https://github.com/websockets/ws/pull/2229#issuecomment-2207912046

ws version

8.18.0

Node.js Version

latest

System

No response

Expected result

No response

Actual result

No response

Attachments

No response

lpinca commented 5 days ago

Are you are setting websocket.binaryType to 'blob'?

lpinca commented 5 days ago

Please share a minimal test case to reproduce the issue. I am unable to do it with the provided info. The following example works as expected.

import { WebSocket, WebSocketServer } from 'ws';
import { pack, unpack } from 'msgpackr';

const wss = new WebSocketServer({ port: 0 }, function () {
  const { port } = wss.address();
  const ws = new WebSocket(`ws://127.0.0.1:${port}`);

  ws.on('open', function () {
    ws.send(pack('Hello'));
  });

  ws.on('message', function (buf) {
    console.log(unpack(buf));
    ws.close();
  });
});

wss.on('connection', function (ws) {
  ws.on('message', function (buf) {
    ws.send(pack(unpack(buf)));
  });

  ws.on('close', function () {
    wss.close();
  });
});
titanism commented 4 days ago

@titanism are you are setting websocket.binaryType to 'blob'? Let's continue the discussion in https://github.com/websockets/ws/issues/2239.

No, not at the moment. All we did was upgrade to latest version of ws and this issue came about.

lpinca commented 4 days ago

Maybe it was already set. It was simply ignored before. I can't help without a test case.