This commit is contained in:
status-im-auto 2024-02-14 00:33:12 +00:00 committed by Jenkins
parent 2791e0ca22
commit ea60c58622
53 changed files with 0 additions and 26899 deletions

View File

@ -1,13 +0,0 @@
# Using Waku Light Push and Filter in JavaScript
**Demonstrates**:
- Waku Light node: Waku Filter + Waku Light Push
- Pure Javascript/HTML.
- Use minified bundle of js from unpkg.com, no import, no package manager.
This example uses Waku Filter to listen to messages and Waku Light Push to send messages.
To test the example, simply download the `index.html` file from this folder and open it in a browser.
The `master` branch's HEAD is deployed at https://examples.waku.org/light-js/.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

View File

@ -1,280 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta content="width=device-width, initial-scale=1.0" name="viewport" />
<title>JS-Waku light node example</title>
<link rel="apple-touch-icon" href="./favicon.png" />
<link rel="manifest" href="./manifest.json" />
<link rel="icon" href="./favicon.ico" />
</head>
<body>
<div>
<h2>Status</h2>
</div>
<div id="status"></div>
<div>
<h2>Local Peer Id</h2>
</div>
<div id="peer-id"></div>
<div>
<h2>Select Peer</h2>
</div>
<div>
<button id="getPeersButton" type="button">Refresh Peers</button>
<select id="peer-select">
<option value=""></option>
</select>
</div>
<div>
<label for="remote-multiaddr">Remote peer's multiaddr</label>
</div>
<div style="margin-right: 1em">
<input
id="remote-multiaddr"
type="text"
value=""
style="width: 100%; max-width: 900px"
/>
</div>
<button disabled id="dial" type="button">Dial</button>
<div>
<h2>Remote Peers</h2>
</div>
<div id="remote-peer-id"></div>
<br />
<button disabled id="subscribe" type="button">Subscribe with Filter</button>
<button disabled id="unsubscribe" type="button">
Unsubscribe with Filter
</button>
<br />
<label for="textInput">Message text</label>
<input id="textInput" placeholder="Type your message here" type="text" />
<button disabled id="sendButton" type="button">
Send message using Light Push
</button>
<br />
<div id="messages"></div>
<div>
<h2>Store</h2>
</div>
<button disabled id="queryStoreButton" type="button">
Retrieve past messages
</button>
<script src="https://unpkg.com/@multiformats/multiaddr@12.1.1/dist/index.min.js"></script>
<script type="module">
import {
createLightNode,
waitForRemotePeer,
createEncoder,
createDecoder,
utf8ToBytes,
bytesToUtf8,
} from "https://unpkg.com/@waku/sdk@0.0.20/bundle/index.js";
import {
enrTree,
DnsNodeDiscovery,
} from "https://unpkg.com/@waku/dns-discovery@0.0.16/bundle/index.js";
import { messageHash } from "https://unpkg.com/@waku/message-hash@0.1.8/bundle/index.js";
const peerIdDiv = document.getElementById("peer-id");
const remotePeerIdDiv = document.getElementById("remote-peer-id");
const statusDiv = document.getElementById("status");
const remoteMultiAddrDiv = document.getElementById("remote-multiaddr");
const dialButton = document.getElementById("dial");
const subscribeButton = document.getElementById("subscribe");
const unsubscribeButton = document.getElementById("unsubscribe");
const queryStoreButton = document.getElementById("queryStoreButton");
const messagesDiv = document.getElementById("messages");
const textInput = document.getElementById("textInput");
const sendButton = document.getElementById("sendButton");
const getPeersButton = document.getElementById("getPeersButton");
const peersSelector = document.getElementById("peer-select");
const ContentTopic = "/js-waku-examples/1/chat/utf8";
const decoder = createDecoder(ContentTopic);
const encoder = createEncoder({ contentTopic: ContentTopic });
// Each key is a unique identifier for the message. Each value is an obj { text, timestamp }
let messages = {};
let unsubscribe;
const updateMessages = (msgs, div) => {
div.innerHTML = "<ul>";
Object.values(msgs)
.sort((a, b) => a.timestamp.getTime() - b.timestamp.getTime())
.forEach(
(msg) =>
(div.innerHTML +=
"<li>" + `${msg.text} - ${msg.timestamp}` + "</li>")
);
div.innerHTML += "</ul>";
};
try {
await getPeers();
} catch (e) {
console.log("Failed to find a peer", e);
remoteMultiAddrDiv.value =
"/dns4/node-01.ac-cn-hongkong-c.wakuv2.test.statusim.net/tcp/8000/wss/p2p/16Uiu2HAkvWiyFsgRhuJEb9JfjYxEkoHLgnUQmr1N5mKWnYjxYRVm";
}
statusDiv.innerHTML = "<p>Creating Waku node.</p>";
const node = await createLightNode();
statusDiv.innerHTML = "<p>Starting Waku node.</p>";
await node.start();
window.waku = node;
console.info(
"Use window.waku to access the waku node running in the browser directly through the console."
);
// Queries all peers from libp2p peer store and updates list of connected peers
const updatePeersList = async () => {
// Generate <p> element with connection string from each peer
const peers = await node.libp2p.peerStore.all();
const peerIdElements = peers.map((peer) => {
const element = document.createElement("p");
element.textContent = `${peer.addresses[1].multiaddr}/p2p/${peer.id}`;
return element;
});
// Update elements displaying list of peers
remotePeerIdDiv.replaceChildren(...peerIdElements);
};
// Refreshes list of connected peers each time a new one is detected
node.store.addLibp2pEventListener("peer:connect", async (event) => {
const peerId = event.detail;
console.log(`Peer connected with peer id: ${peerId}`);
// Wait half a second after receiving event for peer to show up in peer store
setTimeout(async () => {
updatePeersList();
}, 500);
// Update status
statusDiv.innerHTML = `<p>Peer dialed: ${peerId}</p>`;
// Enable send and subscribe inputs as we are now connected to a peer
textInput.disabled = false;
sendButton.disabled = false;
subscribeButton.disabled = false;
queryStoreButton.disabled = false;
});
statusDiv.innerHTML = "<p>Waku node started.</p>";
peerIdDiv.innerHTML = "<p>" + node.libp2p.peerId.toString() + "</p>";
dialButton.disabled = false;
dialButton.onclick = async () => {
const ma = remoteMultiAddrDiv.value;
if (!ma) {
statusDiv.innerHTML = "<p>Error: No multiaddr provided.</p>";
return;
}
statusDiv.innerHTML = "<p>Dialing peer.</p>";
let multiaddr;
try {
multiaddr = MultiformatsMultiaddr.multiaddr(ma);
} catch (err) {
statusDiv.innerHTML = "<p>Error: invalid multiaddr provided</p>";
throw err;
}
await node.dial(multiaddr, ["filter", "lightpush", "store"]);
};
const messageReceivedCallback = (wakuMessage) => {
// create a unique key for the message
const msgHash =
bytesToUtf8(messageHash(ContentTopic, wakuMessage)) +
wakuMessage.proto.timestamp;
const text = bytesToUtf8(wakuMessage.payload);
// store message by its key
messages[msgHash + wakuMessage.proto.timestamp] = {
text,
timestamp: wakuMessage.timestamp,
};
// call function to refresh display of messages
updateMessages(messages, messagesDiv);
};
subscribeButton.onclick = async () => {
unsubscribe = await node.filter.subscribe(
[decoder],
messageReceivedCallback
);
unsubscribeButton.disabled = false;
subscribeButton.disabled = true;
};
queryStoreButton.onclick = async () => {
await node.store.queryWithOrderedCallback(
[decoder],
messageReceivedCallback
);
};
unsubscribeButton.onclick = async () => {
await unsubscribe();
unsubscribe = undefined;
unsubscribeButton.disabled = true;
subscribeButton.disabled = false;
};
sendButton.onclick = async () => {
const text = textInput.value;
await node.lightPush.send(encoder, {
payload: utf8ToBytes(text),
});
console.log("Message sent!");
textInput.value = null;
};
getPeersButton.onclick = async () => {
await getPeers(statusDiv, remoteMultiAddrDiv);
};
peersSelector.addEventListener("change", function (event) {
remoteMultiAddrDiv.value = event.target.value;
});
async function getPeers() {
// Display status
statusDiv.innerHTML = "<p>Discovering peers</p>";
// Clear all options in select element
peersSelector.innerHTML = "";
// Get peers using DNS discovery
const defaultNodeCount = 5;
const dnsDiscovery = await DnsNodeDiscovery.dnsOverHttp();
const peers = await dnsDiscovery.getPeers([enrTree["TEST"]], {
relay: defaultNodeCount,
store: defaultNodeCount,
filter: defaultNodeCount,
lightPush: defaultNodeCount,
});
// Create an option element for each peer's multiaddr and append to select element
const optionElements = peers.map((peer) => {
const optionElement = document.createElement("option");
optionElement.value = `${peer.multiaddrs[1]}/p2p/${peer.peerId}`;
optionElement.text = `${peer.multiaddrs[1]}/p2p/${peer.peerId}`;
return optionElement;
});
peersSelector.append(...optionElements);
// Set first peer as selected
peersSelector.options[0].selected = true;
remoteMultiAddrDiv.value = peersSelector.options[0].value;
statusDiv.innerHTML = "<p>Peers discovered</p>";
}
</script>
</body>
</html>

