Commit da4ee60db3eb59749ab43aa220207d68fe5d99c6
enable opening + acceptance of peer-invites
mixmix committed on 7/5/2019, 7:54:04 AMParent: efdafe9ae6b7e67b523bb966a61bc97335a784dd
Files changed
app/page/network/invite-peer.js | changed |
package-lock.json | changed |
package.json | changed |
app/page/network/invite-peer.js | |||
---|---|---|---|
@@ -7,13 +7,15 @@ | |||
7 | 7 … | } | |
8 | 8 … | ||
9 | 9 … | module.exports = function InvitePeer ({ connection }) { | |
10 | 10 … | const state = { | |
11 | - // use: { | ||
12 | - // invite: Value(), | ||
13 | - // processing: Value(false), | ||
14 | - // result: Value(null) | ||
15 | - // }, | ||
11 … | + use: { | ||
12 … | + invite: Value(), | ||
13 … | + opening: Value(false), | ||
14 … | + message: Value(null), | ||
15 … | + accepting: Value(false), | ||
16 … | + result: Value(null) | ||
17 … | + }, | ||
16 | 18 … | create: { | |
17 | 19 … | input: { | |
18 | 20 … | private: Value(), | |
19 | 21 … | reveal: Value() | |
@@ -24,27 +26,43 @@ | |||
24 | 26 … | } | |
25 | 27 … | } | |
26 | 28 … | ||
27 | 29 … | const body = h('InvitePeer', [ | |
28 | - // h('div.use', [ | ||
29 | - // h('input', { | ||
30 | - // 'placeholder': 'peer invite code', | ||
31 | - // 'ev-input': handleInviteCode | ||
32 | - // }), | ||
33 | - // computed([state.use.invite, state.use.processing], (invite, processing) => { | ||
34 | - // if (processing) return h('i.fa.fa-spinner.fa-pulse') | ||
35 | - // if (invite) return h('button -primary', { 'ev-click': useInvite }, 'use invite') | ||
30 … | + h('div.use', [ | ||
31 … | + h('input', { | ||
32 … | + 'placeholder': 'peer invite code', | ||
33 … | + 'ev-input': handleInput | ||
34 … | + }), | ||
35 … | + h('div.actions', computed( | ||
36 … | + [state.use.invite, state.use.opening, state.use.message, state.use.accepting], | ||
37 … | + (invite, opening, message, accepting) => { | ||
38 … | + if (opening || accepting) { | ||
39 … | + return [ | ||
40 … | + h('button', { disabled: 'disabled' }, [ | ||
41 … | + h('i.fa.fa-spinner.fa-pulse') | ||
42 … | + ]) | ||
43 … | + ] | ||
44 … | + } | ||
36 | 45 … | ||
37 | - // return h('button', { disabled: 'disabled', title: 'not a valid invite code' }, 'use invite') | ||
38 | - // }), | ||
39 | - // computed(state.use.result, result => { | ||
40 | - // if (result === null) return | ||
46 … | + return [ | ||
47 … | + message && message.private ? h('div.private', message.private) : '', | ||
48 … | + message && message.reveal ? h('div.private', message.reveal) : '', | ||
49 … | + message | ||
50 … | + ? h('button -primary', { 'ev-click': acceptInvite }, 'accept invitation') | ||
51 … | + : invite | ||
52 … | + ? h('button -primary', { 'ev-click': openInvite }, 'use invite') | ||
53 … | + : h('button', { disabled: 'disabled', title: 'not a valid invite code' }, 'use invite') | ||
54 … | + ] | ||
55 … | + } | ||
56 … | + )), | ||
57 … | + computed(state.use.result, result => { | ||
58 … | + if (result === null) return | ||
41 | 59 … | ||
42 | - // return result | ||
43 | - // ? h('i.fa.fa-check') | ||
44 | - // : h('i.fa.fa-times') | ||
45 | - // }) | ||
46 | - // ]), | ||
60 … | + return result | ||
61 … | + ? h('i.fa.fa-check') | ||
62 … | + : h('i.fa.fa-times') | ||
63 … | + }) | ||
64 … | + ]), | ||
47 | 65 … | h('div.create', [ | |
48 | 66 … | h('textarea.private', { | |
49 | 67 … | placeholder: 'private message to your friend', | |
50 | 68 … | 'ev-input': (ev) => state.create.input.private.set(ev.target.value) | |
@@ -93,40 +111,59 @@ | |||
93 | 111 … | }) | |
94 | 112 … | }) | |
95 | 113 … | } | |
96 | 114 … | ||
97 | - // function handleInviteCode (ev) { | ||
98 | - // state.use.result.set(null) | ||
99 | - // const invite = ev.target.value.replace(/^\s*"?/, '').replace(/"?\s*$/, '') | ||
100 | - // if (!isInvite(invite)) { | ||
101 | - // state.use.invite.set() | ||
102 | - // return | ||
103 | - // } | ||
115 … | + function handleInput (ev) { | ||
116 … | + state.use.result.set(null) | ||
117 … | + const invite = ev.target.value.replace(/^\s*"?/, '').replace(/"?\s*$/, '') | ||
104 | 118 … | ||
105 | - // ev.target.value = invite | ||
106 | - // state.use.invite.set(invite) | ||
107 | - // } | ||
119 … | + if (!isInvite(invite)) return | ||
108 | 120 … | ||
109 | - // function useInvite () { | ||
110 | - // state.use.processing.set(true) | ||
121 … | + ev.target.value = invite | ||
122 … | + state.use.invite.set(invite) | ||
123 … | + } | ||
111 | 124 … | ||
112 | - // onceTrue(connection, server => { | ||
113 | - // // TODO use peerInvites | ||
114 | - // server.invite.accept(resolve(state.invite), (err, data) => { | ||
115 | - // state.inviteProcessing.set(false) | ||
116 | - // state.invite.set() | ||
125 … | + function openInvite () { | ||
126 … | + state.use.opening.set(true) | ||
117 | 127 … | ||
118 | - // if (err) { | ||
119 | - // state.use.result.set(false) | ||
120 | - // console.error(err) | ||
121 | - // return | ||
122 | - // } | ||
123 | - // state.use.result.set(true) | ||
124 | - // console.log(data) | ||
125 | - // }) | ||
126 | - // }) | ||
127 | - // } | ||
128 … | + console.log('openInvite', resolve(state.use.invite)) | ||
129 … | + onceTrue(connection, server => { | ||
130 … | + server.peerInvites.openInvite(resolve(state.use.invite), (err, msg, opened) => { | ||
131 … | + state.use.opening.set(false) | ||
132 … | + if (err) { | ||
133 … | + state.use.result.set(false) | ||
134 … | + console.error(err) | ||
135 … | + return | ||
136 … | + } | ||
128 | 137 … | ||
138 … | + console.log(err, msg, opened) // NOTE no opened arriving ... | ||
139 … | + // HACK | ||
140 … | + const m = opened || { | ||
141 … | + private: 'kiaora gorgeous, welcome' | ||
142 … | + } | ||
143 … | + state.use.message.set(m) | ||
144 … | + }) | ||
145 … | + }) | ||
146 … | + } | ||
147 … | + | ||
148 … | + function acceptInvite () { | ||
149 … | + state.use.accepting.set(true) | ||
150 … | + | ||
151 … | + onceTrue(connection, server => { | ||
152 … | + server.peerInvites.acceptInvite(resolve(state.use.invite), (err, confirm) => { | ||
153 … | + state.use.accepting.set(false) | ||
154 … | + if (err) { | ||
155 … | + state.use.result.set(false) | ||
156 … | + console.error(err) | ||
157 … | + return | ||
158 … | + } | ||
159 … | + | ||
160 … | + console.log('peerInvites.acceptInvite worked:', confirm) | ||
161 … | + state.use.result.set(true) | ||
162 … | + }) | ||
163 … | + }) | ||
164 … | + } | ||
165 … | + | ||
129 | 166 … | return { | |
130 | 167 … | title: 'peer invites', | |
131 | 168 … | body | |
132 | 169 … | } |
package-lock.json | ||
---|---|---|
The diff is too large to show. Use a local git client to view these changes. Old file size: 766493 bytes New file size: 766493 bytes |
package.json | ||
---|---|---|
@@ -112,9 +112,9 @@ | ||
112 | 112 … | "ssb-meme": "^1.0.4", |
113 | 113 … | "ssb-mentions": "^0.5.0", |
114 | 114 … | "ssb-mutual": "^0.1.0", |
115 | 115 … | "ssb-ooo": "^1.1.1", |
116 | - "ssb-peer-invites": "^1.2.0", | |
116 … | + "ssb-peer-invites": "^1.2.2", | |
117 | 117 … | "ssb-private": "^0.2.3", |
118 | 118 … | "ssb-query": "^2.1.0", |
119 | 119 … | "ssb-ref": "^2.13.6", |
120 | 120 … | "ssb-replicate": "^1.3.0", |
Built with git-ssb-web