|
1 |
| -# js-libp2p-pubsub |
| 1 | +js-libp2p-pubsub |
| 2 | +================== |
| 3 | + |
| 4 | +[](http://ipn.io) |
| 5 | +[](http://libp2p.io/) |
| 6 | +[](http://webchat.freenode.net/?channels=%23ipfs) |
| 7 | +[](https://coveralls.io/github/libp2p/js-libp2p-pubsub?branch=master) |
| 8 | +[](https://travis-ci.org/libp2p/js-libp2p-pubsub) |
| 9 | +[](https://circleci.com/gh/libp2p/js-libp2p-pubsub) |
| 10 | +[](https://david-dm.org/libp2p/js-libp2p-pubsub) [](https://github.com/feross/standard) |
| 11 | +[](https://github.com/RichardLitt/standard-readme) |
| 12 | +[](https://waffle.io/libp2p/js-libp2p-pubsub) |
| 13 | + |
| 14 | +> libp2p-pubsub consits on the base protocol for libp2p pubsub implementation. This module is responsible for all the logic regarding peer connections. |
| 15 | +
|
| 16 | +## Lead Maintainer |
| 17 | + |
| 18 | +[Vasco Santos](https://github.com/vasco-santos). |
| 19 | + |
| 20 | +## Table of Contents |
| 21 | + |
| 22 | +- [Install](#install) |
| 23 | +- [Usage](#usage) |
| 24 | +- [Contribute](#contribute) |
| 25 | +- [License](#license) |
| 26 | + |
| 27 | +## Install |
| 28 | + |
| 29 | +```sh |
| 30 | +> npm install libp2p-pubsub |
| 31 | +``` |
| 32 | + |
| 33 | +## Usage |
| 34 | + |
| 35 | +A pubsub implementation **MUST** override the `_processConnection`, `publish`, `subscribe` and `unsubscribe` functions. `add_peer` and `remove_peer` may be overwritten if the pubsub implementation needs to add custom logic when peers are added and remove. All the remaining functions **MUST NOT** be overwritten. |
| 36 | + |
| 37 | +The following example aims to show how to create your pubsub implementation extending this base protocol. The pubsub implementation will handle the subscriptions logic. |
| 38 | + |
| 39 | +```JavaScript |
| 40 | +const Pubsub = require('libp2p-pubsub') |
| 41 | + |
| 42 | +class PubsubImplementation extends Pubsub { |
| 43 | + constructor(libp2p) { |
| 44 | + super('libp2p:pubsub', '/pubsub-implementation/1.0.0', libp2p) |
| 45 | + } |
| 46 | + |
| 47 | + _processConnection(idB58Str, conn, peer) { |
| 48 | + // Required to be implemented by the subclass |
| 49 | + // Process each message accordingly |
| 50 | + } |
| 51 | + |
| 52 | + publish() { |
| 53 | + // Required to be implemented by the subclass |
| 54 | + } |
| 55 | + |
| 56 | + subscribe() { |
| 57 | + // Required to be implemented by the subclass |
| 58 | + } |
| 59 | + |
| 60 | + unsubscribe() { |
| 61 | + // Required to be implemented by the subclass |
| 62 | + } |
| 63 | +} |
| 64 | +``` |
| 65 | + |
| 66 | +## Implementations using this base protocol |
| 67 | + |
| 68 | +You can use the following implementations as examples for building your own pubsub implementation. |
| 69 | + |
| 70 | +- [libp2p/js-libp2p-floodsub](https://github.com/libp2p/js-libp2p-floodsub) |
| 71 | + |
| 72 | +## Contribute |
| 73 | + |
| 74 | +Feel free to join in. All welcome. Open an [issue](https://github.com/libp2p/js-libp2p-pubsub/issues)! |
| 75 | + |
| 76 | +This repository falls under the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md). |
| 77 | + |
| 78 | +[](https://github.com/ipfs/community/blob/master/contributing.md) |
| 79 | + |
| 80 | +## License |
| 81 | + |
| 82 | +Copyright (c) Protocol Labs, Inc. under the **MIT License**. See [LICENSE file](./LICENSE) for details. |
0 commit comments