Added room list fetching from database and sending of it on user connection

This commit is contained in:
Dmitriy Shishkov 2021-09-04 15:10:04 +03:00
parent 3533230eb1
commit e95f74891f
No known key found for this signature in database
GPG Key ID: 14358F96FCDD8060
2 changed files with 8 additions and 1 deletions

View File

@ -17,4 +17,8 @@ export const connect = () =>
entities: [Room],
});
export const getRoomList = (connection: Connection) => {
return connection.manager.find(Room);
};
export { Room };

View File

@ -1,12 +1,15 @@
import "reflect-metadata";
import { Server } from "ws";
import { connect, getRoomList } from "./db";
(async () => {
const connection = await connect();
const wss = new Server({
port: Number.parseInt(process.env.PORT || "") || 8081,
});
wss.on("connection", async (ws) => {
ws.send("hello");
ws.send(JSON.stringify(await getRoomList(connection)));
});
})();