reuse channel for sub sub

This commit is contained in:
Richard Bondi 2021-02-19 12:08:01 -06:00
parent bdc778314d
commit a25e6c4265
No known key found for this signature in database
GPG Key ID: FB0E9BFF77E167D3
1 changed files with 3 additions and 3 deletions

View File

@ -115,13 +115,13 @@ export function relayConnect(url, onNotice) {
}
}
const sub = async ({cb, filter}) => {
const channel = (await sha256(Math.random().toString())).reduce((str, byte) => str + byte.toString(16).padStart(2, '0'), '')
const sub = async ({ch, cb, filter}) => {
const channel = ch || (await sha256(Math.random().toString())).reduce((str, byte) => str + byte.toString(16).padStart(2, '0'), '')
trySend(['REQ', channel, filter])
channels[channel] = cb
return {
sub: ({cb = cb, filter = filter}) => sub(channel, {cb, filter}),
sub: ({cb = cb, filter = filter}) => sub({ch: channel, cb, filter}),
unsub: () => trySend(['CLOSE', channel])
}
}