Skip to content

Instantly share code, notes, and snippets.

@ritvij14
Created October 8, 2021 10:49
Show Gist options
  • Save ritvij14/648b380d983611cf9372672c25313778 to your computer and use it in GitHub Desktop.
Save ritvij14/648b380d983611cf9372672c25313778 to your computer and use it in GitHub Desktop.
Waku functions in Huddle01 Livestream Viewer chat
import protons from "protons";
const proto = protons(`
message SimpleChatMessage {
uint64 timestamp = 1;
string text = 2;
string sender = 3;
}
`);
const selectFleetEnv = () => {
// Works with react-scripts
if (process?.env?.NODE_ENV === "development") {
return ["fleets", "wakuv2.test", "waku-websocket"];
} else {
return ["fleets", "wakuv2.prod", "waku-websocket"];
}
};
const processMsgs = (msg) => {
if (!msg.payload) return;
const { timestamp, text, sender } = proto.SimpleChatMessage.decode(
msg.payload
);
const time = new Date(timestamp).toLocaleTimeString();
const utf8Text = Buffer.from(text).toString("utf-8");
return { timestamp: time, text: utf8Text, sender };
};
export { proto, selectFleetEnv, processMsgs };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment