diff --git a/docs/documentation/api/Client.md b/docs/documentation/api/Client.md index cb1ebbc09..e1589fe22 100644 --- a/docs/documentation/api/Client.md +++ b/docs/documentation/api/Client.md @@ -41,30 +41,30 @@ const App = Client({ // If this is not provided, the client displays "connecting...". loading: LoadingComponent, - // Can be set to one of the following in order to enable multiplayer: + // Set this to one of the following to enable multiplayer: // - // 1. true + // SocketIO + // Implementation that talks to a remote server using socket.io. // - // This starts sending move updates to the server via socket.io. + // How to import: + // import { SocketIO } from 'boardgame.io/multiplayer' // - // 2. { server: 'hostname[:port]' } + // Arguments: + // Object with 2 parameters + // 1. 'socketOpts' options to pass directly to socket.io client. + // 2. 'server' specifies the server location in the format: [http[s]://]hostname[:port]; + // defaults to current page host. // - // Same as the above, but also specifies the server location. + // Local + // Special local mode that uses an in-memory game master. Useful + // for testing multiplayer interactions locally without having to + // connect to a server. // - // 3. { server: 'http[s]://hostname[:port]' } + // How to import: + // import { Local } from 'boardgame.io/multiplayer' // - // Same as the above, but also specifies the server protocol (for example, HTTPS). - // - // 4. { local: true} - // - // Special local mode that uses an in-memory game master. Useful - // for testing multiplayer interactions locally without having to - // connect to a server. - // - // 5. CustomClass - // - // Your own transport implementation. See `src/client/client.js` for - // details on how to implement a custom transport adapter. + // Additionally, you can write your own transport implementation. + // See `src/client/client.js` for details. multiplayer: false, // Set to false to disable the Debug UI. diff --git a/docs/documentation/multiplayer.md b/docs/documentation/multiplayer.md index bd0957402..b7aefdf49 100644 --- a/docs/documentation/multiplayer.md +++ b/docs/documentation/multiplayer.md @@ -31,21 +31,23 @@ The game master can run completely on the browser. This is useful to set up pass-and-play multiplayer or for prototyping the multiplayer experience without having to set up a server to test it. -All you need to do is add `multiplayer: { local: true }` to your client -config. Now you can instantiate as many of these clients in your app and you -will notice that they're all kept in sync, playing in the same game. +All you need to do is to add `import { Local } from 'boardgame.io/multiplayer'`, +and in your config write `multiplayer: Local()`. Now you can instantiate as many +of these clients in your app and you will notice that they're all kept in sync, +playing in the same game. ```js // src/App.js import { Client } from 'boardgame.io/react'; +import { Local } from 'boardgame.io/multiplayer'; import { TicTacToe } from './game'; import { TicTacToeBoard } from './board'; const TicTacToeClient = Client({ game: TicTacToe, board: TicTacToeBoard, - multiplayer: { local: true }, + multiplayer: Local(), }); const App = () => ( @@ -95,13 +97,14 @@ client can connect to this master (whether it is a browser, an Android app etc.) and it will be kept in sync with other clients in realtime. In order to connect a client to a remote master, we use the `multiplayer` -option again, but this time specify the location of the server. +option again, but this time we add `import { SocketIO } from 'boardgame.io/multiplayer'`, +and specify the location of the server. ```js const TicTacToeClient = Client({ game: TicTacToe, board: TicTacToeBoard, - multiplayer: { server: 'localhost:8000' }, + multiplayer: SocketIO({ server: 'localhost:8000' }), }); ``` @@ -111,7 +114,7 @@ You may also specify a protocol here (if you want to use SSL, for example): const TicTacToeClient = Client({ game: TicTacToe, board: TicTacToeBoard, - multiplayer: { server: 'https://localhost:8000/' }, + multiplayer: SocketIO({ server: 'https://localhost:8000/' }), }); ``` diff --git a/docs/documentation/testing.md b/docs/documentation/testing.md index f2479fd1e..a43aa5d36 100644 --- a/docs/documentation/testing.md +++ b/docs/documentation/testing.md @@ -87,7 +87,7 @@ in unit tests. it('multiplayer test', () => { const spec = { game: MyGame, - multiplayer: { local: true }, + multiplayer: Local(), }; const p0 = Client({ ...spec, playerID: '0' }); diff --git a/examples/snippets/src/multiplayer/index.js b/examples/snippets/src/multiplayer/index.js index 88a9ba4e3..70de117fa 100644 --- a/examples/snippets/src/multiplayer/index.js +++ b/examples/snippets/src/multiplayer/index.js @@ -1,6 +1,7 @@ import React from 'react'; import ReactDOM from 'react-dom'; import { Client } from 'boardgame.io/react'; +import { Local } from 'boardgame.io/multiplayer'; function IsVictory(cells) { const positions = [ @@ -120,7 +121,7 @@ var TicTacToeClient = Client({ board: TicTacToeBoard, game: TicTacToe, debug: false, - multiplayer: { local: true }, + multiplayer: Local(), }); const App = () => ( diff --git a/src/client/client.test.js b/src/client/client.test.js index e584e56fc..5770653e3 100644 --- a/src/client/client.test.js +++ b/src/client/client.test.js @@ -140,7 +140,7 @@ describe('multiplayer', () => { }); }); - describe('multiplayer: true', () => { + describe('multiplayer: SocketIO()', () => { let client; beforeAll(() => { diff --git a/src/core/random.test.js b/src/core/random.test.js index 7d3891519..940e1c2da 100644 --- a/src/core/random.test.js +++ b/src/core/random.test.js @@ -140,7 +140,7 @@ test('Random API is not executed optimisitically', () => { } { - const reducer = CreateGameReducer({ game, multiplayer: true }); + const reducer = CreateGameReducer({ game, multiplayer: () => {} }); let state = InitializeGame({ game }); expect(state.G.die).not.toBeDefined(); state = reducer(state, makeMove('rollDie'));