Skip to content

Commit

Permalink
random name
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Feb 27, 2024
1 parent 37b944b commit 70f0408
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const messages = useState<{ id: number, user: string, message: string, created_a
const userId = useCookie<string>("userId")
if (!userId.value) {
userId.value = Math.random().toString(36).substring(7);
userId.value = generateName()
}
if (!messages.value.length) {
Expand Down
4 changes: 2 additions & 2 deletions server/api/chat-ws.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default defineWebSocketHandler({
users.set(userId, { online: true });

const stats = getStats();
peer.send({ user: "server", message: `Welcome to the server ${peer}! (Online users: ${stats.online}/${stats.total})` });
peer.send({ user: "server", message: `Welcome to the server ${userId}! (Online users: ${stats.online}/${stats.total})` });

peer.subscribe("chat");
peer.publish("chat", { user: "server", message: `${peer} joined!` });
Expand All @@ -33,7 +33,7 @@ export default defineWebSocketHandler({
peer.publish("chat", _message);
}

await addMessage(peer.toString(), message.text());
await addMessage(userId, message.text());
},

close(peer, details) {
Expand Down
Loading

0 comments on commit 70f0408

Please sign in to comment.