|
1 | | -import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' |
2 | | -import { toString as uint8ArrayToString } from 'uint8arrays/to-string' |
3 | 1 | import debug from 'debug' |
4 | 2 | import { configure } from '../lib/configure.js' |
5 | 3 | import { toUrlSearchParams } from '../lib/to-url-search-params.js' |
| 4 | +import { textToUrlSafeRpc, rpcArrayToTextArray, rpcToBytes } from '../lib/http-rpc-wire-format.js' |
6 | 5 | const log = debug('ipfs-http-client:pubsub:subscribe') |
7 | 6 |
|
8 | 7 | /** |
@@ -43,7 +42,7 @@ export const createSubscribe = (options, subsTracker) => { |
43 | 42 | api.post('pubsub/sub', { |
44 | 43 | signal: options.signal, |
45 | 44 | searchParams: toUrlSearchParams({ |
46 | | - arg: topic, |
| 45 | + arg: textToUrlSafeRpc(topic), |
47 | 46 | ...options |
48 | 47 | }), |
49 | 48 | headers: options.headers |
@@ -95,10 +94,10 @@ async function readMessages (response, { onMessage, onEnd, onError }) { |
95 | 94 | } |
96 | 95 |
|
97 | 96 | onMessage({ |
98 | | - from: uint8ArrayToString(uint8ArrayFromString(msg.from, 'base64pad'), 'base58btc'), |
99 | | - data: uint8ArrayFromString(msg.data, 'base64pad'), |
100 | | - seqno: uint8ArrayFromString(msg.seqno, 'base64pad'), |
101 | | - topicIDs: msg.topicIDs |
| 97 | + from: msg.from, |
| 98 | + data: rpcToBytes(msg.data), |
| 99 | + seqno: rpcToBytes(msg.seqno), |
| 100 | + topicIDs: rpcArrayToTextArray(msg.topicIDs) |
102 | 101 | }) |
103 | 102 | } catch (/** @type {any} */ err) { |
104 | 103 | err.message = `Failed to parse pubsub message: ${err.message}` |
|
0 commit comments