From ddb28f21b07fe209917605cde94b1522f1cfa12a Mon Sep 17 00:00:00 2001 From: fiatjaf Date: Thu, 30 Dec 2021 15:03:57 -0300 Subject: [PATCH] first version, reviving @rsbondi's work. --- .gitignore | 4 ++ .prettierrc.yaml | 10 +++++ README | 4 ++ index.html | 8 ++++ main.js | 101 ++++++++++++++++++++++++++++++++++++++++++++++ package.json | 15 +++++++ webpack.config.js | 21 ++++++++++ 7 files changed, 163 insertions(+) create mode 100644 .gitignore create mode 100644 .prettierrc.yaml create mode 100644 README create mode 100644 index.html create mode 100644 main.js create mode 100644 package.json create mode 100644 webpack.config.js diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f138991 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +yarn.lock +node_modules +*.wasm +out.js diff --git a/.prettierrc.yaml b/.prettierrc.yaml new file mode 100644 index 0000000..16c878e --- /dev/null +++ b/.prettierrc.yaml @@ -0,0 +1,10 @@ +semi: false +arrowParens: avoid +insertPragma: false +printWidth: 80 +proseWrap: preserve +singleQuote: true +trailingComma: none +useTabs: false +jsxBracketSameLine: false +bracketSpacing: false diff --git a/README b/README new file mode 100644 index 0000000..d17edae --- /dev/null +++ b/README @@ -0,0 +1,4 @@ +nostr-relay-registry +-------------------- + +a dynamic registry of nostr relays that tests for very basic tasks in real-time. diff --git a/index.html b/index.html new file mode 100644 index 0000000..abbfacc --- /dev/null +++ b/index.html @@ -0,0 +1,8 @@ + + + +Nostr Relay Registry + +
+ + diff --git a/main.js b/main.js new file mode 100644 index 0000000..e3886ae --- /dev/null +++ b/main.js @@ -0,0 +1,101 @@ +import {createApp, h} from 'vue' +import {relayConnect} from 'nostr-tools/relay' + +const App = { + data() { + return { + relays: [ + 'wss://nostr-pub.wellorder.net', + 'wss://relayer.fiatjaf.com', + 'wss://nostr.rocks' + ], + status: {} + } + }, + + mounted() { + this.connections = {} + this.relays.forEach(async url => { + this.status[url] = {} + + try { + let conn = relayConnect( + url, + () => {}, + () => { + this.status[url].didConnect = false + } + ) + this.status[url].didConnect = true + + try { + await conn.publish({ + id: '41ce9bc50da77dda5542f020370ecc2b056d8f2be93c1cedf1bf57efcab095b0', + pubkey: + '5a462fa6044b4b8da318528a6987a45e3adf832bd1c64bd6910eacfecdf07541', + created_at: 1640305962, + kind: 1, + tags: [], + content: 'running branle', + sig: '08e6303565e9282f32bed41eee4136f45418f366c0ec489ef4f90d13de1b3b9fb45e14c74f926441f8155236fb2f6fef5b48a5c52b19298a0585a2c06afe39ed' + }) + this.status[url].didPublish = true + } catch (err) { + this.status[url].didPublish = false + } + + let {unsub} = conn.sub( + { + cb: () => { + this.status[url].didQuery = true + unsub() + clearTimeout(willUnsub) + }, + filter: { + id: '41ce9bc50da77dda5542f020370ecc2b056d8f2be93c1cedf1bf57efcab095b0' + } + }, + 'nostr-registry' + ) + let willUnsub = setTimeout(() => { + unsub() + this.status[url].didQuery = false + }, 3000) + } catch (err) { + this.status[url].didConnect = false + } + }) + }, + + render() { + return h('table', {style: {fontSize: '28px'}}, [ + h('tr', [h('th'), h('th', 'connect'), h('th', 'read'), h('th', 'write')]), + ...this.relays.map(url => + h('tr', [ + h('th', {style: {textAlign: 'right'}}, url), + ...['didConnect', 'didQuery', 'didPublish'].map(attr => + h( + 'td', + { + style: { + fontSize: '50px', + textAlign: 'center', + padding: '5px 35px', + color: + this.status?.[url]?.[attr] === true + ? 'green' + : this.status?.[url]?.[attr] === false + ? 'red' + : 'silver' + } + }, + '•' + ) + ) + ]) + ) + ]) + } +} + +createApp(App).mount('#app') diff --git a/package.json b/package.json new file mode 100644 index 0000000..bf7ec7f --- /dev/null +++ b/package.json @@ -0,0 +1,15 @@ +{ + "dependencies": { + "buffer": "^6.0.3", + "nostr-tools": "^0.12.4", + "readable-stream": "^3.6.0", + "vue": "3" + }, + "devDependencies": { + "webpack": "^5.65.0", + "webpack-cli": "^4.9.1" + }, + "scripts": { + "build": "webpack" + } +} diff --git a/webpack.config.js b/webpack.config.js new file mode 100644 index 0000000..ae2584e --- /dev/null +++ b/webpack.config.js @@ -0,0 +1,21 @@ +const path = require('path') + +module.exports = { + mode: 'development', + entry: './main.js', + output: { + path: __dirname, + filename: 'out.js' + }, + experiments: {asyncWebAssembly: true}, + resolve: { + alias: { + stream: 'readable-stream' + }, + fallback: { + buffer: 'buffer/index.js', + stream: 'readable-stream/readable.js', + crypto: false + } + } +}