index.js (1243B)
1 localStorage.debug = 'völkrom' 2 3 class Völkrom { 4 constructor(debug = true) { 5 this._debug = debug 6 this.state = {} 7 this.bus = bus('völkrom') 8 this.router = router('/404') 9 this.debug = create_debug('völkrom') 10 11 this.node = document.getElementById('volkrom') 12 this.content_node = html`<div></div>` 13 this.node.appendChild(this.content_node) 14 } 15 16 async start() { 17 await this.init() 18 this.debug('successfully started') 19 } 20 21 async init() { 22 this.archive = await DatArchive.load(await DatArchive.resolveName(window.location.href)) 23 this.is_owner = (await this.archive.getInfo()).isOwner 24 this.state.peers = (await experimental.datPeers.list(await DatArchive.resolveName(window.location.href))).length 25 let p = this.state.peers 26 this.debug(`right now there ${p > 1 ? 'are' : 'is'} ${this.state.peers} ${p > 1 ? 'peers' : 'peer'} connected`) 27 if (this.is_owner) { 28 this.debug('current peer is owner') 29 } 30 } 31 32 on(event, callback) { 33 if (this._debug) { 34 this.bus.on(event, (...parameters) => { 35 this.debug(`event '${event}' called with ${!(!(parameters)) ? 'no parameters' : JSON.stringify(parameters)}`) 36 callback( ...parameters ) 37 }) 38 } else { 39 this.bus.on(event, callback) 40 } 41 } 42 } 43 44 export default Völkrom