diff --git a/examples/chat/src/chat.ts b/examples/chat/src/chat.ts index d12221f..18e2cab 100644 --- a/examples/chat/src/chat.ts +++ b/examples/chat/src/chat.ts @@ -1,13 +1,5 @@ import { generateHonoObject } from "hono-do"; -function uuidv4() { - return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (c) { - const r = (Math.random() * 16) | 0, - v = c == "x" ? r : (r & 0x3) | 0x8; - return v.toString(16); - }); -} - export const Chat = generateHonoObject("/chat", (app) => { const messages: { timestamp: string; @@ -26,7 +18,7 @@ export const Chat = generateHonoObject("/chat", (app) => { async function handleWebSocketUpgrade() { const [client, server] = Object.values(new WebSocketPair()); - const clientId = uuidv4(); + const clientId = crypto.randomUUID(); server.accept(); sessions.set(clientId, server); diff --git a/examples/hibernatable-chat/src/chat.ts b/examples/hibernatable-chat/src/chat.ts index 7505d44..429b87b 100644 --- a/examples/hibernatable-chat/src/chat.ts +++ b/examples/hibernatable-chat/src/chat.ts @@ -1,13 +1,5 @@ import { generateHonoObject } from "hono-do"; -function uuidv4() { - return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (c) { - const r = (Math.random() * 16) | 0, - v = c == "x" ? r : (r & 0x3) | 0x8; - return v.toString(16); - }); -} - declare module "hono-do" { interface HonoObjectVars { messages: { @@ -31,7 +23,7 @@ export const Chat = generateHonoObject("/chat", (app, state, vars) => { async function handleWebSocketUpgrade() { const [client, server] = Object.values(new WebSocketPair()); - const clientId = uuidv4(); + const clientId = crypto.randomUUID(); state.acceptWebSocket(server); server.serializeAttachment({ clientId }); diff --git a/examples/hibernatable-chat/src/template.ts b/examples/hibernatable-chat/src/template.ts index 59bdbda..b955480 100644 --- a/examples/hibernatable-chat/src/template.ts +++ b/examples/hibernatable-chat/src/template.ts @@ -102,4 +102,4 @@ export const Template = html` -`.trim(); +`;