View File

@ -1,19 +0,0 @@
{
"name": "Light JS",
"description": "Send messages between several users (or just one) using light client targeted protocols.",
"icons": [
{
"src": "favicon.ico",
"sizes": "64x64 32x32 24x24 16x16",
"type": "image/x-icon"
},
{
"src": "favicon.png",
"type": "image/png",
"sizes": "192x192"
}
],
"display": "standalone",
"theme_color": "#ffffff",
"background_color": "#ffffff"
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

View File

@ -1,200 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta content="width=device-width, initial-scale=1.0" name="viewport" />
<title>Waku Noise</title>
<link rel="apple-touch-icon" href="./favicon.png" />
<link rel="manifest" href="./manifest.json" />
<link rel="icon" href="./favicon.ico" />
<style>
* {
margin: 0;
padding: 0;
word-wrap: break-word;
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
max-width: 100%;
max-height: 100%;
}
html {
font-size: 16px;
overflow: hidden;
}
body {
display: flex;
align-items: center;
padding: 10px;
flex-direction: column;
justify-content: center;
}
.container {
width: 100%;
min-width: 300px;
max-width: 800px;
height: 100%;
display: flex;
flex-direction: column;
align-content: space-between;
}
h2 {
text-align: center;
margin-bottom: 5px;
}
h3 {
margin-bottom: 10px;
}
h3:last-of-type {
margin-bottom: 20px;
}
h2 span,
h3 span {
font-weight: normal;
}
.progress {
color: #9ea13b;
}
.success {
color: #3ba183;
}
.error {
color: #c84740;
}
button.progress {
color: white;
background-color: #9ea13b;
}
button.success {
color: white;
background-color: #3ba183;
}
button.error {
color: white;
background-color: #c84740;
}
.pairingInfo {
display: flex;
flex-direction: column;
align-items: center;
}
.pairingInfo input {
display: block;
min-width: 250px;
width: 100%;
max-width: 600px;
font-size: 1.1rem;
line-height: 1.5rem;
padding: 5px;
margin-bottom: 10px;
}
.pairingInfo button {
flex-grow: 1;
cursor: pointer;
padding: 10px;
}
.pairingInfo button + button {
margin-left: 5px;
}
.chatArea {
}
.chatArea ul {
margin-bottom: 30px;
list-style: none;
}
.chatArea ul li + li {
margin-top: 5px;
}
.chatArea div {
display: flex;
flex-direction: column;
}
.chatArea div > * {
font-size: 1.1rem;
line-height: 1.5rem;
padding: 5px;
margin-bottom: 10px;
}
</style>
</head>
<body>
<div class="container">
<div class="status">
<h3>
<b>Waku Node Status:</b> <span id="waku-status">connecting...</span>
</h3>
<h3 id="handshake-span">
<b>Handshake Status:</b>
<span id="handshake-status" class="progress">waiting for waku</span>
</h3>
</div>
<div class="pairingInfo" id="qr-url-container" style="display: none">
<h2>Pairing information</h2>
<input
type="text"
id="qr-url"
readonly
placeholder="generating URL..."
/>
<div>
<button id="copy-url" style="width: 100px">Copy URL</button>
<button id="open-tab" style="width: 150px">Open in new tab</button>
</div>
<canvas id="qr-canvas"></canvas>
</div>
<div class="chatArea" id="chat-area" style="display: none">
<h2>Chat</h2>
<ul id="messages"></ul>
<div>
<input id="nick-input" placeholder="Choose a nickname" type="text" />
<textarea
id="text-input"
placeholder="Type your message here"
type="text"
></textarea>
<button id="send-btn" type="button" disabled>Send message</button>
</div>
</div>
</div>
<div>
<p>
NOTICE: you can try also try to pair your browser with a
<a href="https://github.com/waku-org/go-waku/tree/master/examples/noise"
>go-waku based node</a
>.
</p>
</div>
<script src="./index.js"></script>
</body>
</html>

File diff suppressed because one or more lines are too long

View File

@ -1,19 +0,0 @@
{
"name": "Waku Noise",
"description": "Example showing Waku noise capabilities.",
"icons": [
{
"src": "favicon.ico",
"sizes": "64x64 32x32 24x24 16x16",
"type": "image/x-icon"
},
{
"src": "favicon.png",
"type": "image/png",
"sizes": "192x192"
}
],
"display": "standalone",
"theme_color": "#ffffff",
"background_color": "#ffffff"
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

View File

@ -1,198 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta content="width=device-width, initial-scale=1.0" name="viewport" />
<title>Waku NoiseRTC</title>
<link rel="apple-touch-icon" href="./favicon.png" />
<link rel="manifest" href="./manifest.json" />
<link rel="icon" href="./favicon.ico" />
<style>
* {
margin: 0;
padding: 0;
word-wrap: break-word;
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
max-width: 100%;
max-height: 100%;
}
html {
font-size: 16px;
overflow: hidden;
}
body {
display: flex;
align-items: center;
padding: 10px;
flex-direction: column;
justify-content: center;
}
.container {
width: 100%;
min-width: 300px;
max-width: 800px;
height: 100%;
display: flex;
flex-direction: column;
align-content: space-between;
}
h2 {
text-align: center;
margin-bottom: 5px;
}
h3 {
margin-bottom: 10px;
}
h3:last-of-type {
margin-bottom: 20px;
}
h2 span,
h3 span {
font-weight: normal;
}
.progress {
color: #9ea13b;
}
.success {
color: #3ba183;
}
.error {
color: #c84740;
}
button.progress {
color: white;
background-color: #9ea13b;
}
button.success {
color: white;
background-color: #3ba183;
}
button.error {
color: white;
background-color: #c84740;
}
.pairingInfo {
display: flex;
flex-direction: column;
align-items: center;
}
.pairingInfo input {
display: block;
min-width: 250px;
width: 100%;
max-width: 600px;
font-size: 1.1rem;
line-height: 1.5rem;
padding: 5px;
margin-bottom: 10px;
}
.pairingInfo button {
flex-grow: 1;
cursor: pointer;
padding: 10px;
}
.pairingInfo button + button {
margin-left: 5px;
}
.chatArea {
}
.chatArea ul {
margin-bottom: 30px;
list-style: none;
}
.chatArea ul li + li {
margin-top: 5px;
}
.chatArea div {
display: flex;
flex-direction: column;
}
.chatArea div > * {
font-size: 1.1rem;
line-height: 1.5rem;
padding: 5px;
margin-bottom: 10px;
}
</style>
</head>
<body>
<div class="container">
<div class="status">
<h3>
<b>Waku Node Status:</b>
<span id="waku-status" class="progress">connecting...</span>
</h3>
<h3 id="handshake-span">
<b>Handshake Status:</b>
<span id="handshake-status" class="progress">waiting for waku</span>
</h3>
<h3>
<b>RTC Status:</b>
<span id="rtc-status" class="progress"
>waiting for noise to be established</span
>
</h3>
</div>
<div class="pairingInfo" id="qr-url-container" style="display: none">
<h2>Pairing information</h2>
<input
type="text"
id="qr-url"
readonly
placeholder="generating URL..."
/>
<div>
<button id="copy-url" style="width: 100px">Copy URL</button>
<button id="open-tab" style="width: 100px">Open in new</button>
</div>
<canvas id="qr-canvas"></canvas>
</div>
<div class="chatArea" id="chat-area" style="display: none">
<h2>Chat</h2>
<ul id="messages"></ul>
<div>
<input id="nick-input" placeholder="Choose a nickname" type="text" />
<textarea
id="text-input"
placeholder="Type your message here"
type="text"
></textarea>
<button id="send-btn" type="button" disabled>Send message</button>
</div>
</div>
</div>
<script src="./index.js"></script>
</body>
</html>

File diff suppressed because one or more lines are too long

View File

@ -1,19 +0,0 @@
{
"name": "Waku NoiseRTC",
"description": "Example showing WebRTC with Waku Noise.",
"icons": [
{
"src": "favicon.ico",
"sizes": "64x64 32x32 24x24 16x16",
"type": "image/x-icon"
},
{
"src": "favicon.png",
"type": "image/png",
"sizes": "192x192"
}
],
"display": "standalone",
"theme_color": "#ffffff",
"background_color": "#ffffff"
}

File diff suppressed because it is too large Load Diff

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.2 KiB

View File

@ -1,14 +0,0 @@
<!DOCTYPE html><html lang="en"><head>
<meta charset="utf-8">
<title>RelayAngularChat</title>
<base href="/relay-angular-chat">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="apple-touch-icon" href="./favicon.png">
<link rel="manifest" href="./manifest.json">
<link rel="icon" href="./favicon.ico">
<link rel="stylesheet" href="/relay-angular-chat/styles.ef46db3751d8e999.css"></head>
<body>
<app-root></app-root>
<script src="/relay-angular-chat/runtime.08a22decfce51efb.js" type="module"></script><script src="/relay-angular-chat/main.a4ab7015647e3037.js" type="module"></script>
</body></html>

File diff suppressed because one or more lines are too long

View File

@ -1 +0,0 @@
(()=>{"use strict";var e,u={},b={};function f(e){var t=b[e];if(void 0!==t)return t.exports;var r=b[e]={exports:{}};return u[e].call(r.exports,r,r.exports,f),r.exports}f.m=u,e=[],f.O=(t,r,a,o)=>{if(!r){var l=1/0;for(n=0;n<e.length;n++){for(var[r,a,o]=e[n],i=!0,c=0;c<r.length;c++)(!1&o||l>=o)&&Object.keys(f.O).every(h=>f.O[h](r[c]))?r.splice(c--,1):(i=!1,o<l&&(l=o));if(i){e.splice(n--,1);var _=a();void 0!==_&&(t=_)}}return t}o=o||0;for(var n=e.length;n>0&&e[n-1][2]>o;n--)e[n]=e[n-1];e[n]=[r,a,o]},f.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return f.d(t,{a:t}),t},(()=>{var t,e=Object.getPrototypeOf?r=>Object.getPrototypeOf(r):r=>r.__proto__;f.t=function(r,a){if(1&a&&(r=this(r)),8&a||"object"==typeof r&&r&&(4&a&&r.__esModule||16&a&&"function"==typeof r.then))return r;var o=Object.create(null);f.r(o);var n={};t=t||[null,e({}),e([]),e(e)];for(var l=2&a&&r;"object"==typeof l&&!~t.indexOf(l);l=e(l))Object.getOwnPropertyNames(l).forEach(i=>n[i]=()=>r[i]);return n.default=()=>r,f.d(o,n),o}})(),f.d=(e,t)=>{for(var r in t)f.o(t,r)&&!f.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},f.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),f.r=e=>{typeof Symbol<"u"&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},(()=>{var e={666:0};f.O.j=a=>0===e[a];var t=(a,o)=>{var c,_,[n,l,i]=o,s=0;if(n.some(d=>0!==e[d])){for(c in l)f.o(l,c)&&(f.m[c]=l[c]);if(i)var p=i(f)}for(a&&a(o);s<n.length;s++)f.o(e,_=n[s])&&e[_]&&e[_][0](),e[_]=0;return f.O(p)},r=self.webpackChunkrelay_angular_chat=self.webpackChunkrelay_angular_chat||[];r.forEach(t.bind(null,0)),r.push=t.bind(null,r.push.bind(r))})()})();

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

