NETGAME
Super-simple realtime API creation for interactive web media.
Installation
npm i netgame # for server
npm i netgame-client # for browser client
Demonstration
The following demonstrates basic RPC.
server setup:
const {Server} = require("netgame");
const server = new Server();
server.register("add_fast", (a, b) => a + b);
server.register("add_slow", (a, b) => new Promise((res, rej) => {
setTimeout(() => {
res(a + b);
}, 5000);
}));
server.listen(1338); // listen on port 1338
client setup:
const {Client} = require("netgame-client");
window.addEventListener("load", async function() {
let client = new Client();
await client.connect("ws://localhost:1338");
console.log(await client.invoke("add_fast", 2, 3)); // -> 5, immediately
console.log(await client.invoke("add_slow", 2, 3)); // -> 5, after 5 seconds
});
Motivations
This package was designed to facilitate online multiplayer for web browsers and the like (electron, web views, etc...). Interestingly, because it is so limited in scope, I've found it useful in several other projects; hopefully it will be helpful to you as well.
This package doesn't provide authorization or authentication because I feel it is best handled with a different package. (for now)
CHANGELOG
1.0.6 (2020-03-01) - moved bundled client library into its own package (netgame-client) because it was too hard to include.