chore(light-chat): bump @waku/core to 0.0.7

This commit is contained in:
fryorcraken.eth 2022-12-16 12:24:20 +11:00
parent 644e8ff703
commit a6f292fb04
No known key found for this signature in database
GPG Key ID: A82ED75A8DFC50A4
1 changed files with 128 additions and 121 deletions

View File

@ -1,9 +1,13 @@
import * as utils from "https://unpkg.com/@waku/byte-utils@0.0.2/bundle/index.js"; import * as utils from "https://unpkg.com/@waku/byte-utils@0.0.2/bundle/index.js";
import * as wakuCreate from "https://unpkg.com/@waku/create@0.0.4/bundle/index.js"; import * as wakuCreate from "https://unpkg.com/@waku/create@0.0.5/bundle/index.js";
import { waitForRemotePeer } from "https://unpkg.com/@waku/core@0.0.6/bundle/lib/wait_for_remote_peer.js"; import {
import * as wakuMessage from "https://unpkg.com/@waku/core@0.0.6/bundle/lib/waku_message/version_0.js"; waitForRemotePeer,
createDecoder,
createEncoder,
} from "https://unpkg.com/@waku/core@0.0.7/bundle/index.js";
const MULTI_ADDR = "/dns4/node-01.ac-cn-hongkong-c.wakuv2.test.statusim.net/tcp/443/wss/p2p/16Uiu2HAkvWiyFsgRhuJEb9JfjYxEkoHLgnUQmr1N5mKWnYjxYRVm"; const MULTI_ADDR =
"/dns4/node-01.ac-cn-hongkong-c.wakuv2.test.statusim.net/tcp/443/wss/p2p/16Uiu2HAkvWiyFsgRhuJEb9JfjYxEkoHLgnUQmr1N5mKWnYjxYRVm";
const CONTENT_TOPIC = "/toy-chat/2/huilong/proto"; const CONTENT_TOPIC = "/toy-chat/2/huilong/proto";
const PROTOCOLS = ["filter", "lightpush"]; const PROTOCOLS = ["filter", "lightpush"];
@ -46,8 +50,8 @@ async function initWakuContext({
contentTopic, contentTopic,
onMessageReceived, onMessageReceived,
}) { }) {
const Decoder = new wakuMessage.DecoderV0(contentTopic); const Decoder = createDecoder(contentTopic);
const Encoder = new wakuMessage.EncoderV0(contentTopic); const Encoder = createEncoder(contentTopic);
const ChatMessage = new protobuf.Type("ChatMessage") const ChatMessage = new protobuf.Type("ChatMessage")
.add(new protobuf.Field("timestamp", 1, "uint64")) .add(new protobuf.Field("timestamp", 1, "uint64"))
@ -60,18 +64,21 @@ async function initWakuContext({
await waitForRemotePeer(node, protocols); await waitForRemotePeer(node, protocols);
// Set a filter by using Decoder for a given ContentTopic // Set a filter by using Decoder for a given ContentTopic
const unsubscribeFromMessages = await node.filter.subscribe([Decoder], (wakuMessage) => { const unsubscribeFromMessages = await node.filter.subscribe(
[Decoder],
(wakuMessage) => {
const messageObj = ChatMessage.decode(wakuMessage.payload); const messageObj = ChatMessage.decode(wakuMessage.payload);
onMessageReceived({ onMessageReceived({
...messageObj, ...messageObj,
text: utils.bytesToUtf8(messageObj.text), text: utils.bytesToUtf8(messageObj.text),
}); });
}); }
);
const localPeerId = node.libp2p.peerId.toString(); const localPeerId = node.libp2p.peerId.toString();
const remotePeers = await node.libp2p.peerStore.all(); const remotePeers = await node.libp2p.peerStore.all();
const remotePeerIds = remotePeers.map(peer => peer.id.toString()); const remotePeerIds = remotePeers.map((peer) => peer.id.toString());
return { return {
unsubscribeFromMessages, unsubscribeFromMessages,
@ -95,7 +102,7 @@ async function initWakuContext({
await node.lightPush.push(Encoder, { await node.lightPush.push(Encoder, {
payload: ChatMessage.encode(protoMessage).finish(), payload: ChatMessage.encode(protoMessage).finish(),
}); });
} },
}; };
} }