Examples: Content Topic moved out of options parameter

This commit is contained in:
Franck Royer 2021-07-28 11:22:29 +10:00
parent 0cfdd34284
commit 9aaac20981
No known key found for this signature in database
GPG Key ID: A82ED75A8DFC50A4
4 changed files with 16 additions and 15 deletions

View File

@ -104,10 +104,13 @@ export default async function startChat(): Promise<void> {
rl.prompt(); rl.prompt();
const chatMessage = ChatMessage.fromUtf8String(new Date(), nick, line); const chatMessage = ChatMessage.fromUtf8String(new Date(), nick, line);
const msg = await WakuMessage.fromBytes(chatMessage.encode(), { const msg = await WakuMessage.fromBytes(
contentTopic: ChatContentTopic, chatMessage.encode(),
timestamp: new Date(), ChatContentTopic,
}); {
timestamp: new Date(),
}
);
if (opts.lightPush) { if (opts.lightPush) {
await waku.lightPush.push(msg); await waku.lightPush.push(msg);
} else { } else {

View File

@ -31,7 +31,7 @@ export default function BroadcastPublicKey({
console.error('Failed to send Public Key Message', e); console.error('Failed to send Public Key Message', e);
}); });
}) })
.catch((e) => { .catch(() => {
console.log('Failed to encode Public Key Message in Waku Message'); console.log('Failed to encode Public Key Message in Waku Message');
}); });
} else { } else {
@ -47,7 +47,7 @@ export default function BroadcastPublicKey({
console.error('Failed to send Public Key Message', e); console.error('Failed to send Public Key Message', e);
}); });
}) })
.catch((e) => { .catch(() => {
console.log( console.log(
'Failed to encode Public Key Message in Waku Message' 'Failed to encode Public Key Message in Waku Message'
); );
@ -75,7 +75,5 @@ async function encodePublicKeyWakuMessage(
publicKeyMessage: PublicKeyMessage publicKeyMessage: PublicKeyMessage
): Promise<WakuMessage> { ): Promise<WakuMessage> {
const payload = publicKeyMessage.encode(); const payload = publicKeyMessage.encode();
return await WakuMessage.fromBytes(payload, { return await WakuMessage.fromBytes(payload, PublicKeyContentTopic);
contentTopic: PublicKeyContentTopic,
});
} }

View File

@ -115,8 +115,7 @@ async function encodeEncryptedWakuMessage(
}); });
const payload = directMsg.encode(); const payload = directMsg.encode();
return WakuMessage.fromBytes(payload, { return WakuMessage.fromBytes(payload, DirectMessageContentTopic, {
contentTopic: DirectMessageContentTopic,
encPublicKey: publicKey, encPublicKey: publicKey,
}); });
} }

View File

@ -65,10 +65,11 @@ async function handleMessage(
} else { } else {
const timestamp = new Date(); const timestamp = new Date();
const chatMessage = ChatMessage.fromUtf8String(timestamp, nick, message); const chatMessage = ChatMessage.fromUtf8String(timestamp, nick, message);
const wakuMsg = await WakuMessage.fromBytes(chatMessage.encode(), { const wakuMsg = await WakuMessage.fromBytes(
contentTopic: ChatContentTopic, chatMessage.encode(),
timestamp, ChatContentTopic,
}); { timestamp }
);
return messageSender(wakuMsg); return messageSender(wakuMsg);
} }
} }