🎨 restructure gateway
This commit is contained in:
+12
-3
@@ -1,7 +1,7 @@
|
||||
import "missing-native-js-functions";
|
||||
import dotenv from "dotenv";
|
||||
dotenv.config();
|
||||
import { closeDatabase, Config, initDatabase, initEvent, RabbitMQ } from "@fosscord/util";
|
||||
import { closeDatabase, Config, initDatabase, initEvent } from "@fosscord/util";
|
||||
import { Server as WebSocketServer } from "ws";
|
||||
import { Connection } from "./events/Connection";
|
||||
import http from "http";
|
||||
@@ -12,15 +12,24 @@ export class Server {
|
||||
public server: http.Server;
|
||||
public production: boolean;
|
||||
|
||||
constructor({ port, server, production }: { port: number; server?: http.Server; production?: boolean }) {
|
||||
constructor({
|
||||
port,
|
||||
server,
|
||||
production,
|
||||
}: {
|
||||
port: number;
|
||||
server?: http.Server;
|
||||
production?: boolean;
|
||||
}) {
|
||||
this.port = port;
|
||||
this.production = production || false;
|
||||
|
||||
if (server) this.server = server;
|
||||
else
|
||||
else {
|
||||
this.server = http.createServer(function (req, res) {
|
||||
res.writeHead(200).end("Online");
|
||||
});
|
||||
}
|
||||
|
||||
this.server.on("upgrade", (request, socket, head) => {
|
||||
console.log("socket requests upgrade", request.url);
|
||||
|
||||
@@ -35,8 +35,11 @@ export async function Connection(
|
||||
// @ts-ignore
|
||||
socket.encoding = searchParams.get("encoding") || "json";
|
||||
if (!["json", "etf"].includes(socket.encoding)) {
|
||||
if (socket.encoding === "etf" && erlpack)
|
||||
throw new Error("Erlpack is not installed: 'npm i -D erlpack'");
|
||||
if (socket.encoding === "etf" && erlpack) {
|
||||
throw new Error(
|
||||
"Erlpack is not installed: 'npm i @yukikaze-bot/erlpack'"
|
||||
);
|
||||
}
|
||||
return socket.close(CLOSECODES.Decode_error);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { Intents, Permissions } from "@fosscord/util";
|
||||
import WS from "ws";
|
||||
import { Deflate } from "zlib";
|
||||
import { Channel } from "amqplib";
|
||||
|
||||
export interface WebSocket extends WS {
|
||||
version: number;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
export * from "./Constants";
|
||||
export * from "./Send";
|
||||
export * from "./SessionUtils";
|
||||
export * from "./setHeartbeat";
|
||||
export * from "./Heartbeat";
|
||||
export * from "./WebSocket";
|
||||
|
||||
Reference in New Issue
Block a user