summary refs log tree commit diff
path: root/gateway/client.js
diff options
context:
space:
mode:
authorFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-08-12 20:22:16 +0200
committerFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-08-12 20:22:16 +0200
commitbdc0cc723c7d5974a4c4e3e8b0793917684ec85d (patch)
tree7123410553a6698d90ddaae69b05cde8402ded36 /gateway/client.js
parent1.3.52 (diff)
parent:sparkles: gateway (diff)
downloadserver-bdc0cc723c7d5974a4c4e3e8b0793917684ec85d.tar.xz
Merge branch 'master' into util
Diffstat (limited to 'gateway/client.js')
-rw-r--r--gateway/client.js51
1 files changed, 51 insertions, 0 deletions
diff --git a/gateway/client.js b/gateway/client.js
new file mode 100644

index 00000000..34a59458 --- /dev/null +++ b/gateway/client.js
@@ -0,0 +1,51 @@ +require("missing-native-js-functions"); +const WebSocket = require("ws"); +const Constants = require("./dist/util/Constants"); + +// const ws = new WebSocket("ws://127.0.0.1:8080"); +const ws = new WebSocket("wss://gateway.discord.gg"); + +ws.on("open", () => { + // ws.send(JSON.stringify({ req_type: "new_auth" })); + // ws.send(JSON.stringify({ req_type: "check_auth", token: "" })); + // op: 0, + // d: {}, + // s: 42, + // t: "GATEWAY_EVENT_NAME", +}); + +function send(data) { + ws.send(JSON.stringify(data)); +} + +ws.on("message", (buffer) => { + let data = JSON.parse(buffer.toString()); + console.log(data); + + switch (data.op) { + case 10: + setIntervalNow(() => { + send({ op: 1 }); + }, data.d.heartbeat_interval); + + // send({ + // op: 2, + // d: { + // token: + // "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjgxMTY0MjkxNzQzMjA2NjA0OCIsImlhdCI6MTYxMzU4MTE1MX0.7Qj_z2lYIgJ0rc7NfGtpW5DKGqecQfv1mLpoBUQHKDc", + // intents: 0n, + // properties: {}, + // }, + // }); + + send({ + op: 6, + }); + + break; + } +}); + +ws.on("close", (code, reason) => { + console.log(code, reason, Constants.CLOSECODES[code]); +});