Installation
The library consists of 3 files:
- bgapi.bundle.js (The bundled JavaScript library)
- signaling.php (PHP file to establish the connections between peers, needs PHP 5.4)
- messages.db (SQLite, needs to be writable by the PHP SQLite extension)
Download
The library can be downloaded in different ways.
From the website
Please find the latest version on http://netzhuffle.github.io/p2pboardgameapi. The download archive contains all three files.
Through npm
You can install the library with npm (Node Package Manager):
$ npm install --save p2pboardgameapi
Build bundle from Git
You can build the bundle yourself from Git:
$ git checkout https://github.com/netzhuffle/P2PboardgameAPI.git
$ cd P2PboardgameAPI
$ npm install
$ npm run prepublish
You will find bgapi.bundle.js in the folder /build/ and signaling.php together with messages.db in the folder /src/.
Include
The library uses the UMD (Universal Module Definition) pattern, which gives you various ways to include the library in your project.
HTML
<script src="bgapi.bundle.js"></script>
<script>
const game = window.p2pboardgameapi('path/to/signaling.php');
/* ... */
</script>
CommonJS modules
E.g. node, webpack or browserify:
const p2pboardgameapi = require('./bgapi.bundle.js').p2pboardgameapi;
const game = p2pboardgameapi('path/to/signaling.php');
/* ... */
AMD (Asynchronous Module Definition) modules
E.g. RequireJS:
define(['./bgapi.bundle.js'], function (bgapi) {
const game = bgapi.p2pboardgameapi('path/to/signaling.php');
/* ... */
});
ECMAScript 2015 modules
If you are able to use ES2015 modules, e.g. because you are using Babel to compile to CommonJS, AMD, or UMD:
import { p2pboardgameapi } from './bgapi.bundle.js';
const game = p2pboardgameapi('path/to/signaling.php');
/* ... */