You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+13-4
Original file line number
Diff line number
Diff line change
@@ -32,7 +32,9 @@ js-libp2p-pubsub
32
32
33
33
## Usage
34
34
35
-
Create your pubsub implementation extending the base protocol.
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.
36
38
37
39
```JavaScript
38
40
constPubsub=require('libp2p-pubsub')
@@ -43,23 +45,30 @@ class PubsubImplementation extends Pubsub {
43
45
}
44
46
45
47
_processConnection(idB58Str, conn, peer) {
48
+
// Required to be implemented by the subclass
46
49
// Process each message accordingly
47
50
}
48
51
49
52
publish() {
50
-
53
+
// Required to be implemented by the subclass
51
54
}
52
55
53
56
subscribe() {
54
-
57
+
// Required to be implemented by the subclass
55
58
}
56
59
57
60
unsubscribe() {
58
-
61
+
// Required to be implemented by the subclass
59
62
}
60
63
}
61
64
```
62
65
66
+
## Implementations using this base protocol
67
+
68
+
You can use the following implementations as examples for building your own pubsub implementation.
0 commit comments