Skip to content

Commit

Permalink
Merge pull request #25 from waku-org/weboko/change-pubsub
Browse files Browse the repository at this point in the history
fix: prevent parsing failure
  • Loading branch information
weboko authored Dec 6, 2023
2 parents 48d0261 + b2391ca commit c48cc59
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,5 @@ npm run build
docker build -t waku_frontend .
docker run -d -p 8080:80 waku_frontend
```

Open [http://localhost:8080](http://localhost:8080) with your browser to see the result.
20 changes: 12 additions & 8 deletions src/hooks/useWaku.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,18 @@ export const useWaku = () => {
const newMessages: Message[] = event.detail;

newMessages.forEach((m) => {
const payload = JSON.parse(atob(m.payload));

const message: MessageContent = {
nick: payload?.nick || "unknown",
text: payload?.text || "empty",
timestamp: m.timestamp || Date.now(),
};
nextMessages.set(`${message.nick}-${message.timestamp}-${message.text}`, message);
try {
const payload = JSON.parse(atob(m.payload));

const message: MessageContent = {
nick: payload?.nick || "unknown",
text: payload?.text || "empty",
timestamp: m.timestamp || Date.now(),
};
nextMessages.set(`${message.nick}-${message.timestamp}-${message.text}`, message);
} catch(error) {
console.error("Failed to parse message:", error);
}
});

setMessages(nextMessages);
Expand Down

0 comments on commit c48cc59

Please sign in to comment.