Files: b05c12ba850a6a9d4f5af6d9f32136f3baf5d75f / scuttlebot.js
970 bytesRaw
1 | var pull = require('pull-stream') |
2 | var ssbKeys = require('ssb-keys') |
3 | var ref = require('ssb-ref') |
4 | var reconnect = require('pull-reconnect') |
5 | |
6 | var config = require('./config')() |
7 | var createClient = require('ssb-client') |
8 | var keys = require('./keys') |
9 | |
10 | var CACHE = {} |
11 | |
12 | var rec = reconnect(function (isConn) { |
13 | function notify (value) { |
14 | isConn(value) |
15 | } |
16 | |
17 | createClient(keys, { |
18 | manifest: require('./manifest.json'), |
19 | remote: config.remote, |
20 | caps: config.caps |
21 | }, function (err, _sbot) { |
22 | if(err) |
23 | return notify(err) |
24 | |
25 | sbot = _sbot |
26 | sbot.on('closed', function () { |
27 | sbot = null |
28 | notify(new Error('closed')) |
29 | }) |
30 | |
31 | notify() |
32 | }) |
33 | }) |
34 | |
35 | module.exports = { |
36 | createLogStream: rec.source(function (opts) { |
37 | return pull( |
38 | sbot.createLogStream(opts), |
39 | pull.through(function (e) { |
40 | CACHE[e.key] = CACHE[e.key] || e.value |
41 | }) |
42 | ) |
43 | }), |
44 | query: rec.source(function (query) { |
45 | return sbot.query.read(query) |
46 | }) |
47 | } |
48 | |
49 |
Built with git-ssb-web