View File

@ -1,73 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta content="width=device-width, initial-scale=1.0" name="viewport" />
<title>Relay direct chat</title>
<link rel="stylesheet" href="./style.css" />
<link rel="apple-touch-icon" href="./favicon.png" />
<link rel="manifest" href="./manifest.json" />
<link rel="icon" href="./favicon.ico" />
</head>
<body>
<div class="content">
<div class="header">
<h3>Status: <span id="status"></span></h3>
<h4><label for="remoteNode">Remote node multiaddr</label></h4>
<div>
<input
id="remoteNode"
value="/dns4/node-01.ac-cn-hongkong-c.go-waku.prod.statusim.net/tcp/443/wss/p2p/16Uiu2HAm1fVVprL9EaDpDw4frNX3CPfZu5cBqhtk9Ncm6WCvprpv"
/>
<button id="connectRemoteNode">Dial</button>
</div>
<h4><label for="webrtcPeer">WebRTC Peer</label></h4>
<div>
<input id="webrtcPeer" />
<button id="connectWebrtcPeer">Dial</button>
</div>
<div>
<button id="relayWebRTC">Ensure WebRTC Relay connection</button>
<button id="dropNonWebRTC">Drop non WebRTC connections</button>
</div>
<details open>
<summary>Peer's information</summary>
<h4>Content topic</h4>
<p id="contentTopic"></p>
<h4>Local Peer Id</h4>
<p id="localPeerId"></p>
<h4>Remote Peer Id</h4>
<p id="remotePeerId"></p>
<h4>Relay mesh's protocols</h4>
<p id="relayMeshInfo"></p>
</details>
</div>
<div id="messages"></div>
<div class="footer">
<div class="inputArea">
<input type="text" id="nickText" placeholder="Nickname" />
<textarea id="messageText" placeholder="Message"></textarea>
</div>
<div class="controls">
<button id="send">Send</button>
<button id="exit">Exit chat</button>
</div>
</div>
</div>
<script src="//cdn.jsdelivr.net/npm/protobufjs@7.X.X/dist/protobuf.min.js"></script>
<script type="module" src="./index.js"></script>
</body>
</html>

