mirror of
https://github.com/logos-messaging/examples.waku.org.git
synced 2026-01-05 22:33:08 +00:00
update noise examples
This commit is contained in:
parent
d7bb3016ff
commit
a6af2a9ff2
@ -1,7 +1,6 @@
|
|||||||
import { createLightNode } from "@waku/create";
|
import { createLightNode } from "@waku/create";
|
||||||
import * as utils from "@waku/utils/bytes";
|
import * as utils from "@waku/utils/bytes";
|
||||||
import { waitForRemotePeer } from "@waku/core";
|
import { waitForRemotePeer } from "@waku/core";
|
||||||
import { Protocols } from "@waku/interfaces";
|
|
||||||
import * as noise from "@waku/noise";
|
import * as noise from "@waku/noise";
|
||||||
import protobuf from "protobufjs";
|
import protobuf from "protobufjs";
|
||||||
import QRCode from "qrcode";
|
import QRCode from "qrcode";
|
||||||
@ -25,17 +24,16 @@ async function main() {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
await node.start();
|
await node.start();
|
||||||
await waitForRemotePeer(node, [Protocols.Filter, Protocols.LightPush]);
|
await waitForRemotePeer(node, ["filter", "lightpush"]);
|
||||||
|
|
||||||
ui.waku.connected();
|
ui.waku.connected();
|
||||||
|
|
||||||
const responder = getResponder(node);
|
|
||||||
const myStaticKey = noise.generateX25519KeyPair();
|
const myStaticKey = noise.generateX25519KeyPair();
|
||||||
const urlPairingInfo = getPairingInfoFromURL();
|
const urlPairingInfo = getPairingInfoFromURL();
|
||||||
|
|
||||||
const pairingObj = new noise.WakuPairing(
|
const pairingObj = new noise.WakuPairing(
|
||||||
node.lightPush,
|
node.lightPush,
|
||||||
responder,
|
node.filter,
|
||||||
myStaticKey,
|
myStaticKey,
|
||||||
urlPairingInfo || new noise.ResponderParameters()
|
urlPairingInfo || new noise.ResponderParameters()
|
||||||
);
|
);
|
||||||
@ -117,59 +115,6 @@ function getPairingInfoFromURL() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getResponder(node) {
|
|
||||||
const msgQueue = new Array();
|
|
||||||
const subscriptions = new Map();
|
|
||||||
const intervals = new Map();
|
|
||||||
|
|
||||||
const responder = {
|
|
||||||
async subscribe(decoder) {
|
|
||||||
const subscription = await node.filter.subscribe(
|
|
||||||
[decoder],
|
|
||||||
(wakuMessage) => {
|
|
||||||
msgQueue.push(wakuMessage);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
subscriptions.set(decoder.contentTopic, subscription);
|
|
||||||
},
|
|
||||||
async nextMessage(contentTopic) {
|
|
||||||
if (msgQueue.length != 0) {
|
|
||||||
const oldestMsg = msgQueue.shift();
|
|
||||||
if (oldestMsg.contentTopic === contentTopic) {
|
|
||||||
return oldestMsg;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return new Promise((resolve) => {
|
|
||||||
const interval = setInterval(() => {
|
|
||||||
if (msgQueue.length != 0) {
|
|
||||||
clearInterval(interval);
|
|
||||||
const oldestMsg = msgQueue.shift();
|
|
||||||
if (oldestMsg.contentTopic === contentTopic) {
|
|
||||||
resolve(oldestMsg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, 100);
|
|
||||||
intervals.set(contentTopic, interval);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
async stop(contentTopic) {
|
|
||||||
if (intervals.has(contentTopic)) {
|
|
||||||
clearInterval(intervals.get(contentTopic));
|
|
||||||
intervals.delete(contentTopic);
|
|
||||||
}
|
|
||||||
if (subscriptions.has(contentTopic)) {
|
|
||||||
await subscriptions.get(contentTopic)();
|
|
||||||
subscriptions.delete(contentTopic);
|
|
||||||
} else {
|
|
||||||
console.log("Subscriptipon doesnt exist");
|
|
||||||
}
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
return responder;
|
|
||||||
}
|
|
||||||
|
|
||||||
async function scheduleHandshakeAuthConfirmation(pairingObj, ui) {
|
async function scheduleHandshakeAuthConfirmation(pairingObj, ui) {
|
||||||
const authCode = await pairingObj.getAuthCode();
|
const authCode = await pairingObj.getAuthCode();
|
||||||
ui.handshake.connecting();
|
ui.handshake.connecting();
|
||||||
|
|||||||
8672
examples/noise-js/package-lock.json
generated
8672
examples/noise-js/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -9,11 +9,10 @@
|
|||||||
"start": "webpack-dev-server"
|
"start": "webpack-dev-server"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@waku/core": "0.0.16",
|
"@waku/core": "0.0.17",
|
||||||
"@waku/create": "0.0.12",
|
"@waku/create": "0.0.13",
|
||||||
"@waku/interfaces": "0.0.11",
|
"@waku/noise": "0.0.3-31510da",
|
||||||
"@waku/noise": "0.0.3",
|
"@waku/utils": "0.0.5",
|
||||||
"@waku/utils": "0.0.4",
|
|
||||||
"protobufjs": "^7.1.2",
|
"protobufjs": "^7.1.2",
|
||||||
"qrcode": "^1.5.1"
|
"qrcode": "^1.5.1"
|
||||||
},
|
},
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
import { createLightNode } from "@waku/create";
|
import { createLightNode } from "@waku/create";
|
||||||
import * as utils from "@waku/utils/bytes";
|
import * as utils from "@waku/utils/bytes";
|
||||||
import { waitForRemotePeer } from "@waku/core";
|
import { waitForRemotePeer } from "@waku/core";
|
||||||
import { Protocols } from "@waku/interfaces";
|
|
||||||
import * as noise from "@waku/noise";
|
import * as noise from "@waku/noise";
|
||||||
import protobuf from "protobufjs";
|
import protobuf from "protobufjs";
|
||||||
import QRCode from "qrcode";
|
import QRCode from "qrcode";
|
||||||
@ -22,17 +21,16 @@ async function main() {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
await node.start();
|
await node.start();
|
||||||
await waitForRemotePeer(node, [Protocols.Filter, Protocols.LightPush]);
|
await waitForRemotePeer(node, ["filter", "lightpush"]);
|
||||||
|
|
||||||
ui.waku.connected();
|
ui.waku.connected();
|
||||||
|
|
||||||
const responder = getResponder(node);
|
|
||||||
const myStaticKey = noise.generateX25519KeyPair();
|
const myStaticKey = noise.generateX25519KeyPair();
|
||||||
const urlPairingInfo = getPairingInfoFromURL();
|
const urlPairingInfo = getPairingInfoFromURL();
|
||||||
|
|
||||||
const pairingObj = new noise.WakuPairing(
|
const pairingObj = new noise.WakuPairing(
|
||||||
node.lightPush,
|
node.lightPush,
|
||||||
responder,
|
node.filter,
|
||||||
myStaticKey,
|
myStaticKey,
|
||||||
urlPairingInfo || new noise.ResponderParameters()
|
urlPairingInfo || new noise.ResponderParameters()
|
||||||
);
|
);
|
||||||
@ -212,59 +210,6 @@ function getPairingInfoFromURL() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getResponder(node) {
|
|
||||||
const msgQueue = new Array();
|
|
||||||
const subscriptions = new Map();
|
|
||||||
const intervals = new Map();
|
|
||||||
|
|
||||||
const responder = {
|
|
||||||
async subscribe(decoder) {
|
|
||||||
const subscription = await node.filter.subscribe(
|
|
||||||
[decoder],
|
|
||||||
(wakuMessage) => {
|
|
||||||
msgQueue.push(wakuMessage);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
subscriptions.set(decoder.contentTopic, subscription);
|
|
||||||
},
|
|
||||||
async nextMessage(contentTopic) {
|
|
||||||
if (msgQueue.length != 0) {
|
|
||||||
const oldestMsg = msgQueue.shift();
|
|
||||||
if (oldestMsg.contentTopic === contentTopic) {
|
|
||||||
return oldestMsg;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return new Promise((resolve) => {
|
|
||||||
const interval = setInterval(() => {
|
|
||||||
if (msgQueue.length != 0) {
|
|
||||||
clearInterval(interval);
|
|
||||||
const oldestMsg = msgQueue.shift();
|
|
||||||
if (oldestMsg.contentTopic === contentTopic) {
|
|
||||||
resolve(oldestMsg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, 100);
|
|
||||||
intervals.set(contentTopic, interval);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
async stop(contentTopic) {
|
|
||||||
if (intervals.has(contentTopic)) {
|
|
||||||
clearInterval(intervals.get(contentTopic));
|
|
||||||
intervals.delete(contentTopic);
|
|
||||||
}
|
|
||||||
if (subscriptions.has(contentTopic)) {
|
|
||||||
await subscriptions.get(contentTopic)();
|
|
||||||
subscriptions.delete(contentTopic);
|
|
||||||
} else {
|
|
||||||
console.log("Subscriptipon doesnt exist");
|
|
||||||
}
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
return responder;
|
|
||||||
}
|
|
||||||
|
|
||||||
async function scheduleHandshakeAuthConfirmation(pairingObj, ui) {
|
async function scheduleHandshakeAuthConfirmation(pairingObj, ui) {
|
||||||
const authCode = await pairingObj.getAuthCode();
|
const authCode = await pairingObj.getAuthCode();
|
||||||
ui.handshake.connecting();
|
ui.handshake.connecting();
|
||||||
|
|||||||
781
examples/noise-rtc/package-lock.json
generated
781
examples/noise-rtc/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -9,11 +9,10 @@
|
|||||||
"start": "webpack-dev-server"
|
"start": "webpack-dev-server"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@waku/core": "0.0.16",
|
"@waku/core": "0.0.17",
|
||||||
"@waku/create": "0.0.12",
|
"@waku/create": "0.0.13",
|
||||||
"@waku/interfaces": "0.0.11",
|
"@waku/noise": "0.0.3-31510da",
|
||||||
"@waku/noise": "0.0.3",
|
"@waku/utils": "0.0.5",
|
||||||
"@waku/utils": "0.0.4",
|
|
||||||
"protobufjs": "^7.1.2",
|
"protobufjs": "^7.1.2",
|
||||||
"qrcode": "^1.5.1"
|
"qrcode": "^1.5.1"
|
||||||
},
|
},
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user