git ssb

16+

Dominic / patchbay



Tree: 80053725d6e9728e8a7002217581df77265f422d

Files: 80053725d6e9728e8a7002217581df77265f422d / modules / invite.js

2460 bytesRaw
1
2var ref = require('ssb-ref')
3var ssbClient = require('ssb-client')
4var id = require('../keys').id
5var h = require('hyperscript')
6
7var plugs = require('../plugs')
8var sbot_publish = plugs.first(exports.sbot_publish = [])
9
10
11exports.screen_view = function (invite) {
12
13 //check that invite is
14 // ws:...~shs:key:seed
15
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
24 //connect to server
25 //request follow
26 //post pub announce
27 //post follow pub
28 var progress = h('h1')
29 var status = h('pre')
30 var div = h('div',
31 progress, status,
32 h('a', 'accept', {href: '#', onclick: function (ev) {
33 ev.preventDefault()
34 ev.stopPropagation()
35 attempt()
36 return false
37 }})
38 )
39
40 function attempt () {
41 progress.textContent = '*'
42 status.textContent = 'connecting...'
43
44 console.log("CONNECT", invite)
45 ssbClient(null, {
46 remote: invite,
47 manifest: { invite: {use: 'async'}, getAddress: 'async' }
48 }, function (err, sbot) {
49 console.log("ERR?", err, sbot)
50 if(err) {
51 progress.textContent = '*!'
52 status.textContent = err.stack
53 return
54 }
55 progress.textContent = '**'
56 status.textContent = 'requesting follow...' + id
57
58 sbot.invite.use({feed: id}, function (err, msg) {
59 if(err) {
60 progress.textContent = '**!'
61 status.textContent = err.stack
62 return
63 }
64 progress.textContent = '***'
65 status.textContent = 'following...'
66
67 //remove the seed from the shs address.
68 //then it's correct address.
69 //this should make the browser connect to this as remote.
70 //we don't want to do this if when using this locally, though.
71 if(process.title === 'browser') {
72 var p2 = invite.split(':')
73 p2.pop()
74 localStorage.remote = p2.join(':')
75 }
76
77 sbot_publish({
78 type: 'contact',
79 contact: sbot.id,
80 following: true
81 }, function (err) {
82 if(err) {
83 progress.textContent = '***!'
84 status.textContent = err.stack
85 return
86 }
87 progress.textContent = '****'
88 status.textContent = 'READY!'
89
90 })
91
92 })
93 })
94 }
95
96 return div
97}
98
99
100

Built with git-ssb-web