File diff suppressed because one or more lines are too long

View File

@ -1,19 +0,0 @@
{
"name": "Relay direct chat",
"description": "Send messages between several users (or just one) using Relay with direct WebRTC connection.",
"icons": [
{
"src": "favicon.ico",
"sizes": "64x64 32x32 24x24 16x16",
"type": "image/x-icon"
},
{
"src": "favicon.png",
"type": "image/png",
"sizes": "192x192"
}
],
"display": "standalone",
"theme_color": "#ffffff",
"background_color": "#ffffff"
}

View File

@ -1,185 +0,0 @@
* {
margin: 0;
padding: 0;
word-wrap: break-word;
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
max-width: 100%;
max-height: 100%;
}
html {
font-size: 16px;
overflow: hidden;
}
body {
display: flex;
align-items: center;
padding: 10px;
justify-content: center;
}
h3 + h4,
div + h4,
div + details,
div + div {
margin-top: 20px;
}
.header div {
display: flex;
justify-content: space-between;
}
.header div input {
min-width: 300px;
min-height: 30px;
width: 80%;
margin-right: 10px;
}
.header div button {
min-width: 50px;
min-height: 30px;
width: 10%;
flex-grow: 1;
}
.header div button + button {
margin-left: 10px;
}
details {
margin-bottom: 15px;
}
details p {
margin-bottom: 10px;
}
summary {
cursor: pointer;
max-width: 100%;
margin-bottom: 5px;
}
span {
font-weight: 300;
}
input,
textarea {
line-height: 1rem;
padding: 5px;
}
textarea {
min-height: 3rem;
}
h3 {
margin-bottom: 5px;
}
.content {
width: 800px;
min-width: 300px;
max-width: 800px;
height: 100%;
display: flex;
flex-direction: column;
align-content: space-between;
}
#messages {
overflow-y: scroll;
overflow-x: hidden;
}
.message + .message {
margin-top: 15px;
}
.message :first-child {
font-weight: bold;
}
.message p + p {
margin-top: 5px;
}
.message span {
font-size: 0.8rem;
}
.inputArea {
display: flex;
gap: 10px;
flex-direction: column;
margin-top: 20px;
}
.controls {
margin-top: 10px;
display: flex;
gap: 10px;
}
.controls button {
flex-grow: 1;
cursor: pointer;
padding: 10px;
}
#send {
background-color: #32d1a0;
border: none;
color: white;
}
#send:hover {
background-color: #3abd96;
}
#send:active {
background-color: #3ba183;
}
#exit {
color: white;
border: none;
background-color: #ff3a31;
}
#exit:hover {
background-color: #e4423a;
}
#exit:active {
background-color: #c84740;
}
.success {
color: #3ba183;
}
.progress {
color: #9ea13b;
}
.terminated {
color: black;
}
.error {
color: #c84740;
}
.footer {
display: flex;
width: 100%;
flex-direction: column;
align-self: flex-end;
}

