Created
October 8, 2021 10:49
-
-
Save ritvij14/648b380d983611cf9372672c25313778 to your computer and use it in GitHub Desktop.
Waku functions in Huddle01 Livestream Viewer chat
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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