@poki/netlib
v0.0.14
Published
<img align="right" src="https://raw.githubusercontent.com/poki/netlib/main/.github/logo.png" width=140> The Poki Networking Library is a peer-to-peer library for web games, using WebRTC datachannels to provide UDP connections between players directly. Lik
Downloads
36
Keywords
Readme
The Poki Networking Library
Project Status: alpha
This library is still under heavy development and considered in alpha. The library API can and will change without warning and without bumping the major version. Make sure to get in touch if you want to go live with this netlib.
One missing feature that is next on the roadmap is lobby listing and discovery. Currently you can only connect peers by having players share a lobby code externally.
Library main advantages:
- peer-to-peer (p2p)
Clients connected to each other using this netlib will be connected directly without a central server in between (unless using the fallback TURN server). This has three main advantages:- No server costs, there is no server running the game.
- No double implementation of the game. You don't need to write your game logic twice (for the client and the server).
- When players are living close by the latency is often a lot lower than when connected via a server
- UDP
Most web games rely on WebSockets or HTTP for communication which is always a TCP connection, but for realtime multiplayer games the UDP protocol is preferred. The main reason is:
When one packet is slow or dropped UDP doesn't pause new, already received, packets, this is great for things like position updates. The Poki netlib also supplies a reliable data channel useful for chat or npc spawn events.
Setup
First add @poki/netlib
as a dependency to your project:
# either using yarn:
yarn add @poki/netlib
# or using npm:
npm i @poki/netlib
Then you can import and create a Network interface:
import { Network } from '@poki/netlib'
const network = new Network('<your-game-id-here>')
(any random UUID is a valid game-id, but if your game is hosted at Poki you should use Poki's game-id)
Next up: read the basic usage guide and make sure to checkout the example code.
STUN, TURN & Signaling Backend
The netlib is a peer-to-peer networking library which means players are connected directly to each other and data send between them is never send to a server.
That said, to setup these connections we need a signaling service. This backend and STUN/TURN servers are hosted by Poki for free. You can however always decide to host the backend yourself.