Commit 728b923cdc959e08d164f7e4f8c3ad7169c0fa7f
simpler example in readme
Dominic Tarr committed on 3/6/2015, 9:51:20 AMParent: 933ab4f9182c91eb147157a749e4181bfd0cc640
Files changed
README.md | changed |
README.md | ||
---|---|---|
@@ -2,44 +2,32 @@ | ||
2 | 2 … | |
3 | 3 … | [scuttlebot](https://github.com/ssbc/scuttlebot) client |
4 | 4 … | |
5 | 5 … | ```js |
6 | -var pull = require('pull-stream') | |
7 | -var ssbkeys = require('ssb-keys') | |
8 | -var ssbclient = require('ssb-client') | |
9 | 6 … | |
10 | -// generate a new keypair | |
11 | -var keys = ssbkeys.generate() | |
7 … | +var Client = require('./') | |
12 | 8 … | |
13 | -// connect to the local scuttlebot | |
14 | -var client = ssbclient(keys, 'localhost', doWork) | |
9 … | +var config = require('ssb-config') | |
10 … | +var ssbKeys = require('ssb-keys') | |
11 … | +var keys = ssbKeys.loadOrCreateSync(config) | |
15 | 12 … | |
16 | -// listen to connection events | |
17 | -client.on('connect', function () { | |
18 | - console.log('connection established, authenticating...') | |
13 … | +function abortIf (err) { | |
14 … | + if(err) throw err | |
15 … | +} | |
16 … | + | |
17 … | +var client = Client(keys, config) | |
18 … | + .connect(abortIf) | |
19 … | + .auth(abortIf) | |
20 … | + | |
21 … | +client.publish({ | |
22 … | + type: 'post', text: 'hello, world!' | |
23 … | +}, function (err, msg) { | |
24 … | + abortIf(err) | |
25 … | + console.log(msg) | |
26 … | + client.close() | |
19 | 27 … | }) |
20 | -client.on('authed', function () { | |
21 | - console.log('authed and ready to go') | |
22 | -}) | |
23 | -client.on('error', function (err) { | |
24 | - console.log('authentication error', err) | |
25 | - client.reconnect({ wait: 5000 }) | |
26 | -}) | |
27 | -client.on('close', function (err) { | |
28 | - console.log('connection closed') | |
29 | - client.reconnect({ wait: 5000 }) | |
30 | -}) | |
31 | -client.on('reconnecting', function () { | |
32 | - console.log('attempting reconnect...') | |
33 | -}) | |
34 | 28 … | |
35 | -// make calls to the scuttlebot api | |
36 | -function doWork() { | |
37 | - // authed and ready to go | |
38 | - pull(client.createFeedStream(), pull.drain(console.log)) | |
39 | - client.publish({ type: 'post', text: 'hello, world!' }, console.log) | |
40 | -} | |
41 | 29 … | ``` |
42 | 30 … | |
43 | 31 … | ## License |
44 | 32 … | |
45 | -MIT, Copyright 2015 Paul Frazee and Dominic Tarr | |
33 … | +MIT, Copyright 2015 Paul Frazee and Dominic Tarr |
Built with git-ssb-web