-
Notifications
You must be signed in to change notification settings - Fork 4
Server API
Josh Feinsilber edited this page Jul 12, 2019
·
5 revisions
To create a Blueboat server, you must provide
- An Express app instance
- Redis Config (Redis used to scale Blueboat across multiple servers)
Example
import Express from 'express'
import { Server, MemoryStorage, EventEmitterPubSub } from 'blueboat'
const expressApp = Express()
const server = new Server({
app: expressApp,
storage: MemoryStorage(),
pubsub: EventEmiiterPubSub(),
redis: {
host: 'localhost',
port: 6379,
password: ''
},
admins: { admin: 'password' }
})
Server Options
key | type | required |
---|---|---|
app | Express.App | true |
storage | Storage | true |
pubsub | PubSub | true |
redis | RedisOptions | true |
admins | Object | true |
adapters | SocketIO.Adapter[] | false |
customRoomIdGenerator | (roomName: string, options?: any) => string | false |
You can run a Blueboat game server alongside serving an API or webpages by routing other requests via Express.
Within Blueboat, you can register multiple types of Rooms for clients to create and join.
Parameters
key | type | required |
---|---|---|
roomName | string | true |
handler | Room | true |
options | Object | false |
Example
server.registerRoom("Trivia", TriviaRoom)
// With custom options
server.registerRoom("Trivia-Bonus-Points", TriviaRoom, {bonusMultiplier: 2})
Will start the Game Server on a specific port
Example
server.listen(4000)
// With callback
server.listen(4000, () => console.log("Server running on port 4000"))
To force the game server to shutdown gracefully. Will dispose and clean all rooms that process is handling.
Example
server.gracefullyShutdown()