git ssb

1+

cheerbitch / dexbot



Tree: 189ea696503edd87a02520c0ce49b108203029a8

Files: 189ea696503edd87a02520c0ce49b108203029a8 / index.js

1084 bytesRaw
1var secretStack = require('secret-stack')
2var keys = require('./keys.json')
3var appkey = require('./appkeys.json')
4var muxrpc = require('muxrpc')
5var ms = require('multiserver')
6var mdns = require('mdns')
7
8var createApp = secretStack({
9 appKey: appkey.private
10}).use({
11 name: 'spot',
12 manifest: {
13 public: {
14 greet: 'async'
15 }
16 },
17 permissions: {
18 anonymous: ['public.greet']
19 },
20 init: function(api, opts){
21 return {
22 'public.greet': function(arg, cb){
23 cb(null, 'GREETINGS')
24 }
25 }
26 }
27})
28
29var node = createApp({
30 keys: keys
31})
32
33var record = {
34 name: process.argv[3] || 'poopface',
35 address: node.getAddress()
36}
37
38var ad = mdns.createAdvertisement(mdns.tcp('http'), 11111, {txtRecord: record})
39ad.start()
40
41var browser = mdns.createBrowser(mdns.tcp('http'), 11111)
42browser.on('serviceUp', function(service){
43 console.log(service.txtRecord.address)
44 node.connect(service.txtRecord.address.split('~')[0], function(rpc){
45 rpc.public.greet(function(err, greets){
46 console.log(greets)
47 })
48 })
49})
50
51
52console.log(node.getAddress())
53

Built with git-ssb-web