File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -26,8 +26,12 @@ const app = Server({
2626 // The return value of Game().
2727 game: game,
2828
29- // The number of players.
30- numPlayers: 2
29+ // Optional, if you want to hook it up to a
30+ // custom storage backend not supported by
31+ // the framework. DbImpl must implement the
32+ // same interface shown in db.js:
33+ // https://github.com/google/boardgame.io/blob/master/src/server/db.js
34+ db: new DbImpl (),
3135});
3236
3337app .listen (8000 );
Original file line number Diff line number Diff line change @@ -12,13 +12,16 @@ const Redux = require('redux');
1212import { InMemory } from './db' ;
1313import { createGameReducer } from '../core/reducer' ;
1414
15- function Server ( { games } ) {
15+ function Server ( { games, db } ) {
1616 const app = new Koa ( ) ;
1717 const io = new IO ( ) ;
1818 app . context . io = io ;
1919 io . attach ( app ) ;
2020
21- const db = new InMemory ( ) ;
21+ if ( db === undefined ) {
22+ db = new InMemory ( ) ;
23+ }
24+
2225 const clientInfo = new Map ( ) ;
2326 const roomInfo = new Map ( ) ;
2427
Original file line number Diff line number Diff line change @@ -155,3 +155,18 @@ test('playerView', () => {
155155 }
156156 } ) ;
157157} ) ;
158+
159+ test ( 'custom db implementation' , ( ) => {
160+ let getId = null ;
161+ class Custom {
162+ get ( id ) { getId = id }
163+ set ( ) { }
164+ }
165+
166+ const game = Game ( { } ) ;
167+ const server = Server ( { games : [ game ] , db : new Custom ( ) } ) ;
168+ const io = server . context . io ;
169+
170+ io . socket . receive ( 'sync' , 'gameID' ) ;
171+ expect ( getId ) . toBe ( 'gameID' ) ;
172+ } ) ;
You can’t perform that action at this time.
0 commit comments