Skip to content

Commit

Permalink
update multiplayer docs (#505)
Browse files Browse the repository at this point in the history
* update multiplayer docs

* some reformatting
  • Loading branch information
amitport authored and nicolodavis committed Nov 28, 2019
1 parent a2c64f8 commit a9d4be6
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 29 deletions.
36 changes: 18 additions & 18 deletions docs/documentation/api/Client.md
Expand Up @@ -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.
Expand Down
17 changes: 10 additions & 7 deletions docs/documentation/multiplayer.md
Expand Up @@ -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 = () => (
Expand Down Expand Up @@ -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' }),
});
```

Expand All @@ -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/' }),
});
```

Expand Down
2 changes: 1 addition & 1 deletion docs/documentation/testing.md
Expand Up @@ -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' });
Expand Down
3 changes: 2 additions & 1 deletion 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 = [
Expand Down Expand Up @@ -120,7 +121,7 @@ var TicTacToeClient = Client({
board: TicTacToeBoard,
game: TicTacToe,
debug: false,
multiplayer: { local: true },
multiplayer: Local(),
});

const App = () => (
Expand Down
2 changes: 1 addition & 1 deletion src/client/client.test.js
Expand Up @@ -140,7 +140,7 @@ describe('multiplayer', () => {
});
});

describe('multiplayer: true', () => {
describe('multiplayer: SocketIO()', () => {
let client;

beforeAll(() => {
Expand Down
2 changes: 1 addition & 1 deletion src/core/random.test.js
Expand Up @@ -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'));
Expand Down

0 comments on commit a9d4be6

Please sign in to comment.