git ssb

16+

Dominic / patchbay



Tree: 97fa340f0460a60182de015b9fbe534ac79b79b0

Files: 97fa340f0460a60182de015b9fbe534ac79b79b0 / modules / invite.js

2137 bytesRaw
1
2var ref = require('ssb-ref')
3var ssbClient = require('ssb-client')
4var id = require('../keys').id
5var h = require('hyperscript')
6
7var Progress = require('hyperprogress')
8
9var plugs = require('../plugs')
10var sbot_publish = plugs.first(exports.sbot_publish = [])
11
12
13//check that invite is
14// ws:...~shs:key:seed
15function parseMultiServerInvite (invite) {
16 var parts = invite.split('~')
17 .map(function (e) { return e.split(':') })
18
19 if(parts.length !== 2) return null
20 if(!/^(net|wss?)$/.test(parts[0][0])) return null
21 if(parts[1][0] !== 'shs') return null
22 if(parts[1].length !== 3) return null
23 var p2 = invite.split(':')
24 p2.pop()
25
26 return {
27 invite: invite,
28 remote: p2.join(':'),
29 }
30}
31
32exports.screen_view = function (invite) {
33
34 var data = parseMultiServerInvite(invite)
35 if(!data) return
36
37 var progress = Progress(4)
38
39 //connect to server
40 //request follow
41 //post pub announce
42 //post follow pub
43 var div = h('div.column',
44 h('div',
45 "invite to:", h('br'),
46 h('code', invite),
47 h('button', 'accept', {onclick: function (ev) {
48 attempt()
49 }})
50 ),
51 progress
52 )
53
54 function attempt () {
55 progress.reset().next('connecting...')
56 ssbClient(null, {
57 remote: invite,
58 manifest: { invite: {use: 'async'}, getAddress: 'async' }
59 }, function (err, sbot) {
60 if(err) return progress.fail(err)
61 else progress.next('requesting follow...')
62
63 sbot.invite.use({feed: id}, function (err, msg) {
64 if(err) return progress.fail(err)
65
66 progress.next('following...')
67
68 //remove the seed from the shs address.
69 //then it's correct address.
70 //this should make the browser connect to this as remote.
71 //we don't want to do this if when using this locally, though.
72 if(process.title === 'browser') {
73 localStorage.remote = data.remote
74 }
75
76 sbot_publish({
77 type: 'contact',
78 contact: sbot.id,
79 following: true,
80 }, function (err) {
81 if(err) return progress.fail(err)
82 progress.complete()
83 })
84
85 })
86 })
87 }
88
89 return div
90}
91
92

Built with git-ssb-web