Expose `fetchCommunityDescription` in request client (#386)
* export val
* add started flag
* use pks[]
* fix export
* throw on stop
* rm log
* Revert "use pks[]"
This reverts commit 5d4d7e4b6e
.
* make fn public
This commit is contained in:
parent
665d2df7e8
commit
ab319aa602
|
@ -15,7 +15,7 @@ export { EthereumClient } from './ethereum-client/ethereum-client'
|
||||||
export type { ChannelInfo } from './request-client/map-channel'
|
export type { ChannelInfo } from './request-client/map-channel'
|
||||||
export type { CommunityInfo } from './request-client/map-community'
|
export type { CommunityInfo } from './request-client/map-community'
|
||||||
export type { UserInfo } from './request-client/map-user'
|
export type { UserInfo } from './request-client/map-user'
|
||||||
export type { RequestClient } from './request-client/request-client'
|
export { RequestClient } from './request-client/request-client'
|
||||||
export { createRequestClient } from './request-client/request-client'
|
export { createRequestClient } from './request-client/request-client'
|
||||||
export { deserializePublicKey } from './utils/deserialize-public-key'
|
export { deserializePublicKey } from './utils/deserialize-public-key'
|
||||||
export {
|
export {
|
||||||
|
|
|
@ -38,9 +38,12 @@ class RequestClient {
|
||||||
/** Cache. */
|
/** Cache. */
|
||||||
public readonly wakuMessages: Set<string>
|
public readonly wakuMessages: Set<string>
|
||||||
|
|
||||||
constructor(waku: WakuLight) {
|
private started: boolean
|
||||||
|
|
||||||
|
constructor(waku: WakuLight, started = false) {
|
||||||
this.waku = waku
|
this.waku = waku
|
||||||
this.wakuMessages = new Set()
|
this.wakuMessages = new Set()
|
||||||
|
this.started = started
|
||||||
}
|
}
|
||||||
|
|
||||||
static async start(options: RequestClientOptions): Promise<RequestClient> {
|
static async start(options: RequestClientOptions): Promise<RequestClient> {
|
||||||
|
@ -67,7 +70,8 @@ class RequestClient {
|
||||||
await waku.start()
|
await waku.start()
|
||||||
await waitForRemotePeer(waku, [Protocols.Store], 10 * 1000)
|
await waitForRemotePeer(waku, [Protocols.Store], 10 * 1000)
|
||||||
|
|
||||||
client = new RequestClient(waku)
|
const started = true
|
||||||
|
client = new RequestClient(waku, started)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (waku) {
|
if (waku) {
|
||||||
await waku.stop()
|
await waku.stop()
|
||||||
|
@ -80,7 +84,13 @@ class RequestClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
public async stop() {
|
public async stop() {
|
||||||
|
if (!this.started) {
|
||||||
|
throw new Error('Waku instance not created by class initialization')
|
||||||
|
}
|
||||||
|
|
||||||
await this.waku.stop()
|
await this.waku.stop()
|
||||||
|
|
||||||
|
this.started = false
|
||||||
}
|
}
|
||||||
|
|
||||||
public fetchCommunity = async (
|
public fetchCommunity = async (
|
||||||
|
@ -127,8 +137,8 @@ class RequestClient {
|
||||||
return mapUser(contactCodeAdvertisement, publicKey)
|
return mapUser(contactCodeAdvertisement, publicKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fetchCommunityDescription = async (
|
public fetchCommunityDescription = async (
|
||||||
/** Uncompressed */
|
/** Compressed */
|
||||||
publicKey: string
|
publicKey: string
|
||||||
): Promise<CommunityDescription | undefined> => {
|
): Promise<CommunityDescription | undefined> => {
|
||||||
const contentTopic = idToContentTopic(publicKey)
|
const contentTopic = idToContentTopic(publicKey)
|
||||||
|
@ -317,4 +327,4 @@ export async function createRequestClient(
|
||||||
return await RequestClient.start(options)
|
return await RequestClient.start(options)
|
||||||
}
|
}
|
||||||
|
|
||||||
export type { RequestClient }
|
export { RequestClient }
|
||||||
|
|
Loading…
Reference in New Issue