mirror of
https://github.com/nbd-wtf/nostr-tools.git
synced 2025-12-08 16:28:49 +00:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d46c5f947c |
@@ -128,7 +128,7 @@ import 'websocket-polyfill'
|
||||
### Interacting with multiple relays
|
||||
|
||||
```js
|
||||
import {SimplePool} from 'nostr-tools'
|
||||
import {pool} from 'nostr-tools'
|
||||
|
||||
const pool = new SimplePool()
|
||||
|
||||
@@ -293,11 +293,6 @@ Please consult the tests or [the source code](https://github.com/fiatjaf/nostr-t
|
||||
</script>
|
||||
```
|
||||
|
||||
## Plumbing
|
||||
|
||||
1. Install [`just`](https://just.systems/)
|
||||
2. `just -l`
|
||||
|
||||
## License
|
||||
|
||||
Public domain.
|
||||
|
||||
29
package.json
29
package.json
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "nostr-tools",
|
||||
"version": "1.4.1",
|
||||
"version": "1.3.2",
|
||||
"description": "Tools for making a Nostr client.",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@@ -9,12 +9,11 @@
|
||||
"main": "lib/nostr.cjs.js",
|
||||
"module": "lib/nostr.esm.js",
|
||||
"dependencies": {
|
||||
"@noble/hashes": "1.0.0",
|
||||
"@noble/secp256k1": "^1.7.1",
|
||||
"@noble/hashes": "^0.5.7",
|
||||
"@noble/secp256k1": "^1.7.0",
|
||||
"@scure/base": "^1.1.1",
|
||||
"@scure/bip32": "^1.1.5",
|
||||
"@scure/bip39": "^1.1.1",
|
||||
"prettier": "^2.8.4"
|
||||
"@scure/bip32": "^1.1.1",
|
||||
"@scure/bip39": "^1.1.0"
|
||||
},
|
||||
"keywords": [
|
||||
"decentralization",
|
||||
@@ -24,20 +23,20 @@
|
||||
"nostr"
|
||||
],
|
||||
"devDependencies": {
|
||||
"@types/node": "^18.13.0",
|
||||
"@typescript-eslint/eslint-plugin": "^5.51.0",
|
||||
"@typescript-eslint/parser": "^5.51.0",
|
||||
"@types/node": "^18.0.3",
|
||||
"@typescript-eslint/eslint-plugin": "^5.46.1",
|
||||
"@typescript-eslint/parser": "^5.46.1",
|
||||
"esbuild": "0.16.9",
|
||||
"esbuild-plugin-alias": "^0.2.1",
|
||||
"eslint": "^8.33.0",
|
||||
"eslint": "^8.30.0",
|
||||
"eslint-plugin-babel": "^5.3.1",
|
||||
"esm-loader-typescript": "^1.0.3",
|
||||
"esm-loader-typescript": "^1.0.1",
|
||||
"events": "^3.3.0",
|
||||
"jest": "^29.4.2",
|
||||
"node-fetch": "^2.6.9",
|
||||
"ts-jest": "^29.0.5",
|
||||
"jest": "^29.3.1",
|
||||
"node-fetch": "2",
|
||||
"ts-jest": "^29.0.3",
|
||||
"tsd": "^0.22.0",
|
||||
"typescript": "^4.9.5",
|
||||
"typescript": "^4.9.4",
|
||||
"websocket-polyfill": "^0.0.3"
|
||||
}
|
||||
}
|
||||
|
||||
6
relay.ts
6
relay.ts
@@ -38,6 +38,10 @@ export type SubscriptionOptions = {
|
||||
export function relayInit(url: string): Relay {
|
||||
var ws: WebSocket
|
||||
var resolveClose: () => void
|
||||
var setOpen: (value: PromiseLike<void> | void) => void
|
||||
var untilOpen = new Promise<void>(resolve => {
|
||||
setOpen = resolve
|
||||
})
|
||||
var openSubs: {[id: string]: {filters: Filter[]} & SubscriptionOptions} = {}
|
||||
var listeners: {
|
||||
connect: Array<() => void>
|
||||
@@ -70,6 +74,7 @@ export function relayInit(url: string): Relay {
|
||||
|
||||
ws.onopen = () => {
|
||||
listeners.connect.forEach(cb => cb())
|
||||
setOpen()
|
||||
resolve()
|
||||
}
|
||||
ws.onerror = () => {
|
||||
@@ -166,6 +171,7 @@ export function relayInit(url: string): Relay {
|
||||
async function trySend(params: [string, ...any]) {
|
||||
let msg = JSON.stringify(params)
|
||||
|
||||
await untilOpen
|
||||
try {
|
||||
ws.send(msg)
|
||||
} catch (err) {
|
||||
|
||||
Reference in New Issue
Block a user