Use WakuLight

This commit is contained in:
Felicio Mununga 2022-11-15 01:47:56 +01:00
parent 48d7f34803
commit 4590d4b852
No known key found for this signature in database
GPG Key ID: 0EB8D75C775AB6F1
2 changed files with 13 additions and 13 deletions

View File

@ -4,7 +4,7 @@
import { hexToBytes } from 'ethereum-cryptography/utils' import { hexToBytes } from 'ethereum-cryptography/utils'
import { Protocols } from 'js-waku' import { Protocols } from 'js-waku'
import { createFullNode } from 'js-waku/lib/create_waku' import { createLightNode } from 'js-waku/lib/create_waku'
import { PeerDiscoveryStaticPeers } from 'js-waku/lib/peer_discovery_static_list' import { PeerDiscoveryStaticPeers } from 'js-waku/lib/peer_discovery_static_list'
import { waitForRemotePeer } from 'js-waku/lib/wait_for_remote_peer' import { waitForRemotePeer } from 'js-waku/lib/wait_for_remote_peer'
import { SymEncoder } from 'js-waku/lib/waku_message/version_1' import { SymEncoder } from 'js-waku/lib/waku_message/version_1'
@ -18,7 +18,7 @@ import { handleWakuMessage } from './community/handle-waku-message'
import { LocalStorage } from './storage' import { LocalStorage } from './storage'
import type { Storage } from './storage' import type { Storage } from './storage'
import type { WakuFull } from 'js-waku/lib/interfaces' import type { WakuLight } from 'js-waku/lib/interfaces'
import type { MessageV1 as WakuMessage } from 'js-waku/lib/waku_message/version_1' import type { MessageV1 as WakuMessage } from 'js-waku/lib/waku_message/version_1'
const THROWAWAY_ACCOUNT_STORAGE_KEY = 'throwaway_account' const THROWAWAY_ACCOUNT_STORAGE_KEY = 'throwaway_account'
@ -37,7 +37,7 @@ export interface ClientOptions {
} }
class Client { class Client {
public waku: WakuFull public waku: WakuLight
public readonly wakuMessages: Set<string> public readonly wakuMessages: Set<string>
/** /**
* Tracks open connections which had their streams silently destroyed * Tracks open connections which had their streams silently destroyed
@ -62,7 +62,7 @@ class Client {
storage: Storage storage: Storage
constructor( constructor(
waku: WakuFull, waku: WakuLight,
wakuDisconnectionTimer: ReturnType<typeof setInterval>, wakuDisconnectionTimer: ReturnType<typeof setInterval>,
options: ClientOptions options: ClientOptions
) { ) {
@ -91,7 +91,7 @@ class Client {
// Waku // Waku
const { environment = 'production' } = options const { environment = 'production' } = options
const waku = await createFullNode({ const waku = await createLightNode({
defaultBootstrap: false, defaultBootstrap: false,
// eslint-disable-next-line @typescript-eslint/ban-ts-comment // eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore // @ts-ignore
@ -110,7 +110,7 @@ class Client {
}, },
}) })
await waku.start() await waku.start()
await waitForRemotePeer(waku, [Protocols.Relay, Protocols.Store], 10 * 1000) await waitForRemotePeer(waku, [Protocols.Store], 10 * 1000)
const wakuDisconnectionTimer = setInterval(async () => { const wakuDisconnectionTimer = setInterval(async () => {
const connectionsToClose: Promise<void>[] = [] const connectionsToClose: Promise<void>[] = []
@ -190,7 +190,7 @@ class Client {
payload, payload,
}) })
await this.waku.relay.send( await this.waku.lightPush.push(
new SymEncoder( new SymEncoder(
contentTopic, contentTopic,
symKey, symKey,

View File

@ -58,7 +58,7 @@ export class Community {
} }
// Observe community description // Observe community description
this.observe() await this.observe()
// Chats // Chats
await this.observeChatMessages(this.description.chats) await this.observeChatMessages(this.description.chats)
@ -97,9 +97,9 @@ export class Community {
return this.description return this.description
} }
private observe = () => { private observe = async () => {
this.client.waku.relay.addObserver( await this.client.waku.filter.subscribe(
new SymDecoder(this.contentTopic, this.symmetricKey), [new SymDecoder(this.contentTopic, this.symmetricKey)],
this.client.handleWakuMessage this.client.handleWakuMessage
) )
} }
@ -119,8 +119,8 @@ export class Community {
this.chats.set(chatUuid, chat) this.chats.set(chatUuid, chat)
const unobserveFn = this.client.waku.relay.addObserver( const unobserveFn = await this.client.waku.filter.subscribe(
new SymDecoder(chat.contentTopic, chat.symmetricKey), [new SymDecoder(chat.contentTopic, chat.symmetricKey)],
this.client.handleWakuMessage this.client.handleWakuMessage
) )