oven-sh / bun

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

WebSocket Strange? #343

Closed rexwu1104 closed 1 year ago

rexwu1104 commented 2 years ago

I use WebSocket to connect this discord gateway, but on onmessage event it doesn't send me anything image image image just a isTrusted property

Jarred-Sumner commented 2 years ago

Does that say: encoding=etf

etf is probably a typo, you probably meant utf8

rexwu1104 commented 2 years ago

no, I use etf.js it is make from discord

rexwu1104 commented 2 years ago

it is a encoding for discord, there have "json" and "etf"

vinayakkulkarni commented 2 years ago

what font is that @rexwu1104 ?

rexwu1104 commented 2 years ago

it must be this image and this is I catched image

rexwu1104 commented 2 years ago

what font is that @rexwu1104 ?

If you use "json" directly for encoding, you will see these results directly

rexwu1104 commented 2 years ago

I use "enoding=json" to try this code, but it still have bug. the discord send me the InvalidSession Event. it mean my packet is wrong, but my packet doesn't have any changes. so, I think it is the bug of WebSocket and the etf.js can't work perfect on bun.

this is the etf.js package url. https://www.npmjs.com/package/etf.js

rexwu1104 commented 2 years ago

what font is that @rexwu1104 ?

do you mean this? https://www.erlang.org/doc/apps/erts/erl_ext_dist.html

Electroid commented 2 years ago

@rexwu1104 If you have time, are you still seeing this issue on the latest version of Bun? bun upgrade

rexwu1104 commented 1 year ago

there is a new error.

image
rexwu1104 commented 1 year ago

it is from erlpack. and here is etf.js error.

image
Electroid commented 1 year ago

This doesn't appear to be a WebSocket issue.

Code:

const ws = new WebSocket("wss://gateway.discord.gg/?encoding=json&v=10");
ws.addEventListener("message", ({ data }) => console.log(Buffer.from(data).toString()));

Output:

{"t":null,"s":null,"op":10,"d":{"heartbeat_interval":41250,"_trace":["[\"gateway-prd-us-east1-b-pn41\",{\"micros\":0.0}]"]}}

I did try using etf encoding with the etf.js package, but received the following error, Incompatible ETF version., which does not seem related to Bun.