1.10.3 • Published 5 years ago
@jacekpietal/sync v1.10.3
1. What is @jacekpietal/sync?
- a boilerplate library / repository
- simplifier for creating multiplayer games in javascript + node
- bouncer.js extended class
- an express-like lib with router
- a lib with static files served from a folder (config.folder)
- files served statically are lazily cached out of the box
- observable mouse events broadcaster from front to backend on uwebsockets
- a library with microwebsockets integration
- a lib with a working demo
- a lib with working tests written in jest
2. Usage
Using as a backend framework / library
$ yarn add @jacekpietal/sync
$ node
const Flow = require("@jacekpietal/sync/flow");
const flow = new Flow({ debug: true, folder: '../' });Running example (multiplayer \$joystick)
$ yarn add @jacekpietal/sync
$ cd node_modules
$ yarn && yarn startOutput of any of above is:
sync 🏄 Starts with config: {
LOGO: 'sync 🏄',
port: 8080,
join: '/join',
leave: '/leave',
plugins: { joystick: [Function: echo] },
idConfig: { lang: 'english', len: 5 },
debug: true
}
sync 🏄 Listens on port 8080- this created a
joystickplugin(websocket room) - with
bouncerlistening on port8080 - with
express-like router - with
socket.io-like wrapper - for micro-WebSocket as ws handler
Example (multiplayer joystick preview)
"use strict";
import Game from "@jacekpietal/sync/game";
import UWebSocket from "@jacekpietal/bouncer.js/client.js";
const game = new Game();
const pre = document.getElementsByTagName("pre")[0];
const state = {};
const address = `ws://${location.hostname}:8080`;
const ws = new UWebSocket(address);
ws.on("*", ({ id, event, data }) => {
if (event === "/leave") {
// cleanup
delete state[id];
} else {
// echo on screen
state[id] = { event, data };
}
// update render
pre.innerText = JSON.stringify(state, null, 2);
});
ws.onopen = () => {
// this is possible now
// ws.emitEvent is like socket.io ws.emit("event", { data })
ws.emitEvent("/join", "joystick");
// any change on the game joystick
// will emit the joystick event to ws server
game.subject$.subscribe(({ event, data }) => {
ws.emitEvent(event, data);
});
};The code should explain itself, read this test if nothing else:
3. Tests
$ yarn test- runs
jesttests, also oncircleci.
| Test Suites: | 2 passed, 2 total |
|---|---|
| Tests: | 10 passed, 10 total |
| Snapshots: | 0 total |
| Time: | 2.301 s, estimated 20 s |
| Ran all test suites. | |
| Done in 2.83s. |
4. Installation
yarn add @jacekpietal/sync --save
Documentation
It is a maintained work in progress.
Clone this repository and check out tests and demo to get the hang of it.
Better yet, read the docs, and the
bouncer.jsdocs then use as a framework.Star if you like.
5. License
Creative Commons Attribution 4.0 International.
Just write somewhere in your app that you used this free library. It may be just a developer readme file.
1.10.3
5 years ago
1.10.2
5 years ago
1.10.1
5 years ago
1.10.0
5 years ago
1.9.4
5 years ago
1.9.3
5 years ago
1.9.2
5 years ago
1.9.1
5 years ago
1.9.0
5 years ago
1.8.0
5 years ago
1.7.1
5 years ago
1.7.0
5 years ago
1.6.0
5 years ago
1.5.2
5 years ago
1.5.1
5 years ago
1.5.0
5 years ago
1.4.0
5 years ago
1.3.0
5 years ago
1.2.1
5 years ago
1.2.0
5 years ago
1.1.1
5 years ago
1.1.0
5 years ago
1.0.2
5 years ago
1.0.1
5 years ago
1.0.0
5 years ago