chore: use filter directly as receiver

This commit is contained in:
Sasha 2023-04-17 23:54:15 +02:00
parent 634a4d2b00
commit 84f7c16646
No known key found for this signature in database
4 changed files with 4 additions and 112 deletions

View File

@ -29,13 +29,12 @@ async function main() {
ui.waku.connected();
const responder = getResponder(node);
const myStaticKey = noise.generateX25519KeyPair();
const urlPairingInfo = getPairingInfoFromURL();
const pairingObj = new noise.WakuPairing(
node.lightPush,
responder,
node.filter,
myStaticKey,
urlPairingInfo || new noise.ResponderParameters()
);
@ -117,59 +116,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) {
const authCode = await pairingObj.getAuthCode();
ui.handshake.connecting();

View File

@ -12,7 +12,7 @@
"@waku/core": "0.0.16",
"@waku/create": "0.0.12",
"@waku/interfaces": "0.0.11",
"@waku/noise": "0.0.3",
"@waku/noise": "0.0.4",
"@waku/utils": "0.0.4",
"protobufjs": "^7.1.2",
"qrcode": "^1.5.1"

View File

@ -26,13 +26,12 @@ async function main() {
ui.waku.connected();
const responder = getResponder(node);
const myStaticKey = noise.generateX25519KeyPair();
const urlPairingInfo = getPairingInfoFromURL();
const pairingObj = new noise.WakuPairing(
node.lightPush,
responder,
node.filter,
myStaticKey,
urlPairingInfo || new noise.ResponderParameters()
);
@ -212,59 +211,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) {
const authCode = await pairingObj.getAuthCode();
ui.handshake.connecting();

View File

@ -12,7 +12,7 @@
"@waku/core": "0.0.16",
"@waku/create": "0.0.12",
"@waku/interfaces": "0.0.11",
"@waku/noise": "0.0.3",
"@waku/noise": "0.0.4",
"@waku/utils": "0.0.4",
"protobufjs": "^7.1.2",
"qrcode": "^1.5.1"