oven-sh / bun

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

Baileys.js ws returns `Connection Terminated` #5287

Closed robobun closed 10 months ago

robobun commented 1 year ago

im trying to build a whatsapp bot using https://github.com/WhiskeySockets/Baileys but kept getting WS errors.

[bun] Warning: ws.WebSocket 'upgrade' event is not implemented in bun
[bun] Warning: ws.WebSocket 'unexpected-response' event is not implemented in bun{"level":30,"time":"2023-09-13T16:06:13.177Z","pid":439,"hostname":"DESKTOP-JEUKCK6","class":"baileys","browser":["Baileys","Chrome","4.0.0"],"helloMsg":{"clientHello":{"ephemeral":"HbtkwwQTDiZ5r/X0F2DacmaZ/9Z0Myc+xR26a3x4YA=="}},"msg":"connected to WA"}

{"level":30,"time":"2023-09-13T16:06:13.445Z","pid":439,"hostname":"DESKTOP-JEUKCK6","class":"baileys","trace":"Error: Connection Terminated\n    at <anonymous> (/mnt/d/Projects/WHAW-BEB/node_modules/@hapi/boom/lib/index.js:80:8)\n    at <anonymous> (/mnt/d/Projects/WHAW-BEB/node_modules/@whiskeysockets/baileys/src/Socket/socket.ts:564:25)\n    at emit (native)\n    at emit (native)\n    at <anonymous> (native)","msg":"connection errored"}

{"level":50,"time":"2023-09-13T16:06:13.446Z","pid":439,"hostname":"DESKTOP-JEUKCK6","class":"baileys","err":{"type":"Error","message":"WebSocket Error (undefined)","stack":"Error: WebSocket Error (undefined)\n    at <anonymous> (/mnt/d/Projects/WHAW-BEB/node_modules/@hapi/boom/lib/index.js:80:8)\n    at <anonymous> (/mnt/d/Projects/WHAW-BEB/node_modules/@whiskeysockets/baileys/src/Socket/socket.ts:737:2)\n    at emit (native)\n    at emit (native)\n    at <anonymous> (native)","data":1006,"isBoom":true,"isServer":true,"output":{"statusCode":500,"payload":{"statusCode":500,"error":"Internal Server Error","message":"An internal server error occurred"},"headers":{}}},"msg":"error in validating connection"}

my config for the socket creation

this.socket = makeWASocket({
  version,
  printQRInTerminal: true,
  // mobile: true,
  auth: {
    creds: state.creds,
    // @ts-ignore
    keys: makeCacheableSignalKeyStore(state.keys, this.app.logger),
  },
});

Originally reported on Discord: Baileys.js ws returnsConnection Terminated``

Electroid commented 10 months ago

We need to test our WebSocket client using the Autobahn test suite to fix these bugs, including this one. For updates, please upvote and subscribe to this issue: https://github.com/oven-sh/bun/issues/6686