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],
|
entities: [Room],
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export const getRoomList = (connection: Connection) => {
|
||||||
|
return connection.manager.find(Room);
|
||||||
|
};
|
||||||
|
|
||||||
export { Room };
|
export { Room };
|
||||||
|
@ -1,12 +1,15 @@
|
|||||||
import "reflect-metadata";
|
import "reflect-metadata";
|
||||||
import { Server } from "ws";
|
import { Server } from "ws";
|
||||||
|
import { connect, getRoomList } from "./db";
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
|
const connection = await connect();
|
||||||
|
|
||||||
const wss = new Server({
|
const wss = new Server({
|
||||||
port: Number.parseInt(process.env.PORT || "") || 8081,
|
port: Number.parseInt(process.env.PORT || "") || 8081,
|
||||||
});
|
});
|
||||||
|
|
||||||
wss.on("connection", async (ws) => {
|
wss.on("connection", async (ws) => {
|
||||||
ws.send("hello");
|
ws.send(JSON.stringify(await getRoomList(connection)));
|
||||||
});
|
});
|
||||||
})();
|
})();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user