sbot-api.jsView |
---|
14 | 14 | if(err && !onHash) throw err |
15 | 15 | onHash && onHash(err, '&'+hash.digest('base64')+'.sha256') |
16 | 16 | }) |
17 | 17 | } |
18 | | -var createClient = require('ssb-client') |
| 18 | +var createClient = require('ssb-lite') |
| 19 | + |
| 20 | +var createConfig = require('ssb-config/inject') |
| 21 | + |
| 22 | +var createFeed = require('ssb-feed') |
| 23 | +var keys = require('./keys') |
19 | 24 | |
| 25 | + |
20 | 26 | module.exports = function () { |
| 27 | + var opts = createConfig() |
21 | 28 | var sbot = null |
| 29 | + |
22 | 30 | var rec = Reconnect(function (isConn) { |
23 | | - console.log("RECONNECT", isConn) |
24 | | - createClient(function (err, _sbot) { |
| 31 | + createClient(keys, opts, function (err, _sbot) { |
25 | 32 | if(err) {console.error(err.stack); isConn(err)} |
26 | 33 | sbot = _sbot |
27 | 34 | sbot.on('closed', function () { |
28 | | - console.log("DISCONNECT") |
29 | 35 | sbot = null |
30 | 36 | isConn(new Error('closed')) |
31 | 37 | }) |
32 | 38 | isConn() |
33 | 39 | }) |
34 | 40 | }) |
35 | 41 | |
| 42 | + var internal = { |
| 43 | + getLatest: rec.async(function (id, cb) { |
| 44 | + sbot.getLatest(id, cb) |
| 45 | + }), |
| 46 | + add: rec.async(function (msg, cb) { |
| 47 | + sbot.add(msg, cb) |
| 48 | + }) |
| 49 | + } |
| 50 | + |
| 51 | + var feed = createFeed(internal, keys) |
| 52 | + |
36 | 53 | return { |
37 | 54 | sbot_blobs_add: rec.sink(function (cb) { |
38 | 55 | return pull( |
39 | 56 | Hash(cb), |
58 | 75 | sbot_get: rec.async(function (key, cb) { |
59 | 76 | sbot.get(key, cb) |
60 | 77 | }), |
61 | 78 | sbot_publish: rec.async(function (msg, cb) { |
62 | | - sbot.publish(msg, cb) |
| 79 | + feed.add(msg, function (err, msg) { |
| 80 | + cb(err, msg) |
| 81 | + }) |
63 | 82 | }), |
64 | 83 | sbot_whoami: rec.async(function (cb) { |
65 | 84 | sbot.whoami(cb) |
66 | 85 | }) |
67 | 86 | } |
68 | 87 | } |
69 | 88 | |
70 | 89 | |
| 90 | + |
| 91 | + |
| 92 | + |
| 93 | + |
| 94 | + |
| 95 | + |
| 96 | + |
| 97 | + |
| 98 | + |
| 99 | + |
| 100 | + |
| 101 | + |