View File

@ -1,13 +0,0 @@
# Using Waku Relay in JavaScript
**Demonstrates**:
- Waku Relay: Send and receive messages using Waku Relay.
- Pure Javascript/HTML.
- Use minified bundle of js from unpkg.com, no import, no package manager.
This example uses Waku Relay to send and receive simple text messages.
To test the example, simply download the `index.html` file from this folder and open it in a browser.
The `master` branch's HEAD is deployed at https://examples.waku.org/relay-js/.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

View File

@ -1,131 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta content="width=device-width, initial-scale=1.0" name="viewport" />
<title>JS-Waku Chat</title>
<link rel="apple-touch-icon" href="./favicon.png" />
<link rel="manifest" href="./manifest.json" />
<link rel="icon" href="./favicon.ico" />
</head>
<body>
<div><h1>Waku Node Status</h1></div>
<div id="status"></div>
<label for="textInput">Message text</label>
<input
disabled
id="textInput"
placeholder="Type your message here"
type="text"
/>
<button disabled id="sendButton" type="button">
Send Message using Relay
</button>
<div><h1>Messages</h1></div>
<div id="messages"></div>
<script type="module">
/**
* Demonstrate usage of js-waku in the browser. Use relay, gossip sub protocol to send and receive messages.
* Recommended payload is protobuf. Using simple utf-8 string for demo purposes only.
*/
import {
waitForRemotePeer,
createDecoder,
createEncoder,
bytesToUtf8,
utf8ToBytes,
createRelayNode,
} from "https://unpkg.com/@waku/sdk@0.0.18/bundle/index.js";
const statusDiv = document.getElementById("status");
const messagesDiv = document.getElementById("messages");
const textInput = document.getElementById("textInput");
const sendButton = document.getElementById("sendButton");
// Every Waku Message has a content topic that categorizes it.
// It is always encoded in clear text.
// Recommendation: `/dapp-name/version/functionality/codec`
// We recommend to use protobuf as codec (`proto`), this demo uses utf-8
// for simplicity's sake.
const contentTopic = "/js-waku-examples/1/chat/utf8";
// Prepare encoder and decoder, `V0` for clear text messages.
const encoder = createEncoder({ contentTopic });
const decoder = createDecoder(contentTopic);
try {
statusDiv.innerHTML = "<p>Starting</p>";
// Create and starts a Waku node.
// `defaultBootstrap: true` bootstraps by connecting to pre-defined/hardcoded Waku nodes.
// `emitSelf`: emits event of sent message to itself and invokes subscribers by it
// We are currently working on migrating this method to DNS Discovery.
//
// https://js.waku.org/functions/lib_create_waku.createPrivacyNode.html
const waku = await createRelayNode({
emitSelf: true,
defaultBootstrap: true,
});
await waku.start();
// Add a hook to process all incoming messages on a specified content topic.
//
// https://js.waku.org/classes/index.waku_relay.WakuRelay.html#addObserver
waku.relay.subscribe(
decoder,
(message) => {
// Checks there is a payload on the message.
// Waku Message is encoded in protobuf, in proto v3 fields are always optional.
//
// https://js.waku.org/interfaces/index.proto_message.WakuMessage-1.html#payload
if (!message.payload) return;
// Helper method to decode the payload to utf-8. A production dApp should
// use `wakuMessage.payload` (Uint8Array) which enables encoding a data
// structure of their choice.
//
// https://js.waku.org/functions/index.utils.bytesToUtf8.html
const text = bytesToUtf8(message.payload);
messagesDiv.innerHTML =
`<p>${text}</p><br />` + messagesDiv.innerHTML;
},
[contentTopic]
);
statusDiv.innerHTML = "<p>Connecting to a peer</p>";
// Best effort method that waits for the Waku node to be connected to remote
// waku nodes (peers) and for appropriate handshakes to be done.
//
// https://js.waku.org/functions/lib_wait_for_remote_peer.waitForRemotePeer.html
await waitForRemotePeer(waku);
// We are now connected to a remote peer, let's define the `sendMessage`
// function that sends the text input over Waku Relay, the gossipsub
// protocol.
sendButton.onclick = async () => {
const payload = utf8ToBytes(textInput.value);
await waku.relay.send(encoder, { payload });
console.log("Message sent!");
// Reset the text input.
textInput.value = null;
};
// Ready to send & receive messages, enable text input.
textInput.disabled = false;
sendButton.disabled = false;
statusDiv.innerHTML = "<p>Ready!</p>";
} catch (e) {
statusDiv.innerHTML = "Failed to start application";
console.log(e);
}
</script>
</body>
</html>

