-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
30 lines (22 loc) · 800 Bytes
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import * as path from 'path';
import * as express from 'express';
import * as WebSocket from 'ws';
import { createServer } from 'http';
import { Server } from 'colyseus';
// Import demo room handlers
import { StateHandlerRoom } from "./room/state-handler";
const port = Number(process.env.PORT || 3553);
const app = express();
// Attach WebSocket Server on HTTP Server.
const gameServer = new Server({
engine: WebSocket.Server,
server: createServer(app)
});
// Register StateHandlerRoom as "state_handler"
gameServer.register("state_handler", StateHandlerRoom);
app.use('/', express.static(path.join(__dirname, "static")));
gameServer.onShutdown(function(){
console.log(`game server is going down.`);
});
gameServer.listen(port);
console.log(`Listening on http://localhost:${ port }`);