git ssb

0+

mixmix / ssb-server-channel



Commit 92f5724222307187f23d545ec3c17c9aeedd6922

basic README + api improvement

mix irving committed on 1/31/2018, 3:18:33 AM
Parent: ceb725feeb3aac110f9c519878705290803c3ce7

Files changed

index.jschanged
package.jsonchanged
README.mdadded
index.jsView
@@ -4,9 +4,9 @@
44
55 const FLUME_VIEW_VERSION = 1.3
66
77 module.exports = {
8- name: 'channels',
8 + name: 'channel',
99 version: require('./package.json').version,
1010 manifest: {
1111 get: 'async',
1212 stream: 'source',
@@ -14,14 +14,15 @@
1414 init: (server, config) => {
1515 console.log('///// CHANNELS plugin loaded /////')
1616
1717 const view = server._flumeUse(
18- 'channels',
18 + 'channel',
1919 FlumeView(FLUME_VIEW_VERSION, reduce, map, null, initialState())
2020 )
2121
2222 return {
2323 get: view.get,
24 + subscription: view.get,
2425 stream: view.stream,
2526 }
2627 }
2728 }
package.jsonView
@@ -1,15 +1,16 @@
11 {
22 "name": "ssb-server-channels",
33 "version": "1.0.0",
4- "description": "",
4 + "repository": "git@github.com:ssbc/ssb-server-channel.git",
5 + "description": "A scuttlebot flumeview for all your channel related questions",
56 "main": "index.js",
67 "scripts": {
78 "test": "echo \"Error: no test specified\" && exit 1"
89 },
9- "keywords": [],
10- "author": "",
11- "license": "ISC",
10 + "keywords": ["scuttlebutt", "flumeview"],
11 + "author": "mixmix",
12 + "license": "AGPL-3.0",
1213 "dependencies": {
1314 "flumeview-reduce": "^1.3.12",
1415 "lodash": "^4.17.4"
1516 }
README.mdView
@@ -1,0 +1,68 @@
1 +# ssb-server-channel
2 +
3 +## Usage
4 +
5 +```js
6 +const Server = require('scuttlebot')
7 +const config = { ... } // needs options
8 +
9 +// Install the plugin
10 +Server
11 + .use(require('scuttlebot/plugins/master')) // required
12 + .use(require('ssb-server-channel'))
13 + .use(require('ssb-backlinks')) // not required, just an example
14 +
15 +// Start the server
16 +const server = Server(config)
17 +```
18 +
19 +## API
20 +
21 +### server.channel.subscriptions(cb)
22 +
23 +Get the channels and who is subscribed where `cb(err, data)` is called with `data` of form:
24 +
25 +```js
26 +{
27 + [ChannelName]: Set // set of FeedIds of users subscribed to that channel
28 +}
29 +```
30 +
31 +e.g
32 +
33 +```js
34 +{
35 + 'ssb-learning': Set { '@gaQw6z...', '@ye+QM09...' },
36 + 'brazil': Set { '@gaQw6z...' }
37 +}
38 +```
39 +
40 +Check your [Set methods **on MDN**](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set)
41 +
42 +And if you really need an Array :
43 +
44 +```js
45 +const s = new Set ()
46 +set.add('mixmix')
47 +set.add('soapdog')
48 +
49 +[...s] // => ['mixmix', 'soapdog']
50 +Array.from(s) // => ['mixmix', 'soapdog']
51 +```
52 +
53 +
54 +### server.channel.get(cb)
55 +
56 +Get the current state of the channel view. This will wait until the view is up to date, if necessary.
57 +
58 +`cb(err, data)` is a standard callback function where `data` is of the form:
59 +
60 +```js
61 +{
62 + [ChannelName]: Set // set of FeedIds of users subscribed to that channel
63 +}
64 +```
65 +
66 +### server.channel.get(cb)
67 +
68 +

Built with git-ssb-web