Added room list fetching from database and sending of it on user connection
This commit is contained in:
parent
3533230eb1
commit
e95f74891f
@ -17,4 +17,8 @@ export const connect = () =>
|
||||
entities: [Room],
|
||||
});
|
||||
|
||||
export const getRoomList = (connection: Connection) => {
|
||||
return connection.manager.find(Room);
|
||||
};
|
||||
|
||||
export { Room };
|
||||
|
@ -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)));
|
||||
});
|
||||
})();
|
||||
|
Loading…
x
Reference in New Issue
Block a user