Files: 189ea696503edd87a02520c0ce49b108203029a8 / index.js
1084 bytesRaw
1 | var secretStack = require('secret-stack') |
2 | var keys = require('./keys.json') |
3 | var appkey = require('./appkeys.json') |
4 | var muxrpc = require('muxrpc') |
5 | var ms = require('multiserver') |
6 | var mdns = require('mdns') |
7 | |
8 | var 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 | |
29 | var node = createApp({ |
30 | keys: keys |
31 | }) |
32 | |
33 | var record = { |
34 | name: process.argv[3] || 'poopface', |
35 | address: node.getAddress() |
36 | } |
37 | |
38 | var ad = mdns.createAdvertisement(mdns.tcp('http'), 11111, {txtRecord: record}) |
39 | ad.start() |
40 | |
41 | var browser = mdns.createBrowser(mdns.tcp('http'), 11111) |
42 | browser.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 | |
52 | console.log(node.getAddress()) |
53 |
Built with git-ssb-web