Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sendMessageBinary throws "TypeError: Buffer expected" when using with Bun #318

Open
mertushka opened this issue Jan 5, 2025 · 0 comments

Comments

@mertushka
Copy link

mertushka commented Jan 5, 2025

Environment:

  • Bun version: 1.1.42
  • node-datachannel version: 0.23.0

Issue:
When using the sendMessageBinary method with a ArrayBuffer, a TypeError: Buffer expected is thrown, even though a Buffer is passed to the method. This issue seems specific to Bun, with using Node it works flawless.

> bun index.ts

data to send: Uint8Array(10) [ 0, 8, 63, 225, 66, 235, 13, 167, 86, 217 ]
159 |       data.arrayBuffer().then((ab) => {
160 |         __privateGet(this, _dataChannel).sendMessageBinary(new Uint8Array(ab));
161 |       });
162 |     }
163 |     else {
164 |       __privateGet(this, _dataChannel).sendMessageBinary(new Uint8Array(data));
                                             ^
TypeError: Buffer expected
at send (\node_modules\node-datachannel\dist\cjs\polyfill\RTCDataChannel.cjs:164:40)

Expected Behavior:

if (length < 1 || !info[0].IsBuffer())

This condition would pass successfully.

Workaround:

this.#dataChannel.sendMessageBinary(new Uint8Array(data));

Using Buffer.from(new Uint8Array(data)) resolves the issue.

Additional Context:
The problem seems to stem from how the method checks for Buffer in the C++ code (TrackWrapper::sendMessageBinary).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant