git ssb

2+

Dominic / ssb-client



Commit 728b923cdc959e08d164f7e4f8c3ad7169c0fa7f

simpler example in readme

Dominic Tarr committed on 3/6/2015, 9:51:20 AM
Parent: 933ab4f9182c91eb147157a749e4181bfd0cc640

Files changed

README.mdchanged
README.mdView
@@ -2,44 +2,32 @@
22
33 [scuttlebot](https://github.com/ssbc/scuttlebot) client
44
55 ```js
6-var pull = require('pull-stream')
7-var ssbkeys = require('ssb-keys')
8-var ssbclient = require('ssb-client')
96
10-// generate a new keypair
11-var keys = ssbkeys.generate()
7 +var Client = require('./')
128
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)
1512
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()
1927 })
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-})
3428
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-}
4129 ```
4230
4331 ## License
4432
45-MIT, Copyright 2015 Paul Frazee and Dominic Tarr
33 +MIT, Copyright 2015 Paul Frazee and Dominic Tarr

Built with git-ssb-web