initial stab at private beacons
parent
6a19e648f2
commit
3fe02c9117
@ -0,0 +1,89 @@
|
||||
|
||||
function beaconsPage (keys) {
|
||||
|
||||
var pubslist = h('select')
|
||||
|
||||
localforage.getItem('securepubs').then(function (servers) {
|
||||
servers.forEach(function (pub) {
|
||||
pubslist.appendChild(
|
||||
h('option', {value: pub}, [pub])
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
var ads = h('div', {classList: 'message'})
|
||||
|
||||
ads.appendChild(h('span', {innerHTML: marked('Sometimes when you\'re lost on the Internet you might want to send out a beacon so that people can see you. \n\n Beacons from guests will run for 100 views before they are deleted by the pub. \n\nSelect a pub:')}))
|
||||
|
||||
ads.appendChild(pubslist)
|
||||
|
||||
var recp = h('input', {placeholder: 'Ex: @Q++V5BbvWIg8B+TqtC9ZKFhetruuw+nOgxEqfjlOZI0='})
|
||||
|
||||
var adstext = h('textarea', {placeholder: 'Hello World!'})
|
||||
|
||||
ads.appendChild(h('span', [
|
||||
h('br'),
|
||||
h('p', [" Send a beacon (leave the 'To:' field blank for a public beacon): "]),
|
||||
h('p', ['To: ',
|
||||
recp
|
||||
]),
|
||||
adstext,
|
||||
h('br'),
|
||||
h('button', {
|
||||
onclick: function () {
|
||||
var split = pubslist.value.split('~')
|
||||
console.log(split)
|
||||
var serverurl = split[0]
|
||||
var serverpub = split[1]
|
||||
var ws = new WebSocket(serverurl)
|
||||
|
||||
if ((recp.value) && (adstext.value)) {
|
||||
var tobox = {
|
||||
author: keys.publicKey,
|
||||
timestamp: Date.now(),
|
||||
content: adstext.value
|
||||
}
|
||||
box(JSON.stringify(tobox), recp.value, keys).then(boxedmsg => {
|
||||
var msg = {
|
||||
type: 'beacon',
|
||||
author: keys.publicKey,
|
||||
box: boxedmsg
|
||||
}
|
||||
ws.onopen = function () {
|
||||
box(JSON.stringify(msg), serverpub, keys).then(boxed => {
|
||||
var obj = {
|
||||
requester: keys.publicKey,
|
||||
box: boxed
|
||||
}
|
||||
ws.send(JSON.stringify(obj))
|
||||
})
|
||||
adstext.value = ''
|
||||
recp.value = ''
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
if ((!recp.value) && (adstext.value)) {
|
||||
var msg = {
|
||||
type: 'beacon',
|
||||
author: keys.publicKey
|
||||
}
|
||||
msg.signature = nacl.util.encodeBase64(nacl.sign(nacl.util.decodeUTF8(JSON.stringify(adstext.value)), nacl.util.decodeBase64(keys.privateKey)))
|
||||
ws.onopen = function () {
|
||||
box(JSON.stringify(msg), serverpub, keys).then(boxed => {
|
||||
var obj = {
|
||||
requester: keys.publicKey,
|
||||
box: boxed
|
||||
}
|
||||
ws.send(JSON.stringify(obj))
|
||||
})
|
||||
adstext.value = ''
|
||||
}
|
||||
}
|
||||
}
|
||||
}, ['Publish'])
|
||||
]))
|
||||
|
||||
scroller.appendChild(ads)
|
||||
}
|
||||
|
Loading…
Reference in New Issue