diff --git a/apps/currencia/app/pages/app/crypto/[symbol].vue b/apps/currencia/app/pages/app/crypto/[symbol].vue index 544c545..bd0f3d2 100644 --- a/apps/currencia/app/pages/app/crypto/[symbol].vue +++ b/apps/currencia/app/pages/app/crypto/[symbol].vue @@ -1,16 +1,16 @@ @@ -76,7 +48,16 @@ onUnmounted(() => {
- {{ displayNumberValue(dynamicData) }} $ + + + +
@@ -102,9 +83,6 @@ onUnmounted(() => {

{{ crypto.description }}

-
- -
diff --git a/apps/currencia/package.json b/apps/currencia/package.json index dacd01c..5783ee0 100644 --- a/apps/currencia/package.json +++ b/apps/currencia/package.json @@ -43,5 +43,8 @@ "vue3-apexcharts": "^1.8.0", "zod": "^3.24.1", "@shelve/cli": "^2.10.0" + }, + "dependencies": { + "@number-flow/vue": "^0.3.3" } } diff --git a/apps/currencia/server/api/crypto/[symbol]/index.get.ts b/apps/currencia/server/api/crypto/[symbol]/index.get.ts new file mode 100644 index 0000000..a3090e3 --- /dev/null +++ b/apps/currencia/server/api/crypto/[symbol]/index.get.ts @@ -0,0 +1,23 @@ +import { z } from 'zod' + +const symbolParams = z.object({ + symbol: z.string(), +}) + +export default defineEventHandler(async (event) => { + const eventStream = createEventStream(event) + const { symbol } = await getValidatedRouterParams(event, symbolParams.parse) + + const sendRandomNumber = () => generateRandomValue() + + const interval = setInterval(async () => { + await eventStream.push(String(sendRandomNumber())) + }, 1500) + + eventStream.onClosed(async () => { + clearInterval(interval) + await eventStream.close() + }) + + return eventStream.send() +}) diff --git a/apps/currencia/server/api/crypto/ws.ts b/apps/currencia/server/api/crypto/ws.ts deleted file mode 100644 index bb45da4..0000000 --- a/apps/currencia/server/api/crypto/ws.ts +++ /dev/null @@ -1,39 +0,0 @@ -import type { Peer } from 'crossws' -import { getQuery } from 'ufo' - -let intervalId: NodeJS.Timeout - -export default defineWebSocketHandler({ - open(peer: Peer) { - console.log(`[ws] open ${peer}`) - const { symbol } = getQuery(peer.url) - console.log(`[ws] symbol ${symbol}`) - - peer.subscribe('value') - - const sendRandomNumber = () => { - const randomNumber = generateRandomValue() - peer.send({ number: randomNumber }) - } - - intervalId = setInterval(sendRandomNumber, 1500) - }, - message(peer, message) { - console.log(`[ws] message ${peer} ${message.text()}`) - - if (message.text() === 'ping') { - peer.send('pong') - } - }, - close(peer) { - console.log(`[ws] close ${peer}`) - clearInterval(intervalId) - }, - upgrade(req) { - return { - headers: { - 'x-powered-by': 'cross-ws', - }, - } - }, -}) diff --git a/bun.lockb b/bun.lockb index 629541e..d6e95ab 100755 Binary files a/bun.lockb and b/bun.lockb differ