mirror of
https://github.com/nbd-wtf/nostr-tools.git
synced 2025-12-09 08:38:50 +00:00
some small fixes.
This commit is contained in:
7
pool.js
7
pool.js
@@ -23,7 +23,7 @@ export function relayPool(globalPrivateKey) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const sub = async (cb, params) => {
|
const sub = async (cb, params) => {
|
||||||
const subControllers = R.map(relay => {
|
const subControllers = R.map(({relay}) => {
|
||||||
return relay.sub(params, cb.bind(null, relay))
|
return relay.sub(params, cb.bind(null, relay))
|
||||||
}, R.filter(R.pipe(R.prop('policy'), R.prop('write'), R.equals(true)), relays))
|
}, R.filter(R.pipe(R.prop('policy'), R.prop('write'), R.equals(true)), relays))
|
||||||
|
|
||||||
@@ -38,6 +38,7 @@ export function relayPool(globalPrivateKey) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
sub,
|
||||||
relays,
|
relays,
|
||||||
setPrivateKey(privateKey) {
|
setPrivateKey(privateKey) {
|
||||||
globalPrivateKey = privateKey
|
globalPrivateKey = privateKey
|
||||||
@@ -71,10 +72,6 @@ export function relayPool(globalPrivateKey) {
|
|||||||
relay.close()
|
relay.close()
|
||||||
delete relays[relayURL]
|
delete relays[relayURL]
|
||||||
},
|
},
|
||||||
offEvent(cb) {
|
|
||||||
let index = eventCallbacks.indexOf(cb)
|
|
||||||
if (index !== -1) eventCallbacks.splice(index, 1)
|
|
||||||
},
|
|
||||||
onNotice(cb) {
|
onNotice(cb) {
|
||||||
noticeCallbacks.push(cb)
|
noticeCallbacks.push(cb)
|
||||||
},
|
},
|
||||||
|
|||||||
6
relay.js
6
relay.js
@@ -29,9 +29,7 @@ export function relayConnect(url, onNotice) {
|
|||||||
var channels = {}
|
var channels = {}
|
||||||
|
|
||||||
function connect() {
|
function connect() {
|
||||||
ws = new WebSocket(
|
ws = new WebSocket(url)
|
||||||
url + (url.indexOf('?') !== -1 ? '&' : '?') + `session=${Math.random()}`
|
|
||||||
)
|
|
||||||
|
|
||||||
ws.onopen = () => {
|
ws.onopen = () => {
|
||||||
console.log('connected to', url)
|
console.log('connected to', url)
|
||||||
@@ -135,7 +133,7 @@ export function relayConnect(url, onNotice) {
|
|||||||
url,
|
url,
|
||||||
sub: R.partial(sub, [sha256(Math.random().toString())]),
|
sub: R.partial(sub, [sha256(Math.random().toString())]),
|
||||||
async publish(event) {
|
async publish(event) {
|
||||||
trySend(JSON.stringify(event))
|
trySend(JSON.stringify(['EVENT', event]))
|
||||||
},
|
},
|
||||||
close() {
|
close() {
|
||||||
ws.close()
|
ws.close()
|
||||||
|
|||||||
Reference in New Issue
Block a user