git ssb

0+

ev / microbay



forked from Dominic / patchbay

Tree: 9e6d7abeec492c4285f15bcf6ff689c60be4062b

Files: 9e6d7abeec492c4285f15bcf6ff689c60be4062b / modules / invite.js

1983 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
14exports.screen_view = function (invite) {
15
16 //check that invite is
17 // ws:...~shs:key:seed
18
19 var parts = invite.split('~')
20 .map(function (e) { return e.split(':') })
21
22 if(parts.length !== 2) return null
23 if(!/^(net|wss?)$/.test(parts[0][0])) return null
24 if(parts[1][0] !== 'shs') return null
25 if(parts[1].length !== 3) return null
26
27 var progress = Progress(4)
28
29 //connect to server
30 //request follow
31 //post pub announce
32 //post follow pub
33 var div = h('div',
34 progress,
35 h('a', 'accept', {href: '#', onclick: function (ev) {
36 ev.preventDefault()
37 ev.stopPropagation()
38 attempt()
39 return false
40 }})
41 )
42
43 function attempt () {
44 progress.next('connecting...')
45 ssbClient(null, {
46 remote: invite,
47 manifest: { invite: {use: 'async'}, getAddress: 'async' }
48 }, function (err, sbot) {
49 if(err) return progress.fail(err)
50 else progress.next('requesting follow...')
51
52 sbot.invite.use({feed: id}, function (err, msg) {
53 if(err) return progres.fail(err)
54
55 progress.next('following...')
56
57 //remove the seed from the shs address.
58 //then it's correct address.
59 //this should make the browser connect to this as remote.
60 //we don't want to do this if when using this locally, though.
61 if(process.title === 'browser') {
62 var p2 = invite.split(':')
63 p2.pop()
64 localStorage.remote = p2.join(':')
65 }
66
67 sbot_publish({
68 type: 'contact',
69 contact: sbot.id,
70 following: true,
71 }, function (err) {
72 if(err) return progress.fail(err)
73 progress.complete()
74 })
75
76 })
77 })
78 }
79
80 return div
81}
82
83
84

Built with git-ssb-web