mirror of
https://github.com/logos-messaging/lab.waku.org.git
synced 2026-01-07 00:03:07 +00:00
feat: message monitor (#95)
This commit is contained in:
parent
5f4b912b4c
commit
8b970b259c
1
.github/workflows/ci.yml
vendored
1
.github/workflows/ci.yml
vendored
@ -20,6 +20,7 @@ jobs:
|
||||
experimental/rln-js,
|
||||
experimental/rln-identity,
|
||||
dogfooding,
|
||||
message-monitor,
|
||||
flush-notes
|
||||
]
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
1
ci/Jenkinsfile
vendored
1
ci/Jenkinsfile
vendored
@ -42,6 +42,7 @@ pipeline {
|
||||
stage('experimental/rln-js') { steps { script { buildExample() } } }
|
||||
stage('experimental/rln-identity') { steps { script { buildExample() } } }
|
||||
stage('dogfooding') { steps { script { buildExample() } } }
|
||||
stage('message-monitor') { steps { script { buildExample() } } }
|
||||
stage('flush-notes') { steps { script { buildNextJSExample() } } }
|
||||
}
|
||||
}
|
||||
|
||||
23
examples/message-monitor/.gitignore
vendored
Normal file
23
examples/message-monitor/.gitignore
vendored
Normal file
@ -0,0 +1,23 @@
|
||||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
|
||||
|
||||
# dependencies
|
||||
/node_modules
|
||||
/.pnp
|
||||
.pnp.js
|
||||
|
||||
# testing
|
||||
/coverage
|
||||
|
||||
# production
|
||||
/build
|
||||
|
||||
# misc
|
||||
.DS_Store
|
||||
.env.local
|
||||
.env.development.local
|
||||
.env.test.local
|
||||
.env.production.local
|
||||
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
46
examples/message-monitor/README.md
Normal file
46
examples/message-monitor/README.md
Normal file
@ -0,0 +1,46 @@
|
||||
# Getting Started with Create React App
|
||||
|
||||
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
|
||||
|
||||
## Available Scripts
|
||||
|
||||
In the project directory, you can run:
|
||||
|
||||
### `npm start`
|
||||
|
||||
Runs the app in the development mode.\
|
||||
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
|
||||
|
||||
The page will reload if you make edits.\
|
||||
You will also see any lint errors in the console.
|
||||
|
||||
### `npm test`
|
||||
|
||||
Launches the test runner in the interactive watch mode.\
|
||||
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
|
||||
|
||||
### `npm run build`
|
||||
|
||||
Builds the app for production to the `build` folder.\
|
||||
It correctly bundles React in production mode and optimizes the build for the best performance.
|
||||
|
||||
The build is minified and the filenames include the hashes.\
|
||||
Your app is ready to be deployed!
|
||||
|
||||
See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
|
||||
|
||||
### `npm run eject`
|
||||
|
||||
**Note: this is a one-way operation. Once you `eject`, you can’t go back!**
|
||||
|
||||
If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
|
||||
|
||||
Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.
|
||||
|
||||
You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.
|
||||
|
||||
## Learn More
|
||||
|
||||
You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
|
||||
|
||||
To learn React, check out the [React documentation](https://reactjs.org/).
|
||||
23
examples/message-monitor/gitignore
Normal file
23
examples/message-monitor/gitignore
Normal file
@ -0,0 +1,23 @@
|
||||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
|
||||
|
||||
# dependencies
|
||||
/node_modules
|
||||
/.pnp
|
||||
.pnp.js
|
||||
|
||||
# testing
|
||||
/coverage
|
||||
|
||||
# production
|
||||
/build
|
||||
|
||||
# misc
|
||||
.DS_Store
|
||||
.env.local
|
||||
.env.development.local
|
||||
.env.test.local
|
||||
.env.production.local
|
||||
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
21224
examples/message-monitor/package-lock.json
generated
Normal file
21224
examples/message-monitor/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
50
examples/message-monitor/package.json
Normal file
50
examples/message-monitor/package.json
Normal file
@ -0,0 +1,50 @@
|
||||
{
|
||||
"name": "waku-message-monitor",
|
||||
"version": "0.1.0",
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"@testing-library/jest-dom": "^5.17.0",
|
||||
"@testing-library/react": "^13.4.0",
|
||||
"@testing-library/user-event": "^13.5.0",
|
||||
"@types/jest": "^27.5.2",
|
||||
"@types/node": "^16.18.111",
|
||||
"@types/react": "^18.3.9",
|
||||
"@types/react-dom": "^18.3.0",
|
||||
"@waku/sdk": "^0.0.29-338250a.0",
|
||||
"protobufjs": "^7.4.0",
|
||||
"react": "^18.3.1",
|
||||
"react-dom": "^18.3.1",
|
||||
"react-scripts": "5.0.1",
|
||||
"typescript": "^4.9.5",
|
||||
"web-vitals": "^2.1.4"
|
||||
},
|
||||
"scripts": {
|
||||
"start": "react-scripts start",
|
||||
"build": "react-scripts build",
|
||||
"test": "react-scripts test",
|
||||
"eject": "react-scripts eject"
|
||||
},
|
||||
"eslintConfig": {
|
||||
"extends": [
|
||||
"react-app",
|
||||
"react-app/jest"
|
||||
]
|
||||
},
|
||||
"browserslist": {
|
||||
"production": [
|
||||
">0.2%",
|
||||
"not dead",
|
||||
"not op_mini all"
|
||||
],
|
||||
"development": [
|
||||
"last 1 chrome version",
|
||||
"last 1 firefox version",
|
||||
"last 1 safari version"
|
||||
]
|
||||
},
|
||||
"devDependencies": {
|
||||
"autoprefixer": "^10.4.20",
|
||||
"postcss": "^8.4.47",
|
||||
"tailwindcss": "^3.4.13"
|
||||
}
|
||||
}
|
||||
6
examples/message-monitor/postcss.config.js
Normal file
6
examples/message-monitor/postcss.config.js
Normal file
@ -0,0 +1,6 @@
|
||||
module.exports = {
|
||||
plugins: {
|
||||
tailwindcss: {},
|
||||
autoprefixer: {},
|
||||
},
|
||||
}
|
||||
BIN
examples/message-monitor/public/favicon.ico
Normal file
BIN
examples/message-monitor/public/favicon.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 3.8 KiB |
43
examples/message-monitor/public/index.html
Normal file
43
examples/message-monitor/public/index.html
Normal file
@ -0,0 +1,43 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<meta name="theme-color" content="#000000" />
|
||||
<meta
|
||||
name="description"
|
||||
content="Web site created using create-react-app"
|
||||
/>
|
||||
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
|
||||
<!--
|
||||
manifest.json provides metadata used when your web app is installed on a
|
||||
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
|
||||
-->
|
||||
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
|
||||
<!--
|
||||
Notice the use of %PUBLIC_URL% in the tags above.
|
||||
It will be replaced with the URL of the `public` folder during the build.
|
||||
Only files inside the `public` folder can be referenced from the HTML.
|
||||
|
||||
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
|
||||
work correctly both with client-side routing and a non-root public URL.
|
||||
Learn how to configure a non-root public URL by running `npm run build`.
|
||||
-->
|
||||
<title>React App</title>
|
||||
</head>
|
||||
<body>
|
||||
<noscript>You need to enable JavaScript to run this app.</noscript>
|
||||
<div id="root"></div>
|
||||
<!--
|
||||
This HTML file is a template.
|
||||
If you open it directly in the browser, you will see an empty page.
|
||||
|
||||
You can add webfonts, meta tags, or analytics to this file.
|
||||
The build step will place the bundled scripts into the <body> tag.
|
||||
|
||||
To begin the development, run `npm start` or `yarn start`.
|
||||
To create a production bundle, use `npm run build` or `yarn build`.
|
||||
-->
|
||||
</body>
|
||||
</html>
|
||||
BIN
examples/message-monitor/public/logo192.png
Normal file
BIN
examples/message-monitor/public/logo192.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 5.2 KiB |
BIN
examples/message-monitor/public/logo512.png
Normal file
BIN
examples/message-monitor/public/logo512.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 9.4 KiB |
25
examples/message-monitor/public/manifest.json
Normal file
25
examples/message-monitor/public/manifest.json
Normal file
@ -0,0 +1,25 @@
|
||||
{
|
||||
"short_name": "React App",
|
||||
"name": "Create React App Sample",
|
||||
"icons": [
|
||||
{
|
||||
"src": "favicon.ico",
|
||||
"sizes": "64x64 32x32 24x24 16x16",
|
||||
"type": "image/x-icon"
|
||||
},
|
||||
{
|
||||
"src": "logo192.png",
|
||||
"type": "image/png",
|
||||
"sizes": "192x192"
|
||||
},
|
||||
{
|
||||
"src": "logo512.png",
|
||||
"type": "image/png",
|
||||
"sizes": "512x512"
|
||||
}
|
||||
],
|
||||
"start_url": ".",
|
||||
"display": "standalone",
|
||||
"theme_color": "#000000",
|
||||
"background_color": "#ffffff"
|
||||
}
|
||||
3
examples/message-monitor/public/robots.txt
Normal file
3
examples/message-monitor/public/robots.txt
Normal file
@ -0,0 +1,3 @@
|
||||
# https://www.robotstxt.org/robotstxt.html
|
||||
User-agent: *
|
||||
Disallow:
|
||||
38
examples/message-monitor/src/App.css
Normal file
38
examples/message-monitor/src/App.css
Normal file
@ -0,0 +1,38 @@
|
||||
.App {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.App-logo {
|
||||
height: 40vmin;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
@media (prefers-reduced-motion: no-preference) {
|
||||
.App-logo {
|
||||
animation: App-logo-spin infinite 20s linear;
|
||||
}
|
||||
}
|
||||
|
||||
.App-header {
|
||||
background-color: #282c34;
|
||||
min-height: 100vh;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-size: calc(10px + 2vmin);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.App-link {
|
||||
color: #61dafb;
|
||||
}
|
||||
|
||||
@keyframes App-logo-spin {
|
||||
from {
|
||||
transform: rotate(0deg);
|
||||
}
|
||||
to {
|
||||
transform: rotate(360deg);
|
||||
}
|
||||
}
|
||||
138
examples/message-monitor/src/App.tsx
Normal file
138
examples/message-monitor/src/App.tsx
Normal file
@ -0,0 +1,138 @@
|
||||
import React, { useState, useEffect, useRef } from 'react';
|
||||
import { setupWaku } from './lib/waku';
|
||||
import { startLightPushSequence } from './lib/waku/lightpush';
|
||||
import { startFilterSubscription } from './lib/waku/filter';
|
||||
import { TelemetryClient } from './lib/telemetry/client';
|
||||
import { TELEMETRY_URL } from './constants';
|
||||
import MessageList from './components/MessageList';
|
||||
import Stats from './components/Stats';
|
||||
import CountdownTimer from './components/CountdownTimer';
|
||||
import { Message } from './lib/telemetry/types';
|
||||
import SuccessIndicator from './components/SuccessIndicator';
|
||||
|
||||
let currentSequenceId = 1;
|
||||
|
||||
function App() {
|
||||
const [sentMessages, setSentMessages] = useState<Message[]>([]);
|
||||
const [receivedMessages, setReceivedMessages] = useState<Message[]>([]);
|
||||
const [selfReceivedMessages, setSelfReceivedMessages] = useState<Message[]>([]);
|
||||
const [stats, setStats] = useState({ sent: 0, received: 0, selfReceived: 0 });
|
||||
const [nextMessageCountdown, setNextMessageCountdown] = useState<number | null>(null);
|
||||
const [lastSentSuccess, setLastSentSuccess] = useState<boolean | null>(null);
|
||||
const [nodeInfo, setNodeInfo] = useState({
|
||||
totalConnections: 0,
|
||||
filterPeers: 0,
|
||||
lightPushPeers: 0,
|
||||
storePeers: 0,
|
||||
});
|
||||
const isRunning = useRef(false);
|
||||
|
||||
useEffect(() => {
|
||||
const initWaku = async () => {
|
||||
const waku = await setupWaku();
|
||||
const telemetryClient = new TelemetryClient(TELEMETRY_URL);
|
||||
telemetryClient.start();
|
||||
|
||||
const updateNodeInfo = () => {
|
||||
setNodeInfo({
|
||||
totalConnections: waku.libp2p.getConnections().length,
|
||||
filterPeers: waku.filter.connectedPeers.length,
|
||||
lightPushPeers: waku.lightPush.connectedPeers.length,
|
||||
storePeers: waku.store.connectedPeers.length,
|
||||
});
|
||||
};
|
||||
|
||||
updateNodeInfo();
|
||||
const nodeInfoInterval = setInterval(updateNodeInfo, 5000);
|
||||
|
||||
startFilterSubscription(waku, telemetryClient, (content, isSelf) => {
|
||||
const message: Message = {
|
||||
content,
|
||||
sequenceId: currentSequenceId,
|
||||
timestamp: Date.now()
|
||||
};
|
||||
|
||||
if (isSelf) {
|
||||
setSelfReceivedMessages(prev => [...prev, message]);
|
||||
setStats(prev => ({ ...prev, selfReceived: prev.selfReceived + 1 }));
|
||||
} else {
|
||||
setReceivedMessages(prev => [...prev, message]);
|
||||
setStats(prev => ({ ...prev, received: prev.received + 1 }));
|
||||
}
|
||||
});
|
||||
|
||||
const updateSequenceId = (newId: number) => {
|
||||
currentSequenceId = newId === 1 ? 1 : currentSequenceId + 1;
|
||||
console.log("Updated sequence ID to:", currentSequenceId);
|
||||
};
|
||||
|
||||
startLightPushSequence(
|
||||
waku,
|
||||
telemetryClient,
|
||||
(messageText, success) => {
|
||||
const message: Message = {
|
||||
content: messageText,
|
||||
sequenceId: currentSequenceId,
|
||||
timestamp: Date.now()
|
||||
};
|
||||
setSentMessages(prev => [message, ...prev]);
|
||||
setStats(prev => ({ ...prev, sent: prev.sent + 1 }));
|
||||
setLastSentSuccess(success);
|
||||
},
|
||||
updateSequenceId,
|
||||
setNextMessageCountdown,
|
||||
isRunning
|
||||
);
|
||||
|
||||
return () => {
|
||||
clearInterval(nodeInfoInterval);
|
||||
telemetryClient.stop();
|
||||
};
|
||||
};
|
||||
|
||||
initWaku();
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div className="min-h-screen bg-gray-100 p-8">
|
||||
<div className="max-w-7xl mx-auto">
|
||||
<h1 className="text-4xl font-bold text-gray-800 mb-8">Waku Message Monitor</h1>
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-8">
|
||||
<div className="space-y-8">
|
||||
<MessageList title="Sent Messages" messages={sentMessages} showSequence={true} />
|
||||
<MessageList title="Received Messages" messages={receivedMessages} showSequence={false} />
|
||||
</div>
|
||||
<div className="space-y-8">
|
||||
<MessageList title="Self-Received Messages" messages={selfReceivedMessages} showSequence={true} />
|
||||
<Stats stats={stats} />
|
||||
<div className="bg-white rounded-lg shadow p-6">
|
||||
<h2 className="text-xl font-semibold mb-4 text-gray-700">Node Info</h2>
|
||||
<div className="grid grid-cols-2 gap-4">
|
||||
<div>
|
||||
<p className="text-sm font-medium text-gray-500">Total Connections</p>
|
||||
<p className="text-lg font-semibold text-gray-800">{nodeInfo.totalConnections}</p>
|
||||
</div>
|
||||
<div>
|
||||
<p className="text-sm font-medium text-gray-500">Filter Peers</p>
|
||||
<p className="text-lg font-semibold text-gray-800">{nodeInfo.filterPeers}</p>
|
||||
</div>
|
||||
<div>
|
||||
<p className="text-sm font-medium text-gray-500">LightPush Peers</p>
|
||||
<p className="text-lg font-semibold text-gray-800">{nodeInfo.lightPushPeers}</p>
|
||||
</div>
|
||||
<div>
|
||||
<p className="text-sm font-medium text-gray-500">Store Peers</p>
|
||||
<p className="text-lg font-semibold text-gray-800">{nodeInfo.storePeers}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<CountdownTimer countdown={nextMessageCountdown} />
|
||||
<SuccessIndicator success={lastSentSuccess} />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default App;
|
||||
17
examples/message-monitor/src/components/CountdownTimer.tsx
Normal file
17
examples/message-monitor/src/components/CountdownTimer.tsx
Normal file
@ -0,0 +1,17 @@
|
||||
import React from 'react';
|
||||
|
||||
interface CountdownTimerProps {
|
||||
countdown: number | null;
|
||||
}
|
||||
|
||||
const CountdownTimer: React.FC<CountdownTimerProps> = ({ countdown }) => {
|
||||
if (countdown === null) return null;
|
||||
|
||||
return (
|
||||
<div className="text-center text-gray-600 mt-4">
|
||||
<p>Next message in: {countdown} seconds</p>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default CountdownTimer;
|
||||
68
examples/message-monitor/src/components/MessageList.tsx
Normal file
68
examples/message-monitor/src/components/MessageList.tsx
Normal file
@ -0,0 +1,68 @@
|
||||
import React from 'react';
|
||||
import { Message } from '../lib/telemetry/types';
|
||||
|
||||
interface MessageListProps {
|
||||
title: string;
|
||||
messages: Message[];
|
||||
showSequence: boolean;
|
||||
}
|
||||
|
||||
const MessageList: React.FC<MessageListProps> = ({ title, messages, showSequence }) => {
|
||||
const shortenMessage = (message: string) => {
|
||||
try {
|
||||
const parsed = JSON.parse(message);
|
||||
return parsed.content || message;
|
||||
} catch {
|
||||
return message;
|
||||
}
|
||||
};
|
||||
|
||||
const getSequenceColor = (sequenceId: number) => {
|
||||
const colors = [
|
||||
'bg-blue-100', 'bg-green-100', 'bg-yellow-100',
|
||||
'bg-red-100', 'bg-indigo-100', 'bg-purple-100'
|
||||
];
|
||||
return colors[sequenceId % colors.length];
|
||||
};
|
||||
|
||||
const groupedMessages = showSequence
|
||||
? messages.reduce((acc, message) => {
|
||||
if (!acc[message.sequenceId]) {
|
||||
acc[message.sequenceId] = [];
|
||||
}
|
||||
acc[message.sequenceId].unshift(message); // Use unshift instead of push
|
||||
return acc;
|
||||
}, {} as Record<number, Message[]>)
|
||||
: { 0: messages.slice().reverse() }; // Reverse the messages array
|
||||
|
||||
if (messages.length === 0) {
|
||||
return (
|
||||
<div className="flex-1 min-w-0">
|
||||
<h2 className="text-xl font-semibold mb-4 text-gray-700">{title}</h2>
|
||||
<div className="bg-gray-50 rounded-lg p-4 h-96 flex items-center justify-center">
|
||||
<p className="text-gray-500">Waiting for messages...</p>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex-1 min-w-0">
|
||||
<h2 className="text-xl font-semibold mb-4 text-gray-700">{title}</h2>
|
||||
<div className="bg-gray-50 rounded-lg p-4 h-96 overflow-y-auto border border-gray-200">
|
||||
{Object.entries(groupedMessages).reverse().map(([sequenceId, sequenceMessages]) => (
|
||||
<div key={sequenceId} className={`mb-4 p-2 rounded-lg ${showSequence ? getSequenceColor(Number(sequenceId)) : ''}`}>
|
||||
{showSequence && <div className="text-xs font-semibold mb-2">Sequence {sequenceId}</div>}
|
||||
{sequenceMessages.map((message: Message, index: number) => (
|
||||
<div key={index} className="text-sm mb-2 font-mono bg-white p-2 rounded shadow-sm">
|
||||
{shortenMessage(message.content)}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default MessageList;
|
||||
33
examples/message-monitor/src/components/Stats.tsx
Normal file
33
examples/message-monitor/src/components/Stats.tsx
Normal file
@ -0,0 +1,33 @@
|
||||
import React from 'react';
|
||||
|
||||
interface StatsProps {
|
||||
stats: {
|
||||
sent: number;
|
||||
received: number;
|
||||
selfReceived: number;
|
||||
};
|
||||
}
|
||||
|
||||
const Stats: React.FC<StatsProps> = ({ stats }) => {
|
||||
return (
|
||||
<div className="mt-8">
|
||||
<h2 className="text-xl font-semibold mb-4 text-gray-700">Stats</h2>
|
||||
<div className="grid grid-cols-3 gap-6">
|
||||
<div className="bg-blue-50 p-4 rounded-lg shadow">
|
||||
<p className="text-sm font-medium text-blue-600">Sent</p>
|
||||
<p className="text-2xl font-bold text-blue-800">{stats.sent}</p>
|
||||
</div>
|
||||
<div className="bg-green-50 p-4 rounded-lg shadow">
|
||||
<p className="text-sm font-medium text-green-600">Received</p>
|
||||
<p className="text-2xl font-bold text-green-800">{stats.received}</p>
|
||||
</div>
|
||||
<div className="bg-yellow-50 p-4 rounded-lg shadow">
|
||||
<p className="text-sm font-medium text-yellow-600">Self-Received</p>
|
||||
<p className="text-2xl font-bold text-yellow-800">{stats.selfReceived}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default Stats;
|
||||
41
examples/message-monitor/src/components/SuccessIndicator.tsx
Normal file
41
examples/message-monitor/src/components/SuccessIndicator.tsx
Normal file
@ -0,0 +1,41 @@
|
||||
import React, { useEffect, useState } from 'react';
|
||||
|
||||
interface SuccessIndicatorProps {
|
||||
success: boolean | null;
|
||||
}
|
||||
|
||||
const SuccessIndicator: React.FC<SuccessIndicatorProps> = ({ success }) => {
|
||||
const [visible, setVisible] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
if (success !== null) {
|
||||
setVisible(true);
|
||||
const timer = setTimeout(() => setVisible(false), 3000);
|
||||
return () => clearTimeout(timer);
|
||||
}
|
||||
}, [success]);
|
||||
|
||||
if (!visible) return null;
|
||||
|
||||
return (
|
||||
<div className={`fixed bottom-4 right-4 p-4 rounded-lg ${success ? 'bg-green-500' : 'bg-red-500'} text-white shadow-lg transition-opacity duration-300 ${visible ? 'opacity-100' : 'opacity-0'}`}>
|
||||
{success ? (
|
||||
<div className="flex items-center">
|
||||
<svg className="w-6 h-6 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
|
||||
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M5 13l4 4L19 7" />
|
||||
</svg>
|
||||
<span>Message sent successfully</span>
|
||||
</div>
|
||||
) : (
|
||||
<div className="flex items-center">
|
||||
<svg className="w-6 h-6 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
|
||||
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M6 18L18 6M6 6l12 12" />
|
||||
</svg>
|
||||
<span>Failed to send message</span>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default SuccessIndicator;
|
||||
11
examples/message-monitor/src/constants.ts
Normal file
11
examples/message-monitor/src/constants.ts
Normal file
@ -0,0 +1,11 @@
|
||||
import { utils } from "@waku/sdk";
|
||||
|
||||
export const DEFAULT_CONTENT_TOPIC = "/js-waku-examples/1/message-ratio/utf8";
|
||||
export const DEFAULT_PUBSUB_TOPIC = utils.contentTopicToPubsubTopic(DEFAULT_CONTENT_TOPIC);
|
||||
export const TELEMETRY_URL = process.env.REACT_APP_TELEMETRY_URL || "http://localhost:8080/waku-metrics";
|
||||
|
||||
export const nodes = [
|
||||
"/dns4/node-01.do-ams3.waku.test.status.im/tcp/8000/wss",
|
||||
"/dns4/node-01.ac-cn-hongkong-c.waku.test.status.im/tcp/8000/wss",
|
||||
"/dns4/node-01.gc-us-central1-a.waku.test.status.im/tcp/8000/wss",
|
||||
];
|
||||
3
examples/message-monitor/src/index.css
Normal file
3
examples/message-monitor/src/index.css
Normal file
@ -0,0 +1,3 @@
|
||||
@tailwind base;
|
||||
@tailwind components;
|
||||
@tailwind utilities;
|
||||
13
examples/message-monitor/src/index.tsx
Normal file
13
examples/message-monitor/src/index.tsx
Normal file
@ -0,0 +1,13 @@
|
||||
import React from 'react';
|
||||
import ReactDOM from 'react-dom/client';
|
||||
import './index.css';
|
||||
import App from './App';
|
||||
|
||||
const root = ReactDOM.createRoot(
|
||||
document.getElementById('root') as HTMLElement
|
||||
);
|
||||
root.render(
|
||||
<React.StrictMode>
|
||||
<App />
|
||||
</React.StrictMode>
|
||||
);
|
||||
61
examples/message-monitor/src/lib/telemetry/client.ts
Normal file
61
examples/message-monitor/src/lib/telemetry/client.ts
Normal file
@ -0,0 +1,61 @@
|
||||
import { TelemetryMessage} from './types';
|
||||
|
||||
export class TelemetryClient {
|
||||
constructor(
|
||||
private readonly url: string,
|
||||
private intervalPeriod: number = 5000
|
||||
) {}
|
||||
|
||||
private queue: TelemetryMessage[] = [];
|
||||
private intervalId: NodeJS.Timeout | null = null;
|
||||
private requestId = 0;
|
||||
|
||||
public push<T extends TelemetryMessage>(messages: T[]) {
|
||||
this.queue.push(...messages);
|
||||
}
|
||||
|
||||
public async start() {
|
||||
if (!this.intervalId) {
|
||||
this.intervalId = setInterval(async () => {
|
||||
if (this.queue.length > 0) {
|
||||
const success = await this.send(this.queue);
|
||||
if (success) {
|
||||
console.log("Sent ", this.queue.length, " telemetry logs");
|
||||
this.queue = [];
|
||||
}
|
||||
}
|
||||
}, this.intervalPeriod);
|
||||
}
|
||||
}
|
||||
|
||||
public stop() {
|
||||
if (this.intervalId) {
|
||||
clearInterval(this.intervalId);
|
||||
this.intervalId = null;
|
||||
}
|
||||
}
|
||||
|
||||
private async send<T extends TelemetryMessage>(messages: T[]) {
|
||||
const telemetryRequests = messages.map((message) => ({
|
||||
id: ++this.requestId,
|
||||
telemetryType: message.type.toString(),
|
||||
telemetryData: message
|
||||
}));
|
||||
|
||||
try {
|
||||
const res = await fetch(this.url, {
|
||||
method: "POST",
|
||||
body: JSON.stringify(telemetryRequests),
|
||||
});
|
||||
if (res.status !== 201) {
|
||||
console.error("Error sending messages to telemetry service: ", res.status, res.statusText, res.json);
|
||||
return false
|
||||
}
|
||||
return true;
|
||||
} catch (e) {
|
||||
console.error("Error sending messages to telemetry service: ", e);
|
||||
console.error("Failed trying to send the following messages: ", telemetryRequests);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
34
examples/message-monitor/src/lib/telemetry/types.ts
Normal file
34
examples/message-monitor/src/lib/telemetry/types.ts
Normal file
@ -0,0 +1,34 @@
|
||||
export enum TelemetryType {
|
||||
LIGHT_PUSH_FILTER = "LightPushFilter",
|
||||
}
|
||||
|
||||
export interface TelemetryRequest {
|
||||
id: number;
|
||||
telemetryType: TelemetryType;
|
||||
telemetryData: any;
|
||||
}
|
||||
|
||||
export interface TelemetryMessage {
|
||||
type: string;
|
||||
timestamp: number;
|
||||
contentTopic: string;
|
||||
pubsubTopic: string;
|
||||
peerId: string;
|
||||
errorMessage: string;
|
||||
extraData: string;
|
||||
}
|
||||
|
||||
export interface TelemetryPushFilter extends TelemetryMessage {
|
||||
type: "LightPushFilter";
|
||||
protocol: string;
|
||||
ephemeral: boolean;
|
||||
seenTimestamp: number;
|
||||
createdAt: number;
|
||||
messageHash: string;
|
||||
}
|
||||
|
||||
export interface Message {
|
||||
content: string;
|
||||
sequenceId: number;
|
||||
timestamp: number;
|
||||
}
|
||||
33
examples/message-monitor/src/lib/util.ts
Normal file
33
examples/message-monitor/src/lib/util.ts
Normal file
@ -0,0 +1,33 @@
|
||||
import { peerIdFromString } from "@libp2p/peer-id";
|
||||
import type { Waku } from "@waku/interfaces";
|
||||
|
||||
export const generateRandomNumber = (): number => {
|
||||
return Math.floor(Math.random() * 1000000);
|
||||
};
|
||||
|
||||
export const sha256 = async (number: number | string): Promise<string> => {
|
||||
const encoder = new TextEncoder();
|
||||
const data = encoder.encode(number.toString());
|
||||
const buffer = await crypto.subtle.digest("SHA-256", data);
|
||||
return Array.from(new Uint8Array(buffer))
|
||||
.map((b) => b.toString(16).padStart(2, "0"))
|
||||
.join("");
|
||||
};
|
||||
|
||||
const DEFAULT_EXTRA_DATA = { sdk: "0.0.28" };
|
||||
export const DEFAULT_EXTRA_DATA_STR = JSON.stringify(DEFAULT_EXTRA_DATA);
|
||||
|
||||
export const buildExtraData = async (node: Waku, peerId: string): Promise<string> => {
|
||||
const peer = await node.libp2p.peerStore.get(peerIdFromString(peerId));
|
||||
const hasWebsockes = peer
|
||||
.addresses
|
||||
.map(addr => addr.multiaddr.toString())
|
||||
.some(addr => addr.includes("ws") || addr.includes("wss"));
|
||||
|
||||
return JSON.stringify({
|
||||
...DEFAULT_EXTRA_DATA,
|
||||
peerId,
|
||||
hasWebsockes,
|
||||
enabledProtocols: peer.protocols,
|
||||
});
|
||||
};
|
||||
44
examples/message-monitor/src/lib/waku/filter.ts
Normal file
44
examples/message-monitor/src/lib/waku/filter.ts
Normal file
@ -0,0 +1,44 @@
|
||||
import { LightNode, DecodedMessage, createDecoder } from '@waku/sdk';
|
||||
import { TelemetryClient } from '../telemetry/client';
|
||||
import { DEFAULT_CONTENT_TOPIC } from '../../constants';
|
||||
import { ProtoSequencedMessage, SequencedMessage } from './proto';
|
||||
import { buildExtraData } from '../util';
|
||||
import { TelemetryType, TelemetryPushFilter } from '../telemetry/types';
|
||||
|
||||
export async function startFilterSubscription(
|
||||
node: LightNode,
|
||||
telemetryClient: TelemetryClient,
|
||||
onMessageReceived: (message: string, isSelf: boolean) => void
|
||||
) {
|
||||
const decoder = createDecoder(DEFAULT_CONTENT_TOPIC);
|
||||
const peerId = node.libp2p.peerId.toString();
|
||||
|
||||
const subscriptionCallback = async (message: DecodedMessage) => {
|
||||
const decodedMessage = ProtoSequencedMessage.decode(message.payload) as unknown as SequencedMessage;
|
||||
const messageText = `${decodedMessage.hash} - ${decodedMessage.index + 1} of ${decodedMessage.total}`;
|
||||
const isSelf = decodedMessage.sender === peerId;
|
||||
|
||||
onMessageReceived(messageText, isSelf);
|
||||
|
||||
const extraData = await buildExtraData(node, peerId);
|
||||
const timestamp = Math.floor(new Date().getTime() / 1000);
|
||||
telemetryClient.push<TelemetryPushFilter>([
|
||||
{
|
||||
type: TelemetryType.LIGHT_PUSH_FILTER,
|
||||
protocol: "filter",
|
||||
timestamp,
|
||||
createdAt: Math.floor(message?.timestamp?.getTime() ?? 0 / 1000),
|
||||
seenTimestamp: timestamp,
|
||||
peerId: decodedMessage.sender,
|
||||
contentTopic: message.contentTopic,
|
||||
pubsubTopic: message.pubsubTopic,
|
||||
ephemeral: message.ephemeral,
|
||||
messageHash: decodedMessage.hash,
|
||||
errorMessage: "",
|
||||
extraData,
|
||||
},
|
||||
]);
|
||||
};
|
||||
|
||||
await node.filter.subscribe([decoder], subscriptionCallback);
|
||||
}
|
||||
21
examples/message-monitor/src/lib/waku/index.ts
Normal file
21
examples/message-monitor/src/lib/waku/index.ts
Normal file
@ -0,0 +1,21 @@
|
||||
import { createLightNode, waitForRemotePeer } from "@waku/sdk";
|
||||
import { nodes as bootstrap, DEFAULT_CONTENT_TOPIC } from "../../constants";
|
||||
import { multiaddr } from '@multiformats/multiaddr'
|
||||
|
||||
export async function setupWaku() {
|
||||
const waku = await createLightNode({
|
||||
networkConfig: {
|
||||
contentTopics: [DEFAULT_CONTENT_TOPIC]
|
||||
},
|
||||
defaultBootstrap: true
|
||||
});
|
||||
await waku.start();
|
||||
await Promise.all(getBootstrapNodes().map((node) => waku.dial(node)));
|
||||
await waitForRemotePeer(waku);
|
||||
|
||||
return waku;
|
||||
}
|
||||
|
||||
function getBootstrapNodes(nodes: string[] = bootstrap) {
|
||||
return bootstrap.map((node) => multiaddr(node));
|
||||
}
|
||||
132
examples/message-monitor/src/lib/waku/lightpush.ts
Normal file
132
examples/message-monitor/src/lib/waku/lightpush.ts
Normal file
@ -0,0 +1,132 @@
|
||||
import { LightNode, createEncoder } from '@waku/sdk';
|
||||
import { TelemetryClient } from '../telemetry/client.js';
|
||||
import { DEFAULT_CONTENT_TOPIC, DEFAULT_PUBSUB_TOPIC } from '../../constants';
|
||||
import { ProtoSequencedMessage } from './proto';
|
||||
import { generateRandomNumber, sha256, buildExtraData } from '../util';
|
||||
import { TelemetryType, TelemetryPushFilter } from '../telemetry/types';
|
||||
|
||||
export async function startLightPushSequence(
|
||||
waku: LightNode,
|
||||
telemetryClient: TelemetryClient,
|
||||
onMessageSent: (message: string, success: boolean) => void,
|
||||
updateSequenceId: (newId: number) => void,
|
||||
updateCountdown: (countdown: number | null) => void,
|
||||
isRunning: { current: boolean },
|
||||
numMessages: number = 10,
|
||||
period: number = 10_000
|
||||
) {
|
||||
if (isRunning.current) {
|
||||
console.log("A sequence is already running. Skipping this call.");
|
||||
return;
|
||||
}
|
||||
|
||||
isRunning.current = true;
|
||||
console.info("Starting a new lightpush sequence");
|
||||
const sequenceHash = await sha256(generateRandomNumber().toString());
|
||||
const sequenceTotal = numMessages;
|
||||
let sequenceIndex = 0;
|
||||
|
||||
const encoder = createEncoder({
|
||||
contentTopic: DEFAULT_CONTENT_TOPIC,
|
||||
});
|
||||
|
||||
const sendMessage = async () => {
|
||||
try {
|
||||
const reportingHash = await sha256(`${sequenceHash}-${sequenceIndex}-${sequenceTotal}`);
|
||||
|
||||
const timestamp = Math.floor(new Date().getTime() / 1000);
|
||||
const message = ProtoSequencedMessage.create({
|
||||
hash: reportingHash,
|
||||
total: sequenceTotal,
|
||||
index: sequenceIndex,
|
||||
sender: waku.libp2p.peerId.toString(),
|
||||
});
|
||||
const payload = ProtoSequencedMessage.encode(message).finish();
|
||||
const result = await waku.lightPush.send(encoder, {
|
||||
payload,
|
||||
timestamp: new Date(),
|
||||
});
|
||||
|
||||
const events = await Promise.all([
|
||||
...result.successes.map(async (peerId) => {
|
||||
const extraData = await buildExtraData(waku, peerId.toString());
|
||||
return {
|
||||
type: TelemetryType.LIGHT_PUSH_FILTER,
|
||||
protocol: "lightPush",
|
||||
timestamp,
|
||||
createdAt: timestamp,
|
||||
seenTimestamp: timestamp,
|
||||
peerId: peerId.toString(),
|
||||
contentTopic: DEFAULT_CONTENT_TOPIC,
|
||||
pubsubTopic: DEFAULT_PUBSUB_TOPIC,
|
||||
ephemeral: false,
|
||||
messageHash: reportingHash,
|
||||
errorMessage: "",
|
||||
extraData,
|
||||
};
|
||||
}),
|
||||
...result.failures.map(async (fail) => {
|
||||
const extraData = await buildExtraData(waku, fail?.peerId?.toString() ?? "");
|
||||
return {
|
||||
type: TelemetryType.LIGHT_PUSH_FILTER,
|
||||
protocol: "lightPush",
|
||||
timestamp,
|
||||
createdAt: timestamp,
|
||||
seenTimestamp: timestamp,
|
||||
peerId: fail?.peerId?.toString() ?? "",
|
||||
contentTopic: DEFAULT_CONTENT_TOPIC,
|
||||
pubsubTopic: DEFAULT_PUBSUB_TOPIC,
|
||||
ephemeral: false,
|
||||
messageHash: reportingHash,
|
||||
errorMessage: fail?.error?.toString() ?? "",
|
||||
extraData,
|
||||
};
|
||||
}),
|
||||
]);
|
||||
|
||||
if (events.length > 0) {
|
||||
telemetryClient.push<TelemetryPushFilter>(events);
|
||||
}
|
||||
|
||||
const success = result.successes.length > 0;
|
||||
if (success) {
|
||||
const messageText = JSON.stringify({ content: `${reportingHash} - ${sequenceIndex + 1} of ${sequenceTotal}`, success: true });
|
||||
onMessageSent(messageText, true);
|
||||
sequenceIndex++;
|
||||
} else {
|
||||
onMessageSent(JSON.stringify({ content: `Failed to send message ${sequenceIndex + 1} of ${sequenceTotal}`, success: false }), false);
|
||||
}
|
||||
|
||||
if (sequenceIndex < sequenceTotal) {
|
||||
let countdown = period / 1000;
|
||||
const countdownInterval = setInterval(() => {
|
||||
countdown -= 1;
|
||||
updateCountdown(countdown);
|
||||
if (countdown <= 0) {
|
||||
clearInterval(countdownInterval);
|
||||
updateCountdown(null);
|
||||
}
|
||||
}, 1000);
|
||||
setTimeout(() => {
|
||||
clearInterval(countdownInterval);
|
||||
sendMessage();
|
||||
}, period);
|
||||
} else {
|
||||
console.info("Lightpush sequence completed");
|
||||
updateSequenceId(sequenceIndex + 1);
|
||||
updateCountdown(null);
|
||||
isRunning.current = false;
|
||||
// Start a new sequence after a delay
|
||||
setTimeout(() => startLightPushSequence(waku, telemetryClient, onMessageSent, updateSequenceId, updateCountdown, isRunning, numMessages, period), period);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Error sending message", error);
|
||||
onMessageSent(JSON.stringify({ content: `Error sending message ${sequenceIndex + 1} of ${sequenceTotal}`, success: false }), false);
|
||||
isRunning.current = false;
|
||||
// Retry starting a new sequence after a delay
|
||||
setTimeout(() => startLightPushSequence(waku, telemetryClient, onMessageSent, updateSequenceId, updateCountdown, isRunning, numMessages, period), period);
|
||||
}
|
||||
};
|
||||
|
||||
sendMessage();
|
||||
}
|
||||
14
examples/message-monitor/src/lib/waku/proto.ts
Normal file
14
examples/message-monitor/src/lib/waku/proto.ts
Normal file
@ -0,0 +1,14 @@
|
||||
import { Field, Type } from "protobufjs";
|
||||
|
||||
export const ProtoSequencedMessage = new Type("SequencedMessage")
|
||||
.add(new Field("hash", 1, "string"))
|
||||
.add(new Field("total", 2, "uint64"))
|
||||
.add(new Field("index", 3, "uint64"))
|
||||
.add(new Field("sender", 4, "string"));
|
||||
|
||||
export type SequencedMessage = {
|
||||
hash: string;
|
||||
total: number;
|
||||
index: number;
|
||||
sender: string;
|
||||
};
|
||||
1
examples/message-monitor/src/logo.svg
Normal file
1
examples/message-monitor/src/logo.svg
Normal file
@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 841.9 595.3"><g fill="#61DAFB"><path d="M666.3 296.5c0-32.5-40.7-63.3-103.1-82.4 14.4-63.6 8-114.2-20.2-130.4-6.5-3.8-14.1-5.6-22.4-5.6v22.3c4.6 0 8.3.9 11.4 2.6 13.6 7.8 19.5 37.5 14.9 75.7-1.1 9.4-2.9 19.3-5.1 29.4-19.6-4.8-41-8.5-63.5-10.9-13.5-18.5-27.5-35.3-41.6-50 32.6-30.3 63.2-46.9 84-46.9V78c-27.5 0-63.5 19.6-99.9 53.6-36.4-33.8-72.4-53.2-99.9-53.2v22.3c20.7 0 51.4 16.5 84 46.6-14 14.7-28 31.4-41.3 49.9-22.6 2.4-44 6.1-63.6 11-2.3-10-4-19.7-5.2-29-4.7-38.2 1.1-67.9 14.6-75.8 3-1.8 6.9-2.6 11.5-2.6V78.5c-8.4 0-16 1.8-22.6 5.6-28.1 16.2-34.4 66.7-19.9 130.1-62.2 19.2-102.7 49.9-102.7 82.3 0 32.5 40.7 63.3 103.1 82.4-14.4 63.6-8 114.2 20.2 130.4 6.5 3.8 14.1 5.6 22.5 5.6 27.5 0 63.5-19.6 99.9-53.6 36.4 33.8 72.4 53.2 99.9 53.2 8.4 0 16-1.8 22.6-5.6 28.1-16.2 34.4-66.7 19.9-130.1 62-19.1 102.5-49.9 102.5-82.3zm-130.2-66.7c-3.7 12.9-8.3 26.2-13.5 39.5-4.1-8-8.4-16-13.1-24-4.6-8-9.5-15.8-14.4-23.4 14.2 2.1 27.9 4.7 41 7.9zm-45.8 106.5c-7.8 13.5-15.8 26.3-24.1 38.2-14.9 1.3-30 2-45.2 2-15.1 0-30.2-.7-45-1.9-8.3-11.9-16.4-24.6-24.2-38-7.6-13.1-14.5-26.4-20.8-39.8 6.2-13.4 13.2-26.8 20.7-39.9 7.8-13.5 15.8-26.3 24.1-38.2 14.9-1.3 30-2 45.2-2 15.1 0 30.2.7 45 1.9 8.3 11.9 16.4 24.6 24.2 38 7.6 13.1 14.5 26.4 20.8 39.8-6.3 13.4-13.2 26.8-20.7 39.9zm32.3-13c5.4 13.4 10 26.8 13.8 39.8-13.1 3.2-26.9 5.9-41.2 8 4.9-7.7 9.8-15.6 14.4-23.7 4.6-8 8.9-16.1 13-24.1zM421.2 430c-9.3-9.6-18.6-20.3-27.8-32 9 .4 18.2.7 27.5.7 9.4 0 18.7-.2 27.8-.7-9 11.7-18.3 22.4-27.5 32zm-74.4-58.9c-14.2-2.1-27.9-4.7-41-7.9 3.7-12.9 8.3-26.2 13.5-39.5 4.1 8 8.4 16 13.1 24 4.7 8 9.5 15.8 14.4 23.4zM420.7 163c9.3 9.6 18.6 20.3 27.8 32-9-.4-18.2-.7-27.5-.7-9.4 0-18.7.2-27.8.7 9-11.7 18.3-22.4 27.5-32zm-74 58.9c-4.9 7.7-9.8 15.6-14.4 23.7-4.6 8-8.9 16-13 24-5.4-13.4-10-26.8-13.8-39.8 13.1-3.1 26.9-5.8 41.2-7.9zm-90.5 125.2c-35.4-15.1-58.3-34.9-58.3-50.6 0-15.7 22.9-35.6 58.3-50.6 8.6-3.7 18-7 27.7-10.1 5.7 19.6 13.2 40 22.5 60.9-9.2 20.8-16.6 41.1-22.2 60.6-9.9-3.1-19.3-6.5-28-10.2zM310 490c-13.6-7.8-19.5-37.5-14.9-75.7 1.1-9.4 2.9-19.3 5.1-29.4 19.6 4.8 41 8.5 63.5 10.9 13.5 18.5 27.5 35.3 41.6 50-32.6 30.3-63.2 46.9-84 46.9-4.5-.1-8.3-1-11.3-2.7zm237.2-76.2c4.7 38.2-1.1 67.9-14.6 75.8-3 1.8-6.9 2.6-11.5 2.6-20.7 0-51.4-16.5-84-46.6 14-14.7 28-31.4 41.3-49.9 22.6-2.4 44-6.1 63.6-11 2.3 10.1 4.1 19.8 5.2 29.1zm38.5-66.7c-8.6 3.7-18 7-27.7 10.1-5.7-19.6-13.2-40-22.5-60.9 9.2-20.8 16.6-41.1 22.2-60.6 9.9 3.1 19.3 6.5 28.1 10.2 35.4 15.1 58.3 34.9 58.3 50.6-.1 15.7-23 35.6-58.4 50.6zM320.8 78.4z"/><circle cx="420.9" cy="296.5" r="45.7"/><path d="M520.5 78.1z"/></g></svg>
|
||||
|
After Width: | Height: | Size: 2.6 KiB |
1
examples/message-monitor/src/react-app-env.d.ts
vendored
Normal file
1
examples/message-monitor/src/react-app-env.d.ts
vendored
Normal file
@ -0,0 +1 @@
|
||||
/// <reference types="react-scripts" />
|
||||
15
examples/message-monitor/src/reportWebVitals.ts
Normal file
15
examples/message-monitor/src/reportWebVitals.ts
Normal file
@ -0,0 +1,15 @@
|
||||
import { ReportHandler } from 'web-vitals';
|
||||
|
||||
const reportWebVitals = (onPerfEntry?: ReportHandler) => {
|
||||
if (onPerfEntry && onPerfEntry instanceof Function) {
|
||||
import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => {
|
||||
getCLS(onPerfEntry);
|
||||
getFID(onPerfEntry);
|
||||
getFCP(onPerfEntry);
|
||||
getLCP(onPerfEntry);
|
||||
getTTFB(onPerfEntry);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
export default reportWebVitals;
|
||||
5
examples/message-monitor/src/setupTests.ts
Normal file
5
examples/message-monitor/src/setupTests.ts
Normal file
@ -0,0 +1,5 @@
|
||||
// jest-dom adds custom jest matchers for asserting on DOM nodes.
|
||||
// allows you to do things like:
|
||||
// expect(element).toHaveTextContent(/react/i)
|
||||
// learn more: https://github.com/testing-library/jest-dom
|
||||
import '@testing-library/jest-dom';
|
||||
9
examples/message-monitor/tailwind.config.js
Normal file
9
examples/message-monitor/tailwind.config.js
Normal file
@ -0,0 +1,9 @@
|
||||
module.exports = {
|
||||
content: [
|
||||
"./src/**/*.{js,jsx,ts,tsx}",
|
||||
],
|
||||
theme: {
|
||||
extend: {},
|
||||
},
|
||||
plugins: [],
|
||||
}
|
||||
26
examples/message-monitor/tsconfig.json
Normal file
26
examples/message-monitor/tsconfig.json
Normal file
@ -0,0 +1,26 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "es5",
|
||||
"lib": [
|
||||
"dom",
|
||||
"dom.iterable",
|
||||
"esnext"
|
||||
],
|
||||
"allowJs": true,
|
||||
"skipLibCheck": true,
|
||||
"esModuleInterop": true,
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"strict": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
"module": "esnext",
|
||||
"moduleResolution": "node",
|
||||
"resolveJsonModule": true,
|
||||
"isolatedModules": true,
|
||||
"noEmit": true,
|
||||
"jsx": "react-jsx"
|
||||
},
|
||||
"include": [
|
||||
"src"
|
||||
]
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user