git ssb

1+

cheerbitch / dexbot



Commit b626415ac9a778373cd5c4b1dcd55f753b35fac8

2 way

Tree committed on 2/9/2017, 11:10:20 PM
Parent: 7ee68cce07619a37738000cf95b21384c9e55ca2

Files changed

core/index.jschanged
index.jschanged
test.jschanged
core/index.jsView
@@ -24,8 +24,9 @@
2424
2525 $.manifest = {
2626 rc: 'duplex',
2727 callback: 'duplex',
28 + emit: 'async',
2829 assimilate: 'duplex',
2930 greet: 'async',
3031 createLog: 'duplex',
3132 getLog: 'source',
@@ -53,8 +54,9 @@
5354 }
5455 }
5556
5657 $.permissions = {
58 + uxer : ['emit'],
5759 anonymous: ['rc', 'assimilate', 'callback', 'greet', 'bonjour', 'connect', 'createLog', 'getLog', 'netcast', 'greeting'],
5860 replicate: ['push', 'pull', 'sync'],
5961 log : ['add', 'append', 'batch', 'get', 'heads', 'headStream', 'updates'],
6062 sign: ['sign', 'onConnect'],
@@ -102,18 +104,24 @@
102104 if(cb) cb(null, true)
103105 }
104106 else cb(null, false)
105107 },
108 + 'emit' : function(channel, data, cb){
109 + dex.emit(channel, data)
110 + if(cb) cb(null, true)
111 + },
106112 'callback' : function(id){
107113 var em = new emitter
108114 var st = emStream(em)
109115 var dupe = toPull.duplex(st)
116 + var rst = emStream(st)
110117 dex.on('to:' + id, function(data){
118 + console.log(data)
111119 em.emit('to:' + id, {from: bot.keys.id, msg: data})
112120 })
113- var rst = emStream(st)
114121
115122 rst.on('to:'+bot.keys.id,function(data){
123 + dex.emit('to:'+bot.keys.id, data)
116124 console.log(data)
117125 })
118126 return dupe
119127 },
@@ -163,21 +171,22 @@
163171 var rc = rpc.dexbot.rc(bot.keys.id)
164172 var local = server.createStream()
165173 pull(rc, local, rc)
166174 */
167- // set up messaging
175 + // set up two way messaging
168176 var pst = rpc.dexbot.callback(bot.keys.id)
169177 var dupe = emStream(toStream(pst))
170-
178 +
171179 var rdupe = emStream(dupe)
172- var tp = toPull(rdupe)
180 + var tp = toPull.duplex(rdupe)
173181
174- pull(tp, pst, tp)
175- setInterval(function(){
176- rdupe.emit('to:'+rpc.id, {from: bot.keys.id, msg: "salt"})
177- }, 1000)
182 + pull(pst, tp, pst)
183 +
184 + dex.on('to:'+rpc.id, function(data){
185 + dupe.emit('to:'+rpc.id, {from: bot.keys.id, msg: data})
186 + })
187 +
178188 dupe.on('to:'+bot.keys.id, function(data){
179-
180189 dex.emit('to:'+bot.keys.id, data)
181190 })
182191
183192
index.jsView
@@ -65,8 +65,8 @@
6565 })
6666 })
6767 Object.assign(bot.do, node.dexbot)
6868 bot.on = node.on
69-
69 + bot.emit = node.emit
7070 return bot
7171
7272 }
test.jsView
@@ -59,8 +59,9 @@
5959 setInterval(function(){
6060 var msg = `helloworld, it's ${(Math.ceil(Date.now() * Math.random()))} fast 0'clock.`
6161 //console.log(msg)
6262 person.log.add([], msg, function(err, ok){
63 + person.do.emit('to:'+friend.keys.id, "YOU MAD")
6364 })}, 3000)
6465
6566
6667

Built with git-ssb-web