Commit 31f416228e9b71e3d3d8d917f863f64625d5a32e
changed to work with rpc:connect - will now work with remote peers, not just local connections
Joran committed on 7/13/2019, 11:13:27 PMParent: 6fb1bd52eeeee6c62ab88945148ae660e8ada5af
Files changed
index.js | changed |
index.js | ||
---|---|---|
@@ -5,45 +5,28 @@ | ||
5 | 5 … | exports.version = '1.1.0' |
6 | 6 … | exports.manifest = {} |
7 | 7 … | |
8 | 8 … | exports.init = (api, opts) => { |
9 | - api.connect.hook((connect, args) => { | |
10 | - const address = args[0] | |
11 | - const cb = args[1] | |
12 | - const our_id = api.whoami().id | |
9 … | + api.on('rpc:connect', function (rpc, args) { | |
10 … | + console.log("connection from: ", rpc.id) | |
13 | 11 … | |
14 | - connect(address, (err, x) => { | |
15 | - if (err) return cb(err) | |
12 … | + var our_id = api.whoami().id | |
13 … | + var connecting_id = rpc.id | |
16 | 14 … | |
17 | - const p = api.multiserver.parse(address) | |
18 | - if (!Array.isArray(p) | |
19 | - || p.length < 1 | |
20 | - || p[0].length < 2 | |
21 | - || !("key" in p[0][1])) | |
22 | - { | |
23 | - console.log("unexpected result when parsing address:", address, " result:", p) | |
24 | - return cb(null, x) | |
15 … | + api.friends.isFollowing({source: our_id, dest: connecting_id}, (err, following) => { | |
16 … | + if (following) { | |
17 … | + console.log("already following:", connecting_id) | |
18 … | + } else { | |
19 … | + // Yay more friendssss | |
20 … | + console.log("stranger! New friend :3", connecting_id) | |
21 … | + | |
22 … | + api.publish({ | |
23 … | + type: "contact", | |
24 … | + contact: connecting_id, | |
25 … | + following: true | |
26 … | + }, () => { | |
27 … | + console.log("Followed", connecting_id) | |
28 … | + }) | |
25 | 29 … | } |
26 | - | |
27 | - const connecting_id = '@' + p[0][1].key.toString('base64') + '.ed25519' | |
28 | - | |
29 | - api.friends.isFollowing({source: our_id, dest: connecting_id}, (err, following) => { | |
30 | - if (following) { | |
31 | - console.log("already following:", connecting_id) | |
32 | - cb(null, x) | |
33 | - } else { | |
34 | - // Yay more friendssss | |
35 | - console.log("stranger! New friend :3", connecting_id) | |
36 | - | |
37 | - api.publish({ | |
38 | - type: "contact", | |
39 | - contact: connecting_id, | |
40 | - following: true | |
41 | - }, () => { | |
42 | - console.log("Followed", connecting_id) | |
43 | - cb(null, x) | |
44 | - }) | |
45 | - } | |
46 | - }) | |
47 | 30 … | }) |
48 | 31 … | }) |
49 | 32 … | } |
Built with git-ssb-web