diff --git a/web-chat/src/command.ts b/web-chat/src/command.ts index 1da11566d4..7c1ae620ac 100644 --- a/web-chat/src/command.ts +++ b/web-chat/src/command.ts @@ -78,6 +78,31 @@ function peers(waku: Waku | undefined): string[] { return response; } +function connections(waku: Waku | undefined): string[] { + if (!waku) { + return ['Waku node is starting']; + } + let response: string[] = []; + waku.libp2p.connections.forEach( + ( + connections: import('libp2p-interfaces/src/connection/connection')[], + peerId + ) => { + response.push(peerId + ':'); + let strConnections = ' connections: ['; + connections.forEach((connection) => { + strConnections += JSON.stringify(connection.stat); + }); + strConnections += ']'; + response.push(strConnections); + } + ); + if (response.length === 0) { + response.push('Not connected to any peer.'); + } + return response; +} + export default function handleCommand( input: string, waku: Waku | undefined, @@ -102,6 +127,9 @@ export default function handleCommand( case '/peers': peers(waku).map((str) => response.push(str)); break; + case '/connections': + connections(waku).map((str) => response.push(str)); + break; default: response.push(`Unknown Command '${command}'`); }