p2p-networking
A simple message-oriented WebRTC (PeerJS) based p2p network.
Resources
Example
// Each peer has a user associated. Users can have application specific properties that// are synchronized across all peers in the network. // An application specific protocol version needs to be specified.// This version should be changed if breaking changes are introduced.// If a peer encounters another peer with a different version, it will refuse to connect.; // Create a peer. If a peer id to connect to is given, connect as client and otherwise host. // Create the host.; // Connect to the host with two different client. This would likely be done in different// browser windows on different devices and not in one application.;; // An enum, string or number can be used to differentiate between messages. // Each message can has a typed specific payload. // In this method, the message for the type `ExampleMessages.EXAMPLE` is registered.// It will return a `MessageFactory` which can be used to subscribe to messages or send then. // Make the host aware of the message `ExampleMessages.MESSAGE` and subscribe to it.registerExampleMessagehost.subscribeconsole.logexample;// Make the first client aware of the message `ExampleMessages.MESSAGE` and subscribe to it.registerExampleMessageclient1.subscribeconsole.logexample;// Make the second client aware of the message `ExampleMessages.MESSAGE`.// Send a message to all peers on the network (including itself) and wait until all// peers have received and acknowledged it.await registerExampleMessageclient2.send.waitForAll;
Contributing
Yarn is used as package manager.
- Install dependencies:
yarn
- Build:
yarn build
- Test:
yarn test
- Lint:
yarn lint
- Build the docs:
yarn docs
Contributors
- Andra Rübsteck
- Frederick Gnodtke (Prior99)