From a22fbd6b818ccb73c2e76b3786f9533d5ad1f51e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Chopin?= Date: Wed, 22 Jan 2025 15:08:11 +0100 Subject: [PATCH] feat: add support for websocket handler --- package.json | 2 +- playground/app.vue | 7 ++ playground/nuxt.config.ts | 1 + playground/package.json | 3 + playground/server/routes/ws/index.ts | 15 +++ pnpm-lock.yaml | 152 +++++++++++++-------------- src/module.ts | 4 + src/runtime/server/plugins/ws.ts | 10 ++ src/runtime/server/utils/session.ts | 12 ++- 9 files changed, 124 insertions(+), 82 deletions(-) create mode 100644 playground/server/routes/ws/index.ts create mode 100644 src/runtime/server/plugins/ws.ts diff --git a/package.json b/package.json index f2cfa068..9d370236 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,7 @@ "@adonisjs/hash": "^9.0.5", "@nuxt/kit": "^3.15.2", "defu": "^6.1.4", - "h3": "^1.13.1", + "h3": "^1.14.0", "hookable": "^5.5.3", "ofetch": "^1.4.1", "ohash": "^1.1.4", diff --git a/playground/app.vue b/playground/app.vue index c04effbd..e8cb4393 100644 --- a/playground/app.vue +++ b/playground/app.vue @@ -201,6 +201,13 @@ const providers = computed(() => external: true, })), ) + +onMounted(() => { + const ws = new WebSocket('/ws') + ws.addEventListener('message', (event) => { + console.log('message', event.data) + }) +})