-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: node connection state #1666
Comments
TODO: we need to when your js-waku node is connected to at least one peer/disconnected from all peers |
For first iteration we can go with implementing something like: get networkState(): string {
return hasPeers ? NetworkState.Online : NetworkState.Offline;
} Or we can use event based approach: const node = createNode();
node.addEventListener("netwrok", (state: online | offline) => { ... }); @adklempner @danisharora099 what do you thing? |
We may want both. I can imagine scenarios where it's more convenient to poll the network status as versus receiving it as an event, and vice-versa. |
Is Here's what I'm thinking of adding #1719 : private online: boolean = false;
public isConnected(): boolean {
return this.online;
}
private toggleOnline(): void {
if (!this.online) {
this.online = true;
this.dispatchEvent(new Event("waku:online"));
}
}
private toggleOffline(): void {
if (this.libp2p.getPeers().length == 0) {
this.online = false;
this.dispatchEvent(new Event("waku:offline"));
}
}
This assumes that having a single peer is enough to be considered "online". In the future we may change it if need be (e.g. if node is setup to use autosharding, it should be connected to at least one peer for each shard to be considered online) What I'm not sure about is a clean way to pass an event listener for the newly dispatched events ( |
I think for functionality but exposed it should be on the root level as we'd like to have it on the surface. Overall to me it seems as good approach, I would also use these events. @danisharora099 what do you think? |
I changed the way |
|
@danisharora099 I tried using that function but it always returned an array of length 0 after two
|
Weekly Update
|
This could be better tested by actually running one nwaku node and dialing it from the js waku node being tested. This should establish an actual connection and it will appear under To disconnect, use this function https://github.com/libp2p/js-libp2p/blob/13a870cbef326a3a3b3c55b886c2109feaa2b628/packages/libp2p/src/libp2p.ts#L301 |
@adklempner |
this issue is resolved |
This is a feature request
Problem
It is problematic for novice people to check if browser node is connected to
Waku network
Proposed Solutions
Enable users to easily check online/offline status and maybe other things. Good reference could be current browser behavior.
The text was updated successfully, but these errors were encountered: