Files: b626415ac9a778373cd5c4b1dcd55f753b35fac8 / test.js
2302 bytesRaw
1 | var spawnBot = require('./bot') |
2 | var ps = require('pull-stream') |
3 | var toStream = require('pull-stream-to-stream') |
4 | var hyperlog = require('hyperlog') |
5 | var db = require('memdb') |
6 | var emStream = require('emit-stream') |
7 | |
8 | var person = spawnBot() |
9 | var friend = spawnBot() |
10 | |
11 | console.log(friend.keys) |
12 | friend.on('rpc:connect', function(whom){ |
13 | console.log(whom) |
14 | }) |
15 | |
16 | friend.do.connect(person, function(err, peer){ |
17 | |
18 | var rs = peer.dexbot.replicate.sync({live: true}, function(err){ |
19 | //console.log('*************************\n', err) |
20 | }) |
21 | /* // this was added to dexbot.connect |
22 | var dupe = emStream(toStream(peer.dexbot.callback(friend.keys.public))) |
23 | |
24 | dupe.on('to:'+friend.keys.public, function(data){ |
25 | console.log(data) |
26 | }) |
27 | */ |
28 | |
29 | // this should become part of replicate |
30 | // mkdirp a log per public key |
31 | // treat all logs the same |
32 | |
33 | var srs = friend.do.createLog(person.keys.id) // cheatcode for id |
34 | var xrs = friend.do.assimilate(Math.random() + "") // cheatcode for id |
35 | |
36 | ps(rs, srs, rs) |
37 | |
38 | |
39 | // one way, get a rpc log, toStream it and listen to data events |
40 | var hlog = friend.do.getLog(person.keys.id) |
41 | var log = toStream.source(hlog) |
42 | |
43 | // another way, but the same, listen for the rpc pull stream drain events or use the following flow |
44 | //ps(hlog, ps.log()) |
45 | |
46 | |
47 | // local bot way, get the hyperlog replication stream directly |
48 | // note, should modify this to be a createReadStream, not replication? |
49 | // or, make replicate{push,pull,sync} general |
50 | |
51 | log = friend.logs[person.keys.id] // a replication stream |
52 | |
53 | log.on('add', function(data){ |
54 | console.log(data.value.toString()) |
55 | }) |
56 | |
57 | }) |
58 | |
59 | setInterval(function(){ |
60 | var msg = `helloworld, it's ${(Math.ceil(Date.now() * Math.random()))} fast 0'clock.` |
61 | //console.log(msg) |
62 | person.log.add([], msg, function(err, ok){ |
63 | person.do.emit('to:'+friend.keys.id, "YOU MAD") |
64 | })}, 3000) |
65 | |
66 | |
67 | |
68 | /* |
69 | |
70 | |
71 | friend.do.bonjour() |
72 | friend.do.onConnect(function(peer){ |
73 | peer.dexbot.greeting(friend.name, function(err, address){ |
74 | console.log(err, address) |
75 | peer.dexbot.sign(`${friend.name} says ${peer.id} is all right with ${friend.keys.id}`, function(err, msg){ |
76 | console.log(err, msg) |
77 | }) |
78 | //friend.do.greeting(friend.name, console.log) |
79 | }) |
80 | }) |
81 | mom.do.bonjour() |
82 | mom.do.greet(function(bot){ |
83 | //console.log(bot) |
84 | mom.do.connect(bot, function(rpc){ |
85 | |
86 | }) |
87 | }) |
88 | */ |
89 |
Built with git-ssb-web