oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
71.78k stars 2.55k forks source link

`obs-websocket-js` is not compatible with Bun #10672

Open Saamoz opened 2 months ago

Saamoz commented 2 months ago

What version of Bun is running?

1.1.6+e58d67b46

What platform is your computer?

Microsoft Windows NT 10.0.22631.0 x64

What steps can reproduce the bug?

First, OBS must be installed with WebSocketServer enabled.

Then, the following minimal code works with node.

const OBSWebSocket = require('obs-websocket-js').default;
const obs = new OBSWebSocket();
obs.connect();

With run with bun, there is an error. On both Windows and WSL it seems to fail.

What is the expected behavior?

The file will run without an issue. In addition, in the OBS logs, it will say

19:47:15.485: [obs-websocket] [WebSocketServer::onOpen] New WebSocket client has connected from [::ffff:127.0.0.1]:61065

What do you see instead?

I see the following error in bun

PS E:\twitch-dungeon-bot> bun src/test.ts 
82 |       var instance = new Constructor();
83 |       if (Class) _setPrototypeOf(instance, Class.prototype);
84 |       return instance;
85 |     };
86 |   }
87 |   return _construct.apply(null, arguments);
              ^
error: Server sent no subprotocol
 code: "-1"

      at _construct (E:\twitch-dungeon-bot\node_modules\obs-websocket-js\dist\json.cjs:87:10)
      at Wrapper (E:\twitch-dungeon-bot\node_modules\obs-websocket-js\dist\json.cjs:104:14)
      at new OBSWebSocketError (E:\twitch-dungeon-bot\node_modules\obs-websocket-js\dist\json.cjs:373:13)
      at E:\twitch-dungeon-bot\node_modules\obs-websocket-js\dist\json.cjs:589:17```

In addition, in the OBS logs it says

19:49:25.591: [obs-websocket] [WebSocketServer::onOpen] New WebSocket client has connected from [::ffff:127.0.0.1]:61149
19:49:25.594: [obs-websocket] [WebSocketServer::onClose] WebSocket client `[::ffff:127.0.0.1]:61149` has disconnected with code `1006` and reason: An existing connection was forcibly closed by the remote host.

Additional information

Even though this is a compatibility issue with obs-websocket-js, it seems like something may be going wrong deeper in bun. Ideally it should match the behaviour of node as much as possible. If there's any workaround or fix, please let me know.

Saamoz commented 2 months ago

This seems to be a duplicate of https://github.com/oven-sh/bun/issues/10459