How to use the colyseus.matchMaker.query function in colyseus

To help you get started, we’ve selected a few colyseus examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github colyseus / colyseus-monitor / src / api.ts View on Github external
api.get("/", async (req: express.Request, res: express.Response) => {
        try {
            const rooms: any[] = await matchMaker.query({});

            res.json(rooms.map(room => {
                const data = room.toJSON();

                // additional data
                data.locked = room.locked || false;
                data.private = room.private;

                data.elapsedTime = Date.now() - new Date(room.createdAt).getTime();
                return data;
            }));
        } catch (e) {
            const message = e.message;
            console.error(message);
            res.status(500);
            res.json({ message });