View File

@ -1,19 +0,0 @@
{
"name": "Relay JS",
"description": "This example uses Waku Relay to send and receive simple text messages.",
"icons": [
{
"src": "favicon.ico",
"sizes": "64x64 32x32 24x24 16x16",
"type": "image/x-icon"
},
{
"src": "favicon.png",
"type": "image/png",
"sizes": "192x192"
}
],
"display": "standalone",
"theme_color": "#ffffff",
"background_color": "#ffffff"
}

View File

@ -1,11 +0,0 @@
{
"files": {
"main.css": "/relay-reactjs-chat/static/css/main.4efb37a3.css",
"main.js": "/relay-reactjs-chat/static/js/main.65b1e767.js",
"index.html": "/relay-reactjs-chat/index.html"
},
"entrypoints": [
"static/css/main.4efb37a3.css",
"static/js/main.65b1e767.js"
]
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

View File

@ -1 +0,0 @@
<!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="icon" href="/relay-reactjs-chat/favicon.ico"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><meta name="description" content="A barebone chat app to illustrate the ReactJS Relay guide."/><link rel="apple-touch-icon" href="/relay-reactjs-chat/favicon.png"/><link rel="manifest" href="/relay-reactjs-chat/manifest.json"/><title>React Relay</title><script defer="defer" src="/relay-reactjs-chat/static/js/main.65b1e767.js"></script><link href="/relay-reactjs-chat/static/css/main.4efb37a3.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>

View File

@ -1,19 +0,0 @@
{
"name": "Waku Relay",
"description": "A barebone chat app to illustrate the ReactJS Relay guide.",
"icons": [
{
"src": "favicon.ico",
"sizes": "64x64 32x32 24x24 16x16",
"type": "image/x-icon"
},
{
"src": "favicon.png",
"type": "image/png",
"sizes": "192x192"
}
],
"display": "standalone",
"theme_color": "#ffffff",
"background_color": "#ffffff"
}

View File

@ -1,3 +0,0 @@
# https://www.robotstxt.org/robotstxt.html
User-agent: *
Disallow:

View File

@ -1 +0,0 @@
body{-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale;font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen,Ubuntu,Cantarell,Fira Sans,Droid Sans,Helvetica Neue,sans-serif;margin:0}code{font-family:source-code-pro,Menlo,Monaco,Consolas,Courier New,monospace}

File diff suppressed because one or more lines are too long

View File

@ -1,63 +0,0 @@
/*
* [hi-base32]{@link https://github.com/emn178/hi-base32}
*
* @version 0.5.0
* @author Chen, Yi-Cyuan [emn178@gmail.com]
* @copyright Chen, Yi-Cyuan 2015-2018
* @license MIT
*/
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
/*! noble-ed25519 - MIT License (c) 2019 Paul Miller (paulmillr.com) */
/*! noble-secp256k1 - MIT License (c) 2019 Paul Miller (paulmillr.com) */
/**
* @license React
* react-dom.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
/**
* @license React
* react-jsx-runtime.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
/**
* @license React
* react.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
/**
* @license React
* scheduler.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
/**
* [js-sha3]{@link https://github.com/emn178/js-sha3}
*
* @version 0.8.0
* @author Chen, Yi-Cyuan [emn178@gmail.com]
* @copyright Chen, Yi-Cyuan 2015-2018
* @license MIT
*/

View File

@ -1,14 +0,0 @@
{
"files": {
"main.css": "/web-chat/static/css/main.de5d5b6b.css",
"main.js": "/web-chat/static/js/main.61489538.js",
"static/media/rpc.cjs": "/web-chat/static/media/rpc.3ba5ca7bdb004060d5e2.cjs",
"index.html": "/web-chat/index.html",
"main.de5d5b6b.css.map": "/web-chat/static/css/main.de5d5b6b.css.map",
"main.61489538.js.map": "/web-chat/static/js/main.61489538.js.map"
},
"entrypoints": [
"static/css/main.de5d5b6b.css",
"static/js/main.61489538.js"
]
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.1 KiB

View File

@ -1 +0,0 @@
<!doctype html><html lang="en"><head><meta charset="utf-8"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700&display=swap"/><meta name="description" content="Chat app powered by js-waku"/><link rel="manifest" href="/web-chat/manifest.json"/><link rel="apple-touch-icon" href="/web-chat/favicon.png"/><link rel="icon" href="/web-chat/favicon.ico"/><title>Waku v2 chat app</title><script defer="defer" src="/web-chat/static/js/main.61489538.js"></script><link href="/web-chat/static/css/main.de5d5b6b.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>

View File

@ -1,20 +0,0 @@
{
"short_name": "Waku v2 Chat",
"name": "Chat app powered by js-waku",
"icons": [
{
"src": "favicon.ico",
"sizes": "64x64 32x32 24x24 16x16",
"type": "image/x-icon"
},
{
"src": "favicon.png",
"type": "image/png",
"sizes": "192x192"
}
],
"start_url": ".",
"display": "standalone",
"theme_color": "#000000",
"background_color": "#ffffff"
}

View File

@ -1,3 +0,0 @@
# https://www.robotstxt.org/robotstxt.html
User-agent: *
Disallow:

File diff suppressed because one or more lines are too long

View File

@ -1 +0,0 @@
{"version":3,"file":"static/css/main.de5d5b6b.css","mappings":"AAAA;;CAAc,CAAd,uCAAc,CAAd,qBAAc,CAAd,8BAAc,CAAd,kCAAc,CAAd,4BAAc,CAAd,gMAAc,CAAd,8BAAc,CAAd,eAAc,CAAd,UAAc,CAAd,wBAAc,CAAd,QAAc,CAAd,uBAAc,CAAd,aAAc,CAAd,QAAc,CAAd,4DAAc,CAAd,gCAAc,CAAd,mCAAc,CAAd,mBAAc,CAAd,eAAc,CAAd,uBAAc,CAAd,2BAAc,CAAd,qHAAc,CAAd,aAAc,CAAd,mBAAc,CAAd,qBAAc,CAAd,aAAc,CAAd,iBAAc,CAAd,sBAAc,CAAd,iBAAc,CAAd,aAAc,CAAd,8BAAc,CAAd,oBAAc,C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sBAAmB,CAAnB,sCAAmB,CAAnB,+BAAmB,CAAnB,gCAAmB,CAAnB,8CAAmB,CAAnB,gCAAmB,CAAnB,8EAAmB,CAAnB,gFAAmB,CAAnB,wBAAmB,CAAnB,iCAAmB,CAAnB,sCAAmB,CAAnB,sDAAmB,CAAnB,sCAAmB,CAAnB,sDAAmB,CAAnB,8BAAmB,CAAnB,sDAAmB,CAAnB,8BAAmB,CAAnB,qDAAmB,CAAnB,8BAAmB,CAAnB,mDAAmB,CAAnB,kBAAmB,CAAnB,iBAAmB,CAAnB,uBAAmB,CAAnB,kBAAmB,CAAnB,4CAAmB,CAAnB,0BAAmB,CAAnB,mBAAmB,CAAnB,kCAAmB,CAAnB,6CAAmB,CAAnB,kCAAmB,CAAnB,0CAAmB,CAAnB,+BAAmB,CAAnB,6CAAmB,CAAnB,wLAAmB","sources":["index.css"],"sourcesContent":["@tailwind base;\n@tailwind components;\n@tailwind utilities;\n"],"names":[],"sourceRoot":""}

File diff suppressed because one or more lines are too long

View File

@ -1,65 +0,0 @@
/*
* [hi-base32]{@link https://github.com/emn178/hi-base32}
*
* @version 0.5.0
* @author Chen, Yi-Cyuan [emn178@gmail.com]
* @copyright Chen, Yi-Cyuan 2015-2018
* @license MIT
*/
/*
object-assign
(c) Sindre Sorhus
@license MIT
*/
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
/*! noble-ed25519 - MIT License (c) 2019 Paul Miller (paulmillr.com) */
/*! noble-secp256k1 - MIT License (c) 2019 Paul Miller (paulmillr.com) */
/**
* [js-sha3]{@link https://github.com/emn178/js-sha3}
*
* @version 0.8.0
* @author Chen, Yi-Cyuan [emn178@gmail.com]
* @copyright Chen, Yi-Cyuan 2015-2018
* @license MIT
*/
/** @license React v0.20.2
* scheduler.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
/** @license React v17.0.2
* react-dom.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
/** @license React v17.0.2
* react-jsx-runtime.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
/** @license React v17.0.2
* react.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long