From a25e6c4265374bf5448105d89439004a86132014 Mon Sep 17 00:00:00 2001 From: Richard Bondi Date: Fri, 19 Feb 2021 12:08:01 -0600 Subject: [PATCH] reuse channel for sub sub --- relay.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/relay.js b/relay.js index 488674b..41bb652 100644 --- a/relay.js +++ b/relay.js @@ -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]) } }