a demonstration replicated social networking web app built with anproto wiredove.net/
social ed25519 protocols
at main 57 lines 1.5 kB view raw
1import { apds } from 'apds' 2import { joinRoom } from './trystero-torrent.min.js' 3import { render } from './render.js' 4 5export let chan 6 7export const sendTry = (m) => { 8 if (chan) { 9 if (m.length === 44) { 10 chan.sendHash(m)} 11 else { 12 chan.sendBlob(m) 13 } 14 } else { 15 setTimeout(() => {sendTry(m)}, 1000) 16 } 17} 18 19export const makeRoom = async (pubkey) => { 20 if (!chan) { 21 const room = joinRoom({appId: 'wiredovetestnet', password: 'iajwoiejfaowiejfoiwajfe'}, pubkey) 22 const [ sendHash, onHash ] = room.makeAction('hash') 23 const [ sendBlob, onBlob ] = room.makeAction('blob') 24 25 room.sendHash = sendHash 26 room.sendBlob = sendBlob 27 28 onHash(async (hash, id) => { 29 console.log(`Received: ${hash}`) 30 const get = await apds.get(hash) 31 if (get) { sendBlob(get, id)} 32 const latest = await apds.getLatest(hash) 33 if (latest) { sendBlob(latest.sig)} 34 }) 35 36 onBlob(async (blob, id) => { 37 console.log(`Received: ${blob}`) 38 //await process(blob) <-- trystero and ws should use the same process function 39 await apds.make(blob) 40 await render.shouldWe(blob) 41 await apds.add(blob) 42 await render.blob(blob) 43 }) 44 45 room.onPeerJoin(async (id) => { 46 console.log(id + ' joined the room ' + pubkey) 47 const latest = await apds.getLatest(await apds.pubkey()) 48 if (latest) { sendblob(latest.sig) } 49 }) 50 51 room.onPeerLeave(id => { 52 console.log(id + ' left the room ' + pubkey) 53 }) 54 55 chan = room 56 } 57}